Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Fence vs. Posts

by QM (Parson)
on Jun 08, 2018 at 09:57 UTC ( #1216179=note: print w/replies, xml ) Need Help??

in reply to Fence vs. Posts

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.

Quantum Mechanics: The dreams stuff is made of

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2021-03-02 21:54 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (64 votes). Check out past polls.