in reply to Re^2: Matching Regular expression at EOF
in thread Matching Regular expression at EOF

No... its not on a single variable... i am opening the file and reading it line by line...

Try:

my $last_line = undef;
while( <$fh> ){
  $last_line = $_;
  # process file contents, if needed
}
if( defined $last_line ){
  $last_line =~ m/$pat\z/;
}else{
  warn "file is empty\n";
}
  • Comment on Re^3: Matching Regular expression at EOF

Replies are listed 'Best First'.
Re^4: Matching Regular expression at EOF
by ikegami (Patriarch) on Feb 20, 2010 at 20:06 UTC
    That will erroneously claim the file is empty if the last occurrence of the pattern in on the second-last line (for example).