c has asked for the wisdom of the Perl Monks concerning the following question:
I read through grep, but the doc doesnt seem to indicate whether or not a situation where grep matches nothing results as undef or an emptry string. My code:
my $vndr_key = (grep { $args->{desc} =~ m/$_/i } keys %vendors)[0]; if ($vndr_key ne '') { #do something } else { #do something else }
I'm getting an error Use of uninitialized value in string ne when the grep finds nothing. Would a if (!$vndr_key) be a better fit? And if so, I'd still like to understand just what grep is returning.
Thanks -c
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: no grep match returns undefined?
by kvale (Monsignor) on Sep 05, 2002 at 16:18 UTC | |
by davorg (Chancellor) on Sep 05, 2002 at 16:22 UTC | |
•Re: no grep match returns undefined?
by merlyn (Sage) on Sep 05, 2002 at 17:04 UTC | |
Re: no grep match returns undefined?
by thelenm (Vicar) on Sep 05, 2002 at 16:16 UTC | |
Re: no grep match returns undefined?
by bart (Canon) on Sep 05, 2002 at 19:01 UTC | |
by Aristotle (Chancellor) on Sep 06, 2002 at 04:59 UTC |
Back to
Seekers of Perl Wisdom