Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: Re: A few random questions from Learning Perl 3

by TheHobbit (Pilgrim)
on Jan 06, 2003 at 13:23 UTC ( [id://224621]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: A few random questions from Learning Perl 3
in thread A few random questions from Learning Perl 3

Hi,
I'll add some considerations which looks needed. This will also be an answer to the 'Anonymous' below, who thinks he or she can hide and insult people without even disturbing him ore herself to register into the community...

Stricly speaking, Perl regex are realy much more powerfull than those described in the wonderfull books you refer to. To understand regex as they are used in perl (but also in other langages & tools) I'd rathere refer to

A basic thing that one always see written about regex is that the can not count. Meaning that you must know the maximum number of times the <em>...</em> will be embedded..

While this is true of 'standard' regex, this is not true for Perl regex. By using carefull combination of the /e modifier and of the (?{}) programmatic pattern you can do using regex, everithing a parser will do.

IMHO, using a regex or another approach is a matter of taste, and a careful crafted and optimized regex will be more efficent than a sloppy written rec descent parser.

Just my 5 (euro) cents.

Cheers


Leo TheHobbit

Replies are listed 'Best First'.
Re: Re: Re: Re: A few random questions from Learning Perl 3
by ihb (Deacon) on Jan 06, 2003 at 14:45 UTC
    By using carefull combination of the /e modifier and of the (?{}) programmatic pattern you can do using regex, everithing a parser will do.

    My guess is that you probably mean the (??{...}) assertion.

    (?{...}) merely executes, whereas
    (??{...}) executes and interpolates.

    (A possibly confusing mnemonic would be that one ? would be like one q, which doesn't interpolate. Double ? would be like double q, which interpolates. It's different types of interpolations (one interpolates into the construction, one interpolates its result), so ignore this if it doesn't make sense to you.)

    A bit generalized you may say that:
    (?{...}) is used for debugging and/or setting state.
    (??{...}) is used for generating patterns at "match-time".

    Beware of using =~ inside either of these assertions though. The engine is known to often blow upon that.

    Update:
    A good example that uses both these assertion is to be found at Re: Capturing brackets within a repeat group [plus dynamic backreferences].

    Hope I've helped,
    ihb
Re: Re: Re: Re: A few random questions from Learning Perl 3
by Anonymous Monk on Jan 07, 2003 at 01:46 UTC
    I am the previous anonymous monk.

    Perl 6's regex syntax will make using it for parsing reasonable. But while you theoretically can do that with a lot of care and using constructs that very people know about, the odds are strongly that the average programmer who thinks that they can just misunderstands and underestimates the difficulties.

    Therefore on the odds I stand by my previous comments.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-23 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found