in reply to Re: lsearch for perl?
in thread lsearch for perl?
When you're using lists, ask yourself if it could be done more easily with a hash.In my opinion, they address different problems. Arrays are an ordered set of things, hashes are an unordered set of associations. Sure, if you find yourself doing something like this:
then yes...use a hash. Don't try to shoehorn it, though.my (@item, @color); while(<DATA>) { chomp; my($item, $color) = split(/,/); push @item, $item; push @color, $color; } for(my $i=0; $i < @item; $i++) { print "$item[$i] has color $color[$i]\n"; } __DATA__ apple,red orange,orange banana,yellow
thor
The only easy day was yesterday
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: lsearch for perl?
by ikegami (Patriarch) on Dec 05, 2005 at 18:18 UTC | |
by thor (Priest) on Dec 05, 2005 at 19:40 UTC | |
by ikegami (Patriarch) on Dec 05, 2005 at 19:44 UTC | |
Re^3: lsearch for perl?
by aufflick (Deacon) on Dec 06, 2005 at 01:44 UTC |
In Section
Seekers of Perl Wisdom