in reply to Line Renumbering

Note: untested.

$ perl -i.bak -lpe "s/^(N\d+ )?/$./" *.input

--
F o x t r o t U n i f o r m
Found a typo in this node? /msg me
The hell with paco, vote for Erudil!

Replies are listed 'Best First'.
Re: Re: Line Renumbering
by thelenm (Vicar) on Aug 29, 2002 at 16:47 UTC
    Unfortunately, when using <> (as -p does), $. is not reset after the close of each file. However, there is an example in the perlfunc:eof documentation of how to get around this (basically, you just have to do an explicit test of eof, then close the filehandle when it is found). The example is easily modified to fit this problem:
    #!/usr/bin/perl -i.bak while (<>) { s/^(N\d+ )?/N$. /; } continue { print; close ARGV if eof; }

    -- Mike

    --
    just,my${.02}

Re: Re: Line Renumbering
by fruiture (Curate) on Aug 29, 2002 at 16:52 UTC

    There's only a nasty caveat about $. on ARGV: it is not reset for each file, so it seems neccessary to "recode" the behaviour of <> in order to make this work as intended.

    --
    http://fruiture.de