Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Condensing Perl Transpose code

Tags:

perl

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.

like image 217
Zenshai Avatar asked Dec 20 '25 03:12

Zenshai


1 Answers

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.

like image 110
Plutor Avatar answered Dec 22 '25 23:12

Plutor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!