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

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