It is important to use copy and paste to post your code otherwise we end up chasing transcription errors. In this case while(<fhand>}{ is bad syntax and is probably a transcription error. But what about if($First = 1); (assign 1 to $first - the test is always true)? Transcription error or bug?

You should always add use strict; use warnings; to your code. They will catch many silly mistakes. In this case both the errors pointed out above would have been caught.

Of less importance in ($_ =~/ the $_ =~ is redundant.

You don't actually provide any test data and you don't say under what circumstances the result is incorrect. The followign code should serve as a starting point for elaborating on the actual problem you are having:

use strict; use warnings; while (<DATA>) { next if (m/First Name/ .. m/Last Name/); next if ! m/Last Name/; print "Order is not correct\n"; last; } __DATA__ ....... Last Name ...... ....... First Name .......

Prints:

Order is not correct

DWIM is Perl's answer to Gödel

In reply to Re: File reading by GrandFather
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.