perl one liner error
for some reason i can't get this to work
Code:
perl –e ‘$_ = “The quick brown fox”; print scalar(split),”\n”;’ Code:
bash: syntax error near unexpected token `(' |
Starting with the bare basics:
Code:
$ perl -e '$_ = qq(The foxy fox) ; print' What gives? :) |
Stop using "smart" quotes and hyphens.
This works: Code:
perl -e '$_ = "The quick brown fox"; print scalar(split),"\n";' “” is completely different than two "s, and wrong The "–" you have is actually not the same as a "-". It is an EN DASH (E2 80 93) rather than a hyphen (2D). |
does the split function default to a space when nothing is specified, and doesn't the scalar function return the number of fields in an array?
|
Good catch about the bad characters.
@casperdaghost: what editor are you using to write your Perl? |
Quote:
If all you want is a word count, how about: Code:
$ perl -e '@sentence = qw(The foxy fox) ; print @sentence . "\n" ;' |
Hey guys - I picked up that one liner from a tutorial pasted on a word doc. I cut and pasted it into a terminal, and it would not work. It drove me crazy because I was pretty sure what the result would be, but it was erring out. Really, really astute observation AlucardZero - and a good lesson for me.
|
All times are GMT -5. The time now is 08:33 AM. |