in reply to Delimitiations
Better than caffeine! (Almost ;-) Thanks!# # Declare three arrays and populate two of them. # my @a; my(@x) = (10, 19, 0, 14, 20, 5, 0, 5, 12, 8, 3, 5); my(@y) = (21, 20, 1, 15, 8, 18, 16, 18, 0, 1, 11, 18); # # Set $_ to a string that looks suspiciously like code. # (Use ' instead of q{} to make the string stand out better.) # $_ = 'map{s@a,g@y;s@a,g@x;}@y;'; # # Change the letter s to 'unshift', and g to 'pop' + newline # (Use a more conventional / instead of ; to separate parts of s.) # s/s/unshift/g; s/g/pop\n/g; # $_ now looks like # map{unshift@a,pop # @y;unshift@a,pop # @x;}@y; # # or equivalently # # map { unshift(@a, pop @y); unshift(@a, pop @x) } @y; # # which if executed, would populate @a with alternating elements # of @x and @y (@x and @y would be empty, but that's immaterial). # # @a = qw(10 21 19 20 0 1 14 15 20 8 5 18 0 16 5 18 12 0 8 1 3 11 5 +18) # # Note that with a simple encoding of 1 = a, 2 = b, ..., # (with 0 = space) this is: # # @a = (qw(j u s t), ' ', qw(a n o t h e r) # , ' ' , qw(p e r l) , ' ' , qw(h a c k e r)) # # Execute the map, populating @a eval; # Now set $_ to this literal string # # print join'',(' ','a'..'z')[ # # followed by all the elements of @a, separated by commas, # and a closing square bracket. # The expression argument to join is now an array slice: # just those elements of (' ', 'a', ... 'z') # that are indexed by members of @a. # # (Using more conventional " instead of qs s and ' instead of q; ;.) # $_ = "print join'',(' ','a'..'z')[" . join(',', @a) . '];'; # Create the slice, join the elements and print it. eval;
|
---|