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

Dear Monks, I have this weird case of string substitution that work on perl 5.10 but doesn't work on 5.8.3 solaris. I was wondering if it's a bug?
sub rpt_parsetoken($$$$$) { my ($rptsql,$n,$sd,$ed,$d) = @_; my $newval; while ($rptsql =~ m/{(\w+)}/) { print "token : $&\n"; my $token = $&; my $newval; my $streval; if ($1 eq 'node') { $newval = qq{$n}; } elsif ($1 eq 'startdate') { $newval = qq{$sd}; } elsif ($1 eq 'enddate') { $newval = qq{$ed}; } elsif ($1 eq 'date') { $newval = qq{$d}; } print ("getting value from token: ".$newval."\n"); print (" eval = $streval\n"); #eval $streval; $rptsql =~ s/{$token}/'$newval'/; } print $rptsql."\n"; return $rptsql; } sub test($) { my ($str) = @_;#q{ this is nothing to $fess about}; my $nstr; #while ($str =~ m/##\w+##/) { while ($str =~ m/\$\w+/) { my $token = $&; print "original: $str\n"; print "token: $token\n"; $token = "\\".$token; print "modified token : $token\n"; my $newval = qq{'wierd'}; $str =~ s/$token/$newval/; print "patched: $str\n"; } } output from solaris 9 + perl 5.8.3: ----------------------------------- token : {node} getting value from token: dws2 '/val = $rptsql =~ s/$token/'dws2 'elect 1, 2 from RECON_SAP_DATA where DWS_NODE = 'dws2 '0080910-07:26:21 : preparing sql: select 1, 2 from RECON_SAP_DATA whe +re DWS_NODE = 'dws2 output from windows + perl 5.10: --------------------------------- token : {node} getting value from token: dws2 eval = $rptsql =~ s/$token/'dws2'/ 20080910-12:42:44 : preparing sql: select 1, 2 from RECON_SAP_DATA whe +re DWS_NODE = 'dws2' for some reason the ' is getting shuffled around to start of the strin +g
Am I missing something here? If you can enlighten me, it will be greatly appreciated. Regards Troy

Replies are listed 'Best First'.
Re: Perl 5.10 & perl 5.8.3 solaris
by moritz (Cardinal) on Sep 10, 2008 at 06:12 UTC
    I somehow suspect that this is more due to the platform difference than different perl versions. In particular you could check if the line endings differ on both platforms, and if they were removed correctly.

    A good way to print strings that might contain non-printable characters is Data::Dumper:

    use Data::Dumper; local $Data::Dumper::Useqq = 1; ... print Dumper($str_eval);
      Hi, Thanks a lot, it works like charms. I was so fix with the bug to overlook such small thing. it was the \r character that screw up the apps. Regards troy
Re: Perl 5.10 & perl 5.8.3 solaris
by Mutant (Priest) on Sep 10, 2008 at 10:30 UTC

    Don't have any specific help for you, but I discovered recently that the Perl that ships with Solaris is not the most reliable of things. If it's an option, I'd recommend installing your own version. You can compile it yourself, or better yet download it.

    As an added bonus, the perl on that site was also built with gcc, meaning you'll probably have less problems installing certain CPAN modules.