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

Hi there, a simple problem, probably quickly solved: I cannot execute a Perl program as expected:

gerd@gm2015:~/Programming/Perl> ./FirstTrial ./FirstTrial: line 1: #!/usr/bin/perl: No such file or directory ./FirstTrial: line 2: use: command not found ./FirstTrial: line 6: say: command not found gerd@gm2015:~/Programming/Perl> which perl /usr/bin/perl gerd@gm2015:~/Programming/Perl> echo $PATH /home/gerd/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games gerd@gm2015:~/Programming/Perl> perl FirstTrial Hello gerd@gm2015:~/Programming/Perl> more FirstTrial #!/usr/bin/perl -w use 5.18.2; #use strict; #use warnings; #use utf8; say "Hello"; gerd@gm2015:~/Programming/Perl>
I'm grateful for any comment. Thanks!

2017-11-28 Athanasius fixed closing code tag

Replies are listed 'Best First'.
Re: Executing a Perl program
by NetWallah (Canon) on Nov 27, 2017 at 20:32 UTC
    See this stackoverflow post.

    You probably have a BOM in the file , which is not visible.

    Try listing your file using:

    xxd FirstTrial
    to see if it has funny characters.

                    All power corrupts, but we need electricity.

Re: Executing a Perl program
by shmem (Chancellor) on Nov 27, 2017 at 20:20 UTC
    #!/usr/bin/perl: No such file or directory

    The shell reports the whole shebang line as a non-existent file? Something's wrong with that line. What's there before the shebang? Is there by chance a <Ctrl>H or such? Delete that line and write it again.

    Then,

    #!/usr/bin/perl -w use 5.18.2; #use strict; #use warnings; #use utf8; say "Hello";

    you should not comment out use strict; and use warnings; until your program runs and you are dead sure it does what it is meant to do with no ways left to fail.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: Executing a Perl program
by marto (Cardinal) on Nov 27, 2017 at 19:58 UTC

    As mentioned in the chatterbox, How do I post a question effectively? is a good read. Your closing code tag should be </code rather than <\code>, this can't have looked right when previewing your post. On to your perl problem. What does the following produce when run from the command line:

    file /usr/bin/perl

    Do you have any weird line endings breaking the shebang line?

Re: Executing a Perl program
by karlgoethebier (Abbot) on Nov 28, 2017 at 09:30 UTC
    "...funny characters..."

    Or inspect it with hexdump, like this:

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help