sub my_sub {
my $str = shift;
$str =~ s/some/regex/;
return $str;
}
Five lines seems too long for such a simple subroutine. Can it be simplified, e.g. by not using an intermediary variable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Without intermediary variable and one line shorter:
Edit: As @pavel noted, this will modify the original variable.
Since Perl 5.13.2, there is the non-destructive modifier
/r(for reference, see perlop), which will not modify the variable the regex operates on – this also allows to ditch another line: