in reply to Re: Fence vs. Posts
in thread Fence vs. Posts

you wrote: "I would have used is map"

 {@arr[$_,$_+1]} 0..$#arr-1

Thanks! this is just the sort of thing I was seeking . . . new knowledge. I was unaware of $_+1 . Also later you noted:

"The reason your creation of the %info hash isn't working in the original code is that you're not dereferencing the pairs."

Nice, I thought I was close to getting it to work, this did the trick.

As the lyric goes . . . I am hip to your timely tip!! Thannk again.

However, the while pare of the code below looks like Devilry I will have to spend more time with it to figure it out

local $_ = join "\n", @trip; printf "%15s to %-15s\n", $1, $2 while /^(.*)\n(?=(.*))/gm;

Replies are listed 'Best First'.
Re^3: Fence vs. Posts
by Veltro (Hermit) on Jun 09, 2018 at 15:59 UTC

    Hi rodinski,

    I'll try to explain that last one:

    local $_ = join "\n", @trip; printf "%15s to %-15s\n", $1, $2 while /^(.*)\n(?=(.*))/gm;

    Let's remove the while for a moment and see what happens:

    my $test = "Chicago Saint Looey Joplin OKC Amarillo Gallup Flagstaff Winona Kingman Barstow San Bernandino LA" ; if ( $test =~ /^(.*)\n(?=(.*))/gm ) { printf "%15s to %-15s\n", $1, $2 ; } __END__ Chicago to Saint Looey

    (.*) = Chicago

    \n = enter

    (?=pattern) = Look around assertion. It is used to look ahead after the enter without changing the position where the last match ended. This is done so that the last arrival location becomes the depart location in the next search. https://perldoc.perl.org/perlre.html#Extended-Patterns

    (.*) = Saint Looey

    g = is in this case used to change the position where the last match ended. If you leave it out, you get a never ending loop (it will match the first found text over and over again) edit:See https://perldoc.perl.org/perlrequick.html#More-matching

    m = Treat string as multiple lines

Re^3: Fence vs. Posts
by rodinski (Novice) on Jun 14, 2018 at 13:15 UTC

    Now that I have had time to look at this:

    {@arr[$_,$_+1]} 0..$#arr-1

    Pardon me restating the obvious here.

    There is no new functionality that I was unaware of. In this case $_ is an integer and you are just incrementing it. I was somehow originally thinking you where feeding the block a list of cities. This is still good stuff and I appreciate it.

    I had started reading about the routines available in List::Utils and had dealing with the list values in my head. Looping over the indices may make more seance in this case.