Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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$_.$/}

In reply to Re: Mini Japh by domm
in thread Mini Japh by kelan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found