Click here to get back home

Re: Unpack - getting values directly into the correct variables

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Re: Unpack - getting values directly into the correct variables A. Sinan Unur 04-10-2008
Posted by A. Sinan Unur on April 10, 2008, 7:27 pm
Please log in for more thread options
$pb5.25660@edtnps89:

> A. Sinan Unur wrote:
...

>> @obs{ @fields } = unpack $unpack_tmpl;
>
> Don't forget the variable that you want to unpack:
>
> @obs{ @fields } = unpack $unpack_tmpl, $_;

I didn't ;-) From perldoc -f unpack:

unpack TEMPLATE,EXPR
unpack TEMPLATE
...
If EXPR is omitted, unpacks the $_ string.

Sinan

--
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Posted by John W. Krahn on April 11, 2008, 12:31 am
Please log in for more thread options
A. Sinan Unur wrote:
> $pb5.25660@edtnps89:
>
>> A. Sinan Unur wrote:
> ...
>
>>> @obs{ @fields } = unpack $unpack_tmpl;
>> Don't forget the variable that you want to unpack:
>>
>> @obs{ @fields } = unpack $unpack_tmpl, $_;
>
> I didn't ;-) From perldoc -f unpack:
>
> unpack TEMPLATE,EXPR
> unpack TEMPLATE
> ...
> If EXPR is omitted, unpacks the $_ string.

That must be new for 5.10 cause it doesn't work in 5.8.8

$ perl -le'
$_ = q[1234567890123456789012345678901234567890];
print for unpack q[a4 a7 a3];
'
Not enough arguments for unpack at -e line 3, near "q[a4 a7 a3];"
Execution of -e aborted due to compilation errors.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Posted by Brian McCauley on April 12, 2008, 6:03 am
Please log in for more thread options
> A. Sinan Unur wrote:
> > unpack TEMPLATE,EXPR
> > unpack TEMPLATE
> > ...
> > If EXPR is omitted, unpacks the $_ string.
>
> That must be new for 5.10

And about $EXPLETIVE time! It's always bugged me that unpack didn't do
this.

Similar ThreadsPosted
Re: Unpack - getting values directly into the correct variables April 10, 2008, 12:02 pm
Re: Unpack - getting values directly into the correct variables April 10, 2008, 7:50 pm
pack, unpack and 64-bit values February 9, 2006, 12:55 pm
Uploaded File Empty but in correct folder with correct name February 27, 2006, 9:59 pm
assigning multiple hash values to multiple variables May 2, 2006, 7:55 pm
Writing directly to system memory July 14, 2005, 9:51 pm
protect calling files directly? September 29, 2005, 6:47 pm
Exists a Module to transform RTF to PDF, directly January 23, 2008, 3:27 pm
using sort directly on subroutine returning list November 25, 2004, 6:12 pm
How to get array item directly from split result? November 9, 2005, 9:53 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap