in reply to Re: /g matches not really global in scalar context!
in thread /g matches not really global in scalar context!

Huh?!?

I think you misunderstood me! I do use very often the /g modifier in list context:

my $n =()= / \b aiutino \b /gix; warn "Argh, $n times";
or
warn "$_ => Argh!\n" for / \b aiutino \b /gix; # Ok: not that interesting with a fixed lenght string!

Update: in the code above I did s/smart/interesting/, as per Aristotle's remark: indeed the latter adjective better reflects my feeling - I meant that $_ saves me some typing but will always have the value 'aiutino', and it would be more interesting with a more complex regex. Well, thinking of it better, not quite always 'aiutino', because I used /i, but still there ought to be more interesting cases...

Replies are listed 'Best First'.
Re^3: /g matches not really global in scalar context!
by Aristotle (Chancellor) on Nov 14, 2005 at 22:17 UTC

    not that smart with a fixed lenght string!

    Why not? Firstly, you’re using \b, which condition you’d have to code manually if you were to use a string search – that would require a lot of extra code and would be slower. Secondly, the regex engine is smart enough to do a simple string search itself when it sees simple patterns like yours.

    So absolutely, you should use a pattern for the job you’re after.

    Makeshifts last the longest.