Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: syntax error near unexpected token `)'

by vit (Friar)
on May 20, 2012 at 17:13 UTC ( [id://971505]=note: print w/replies, xml ) Need Help??


in reply to Re: syntax error near unexpected token `)'
in thread syntax error near unexpected token `)'

But the expression is correct and meets my purposes, right?
  • Comment on Re^2: syntax error near unexpected token `)'

Replies are listed 'Best First'.
Re^3: syntax error near unexpected token `)'
by aaron_baugher (Curate) on May 20, 2012 at 18:32 UTC

    You didn't tell us your purpose, so it's hard to say. But the error boils down to this: You can use either single or double quotes around an argument in the shell (bash, in this case), and either type can quote the other, but just as in Perl, there is no interpolation or escaping within single quotes. So:

    echo "'$SHELL'" -> outputs 'bash' echo '"$SHELL"' -> outputs "$SHELL"

    So if you need to include both kinds of quotes in a command line's arguments, you have a couple of choices: One is to use double quotes around the arguments and escape any double quotes within them. The problem with that is that you'll also need to escape other shell meta characters like ! and (), and that can lead to a complicated mess of backslashes. The other option is to switch back and forth between quote types as needed. You can do this in shell:

    echo "a ' quote"' and a " quote' outputs: a ' quote and a " quote

    So you can do your pipeline something like this, using single quotes around most of it but switching to double quotes around your literal single quotes:

    cat file.txt | perl -ne '{chomp; ($a, $b) = split/\s+/; $s = "$a $b"; + next if($s !~ /^\w+\'"'"'?\w+?\s+\w+\'"'"'?\w+?$/); print "$_\n"}' | + wc -l

    Aaron B.
    Available for small or large Perl jobs; see my home node.

Re^3: syntax error near unexpected token `)'
by jwkrahn (Abbot) on May 20, 2012 at 18:36 UTC

    I would write it as:

    perl -lne '$s += /^\w+\047?\w+\s+\w+\047?\w+\s/ }{ print $s' file.txt

    Update: After re-reading the original post again that should be:

    perl -lne '$s += /^\w+(?:\047\w+)?\s+\w+(?:\047\w+)?/\s/ }{ print $s' +file.txt

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-19 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found