Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Perl program does not seem to be understood by Fedora 21

by swampyankee (Parson)
on Apr 29, 2015 at 21:44 UTC ( [id://1125168]=perlquestion: print w/replies, xml ) Need Help??

swampyankee has asked for the wisdom of the Perl Monks concerning the following question:

I'm evidently doing something stupid. I have about 2 dozen working perl programs on my laptop (Fedora 21) which work.

And one that doesn't in ways that I don't quite understand. First, it compiles fine: perl -c tells me the syntax is ok. Second, it runs when I use it as an argument to perl: perl inv (inv is the program's name). When I try to run it by using inv, I get this:

/home/emc/bin/inv: line 1: #!/usr/bin/perl: No such file or directory /home/emc/bin/inv: line 4: use: command not found /home/emc/bin/inv: line 5: use: command not found /home/emc/bin/inv: line 7: my: command not found /home/emc/bin/inv: line 9: my: command not found /home/emc/bin/inv: line 11: my: command not found

I'm stumped. I basically use the same few header lines for all my perl programs: the shebang line, use warnings, and use strict.

I know somebody here has a clue, so hit me with those clue-bats.


Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Replies are listed 'Best First'.
Re: Perl program does not seem to be understood by Fedora 21
by Paladin (Vicar) on Apr 29, 2015 at 21:57 UTC
    My guess is an non-printing character (like ^M) at the end of the #! line. Try deleting that entire line and re-typing it in and see if that fixes the issue. Alternatively, the file may be using DOS line endings instead of *nix line endings, in which case try running it through dos2unix to convert the line endings. (This is really the same issue as above, but will fix all the other line endings as well).
      Hmm, my first reaction was that it seems to me that Perl is able to deal with DOS end-of-lines (^M) under *nix without any problem within the script itself (and I think the other way around too). Not that I have ascertained it by making a decisive test on it, but after having developed programs under Windows and run them under Unix for so many years, it is almost doubtless that I would have encountered the problem if Perl wasn't able to deal with that, and I am almost sure I have never met it.

      Having said that, other non-printing characters is definitely a possibility, I ran into this type of problem just a couple of days ago under VMS: for some reason, my Windows editor added some presumably utf-8 character at the very beginning of my program, which refused to even compile.

      And, thinking back to my initial reaction in my first sentence above, it is absolutely true that if the shebang line is faulty, well, it is not interpreted by Perl but by the shell. And the shell is not as clever as Perl. But then, maybe I should have met the problem with DOS formated Perl script? Well, probably not, because I actually almost never really use the shebang line, my Unix shell scripts running Perl programs almost always launch the Perl program with a command such as perl my_script.pl (this way I don't run into RWE problems if I forgot to change privileges). And the same when I run a Perl program directly from the shell prompt. So that, in the end, your hypothesis might very well be right.

      Well, all this to say that I initially thought you were probably wrong, and that, after a second thought, I think you might be right.

      Je suis Charlie.
        Perl can handle the DOS line endings just fine, but as you said, it's the shell that can't (it tries to find a program named /usr/bin/perl^M to pass the script to). The cases you had where you didn't have issues with DOS line endings could have been that your #! line was something like: #!/usr/bin/perl -w^M, in which case the shell can find /usr/bin/perl and passes it the command line argument -w^M along with the script name, and perl can process those fine.
Re: Perl program does not seem to be understood by Fedora 21
by Perlbotics (Archbishop) on Apr 29, 2015 at 21:57 UTC

    • is perl the same as /usr/bin/perl? -- run: type perl
    • does inv really start with #! or perhaps with a BOM? -- run: od -N 32 -x inv
    • is /home/enc/bin/ accidentally mounted with noexec flag? -- run: mount and search for the appropriate path

      Thanks!

      I opened it up with vim -b and, lo, there was a non-displayable character before the # in the shebang. I probably fat-fingered something in emacs.


      Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

Re: Perl program does not seem to be understood by Fedora 21
by fishmonger (Chaplain) on Apr 29, 2015 at 21:56 UTC

    Are you sure that the path in the shebang line is correct?

Re: Perl program does not seem to be understood by Fedora 21
by RichardK (Parson) on Apr 29, 2015 at 22:15 UTC

    I don't think that it's /usr/bin/perl on fedora 21, it's usually in /bin/perl.

    run 'which perl' and it will tell you.

      Did that -- "which perl" returns /usr/bin/perl


      Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

        Try a shebang of #!/usr/bin/perl --
Re: Perl program does not seem to be understood by Fedora 21
by karlgoethebier (Abbot) on Apr 30, 2015 at 08:24 UTC

    Examine what's really in the file like that:

    $ hexdump -c -n 17 file.pl 0000000 # ! / u s r / b i n / p e r l \ +r 0000010 \n 0000011

    If you see \r\n in your file try $ dos2unix file.pl

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1125168]
Approved by marinersk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found