Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Do you know where your variables are?
 
PerlMonks  

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

by radiantmatrix (Parson)
on Feb 07, 2006 at 12:53 UTC ( [id://528576]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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

Why not just store $$s in a local copy of $_?

#Either local $_ = $$s; #Or s//$$s/; #tricky.. ;-)

Actually, in this case, I'd be tempted to alter your approach altogether and use a regex table.

sub lexer { my ($parser) = shift; my $s = $parser->YYData->{INPUT}; # I don't get your line: 'm/\G\s+/gc; skip any spaces' my %dispatch = ( INT => qr/\G(\d+)/gc, ID => qr/\G([A-Z]\w*)/gc, #.. and so on .. ); while (my ($key, $regex) = each %dispatch) { return ($key, $1) if $$s =~ $regex; } }
<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

Replies are listed 'Best First'.
Re^2: when $$s =~ m/\G.../gc is too verbose
by Corion (Patriarch) on Feb 07, 2006 at 12:58 UTC

    Your second solution is no solution:

    $_ = '!'; $s = \'No'; s//$$s/; print;

    You'd need to empty out $_ first, so the local $_ is the way.

      Absolutely. That's the tricky part. ;-) It will work when $_ is undefined, but not otherwise. Of course, you could always change it to s/.*/$$s/, but still not advisable. More of an obfu trick...

      <-radiant.matrix->
      A collection of thoughts and links from the minds of geeks
      The Code that can be seen is not the true Code
      I haven't found a problem yet that can't be solved by a well-placed trebuchet
Re^2: when $$s =~ m/\G.../gc is too verbose
by stefp (Vicar) on Feb 07, 2006 at 17:31 UTC
    About the copy: before even thinking about positions in strings, using a string copy is a no-no. Copying the string to be parsed for each token is madness.

    About a table for lexing : this is irrelevant to the discussion. Also, lexing can be more complex than matching. Yes, one can insert regular code in regex but that the sign that a table based lexing is not appropriate.

    As I said tye, using for is the right way to alias to $_. I don't like it because in the programming space, for is a loop... for me. :)

    In the natural language space, well, English is not my first language.

    So to paraphrase Churchill, for is the worst solution, but it is the only one.

    Hopefully, like said TimToady, Perl6 will be cleaner.

    -- stefp

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://528576]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.