I've had a look back at Split pattern doesn't match last line of file and I don't think your chomp; next unless $_; is going to cope if your data has lines containing just spaces (as implied in your OP), although it does cope with those that are just a newline. Given this data file

1st line 2nd line, next line is just a newline 4th line, next line spaces and newline 6th and last line

this script that uses your construct

use strict; use warnings; my $inFile = q{spw592594.dat}; open my $inFH, q{<}, $inFile or die qq{open: $inFile: $!\n}; while (<$inFH>) { chomp; next unless $_; print qq{-->$_<--\n}; } close $inFH or die qq{close: $inFile: $!\n};

produces

-->1st line<-- -->2nd line, next line is just a newline<-- -->4th line, next line spaces and newline<-- --> <-- -->6th and last line<--

and, as you can see, the line with spaces does not get rejected and the empty line does. A string of spaces is boolean true. Changing the script to

... while (<$inFH>) { chomp; # reject if 0 or more spaces anchored to start and end next if m{^\s*$}; print qq{-->$_<--\n}; } ...

does reject correctly and produces

-->1st line<-- -->2nd line, next line is just a newline<-- -->4th line, next line spaces and newline<-- -->6th and last line<--

I hope this is of use.

Cheers,

JohnGG


In reply to Re: Make calculation with values from hash by johngg
in thread Make calculation with values from hash by GertMT

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.