Why program can't open the file? i.e dies. I searched for this problem, but it seems all fine to me. Funny thing is this code worked before, and i don't think i changed something from that moment in open function.
my $i;
my $regex = $ARGV[0];
for (@ARGV[1 .. $#ARGV]){
open (my $fh, "<", "$_") or die ("Can't open, $!");
$i++;
foreach (<$fh>){
print "Given regexp: $regex\nfile$i:\n line $.: $1\n" if $_ =~ /(\b$regex\b)/;
}
}
OUTPUT: Can't open Not a directory
.. or die "[$_] $!";or dieto beor die ("Can't open {$_}, $!"). Note the curly braces around$_so you see exactly what was being opened.