perl.. quick sanity check..

halz

n00b
Joined
Aug 30, 2006
Messages
4
I've got a one-liner in perl that works at the command line, but doesn't work within my script..


Code:
from the command line...
$perl -ne 'print if /Begin of text select/ .. /End of text select/' input.txt > output.txt

Code:
#within the script..
$content =~ /Begin of text select/ .. /End of text select/;
print $content;

...am I just not using the one-liner in perl correctly? Otherwise.. How else can I easily select a block of text from a variable containing multiple lines and print it..?
 
what is the script supposed to do? print out the lines between "Begin of text select" and "End of text select"?

i think the -n flag automatically wraps the code inside of a while(<>) loop, which reads each line (of the provided filename) into $_ until it hits EOF

if you werent using the -n flag, the command would be something like:
perl -e 'while(<>) { print $_ if (/Begin of blah/ .. /End of blah/); }'

so for the script to work properly, you'd also have to do so manually.
 
Ah.. thats the stuff.. I didn't question the -n option!

I've got it in a while loop and its working happily now.. thanks!
 
Back
Top