in reply to I don't understand why I'm getting an unitialized value warning

Here's how I'd make sure there are no blank records in the file,
to get an accurate count of the records that have data in them:
(I've been doing a lot with regular expressions and file parsing lately)

local $/;             # Perl's record separator - default is \n unless...
$/ = undef;           # ... we make it undefined!
open(SESAME,$file);   # open the file
$f = (<SESAME>);      # the entire file, including all \n chars, is now sitting in a single scalar!
close(SESAME);
$f = s/\n+/\n/gs;     # regular expression replaces contiguous strings of \n chars with single \n chars.
$f = s/^\n//s;        # regex removes \n at the start of the string, if there is one.
$f = s/\n$//s;        # regex removes \n at the end of the string, if there is one.
@x = split(/\n/,$f);  # split string on the \n char, store split values in array @x
$x = @x;              # the number of elements in @x
print "There are $x records in file $file\n";
exit(0);
  • Comment on Re: I don't understand why I'm getting an unitialized value warning

Replies are listed 'Best First'.
RE: Re: I don't understand why I'm getting an unitialized value warning
by Doc Technical (Initiate) on Apr 13, 2000 at 10:38 UTC
    Sorry about the repetition. new here and getting the hang of the way response submissions must be formatted. The last one is correct. BTW, it would sure be nice if the folks who run this put up a "your response has been submitted" screen when a submission is made, instead of re-displaying the submission request page again.