in reply to (Mis)Understanding grep...eq $_
grep doesn't search in strings, it searches arrays or lists. It makes no sense to use it on scalars. You give grep a list, and an operation to execute on each element of the list. For example:
my @list= (1,8,3,9,2); my @newlist= grep $_<5, @list; # @newlist would be (1,3,2);
grep is sort of a loop and what you did was create a loop that always loops only once. So the following two lines are practically equivalent
unless ( grep $person_has eq $_, $item ) { unless ( $person_has eq $item ) {
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: (Mis)Understanding <c>grep...eq $_<c>
by ysth (Canon) on Feb 24, 2009 at 07:21 UTC | |
by grinder (Bishop) on Feb 24, 2009 at 07:50 UTC | |
by parv (Parson) on Feb 24, 2009 at 08:08 UTC | |
by grinder (Bishop) on Feb 24, 2009 at 23:39 UTC | |
Re^2: (Mis)Understanding <c>grep...eq $_<c>
by ikegami (Patriarch) on Feb 24, 2009 at 07:09 UTC | |
by Marshall (Canon) on Feb 25, 2009 at 08:22 UTC | |
by ikegami (Patriarch) on Feb 25, 2009 at 13:10 UTC | |
by tye (Sage) on Feb 25, 2009 at 15:27 UTC | |
by ikegami (Patriarch) on Feb 25, 2009 at 16:03 UTC | |
|
In Section
Seekers of Perl Wisdom