davorg has correctly identified where the bug lies. 'if ( $first = 1 )' will assign 1 to $first and then submit the same as the value of the 'if' condition (1 being a true value). But there are some things which should become habitual, even when writing the first version:
#!/usr/bin/perl use strict; # avoid typos and unclear scoping... use warnings; # ...amongst other things # open fhand,file.txt; # this will now cause the # compilation error that it should # ...replacement further down... # declare and init your vars, including file handles my $file = 'file.txt' my $path = $ENV{ SOME_PATH } . '/' . $file; # or must cd? open my $fh, "<$path" or warn "$!: $file\n" and exit $?; # assume I/O can and will go wrong sometimes my $first = 0; while( <$fh> ){ # indent your nests for clarity # avoid falling thru from one case into the next if ( /First Name/ ) { $first = 1; # any other processing of First name line } elseif ( /Last Name/ ) { $first or die "Order is not correct\n"; # any other processing of Last name line } elsif ( 0 ) { # ...etc.... else { # default or 'all other' case if applicable } } close $fh; # specifically close filehandles

-M

Free your mind


In reply to Re: File reading by Moron
in thread File reading by qsl

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.