Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How's your Perl? (II)

by ambrus (Abbot)
on Jul 22, 2004 at 13:55 UTC ( [id://376571]=note: print w/replies, xml ) Need Help??


in reply to How's your Perl? (II)

Spoilers:

1:

$foo = *bar; \$foo =~ /^[A-G]/ and print "Ok!\n";

7:

*foo = *1; !eval { ($foo) = $foo } and print "Ok\n";

6: I don't know weather this is cheating or not, but it does make the (updated) expression true:

*foo = *_; sub { \$foo[0] == \$foo[1] && !$[ and print "Ok\n"; } -> ($ +x, $x);

Update: a clean solution for 6:

sub{*foo=\@_}->($x,$x); \$foo[0] == \$foo[1] && !$[ and print "Ok!\n";

Update again: 2:

*foo = \substr(1,0,1); \$foo =~ /^[H-N]/ and print "Ok!\n";

Update: a wildcard solution for 3:

BEGIN{$^H{"qr"}=sub{""};$^H|=3<<16}; \$foo =~ /^\0/ and print "Ok!\n";

Update: I finally realized that I should have known 12 from the start: it was in last year's quiz.

$[ = 2; *| = *[; ($| = 1) == 2 and print "Ok!\n"; warn 0+$|;

Update: and here's an answer for 8, although you might take it as cheating as it requires an adittional option on the command line to be set.

perl -wde 'sub DB::DB { ++$foo==2 and die "break out the eval"; }; !ev +al { [ @foo ] } and print "Ok!\n"; '

Note that I'm not just executing the print Ok statement with some trick. The expression !eval { [ @foo ] } actually gets evaluated, but somehow an exception gets generated inside the eval, thus eval returns false.

Update: you can give the switch in the shebang line too. If you write this to a file and execute it with perl, it works.

#!perl -d sub DB::DB { ++$foo==2 and die "break out the eval"; }; !eval { [ @foo + ] } and print "Ok!\n";

Replies are listed 'Best First'.
Re^2: How's your Perl? (II)
by wog (Curate) on Jul 22, 2004 at 19:37 UTC
    You don't need any switches!

    BEGIN{$^P=0x22;sub DB::DB{++$foo==2 and die}}

    (I am pretty sure that is not the official solution, by the way, and it means that 8 does not need to exploit actual bugs.)

    updated: Oops, copied a wrong version initially. One character difference.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-23 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found