in reply to Different behavior when parsing $0 on Solaris and Win32

Works for me with

This is perl, v5.8.4 built for i86pc-solaris-64int (with 32 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall

But note that you are not really taking the script name, you are also potentially taking the whole path to the script name. And you are not replacing the end of the script name by .log but you are replacing the complete part after the first dot in the script path and replace it by .log. I would do it this way:

(my $logname = $0) =~ /\.pl$/.log/;

Replies are listed 'Best First'.
Re^2: Different behavior when parsing $0 on Solaris and Win32
by toolic (Bishop) on Sep 28, 2011 at 12:53 UTC
    you are replacing the complete part after the first dot in the script path and replace it by .log
    Good point. And here is one way of calling the script to reproduce the OP's result:
    $ ./my_script_name.pl .log
    Perhaps the OP has invoked the script differently on the 2 OS's.

      yes, this is exactly what happens, even setting PATH with the current dir and invoking with:

      $ my_script_name.pl

      The value of $0 is still the same:

      ./my_script_name.pl
Re^2: Different behavior when parsing $0 on Solaris and Win32
by dirac (Beadle) on Sep 28, 2011 at 13:35 UTC

    With this, work fine (note the 's/')

    (my $log_file = $0 )=~ s/pl$/log/;