quick perl sanity check

Halz

Senior member
Jun 25, 2000
335
0
0
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..?
 

Halz

Senior member
Jun 25, 2000
335
0
0
Turns out I didn't question the '-n' option..

$ perl -n -e 'print "$. - $_"' file

is equal to...

LINE:
while (<>) {
print "$. - $_"
}