What is the cleanest way of picking up a match variable from a substitution in Perl I sometimes find myself writing
s/(something)// ;
my $x = $1 ;
then I realise that if the s/ / /
fails $1
might be carrying over a value from a previous match. So I try
my $x = 'defaultvalue' ;
if ( s/(something)// )
{
$x = $1 ;
}
Is this the cleanest way of doing it?