in reply to Regex, Function and Default variables

Also remember that m// behaves differently depending on context, flags, whether () groups are present...

In particular, when $str =~ m//g is used in scalar context (as in your posted examples), it requests match position pos($str) to be remembered; further m//g continue from there. (But assigning to $str will forget the pos!)

# m// in list context, no g flag if (my @match = $str =~ m/(pattern1)(pattern2)/i) { $str = function($match[0]); $var1 = function($match[1]); }

Replies are listed 'Best First'.
Re^2: Regex, Function and Default variables
by tosaiju (Acolyte) on Nov 21, 2013 at 09:00 UTC
    First of all apologize for not giving the complete example or sample. Thanks a lot for the advice and solution; I think this is basically of function call – which overwrites the value. Thank you Monks