Your syntax is wrong. Each time you say <FILE> you get another line - you do this twice for each while loop but only assign and print one line. Thus you skip every second line. You don't need the ' quotes either. Here is a script that does it two different ways. $. is the current line in the file. $_ is a magical Perl var that contains the line in the first chunk of example code. First you see the code, then its output.

C:\>type test.pl print "\nRead files off command line\n"; while(<>) { print "$. $_"; } print "\n\nRead file in usual way\n"; $file = 'c:/test.pl'; open F, "<$file" or die "Oops Perl says $!"; while (my $line = <F>) { print "$. $line"; } close F; print "\n\n\nPerl Rocks!\n"; C:\>perl test.pl test.pl Read files off command line 1 print "\nRead files off command line\n"; 2 while(<>) { 3 print "$. $_"; 4 } 5 6 print "\n\nRead file in usual way\n"; 7 $file = 'c:/test.pl'; 8 open F, "<$file" or die "Oops Perl says $!"; 9 while (my $line = <F>) { 10 print "$. $line"; 11 } 12 close F; 13 14 print "\n\n\nPerl Rocks!\n"; Read file in usual way 1 print "\nRead files off command line\n"; 2 while(<>) { 3 print "$. $_"; 4 } 5 6 print "\n\nRead file in usual way\n"; 7 $file = 'c:/test.pl'; 8 open F, "<$file" or die "Oops Perl says $!"; 9 while (my $line = <F>) { 10 print "$. $line"; 11 } 12 close F; 13 14 print "\n\n\nPerl Rocks!\n"; Perl Rocks! C:\>

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Reading HTML? by tachyon
in thread Reading HTML? by martin82

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.