Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

pattern matching in array

by torres09 (Acolyte)
on Jun 20, 2013 at 11:07 UTC ( #1039949=perlquestion: print w/replies, xml ) Need Help??
torres09 has asked for the wisdom of the Perl Monks concerning the following question:

Hey

I have an array of words and I want to find those words which start with "(inverted comma ) , can we do it with regex . and if yes please tell how to do it

Replies are listed 'Best First'.
Re: pattern matching in array
by hdb (Prior) on Jun 20, 2013 at 11:10 UTC
Re: pattern matching in array
by gurpreetsingh13 (Scribe) on Jun 20, 2013 at 11:24 UTC
    Simple one liner for the same.
    perl -e 'my @ar = qw( adf "afaf faf ff" af "abf"); $_ =~ m/^\".+$/ && +print "Yes=",$_,"\n" foreach(@ar);'
    Output:
    Yes="afaf Yes="adf"

      You don't need to escape the quote, nor gobble up the entire string. Simply: m/^"/

        hey

        now i am trying to work to find words starting with "" in array and I am doing this

         @foo_d = grep(/""/, @arr);  

        but it is not working , @foo_d always holds 1

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1039949]
Approved by hdb
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2017-01-24 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (200 votes). Check out past polls.