in reply to slow generation

These things never stop to stun me so here's my try at the decoding game :)

\@.=~/(?<=\w{3})(\w)(.(.))(7325,20)*/; @_=$1..$3.$3.$3;; @_=(' ',@_,0); 1055||13733*{0}.18^0.10964||12.0&&5437; open _, $0 ; do{ 7584, print$_[$1] while /(?<!\$)(\d+)[^\}]/g } while <_>
\@. is a reference to some undefined array named @.
it has a value of the form ARRAY(0x1824444)
On which you match and record the 4th letter with  (?<=\w{3})(\w) ;
Then you match  (.(.))
That's a regex record inside a record so $2 will hold the next two letter and $3 only the 6th, which is a ( .

Now $1..$3.$3.$3 ,as with the ".." operator, will create a list of all the letters from A to ((( . This will generate a list from A to ZZZ .
Interesting behavior, since 1- it ignores non letters and 2- it understands that it will iterate up to three letters words.
This list ends up in @_ with a space in front and a zero at the end.

Now for some calculous :

1055||13733*{0}.18^0.10964||12.0&&5437
returns 1055 , since it a first true in a short circuit. It does nothing else so it's just a line that sits here.

 open _,$0; opens the file itself ($0) into the _ filehandle.

While reading that filehandle we have each line in $_ ; on this we apply  /(?<!\$)(\d+)[^\}]/g

 (?<!\$)(\d+) will match a number but not (negative look behind) if it is preceded by a $ . This wont match things like $1 , $2 ...
That number will be recorded in $1 but only if it is not followed by a } or by a \ ( negated character class, the \ changes nothing ) .

The match is global and the while loop will run it over each line of the file.
Given the matching rules and the numbers present in the file, $1 will take these values :

  • 7325 and 20 from the first regexp
  • 0 from @_ = ( ' ', @_, 0)
  • 1055 13733 18 0 10964 12 0 5437 from that "useless" calculous line ;
  • 7584 from before the print .

    Each of these will be used to  print$_[$1] .

    And this is where it happens : that $_ is not coming from any of these while : it's a subscript from our previous @_ .

    @foo= 'A'..'ZZZ' ; @foo = (' ',@foo,0) ; print @foo[7325,20,0,1055,13733,18,0,10964,12,0,5437,7584] ;

    phew ... zlr .

  • Replies are listed 'Best First'.
    Re^2: slow generation
    by sh1tn (Priest) on Mar 05, 2005 at 16:57 UTC
      Absolutely right. In essence - the same:
      print ((' ','A'..'ZZZ')[7325,20,0,1055,13733,18,0,10964,12,0,5437,7584 +])
      Update: "slow generation" because of the list 'A'..'ZZZ' creation time.