in reply to functions inside patterns

What are you talking about cheesyjames? I can guess, and it'd be a pretty good guess at that, but I do not want to. You must tell me what you mean cheesyjames.
#!/usr/bin/perl -lw use strict; # here is one thing you might want sub what { my $what = shift; return ($what - 5); } my $string = 'a and a b and a 5 and a 6 and a 8 an what?'; print $string; $string =~ s/(\d)/&what($1)/ge;
The other thing I think you might be thinking (dang that sounds stupid) is something along the lines of m/\d$pattern\b\l\a\h &what('what')/ where you want &what('what') to be expanded, in which case the only thing I can think of is for you to either store the value of &what in a variable.

update: well you could always use eval, but I find that is in poor taste (I think it is a piss poor choice in design, when one must resort to "passing" functions via STDIN).

 
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Replies are listed 'Best First'.
Re: (crazyinsomniac) Re: functions inside patterns
by cheesyjames (Novice) on Dec 20, 2001 at 10:55 UTC
    the function changes dynamically. So I can not call a sub. The script is running from a wrapper program which passes it functions via STDIN. I cant define too much in the perl code without breaking dependencies in the wrapper script. I could get in trouble for disclosing too much but thank you very much for your input!
      "the function changes dynamically. So I can not call a sub."

      A function is a sub, whether it be predeclared ( sub foo{return 'foo'}) or "dynamic" so to speak (a closure my $function = sub {return 'fooo'}; print &$function;).

      "The script is running from a wrapper program which passes it functions via STDIN"

      That sugguests to me you should be well versed in perlsec, cause in my opinion, that no good stratogy.

       
      ___crazyinsomniac_______________________________________
      Disclaimer: Don't blame. It came from inside the void

      perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Re: (crazyinsomniac) Re: functions inside patterns
by cheesyjames (Novice) on Dec 20, 2001 at 11:05 UTC
    Good call! I have been trying to campaign to get the entire code base re-written in C. Just C. Not 4 languages. The bottom line rules I guess.