in reply to open and read text file
G'day hchana,
Welcome to the Monastery.
As there was some discussion regarding your error message and platform, here's what I get running on "macOS Sierra 10.12.5".
$ cat > pm_1195740_bad_shebang.pl #!/user/bin/perl print "Hello, world!\n"; $ chmod +x pm_1195740_bad_shebang.pl $ pm_1195740_bad_shebang.pl -bash: ./pm_1195740_bad_shebang.pl: /user/bin/perl: bad interpreter: N +o such file or directory $ cat > pm_1195740_good_shebang.pl #!/usr/bin/perl print "Hello, world!\n"; $ chmod +x pm_1195740_good_shebang.pl $ pm_1195740_good_shebang.pl Hello, world! $
You'll need to show us exactly how you're running your command. Please put that, and whatever output you get, within <code>...</code> tags.
I also tried a couple of other things to replicate your error message. Here's what I get when (a) it doesn't have execute access, and (b) I use an incorrect path; neither of which, incidentally, match your error message.
$ chmod -x pm_1195740_good_shebang.pl $ pm_1195740_good_shebang.pl -bash: ./pm_1195740_good_shebang.pl: Permission denied $ ../pm_1195740_good_shebang.pl -bash: ../pm_1195740_good_shebang.pl: No such file or directory $
A much better shebang line, which I use, is:
#!/usr/bin/env perl
That will use whatever your current Perl is. You won't need to change your scripts when you upgrade to a newer version of Perl.
You also really shouldn't use the system perl (/usr/bin/perl) anyway. This is provided with the OS for the OS to use. At some point you'll probably want to install one or more CPAN modules; which has the potential to break some part of the OS. Furthermore, when you next upgrade macOS, that stands a good chance of installing a newer Perl and removing the old one (including all the modules you installed). Instead, use Perlbrew: I've been using this for many years without any problems.
Finally, do follow the good advice from stevieb regarding strict, warnings and open. You can save yourself some time and effort hand-crafting '... or die "...";' messages with the autodie pragma. I'd also recommend you read "perlintro -- a brief introduction and overview of Perl".
— Ken
|
---|