in reply to flip flop behaviour of regex match

As ikegami pointed out, /g in scalar context
doesn't reset pos. Your example will work fine
after some small modifications, eg.:
... sub func { print 'The Command Seperator is: ', $^O =~ /MSWin32/i ? '&' : ';', " +\n" } func(); func(); ...


<Addendum>
After thinking about an idiomatic switch between alternatives
I got this one, which I like somehow:
sub func { print 'The Command Seperator is: ', qw(; &)[ $^O =~ /MSWin32/i ], "\n" }
which evaluates the regex in scalar context as 0/1 (array index of the qw...)

</Addendum>

Regards

mwa

Replies are listed 'Best First'.
Re^2: flip flop behaviour of regex match
by harsha.reddy (Acolyte) on Oct 10, 2007 at 14:54 UTC
    Hi ikegami and mwa
    
    Wow awesome!! this is a super cool feature.
    
    Thanks a lot.