http://www.perlmonks.org?node_id=302421


in reply to How's your Perl?

My answers without looking at existing ones...
  1. 1: I've seen this in chatter mentioned by tye, but the trick slips my memory at the moment. :-(
  2. 2: {foo;redo} # See RE: My favorite looping mechanism in Perl is:
  3. 3: This is actually two questions
    • My first thought was pseudohashes but pseudohashes are deprecated and IIRC removed in 5.8.0. Then it was $foo = \*bar; $$foo->[1] = $$foo->{1} = "hello" Hrm, Pseudohashes are allowed? OK then, $x = [{1=>1}, "hi"]; Your test will pass, albeit with an ugly scalar for each, but they are not accidentally the same, they are both references to the same string.
    • Trivial with overload, but I am not sure if that is breaking your rules. OK, sub bar {$bar[$_[0]]} $foo = \*bar; $bar[1]="hi";, that isn't a different idea than what I originally did for 3a, but it works. UPDATE 3 I don't know how to do this after all.
  4. 4: dump # So sorry, did you want solutions that aren't supposed to core dump? :-P
  5. 5: my $static if 0; # See Tie::Static for my opinion on this...
  6. 6: Is it cheating for me to use a module but not write one?
    # Reformat to one line if you want -e use overload qq("")=>sub{"same"}; $x = bless \$foo; $y = bless \$bar; $$x= "x"; $$y= "x";
    UPDATE You do this like so: $x = do {local *foo}; $y = *foo; $foo = "hello";
  7. 7: UPDATE 2 $foo = *STDOUT{IO};
  8. 8: *x = \$|
  9. 9: This is actually two questions UPDATE Um, in the questions shouldn't q be qq everywhere? If you don't let $$foo interpolate, it shouldn't matter what is in it...
    • UPDATE 3 $foo = \$!; $!=1; UPDATE 5 Oops, this is wrong. I should test these answers a little, ya think?
    • 9b
  10. 10
  11. 11: UPDATE 4 Put sub CORE'GLOBAL'glob{""} at the END of your code. Location matters, this code has to be seen by the Perl interpreter after Perl has seen some evidence that it needs to load File::Glob (which will overwrite us).
Bonus
I, um, would have gotten more if I didn't have to go to work. Yeah, that's the ticket...

UPDATE Minor fixes. BTW I should add that while I am not terribly bad at this kind of trivia, I think that focussing on it is a horrible mistake.

UPDATE 2 Answered 7.

UPDATE 3 Took time out for 9a. I had been thinking about 10, but because nobody else bothers to hide their answers, I saw mtye's version already. 3b has me puzzled again (see Roy Johnson's note).

UPDATE 4 Added a solution to problem 11.

UPDATE 5 Admit my mistake in problem 9a. I think that I'll admit to not knowing stupid Perl trivia that well these days. Particularly since nobody else seems to be trying these too hard. Also note that my solution to problem 11 can't be placed in front with glob-assign without adding a semi-colon, which puts you over the character limit.