http://qs321.pair.com?node_id=928314


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

Hi dirac,

When a script doesn't work as expected, you need to debug it. To aid in that venture, be verbose. Don't get fancy and try to do everything in a single line (eg. my $log_file = (split /\./, $0)[0] . '.log';). Rather, do the minimum possible in each step, and display all intermediate results, such as:

#!/usr/local/bin/perl -w # my_script_name.pl use strict; my $arg0 = $0; print "Debug> Before split -- arg0 = '$arg0'\n"; my @words = split /\./, $0; my $count = @words; print "Debug> After split -- $count words: [@words]\n"; my $base = $words[0]; print "Debug> First word (word[0]) = '$base'\n"; my $log_file = $base . '.log'; print "Debug> Full logfile name = '$log_file'\n";

You should never find yourself saying "I know the contents of the variable should be X at this point". Rather, "I think the contents of the variable should be X, so I'll print them out to be sure..."


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/