Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Live and Die

by de_cristian_izer (Initiate)
on May 27, 2005 at 16:08 UTC ( #461122=note: print w/replies, xml ) Need Help??


in reply to Live and Die

So this one was tricky since it didn't run out of the box due to a problem with quote escaping in the exec ... So here is the solution, that we, a collective of rebel monks for CLEAN CODE have to offer :
Most of the steps are unclosed in {} , to add some obfu .

  • First of all we have a split on either @ARGV or on a long list of num ber if @ARGV is empty . The result goes into @_ (deprecated implicit split to @_ )

  • After this we shift an element that goes to $^ ( the fact that this variable has a meaning for perl formats is here for confusion ...)

    Then we initialize the hash %$^ with two values.Key 1 is the strange _/ sign and key 0 is the new line operator ! This is very tricky since it looks like an empty string but the fact that the carriage return is between the two quotes is taken into account !

  • Then we test (with the ternary operator ? : ) the value of $^ if it is 1 or 0 we print the corresponding value from that %$^ hash . If it is some other value we will print that number of spaces (use of x for strings).

  • At this point we join the list @_ , which has one less element since we shifted something from it .

    In the next block we do :

    {$^="'$^'"}
    This is done to protect the arguments passed to the exec and didn't work with perl 5.6 on windows and 5.005 solaris . So we did instead :
    {$^="\"$^\""}
    Now comes the call to this same script via exec, passing the shifted @_ as an argument and testing if there is more than one argument .

    At this point you see that this will either print _/ or spaces or new lines and it is the choice of the numbers in the initial list that gives the following result :

    _/ _/_/_/_/ _/_/_/_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/_/_/ _/_/_/_/ _/_/_/_/ _/ _/ _/ _/ _/ _/ _/ _/_/_/_/ _/ _/ _/ _/ _/
  • Rock on !

    ps : since it failed on our box could you tell us on what kind of OS and perl version did you run it ??

    Replies are listed 'Best First'.
    Re^2: Live and Die
    by cristian (Hermit) on May 27, 2005 at 19:37 UTC
      #!/usr/bin/perl package ::Job::Bug::Hack::CLEAN::CODE; sub present::a{ $_=(caller())[//-//]; $_=~s/:+/\nGood /g; "$_\n\n" } print a present;

    Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (3)
    As of 2022-05-25 23:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Do you prefer to work remotely?



      Results (91 votes). Check out past polls.

      Notices?