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

Following the oft-given advice to get the simplest code that fails for a given error, I wind up with this:
#!/opt/bin/perl print "test\n";
the above code works. (duh)
The code below fails.
#!/opt/bin/perl -w print "test\n";
When invoked from the command line, I get the following error.
%perl tn52400.pl on #! line at tn52400.pl line 1.
(There is a space before the 'on #!' part of the error msg, if that's significant.)
My current theory is gremlins, but I'm hoping someone has a better idea.
PS: perl version 5.005_02 built for sun4-solaris

-theo-
(so many nodes and so little time ... )
Note: All opinions are untested, unless otherwise stated

Replies are listed 'Best First'.
Re: using -w breaks simple script
by jasonk (Parson) on Oct 15, 2003 at 19:45 UTC

    Generally when you get funky error messages that seem to have words missing at the beginning, it's because the words that were printed included some funky unprintable characters (frequently \r, which causes the second part of the error message to overwrite the first part). Try this: 'perl tn52400.pl | cat -vet', and if you see funky characters in there, try 'cat -vet tn52400.pl' to see if they are in your script too...


    We're not surrounded, we're in a target-rich environment!
      The first test showed nothing odd. The second test revealed the gremlin: ^M$ after each line. I now remember reading about anothermonk with the same problem. Without the -w flag, Perl ignored everything after the filename. Add a flag after the filename and Perl kept looking till it found the gremlin!

      Thank you jasonk!

      -theo-
      (so many nodes and so little time ... )
      Note: All opinions are untested, unless otherwise stated

Re: using -w breaks simple script
by Abigail-II (Bishop) on Oct 15, 2003 at 20:19 UTC
    You have a control-M character after your '-w':
    $ cat -v xx #!/usr/bin/perl -w^M print "test\n"; $ /opt/perl/5.005_02/bin/perl xx on #! line at xx line 1. $ /opt/perl/5.6.0/bin/perl xx test

    So, either upgrade, or remove the ^M character.

    Abigail

      Very good catch.

      --
      I'm not belgian but I play one on TV.

Re: using -w breaks simple script
by belg4mit (Prior) on Oct 15, 2003 at 18:55 UTC
    No idea, but did you try the following?
    /opt/bin/perl -we 'print "test\n";'
    PS> that works fine with 5.00404 on a Blade 100 with Solaris 9

    --
    I'm not belgian but I play one on TV.

      That works, belg4mit. Any other ideas???

      -theo-
      (so many nodes and so little time ... )
      Note: All opinions are untested, unless otherwise stated

        Well there's always the arcane -d, though I don't see it helping much in this case. And as this is 5.4 you don't have diagnostics at your disposal, so nope :-/

        --
        I'm not belgian but I play one on TV.

Re: using -w breaks simple script
by Taulmarill (Deacon) on Oct 15, 2003 at 19:33 UTC
    hm, something strange is going on there, i would agree whith the gremlins. open the case and look if they have bitten some cables through (gremlines do that sometimes).

    ok, seriously now! if you are admin of the mashine, i would recomend to install a newer version of perl. look at Sunfreeware. they have prebuild packages which worked fine for me.
    oh, and /opt/bin/perl isnīt the standard path for perl on solaris, try /usr/bin/perl and look whatīs there. This all semes to me like the perl you are using is some messed up self compiled version.
    as last advise: try use warnings; instead the -w. Maybe that helps, dunno.

    hope this helps you.

Re: using -w breaks simple script
by vek (Prior) on Oct 15, 2003 at 19:17 UTC

    Hmm, the code works fine for me using an old 5.005_03 Perl install on Solaris 8.

    -- vek --