I am trying to replace whitespaces in a string after matching it against a regular expression.
my $string = "watch download Buffy the Vampire Slayer Season 1 Episode 1 Gorillavid";
if ($string =~ m!(Season\s\d+\sEpisode\s\d+)!){
$1 =~ s!\s+!!g;
say $1;
}
Now when I run the above code I get Modification of a read-only value attempted. Now if I store the value of $1 in a variable than try to perform a substitution on that variable it works fine.
So, is there any way I can perform a substitution in place without creating a new temporary variable.
PS: Can someone show me how to write the above code as one-liner because I am not able to 🙂
Don’t mess with special variables and just capture the data you want, while construction output yourself.