Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: when $$s =~ m/\G.../gc is too verbose (for)

by tye (Sage)
on Feb 03, 2006 at 05:00 UTC ( #527537=note: print w/replies, xml ) Need Help??

in reply to when $$s =~ m/\G.../gc is too verbose

for( $$s ) { .... }

- tye        

Replies are listed 'Best First'.
Re^2: when $$s =~ m/\G.../gc is too verbose (for)
by stefp (Vicar) on Feb 03, 2006 at 09:49 UTC
    This is the trick used by Calc.yp in the Parse::Yapp distribution. It indeed creates an alias but conveys the wrong message because the the block is not really used as a loop.

    -- stefp

      That's why I wished Perl allowed another keyword as yet another synonym for for/foreach — I'd propose "with", for example:
      with($$s) { ... }
      But in the meantime, I've trained myself to actually read/see
      for(SCALAR) { ... }
      with(SCALAR) { ... }

      Chalk it up as another Perl idiom.

        It's called "given" in Perl 6 (or in Perl6::Switch, if you want to play with 6ish topicalizers in Perl 5).

        Perl 6 also has syntactic relief for the m/\G.../gc monstrosity as well. That turns into m:p/.../, where the :p tells it to start matching at the current position. (But generally you don't even need that since subrules in a grammar always anchor to the current position anyway.)

      Much like in English, you can use Perl's for() for iterating over a list, iterating via initialization + check + step, or associating a single topic with a block of syntax. So I, without apology, use for() for topicalizing. For you, I won't stop doing this. (: Excuse me for not demonstrating the use of English "for" analogous to init + check + step.

      - tye        

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://527537]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2020-11-27 17:10 GMT
Find Nodes?
    Voting Booth?

    No recent polls found