Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Mini Japh

by domm (Chaplain)
on Sep 06, 2002 at 07:28 UTC ( [id://195589]=note: print w/replies, xml ) Need Help??


in reply to Mini Japh

nice one!

SPOILER:

s iir ejkucsath  alnroetph eri;
unobfu: s//r ejkucsath  alnroetph er/;

Using i as a delimiter, you substitute nothing with the string "r ejkucsath alnroetph er" (BTW, this only works if you put a space between the s (or q, qq, etc) and the delimiter), thus putting the string in $_;

split$+

This splits the string in $_ on the value of $+ (Last Paren Match), which is undef. So we end up with the array @_ containing each letter of the string in $_ as an element.

print$_[$-++]until($-++>$#_);

This prints every other element of @_, starting with 0 (i.e. 0,2,4,6,8..). $- (default 0) is used as an array index, but it is incremented twice: One time in the until-test, and one time in the array-indexing itself. The printing stops when $- is greater then the number of elements in @_ ($#_)

print$_[$---]until($---<1);

Basically the same as the last line, only in the other direction. $- now points to the last element of @_. $- gets decremented twice, so now all odd numbers are printed (.. 7,5,3,1) until $- is smaller then 1.

And that's it.

One small comment on the last command: This works, too, and is shorter:

print$_[$---]while($---);

But in fact I like the symmetry more...

-- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-24 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found