use warnings and -w behaviour

J

Jorge

I apologize for going over the -w / warnings issue againg but didn't
find anything in the FAQ's nor on this forum that addressed the exact
problem ...

I'm running on XP and using Exceed and F-secure ssh to establish a
Unix connection to our Solaris (SunOS 4) server where I run my perl
scripts.

When I use the -w in the shebang line ...

#!/usr/local/bin/perl -w

the scripts run just fine but when I switch to the 'use warnings'
pragma ...

use strict;
use warnings;
use lib '/opt/somedir/local/bin';
use defaults;
use lib "$this_lib";
use lib '/home/mmouse/lib/lib/perl5/site_perl/5.8.3';
use LWP::Simple;
use Spreadsheet::Read;
use IO::Tee;
use Cwd;
use File::stat;

I get the error ...

Command not found

I thought I had a good understanding of the both -w and warnings but
apparently I don't.

Can anyone shed some light on this?

Thanks

Jorge
 
G

Gunnar Hjalmarsson

Jorge said:
When I use the -w in the shebang line ...

#!/usr/local/bin/perl -w

the scripts run just fine but when I switch to the 'use warnings'
pragma ...

use strict;
use warnings;

I get the error ...

Command not found

Which Perl version are you using? The use warnings pragma doesn't work
with pre 5.6 versions of Perl.
 
G

Gary E. Ansok

When switching to "use warnings;" you didn't by accident delete
or modify the rest of the shebang line (i.e. #!/usr/local/bin/perl)?

The error itself doesn't look like a Perl message, so it's either
the shell on the Solaris server or your local cmd that emits it.

One possibility to check out is that your script still has
the Windows \r\n line endings. Perl generally treats the
\r (CR, CTRL-M, \015) as just another space character, but
on the shebang line it can make a difference:

#! /usr/local/bin/perl -w\r
The shell looks for /usr/local/bin/perl, finds it, and passes -w\r
to perl as a command-line argument (and perl ignores the \r).

#! /usr/local/bin/perl\r
The shell looks for /usr/local/bin/perl\r and can't find it.

If your file transfer program has an option to transfer files
in "text" mode, use that -- it will convert the line endings.
If your file transfer program doesn't have such an option, or
if you're transferring an archive full of scripts at once,
then see if your system has a utility like "dos2unix" available.
If not, it's easy enough to write a quick Perl script to remove
the \r characters.

Gary Ansok
 
J

Jorge

One possibility to check out is that your script still has
the Windows \r\n line endings. Perl generally treats the
\r (CR, CTRL-M, \015) as just another space character, but
on the shebang line it can make a difference:

#! /usr/local/bin/perl -w\r
The shell looks for /usr/local/bin/perl, finds it, and passes -w\r
to perl as a command-line argument (and perl ignores the \r).

#! /usr/local/bin/perl\r
The shell looks for /usr/local/bin/perl\r and can't find it.

If your file transfer program has an option to transfer files
in "text" mode, use that -- it will convert the line endings.
If your file transfer program doesn't have such an option, or
if you're transferring an archive full of scripts at once,
then see if your system has a utility like "dos2unix" available.
If not, it's easy enough to write a quick Perl script to remove
the \r characters.

Gary Ansok


Yup -- it was the 2-byte newlines that were causing the problem.

dos2unix fixed it.

Thanks much to all that sent a reply.

Jorge
 
S

Simon Andrews

Jorge said:
Yup -- it was the 2-byte newlines that were causing the problem.

dos2unix fixed it.

Another useful tip is to use

#!/usr/local/bin/perl --
use warnings;
etc..

The -- stops the shell from reading any further and will work on a
system using any kind of line ending.

Simon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top