H
Henry Law
I frequently have the need to take copy of a variable and edit it (for
printing or some such). I code it like this:
my $ugly_variable = some_function(); # Or read from a file maybe
my $nice_variable = $ugly_variable; # Take a copy ...
$nice_variable =~ s/nasty/nice/g; # ... and then make it look nice
Of course that works very well. But it doesn't look perlish, and it
takes two statements. I'm looking for some one-shot construction, along
the lines of this
my $nice_variable = ($ugly_variable =~ s/nasty/nice/g);
.... but if course that doesn't do what I want: $nice_variable ends up as
the number of substitutions done by s///. But is there a neater, more
succinct (but not hard to maintain) way of doing what I want? I'm sure
I saw something that looked like my wrong example above, but it must
have been different in some subtle way.
Of course I Googled for an answer to this; it's not that I found
nothing, more that I couldn't structure a query that returned anything
useful.
printing or some such). I code it like this:
my $ugly_variable = some_function(); # Or read from a file maybe
my $nice_variable = $ugly_variable; # Take a copy ...
$nice_variable =~ s/nasty/nice/g; # ... and then make it look nice
Of course that works very well. But it doesn't look perlish, and it
takes two statements. I'm looking for some one-shot construction, along
the lines of this
my $nice_variable = ($ugly_variable =~ s/nasty/nice/g);
.... but if course that doesn't do what I want: $nice_variable ends up as
the number of substitutions done by s///. But is there a neater, more
succinct (but not hard to maintain) way of doing what I want? I'm sure
I saw something that looked like my wrong example above, but it must
have been different in some subtle way.
Of course I Googled for an answer to this; it's not that I found
nothing, more that I couldn't structure a query that returned anything
useful.