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


In reply to Re: open and read text file by kcott
in thread open and read text file by hchana

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.