perl -le '$_="Just another Perl hacker";/e/;sub AUTOLOAD{eval qq{sub $ +{(caller"Just")[scalar(()="a coke please"=~//g)]}}.qq}{(caller"Just") +[scalar(()="give me a coke"=~//g)]=~m(([^\072]*)\$)\x7d};&${(caller"J +ust")[scalar(()="coke, no more pepsi"=~//g)]}};print+(join$",map{join +$,,map{eval"main::$_()"}split//}split),","'

Windows users might want to put it in a file first. (Translating quotes might be tedious.)

Update: This requires 5.8. Sorry about that. I'll try to figure it out later.

Later: Here is a fix for older perls.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: "no more pepsi" JAPH
by simonm (Vicar) on Aug 13, 2003 at 01:34 UTC
    Hmm... I run it, but get no output, just a pause as if it were waiting for input.

    What did I do wrong?

      What did I do wrong?

      I'm not sure. If you cut and paste it, you have to be careful of the line wrappings. In particular, you have to remove the little "+"s prepended to each wrapped line.

      Other than that, my only guess is that it might be a platform issue. What OS and perl version?

      -sauoq
      "My two cents aren't worth a dime.";
      

        It works fine for me with 5.8.0 but not 5.6.1, on RedHat 9.

        -- Mike

        --
        XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
        -- grantm, perldoc XML::Simpler

        I see the same symptoms on 5.6.0/darwin and 5.00503/freebsd.
        I'm experiencing the same problem on a Suse8.0, perl 5.6.1 (P4, 1.7ghz) box. It loved it.
        CPU states: 90.1% user, 9.8% system, 0.0% nice, 0.0% idle Mem: 126380K av, 123424K used, 2956K free, 0K shrd, 100 +4K buff Swap: 672832K av, 356924K used, 315908K free 350 +4K cached PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 18144 deliria 0 0 371M 87M 480 R 94.1 70.6 1:05 perl
Re: "no more pepsi" JAPH
by sauoq (Abbot) on Aug 13, 2003 at 20:01 UTC

    It seems as if a perl bug prevented the original code from running on versions previous to 5.8. It sure looks like the bug was fixed in 5.8, but I didn't find any reference to it in perldelta or a quick search of the mailing list archives. Maybe I missed it or it was fixed "by accident" (as if there is any such thing as an accidental bug fix... ;-) If anyone has more information, please fill me in.

    The following version runs under, at least, 5.6.1 on Solaris 7 and 5.005_03 on OpenBSD. It isn't that different and the difference doesn't make it a spoiler, but it does give away one small detail. Sigh. Here you go:

    perl -le '$_="Just another Perl hacker";/e/;sub AUTOLOAD{eval qq{sub $ +{(caller"Just")[scalar(()="a coke please"=~/e/g)]}}.qq}{(caller"Just" +)[scalar(()="give me a coke"=~/e/g)]=~m(([^\072]*)\$)\x7d};&${(caller +"Just")[scalar(()="coke, no more pepsi"=~/e/g)]}};print+(join$",map{j +oin$,,map{eval"main::$_()"}split//}split),","'
    -sauoq
    "My two cents aren't worth a dime.";