jesuashok has asked for the wisdom of the Perl Monks concerning the following question:
Fantasy monks,
Apologies If this has been discussed already,
# Program : 1 #!/usr/bin/perl use strict; my $match = 'A'; my @array = qq[Anthony Mark Alex A]; if ( grep( /^$match/,@array ) ) { print "Matched\n"; }
Output : Matched
# Program : 2 #!/usr/bin/perl use strict; my $match = 'A'; my @array = qq[Anthony Mark Alex A]; if ( grep( /$match$/,@array ) ) { print "Matched\n"; } <code> Output : Matched
What is the problem with the 3rd program ? am I missing something there ?# Program : 3 #!/usr/bin/perl use strict; my $match = 'A'; my @array = qq[Anthony Mark Alex A]; if ( grep( /^$match$/,@array ) ) { print "Matched\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: perl's grep function with '^' and '$'
by shmem (Chancellor) on May 25, 2007 at 09:13 UTC | |
Re: perl's grep function with '^' and '$'
by clinton (Priest) on May 25, 2007 at 09:13 UTC | |
Re: perl's grep function with '^' and '$'
by moritz (Cardinal) on May 25, 2007 at 09:16 UTC |
Back to
Seekers of Perl Wisdom