In a comment, you say:
I had to run with a space between < and D:/
Using the three-argument version of open
would have avoided this issue. This has been the approach recommended in the Perl documentation for many years now.
open(my $fh, '<', 'D:/pay_info.txt')
or die "Couldn't open file pay_info.txt, $!";
while (<$fh>) {
print $_;
}
I've changed a few other things:
- Used a lexical filehandle (
$fh
) instead of a global one (DATA
). Actually, DATA
is a special filehandle in Perl so it shouldn't be used for in most code.
- Switched to using single quotes whenever possible (single-quoted strings recognise fewer special characters so it's a good idea to use them whenever possible).
- Removed unnecessary quotes in your
print
line (actually, the $_
is optional there as well).
- Light reformatting to make it more readable.