http://www.perlmonks.org?node_id=20953

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I want to print the contents of file line by line, with some additional formatting added to each line.

Here's what I've tried:

print <IN> , "<br/>\n" ;

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How to print a file line by line?
by Anonymous Monk on Jul 04, 2000 at 03:28 UTC

    <IN> in scalar context will only return one line per call, while in list context it will return a list of all the (remaining) lines in the file. Therefore, replace

    print <IN> , "<br/>\n" ;
    with
    print map "$_<br/>\n", <IN>;
Re: How to print a file line by line?
by Anonymous Monk on Jul 04, 2000 at 06:44 UTC
    print "$_<br>\n", while <IN>;

    You could also add a little $\ and local magic:

    { local $\ = "<br>\n"; print while <IN>; }