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

Re: Passing $2 to a sub

by Gloom (Monk)
on Feb 13, 2001 at 22:56 UTC ( #58193=note: print w/replies, xml ) Need Help??


in reply to Passing $2 to a sub

Try something like this :

if( /^\s*>/ ) { print "$'\n"; createTable( $' ); } sub createTable { print shift; }

Hope this helps

Replies are listed 'Best First'.
Re: Re: Passing $2 to a sub
by the_slycer (Chaplain) on Feb 13, 2001 at 23:13 UTC
    I may be wrong (I've only read Mastering Regular Expressions once), but doesn't using $&, $'or $` anywhere in your program cause some fairly severe performance issues?

    Looks like the regex originally used should work - just trying to print $_ instead of $_[0]
      Yep, you are right. From perlre:
      WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in the program, it has to provide them for every pattern match. This may substantially slow your program. Perl uses the same mechanism to produce $1, $2, etc, so you also pay a price for each pattern that contains capturing parentheses. (To avoid this cost while retaining the grouping behaviour, use the extended regular expression (?: ... ) instead.) But if you never use $&, $` or $', then patterns without capturing parentheses will not be penalized. So avoid $&, $', and $` if you can, but if you can't (and some algorithms really appreciate them), once you've used them once, use them at will, because you've already paid the price. As of 5.005, $& is not so costly as the other two.
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2022-01-25 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (67 votes). Check out past polls.

    Notices?