Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Check exist of anonymous subroutine before calling it within regexp substitute?

by oha (Friar)
on Oct 30, 2009 at 08:57 UTC ( #804116=note: print w/replies, xml ) Need Help??


in reply to Re^2: Check exist of anonymous subroutine before calling it within regexp substitute?
in thread Check exist of anonymous subroutine before calling it within regexp substitute?

ty, i confess that at a first look i didn't understand why, could you elaborate plz?
  • Comment on Re^3: Check exist of anonymous subroutine before calling it within regexp substitute?

Replies are listed 'Best First'.
Re^4: Check exist of anonymous subroutine before calling it within regexp substitute?
by ikegami (Patriarch) on Oct 30, 2009 at 14:53 UTC
    use strict; use warnings; my %d = ( foo => sub { "[@_]"; }, bar => sub { "(@_)"; }, ); $_ = 'baz1'; s/(\w+)(??{!$d{$1}})/$d{$1}->($1)/ge; print "$_\n";
    Use of uninitialized value in subroutine entry at line 10. Can't use string ("") as a subroutine ref while "strict refs" in use a +t line 10.

    $1 is is "baz", so $d{$1} is undef, so !$d{$1} is 1, so the match tries to match "1". It does, so the replacement expression is executed.

Log In?
Username:
Password:

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

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












    Results (69 votes). Check out past polls.

    Notices?