You're intentionally skipping the first line of your CSV, which is probably because it contains field names, and isn't useful to you. But there's nothing to test your assertion that the first line of the file will be field names, or that it even exists. You might change it to:

my $head = $csv->getline($fh); die "Empty CSV." unless defined $head; warn "Field names detected: (@{$head})\n" if $ENV{MYSCRIPT_DEBUG}; die "No more CSV rows to process after header.\n" if $csv->eof;

Set an environment variable named "MYSCRIPT_DEBUG" to a true value before running if you want debugging info (the warn statement). This will at least test the assertion that your CSV file is not empty, that it starts out with field names, and that there are additional rows available to process after the header row.


Dave


In reply to Re: Cannot work on second file after reading first file. by davido
in thread Cannot work on second file after reading first file. by 1straw

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.