Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I often have a list where I need to do adjacent pairs.
my @trip = ("Chicago", "Saint Looey", "Joplin", "OKC", "Amarillo", " +Gallup", "Flagstaff", "Winona", "Kingman", "Barstow", +"San Bernandino", "LA" ); map { printf "%15s to %-15s\n", @trip[$_..$_+1] } 0..$#trip-1;

which emits:

Chicago to Saint Looey Saint Looey to Joplin Joplin to OKC OKC to Amarillo Amarillo to Gallup Gallup to Flagstaff Flagstaff to Winona Winona to Kingman Kingman to Barstow Barstow to San Bernandino San Bernandino to LA

If you did this often, you might want a pairs_overlapping function. Or, going with a generic version:

subsequence(length=>3, step=>1, list=>\@trip);

a function that returns an arbitrary list of adjacent elements, with an arbitrary step size.

As to the next bit, I think several good solutions have been shown by others.

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re: Fence vs. Posts by QM
in thread Fence vs. Posts by rodinski

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 studying the Monastery: (5)
As of 2024-04-25 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found