use warnings and -w behaviour

Discussion in 'Perl Misc' started by Jorge, May 11, 2007.

  1. Jorge

    Jorge Guest

    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
     
    Jorge, May 11, 2007
    #1
    1. Advertising

  2. 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
     
    Gunnar Hjalmarsson, May 11, 2007
    #2
    1. Advertising

  3. In article <4644d263$0$6396$-online.net>,
    Christian Winter <> 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
     
    Gary E. Ansok, May 11, 2007
    #3
  4. Jorge

    Jorge Guest

    On May 11, 1:44 pm, (Gary E. Ansok) wrote:
    > In article <4644d263$0$6396$-online.net>,
    > Christian Winter <> 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
     
    Jorge, May 12, 2007
    #4
  5. 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.
     
    Simon Andrews, May 16, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted Sung
    Replies:
    1
    Views:
    313
    Sherm Pendley
    Aug 30, 2004
  2. Marius Gavrilescu

    Re: use strict; use warnings;

    Marius Gavrilescu, Feb 24, 2014, in forum: Perl Misc
    Replies:
    152
    Views:
    515
    $Bill
    Mar 11, 2014
  3. Kaz Kylheku

    Re: use strict; use warnings;

    Kaz Kylheku, Feb 24, 2014, in forum: Perl Misc
    Replies:
    0
    Views:
    68
    Kaz Kylheku
    Feb 24, 2014
  4. George Mpouras

    Re: use strict; use warnings;

    George Mpouras, Feb 24, 2014, in forum: Perl Misc
    Replies:
    0
    Views:
    58
    George Mpouras
    Feb 24, 2014
  5. Mart van de Wege

    Re: use strict; use warnings;

    Mart van de Wege, Feb 24, 2014, in forum: Perl Misc
    Replies:
    1
    Views:
    55
    Mart van de Wege
    Feb 25, 2014
Loading...

Share This Page