Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > use warnings and -w behaviour

Reply
Thread Tools

use warnings and -w behaviour

 
 
Jorge
Guest
Posts: n/a
 
      05-11-2007
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

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      05-11-2007
Jorge wrote:
> 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;


<snip>

> 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.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Gary E. Ansok
Guest
Posts: n/a
 
      05-11-2007
In article <4644d263$0$6396$(E-Mail Removed)-online.net>,
Christian Winter <(E-Mail Removed)> wrote:
>Jorge wrote:
>> 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 ...
>>
>> I get the error ...
>>
>> Command not found
>>
>> Can anyone shed some light on this?

>
>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
--
Besides, there's nothing like the threat of imminent death
to force one to delegate. -- Lois McMaster Bujold
 
Reply With Quote
 
Jorge
Guest
Posts: n/a
 
      05-12-2007
On May 11, 1:44 pm, (E-Mail Removed) (Gary E. Ansok) wrote:
> In article <4644d263$0$6396$(E-Mail Removed)-online.net>,
> Christian Winter <(E-Mail Removed)> wrote:
>
>
>
> >Jorge wrote:
> >> 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 ...

>
> >> I get the error ...

>
> >> Command not found

>
> >> Can anyone shed some light on this?

>
> >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
> --
> Besides, there's nothing like the threat of imminent death
> to force one to delegate. -- Lois McMaster Bujold



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

dos2unix fixed it.

Thanks much to all that sent a reply.

Jorge

 
Reply With Quote
 
Simon Andrews
Guest
Posts: n/a
 
      05-16-2007
Jorge wrote:
>>>> 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 ...
>>>> I get the error ...
>>>> Command not found

>
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
debugger behaviour different to execution behaviour Andy Chambers Java 1 05-14-2007 09:51 AM
catching "Use of uninitialized value" warnings badarisj@gmail.com Perl Misc 3 10-03-2006 08:12 PM
use warnings; and use Warnings; give different results Ted Sung Perl Misc 1 08-30-2004 10:22 PM
vector use warnings Alan Benn C++ 1 10-17-2003 04:44 AM
"use warnings" or "-w" Rohan Romanus Almeida Perl Misc 2 08-14-2003 01:51 PM



Advertisments