Reputation: 10737
I always find myself writing code like this:
my $var = $result[0];
my $var_changed = $var;
$var_changed =~ s/somepattern/somechange/g;
What would be a better way to do this? And by 'better' I mean: less typing while remaining understandable.
Thanks.
Upvotes: 2
Views: 243
Reputation: 64929
Or even
(my $var_changed = my $var = $result[0]) =~ s/somepattern/somechange/g;
But that starts to bring into question why you need $var in the first place.
Upvotes: 1
Reputation: 2897
This would do the same thing as the second and third lines;
(my $var_changed = $var) =~ s/somepattern/somechange/g;
How legible it is is your call.
Upvotes: 15