Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: perl's grep function with '^' and '$'

by shmem (Chancellor)
on May 25, 2007 at 09:13 UTC ( [id://617439]=note: print w/replies, xml ) Need Help??


in reply to perl's grep function with '^' and '$'

Try:
perl -le 'my @array = qq[Anthony Mark Alex A]; print for @array'

See? What does the qq[] operator do? you want qw[].

You would have spotted that had you written e.g.

# Program : 2 #!/usr/bin/perl use strict; my $match = 'A'; my @array = qq[Anthony Mark Alex A]; if ( my @list = grep( /$match$/,@array ) ) { print "Matched: ".join(', ', map {"'$_'"} @list)."\n"; } __END__ Matched: 'Anthony Mark Alex A'

learn to debug... ;-)

--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}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://617439]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found