in reply to Re^3: I wrote a script to grep
in thread I wrote a script to grep

Hi mr_mischief
open $my_file, '<', $fn or die "Cannot open $fn: $!\n";
Is this line working with use strict; and use warnings;?

I'd assume you wanted to have rather:

open my $file, '<', $fn or die "Cannot open $fn: $!\n";
But then, you also have to change the while loop and your close statement.

I would also recommend that you localize $/ in a block before changing its value (although it may not be necessary in such a short script).

Replies are listed 'Best First'.
Re^5: I wrote a script to grep
by mr_mischief (Monsignor) on Jul 22, 2014 at 18:01 UTC

    You're right. I didn't use strict and warnings this time. I made minimal changes to the original code to make my points. The file handle is called $my_file not because I intended my $file but because the original bareword file handle was MYFILE.

    You have a valid point that strictures and warnings should have also been mentioned. That wasn't part of my intent as I scribbled out a response, but maybe it should have been.