Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^3: perl onliner on multiple files

by 7stud (Deacon)
on Feb 08, 2013 at 23:54 UTC ( #1017906=note: print w/replies, xml ) Need Help??

in reply to Re^2: perl onliner on multiple files
in thread perl onliner on multiple files

In a bash shell, I get:
$ perl -nE "/: / and $c += (split/: /)[0]; if( eof(ARGV) ){ say qq[SUM +.$ARGV =$c]; $c=0 }" tmp_* syntax error at -e line 1, near "+=" syntax error at -e line 1, near "; =" Execution of -e aborted due to compilation errors.


$ c=10 $ echo c c $ echo $c 10 $ echo "The total is: $c" The total is: 10 $ echo 'The total is: $c' The total is: $c
So within double quotes, the shell expands $variables, which of course happens *before* the shell hands the text over to the perl command. That is similar to the way the shell expands your glob: tmp_* and replaces it with a list of file names, which is what the perl command ends up seeing.

Replies are listed 'Best First'.
Re^4: perl onliner on multiple files
by abhay180 (Acolyte) on Feb 09, 2013 at 10:05 UTC
    ok. i figured that out...but since i was using perl version 5.8, the -E option and "say" keyword were not recognized. Once i use the perl version 5.10 and above...the above line works exactly the way i want it to. Thanks a lot.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017906]
[Discipulus]: erix the problem was not rain in the brain.. ;=)
[erix]: I'll think about that for a bit; I'll figure it out
[erix]: (damn Discipulus for speaking in IQ tests :P )

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-11-17 20:28 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (272 votes). Check out past polls.