in reply to File Handle Basics
You are almost there. Just "print". Then output to whatever file you want using yourscript.pl > outputfile.txt
#!/usr/bin/perl -w print "File name to renumber:"; my $file = <STDIN>; open (FILE, "$file") || die $!; $|++; my $line = 0; while (<FILE>) { next if /^%/ ; s/^(?:N\d+\s?)?(?{$line++})/N$line / ; print; } close (FILE);
You might also want to use these switches in your command line:
-i[extension] edit <> files in place (makes backup if extension supplied) -n assume 'while (<>) { ... }' loop around program
If you call your script with perl -i -n all you need is:
s/^(?:N\d+\s?)?(?{$line++})/N$line / unless /^%/;
update: thanks Arien
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re(2): File Handle Basics
by Arien (Pilgrim) on Sep 04, 2002 at 00:17 UTC |