Re: Metaprogramming
Steffen Mueller: So any code that uses closures is pathological? Hmm, let's see: perl -MO=Deparse -e 'my $x; {my $foo = Hello!; $x=sub{print $foo};}; $x-()' my $x; { my $foo = 'Hello!'; $x = sub { print $foo; } ; } $x(); Nope, seems not. -- Citizen_X I detest people who get in their cars before turning off the alarm, fiddle around a bit, and then turn it off Citizen_X maybe they're afraid someone might steal the car in the short time before they turn off the alarm and actually get in Citizen_X it's a race condition, you know
Re: Metaprogramming
Simon Cozens wrote: Steffen Mueller: I've been wondering whether it is possible to implement some kind of mechanism that allows a Perl script to modify itself at runtime. B::Generate's been doing this for ages. Okay, I read up on it, but: You are expected to have read the Perl and XS sources to this module before attempting to do anything with it. I cannot read XS :) Well, eventually, I might teach myself to, but I doubt that will be just to implement foolish things as described in the other post. Thanks for the pointer anyway. Steffen -- sub'_{q} tsuJ}}_();sub's{seek+DATA,0,0}sub'p{print_}sub'r{reverse$_[0]} @_=(('')x2,split ,DATA);s!!s,$_=DATA;s/}.*?}/$_[$s+1]/ if$s;s/(}.*?})/r$1/e;eval$_;p,$s++!efor@_[0..3]; __DATA__ } rehtona} } lreP} },rekcah}
Re: Metaprogramming
Steffen Mueller: Okay, I read up on it, but: You are expected to have read the Perl and XS sources to this module before attempting to do anything with it. I cannot read XS :) Yeah, it was just a long-term plot to sell more books. -- IBM: It may be slow, but it's hard to use.
Re: Metaprogramming
Michael == Michael G Schwern [EMAIL PROTECTED] writes: Nope, I've given examples of subroutines that cannot currently be accurately deparsed. Michael Because of the nature of Perl or because of a mistake in B::Deparse? Not completely sure. The problem is closures, because you end up having to figure out how to construct the right sharing of lexicals amongst the various coderefs you've discovered. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Re: fun with regex
On Dec 12, Abigail said: On Thu, Dec 12, 2002 at 12:48:11AM -0500, Jeff 'japhy' Pinyan wrote: On Dec 12, Jonathan E. Paton said: (my $sql = '--') =~ s/\A(\s+)(?{$::c = $^N})|^(??{$::c})//gm; all over SQL related source code then your head is on the block! While it's cool, and I'D use it, for readability purposes, might I suggest: $sql =~ /(\s*)/ and $sql =~ s/^$1//mg; The question was how to do it in one regex; the original poster already knew how to do it with two regexes. Yes, that's all well and good. Your one-regex solution is the way I would do it (with one regex too), but if you're going to use two regexes, I'd use my method. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ]
grep substitute
FWPers, Pretending your machine did not have e?grep, how concisely could you duplicate the GNUish -q (silent) functionality: stop scanning on first match and exit(0). If no match, exit(1). Here's something simple to start with: perl -n0777 exit !(/pattern/) Necessary Improvements: - concisely get the pattern from the command-line (e.g., pattern as $ARGV[0] and the file as $ARGV[1]) such that the syntax is more like grep (e.g., grep 'pattern' filename = perl -args 'pattern' filename)? Extra Credit: - is there a short way to do it without slurping the whole file? Any takers? Scott -- Scott Wiersdorf [EMAIL PROTECTED]
Re: grep substitute
On Fri, Dec 13, 2002 at 05:31:35PM -0700, Scott Wiersdorf wrote: FWPers, Pretending your machine did not have e?grep, how concisely could you duplicate the GNUish -q (silent) functionality: stop scanning on first match and exit(0). If no match, exit(1). Extra Credit: - is there a short way to do it without slurping the whole file? perl -n /pattern/ exit 1; END { exit !$? } Scott -- Scott Wiersdorf [EMAIL PROTECTED]
Re: Metaprogramming
Steffen == Steffen Mueller [EMAIL PROTECTED] writes: Steffen Okay, I admit to have relied on an overgeneralized interpretation of Steffen Randal's post about closures being a problem for B::Deparse. Steffen I *do*, however, remember B::Deparse failing to deparse some entries Steffen to the tpr04b golf contest which posed some trouble to my judging the Steffen entries. Those pieces of code qualify as pathological, I suppose. :) Let's see if this is the one: sub black_adder { my $constant = shift; sub { $constant + shift; } } my $to_deparse = black_adder(42); use B::Deparse; print \n, B::Deparse-new-coderef2text($to_deparse), \n; == { $constant + shift(@_); } Ayup. That's the one. *What* constant? :) And that was the first odd one I tried. I could probably construct weirder ones once that one is fixed. So, coderefs that have been closed, break. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!