in reply to Re: Non-destructive string substitution
in thread Non-destructive string substitution

This doesn't work either:
my $foo = "foo"; print map {s/foo/bar/g; $_} do{$foo}; print "\n$foo\n";
prints
bar bar
This, however, does:
my $foo = "foo"; print map {s/foo/bar/g; $_} @{[$foo]}; print "\n$foo\n";

-Mark

Replies are listed 'Best First'.
Re: Re: Re: Non-destructive string substitution
by japhy (Canon) on Apr 20, 2004 at 18:39 UTC
    Hmm. The debugger runs them differently. Oh well. Regardless, if you don't mind stringification, you can use "$foo" as the argument to map().
    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;