Chris Charley wrote:

> "Chris Charley" <[EMAIL PROTECTED]> wrote in message news:...
> [snip]
> > while (<>) {
> >       s/^/Line: $. /;
> > }
>
> Should be (works correctly):
>
>  while (<>) {
>        s/^/Line: $. /;

You don't need a regular expression to do this. This should suffice
$_ = "Line: $. $_";

I hope you are aware of the fact that $. does not loop back to 0 when you pass
multiple files in the argument list.
When the call is 'perl prepend.pl somefile1.txt somefile2.txt', $. will not
loopback to 0 when the processing of 'somefile1.txt' finishes and
'somefile2.txt' starts.
perldoc perlop #Search for 'null filehandle'

>
>        print;
>  }
>
> Then the command could be:    perl prepend.pl somefile.txt > somefile.new
> which would correctly print to the 'new' file the somefile.txt file with the
> line numbers prepended.
>
> Chris
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to