[pm-h] newbie confusion: executing a perl script

G. Wade Johnson gwadej at anomaly.org
Mon Aug 4 05:16:49 PDT 2008


Hello,

On Mon, 4 Aug 2008 03:07:50 -0500
"Russell L. Harris" <rlharris at oplink.net> wrote:

> At the URL:
> 
>     http://69.51.152.43/morse/#GUS-3
> 
> I discovered the nifty "KY8D Morse Code Perl Script", which has the
> capability of converting any text -- even an entire book -- into Morse
> code in a .WAV file, for subsequent conversion into mp3 or ogg vorbis
> for use with a personal mp3 player.
> 
> (This is one way to circumvent the problem of a book for which the
> only available audio edition has been read by someone with a voice you
> find intolerable.  If you can find a machine-readable copy of the
> book, you can create your own Morse edition.)
> 
> The first line of the script is:
> 
>     #!/usr/pkg/bin/perl
> 
> I am running Debian on an i386, so I used chmod to make the script
> executable and I changed the first line of the script to read:
> 
>     #!/usr/bin/perl
> 
> which works for all the Perl scripts I have been using over the past
> year.  But when I attempted to execute the script bash returned an
> error message:
> 
>     $ ./gus_morse.pl --path ~/scratch/message.txt
> 
>     bash: ./gus_morse.pl: /usr/bin/perl^M: bad interpreter: No such
>     file or directory

The error message actually tells you exactly what you need to know. The
perl program it is trying to run is wrong, because it has a carriage
return in the name.

This is usually caused by trying to run a DOS/Windows formatted file on
some UNIX flavor.

Run dos2unix on the script. This will remove the unwanted characters.
If you don't have dos2unix (unlikely, but possible), you can use the
following perl one-liner:

  perl -i.bak -pe'tr/\r//d' script.pl

where 'script.pl' is the script you want to fix.

> I then consulted the README file supplied by the author of the script,
> and saw there the example invocation:
> 
>     $ perl gus_morse.pl --path message.txt
> 
> which worked.
> 
> Would someone kindly explain to me why the "perl ..." invocation
> worked, whereas the "./..." invocation did not?

Hope that helps,
G. Wade
-- 
If it doesn't have to be right, I can make it arbitrarily fast.
                                                    -- Rick Hoselton


More information about the Houston mailing list