Hello again,
After some testing, I am even more baffled than before. After attempting to create some small test cases, I'm sure there is a perl bug lurking here. Here are our (teichman's and my) findings:
This code will break:
#!/usr/bin/perl -w $data = { key1 => 'value1', key2 => 'value2', }; sub macro_replace { $_ = shift; my $helper = sub { $_ = shift; return $data->{$_} if $data->{$_}; return undef; }; chomp (my $pwd = `pwd`); s/\[\[(pwd)\]\]/$pwd/g; s/\[\[(\w+)\]\]/@{[$helper->($1)]}/g; return $_; } print macro_replace ("blah [[key1]] [[key2]] [[pwd]] blah blah\n");
Note the use of $_ in the helper function. Changing this to use another variable makes it all work as expected, as teichman said.
Strangely, however, taking out the pwd substitution (i.e., commenting out lines 15 and 16) seems to stop it from crashing as well, but only in this test case. I haven't been able to reproduce the exact behavior we see in our program yet.
This is being tested on Red Hat Linux 8.0 and SuSE Linux 8.1, both of which come with perl 5.8.0 (+/- a few patches of their own--which I believe are all unrelated to this).
Thanks for the useful tips!
-Dan
In reply to Re: Functions in substitutions (s///) and Perl 5.8.
by v_thunder
in thread Functions in substitutions (s///) and Perl 5.8.
by v_thunder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |