in reply to Re: printing array reference and storing this data in a hash.
in thread printing array reference and storing this data in a hash.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: printing array reference and storing this data in a hash.
by shmem (Chancellor) on Dec 19, 2006 at 17:55 UTC | |
means "make an anonymous array (an array reference) and insert into it the results of the split operation; then assign the reference to the variable $var". More about split:
It's odd that a split with LIMIT 1 behaves different when assigning to a list with a single or two variables; but it does. That's why I prefer to say
if I want just the first element of the resulting list. The (split)[0] thingy means "give me the element 0 of the list returned by split". Thanks to BooK++ for Acme::MetaSyntactic --shmem update: added missing backslashes to /s+/ :~}
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] [d/l] [select] |
by mikejones (Scribe) on Dec 19, 2006 at 20:13 UTC | |
The code below works, yet I am still trying to figure out why the above code does not:
| [reply] [d/l] [select] |
by mikejones (Scribe) on Dec 20, 2006 at 18:04 UTC | |
| [reply] |
by shmem (Chancellor) on Dec 20, 2006 at 18:26 UTC | |
Well, I was busy doing work (hrm. ;-) and reading other interesting posts. I also thought you would figure out, or somebody else would answer.
With that code, each split works on a new line read off the file handle FILE. The correct way would be:
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] [d/l] [select] |
|
Re^3: printing array reference and storing this data in a hash.
by mr_mischief (Monsignor) on Dec 19, 2006 at 18:55 UTC | |
??? If that's the case, then look very carefully and you'll realize that the bracketed portion is not the optional third parameter to split(). The construct: or is called an array slice (or list slice). The indexes are the only ones from the list/array that end up being returned. The parentheses are there basically to bind the index to the whole list that's being returned. List slices are a very handy idiom, and can be used to great effect in Perl. Like lots of conveniences in Perl or any other higher-level dynamic language, this can also be abused since there are sometimes much more efficient solutions. Learning when to use slices and when to avoid generating the whole list to use just part of it is a classic machine time/programmer time trade-off. I always try to err on the side of saving programmer time until I actually need to worry about a specific hotspot in a program. Christopher E. Stith | [reply] [d/l] [select] |
by mikejones (Scribe) on Dec 19, 2006 at 21:43 UTC | |
The code below works, yet I am still trying to figure out why the above code does not: I ran it in debug mode and I am seeing:
| [reply] [d/l] [select] |