in reply to get a text out from a string

so instead of :
my $productcode = "FCLA"; if($productcode =~ /^FCL/){ $productcode = "FCL"; }
is there a one liner that actually returns what i specify directly without having to write a conditional statement?

Replies are listed 'Best First'.
Re^2: get a text out from a string
by moritz (Cardinal) on Feb 27, 2008 at 09:14 UTC
    What's wrong with a conditional statement? And what should happen to $productcode if it doesn'T start witch FCL?

    You can do something like this:

    $productcode = $productcode =~ m/^FCL/ ? : 'FCL' : "No, sorry";
    But that only hides the conditional in the ternary operator. And you can use parenthesis in the regex and access the matched value with $1, but you still need a conditional somewhere to check its value.