Note: After composing this question I realized I could use just one array to store references to anonymous arrays containing the three fields I'm interested in. Still, I'm curious to learn one or more ways to accomplish my original question.

In the code below, what is the "Perl way" to simultaneously push $1, $2, and $3 to the three arrays @ids, @urls, and @titles? That is, I'd like to learn a way to do this with just one assignment (unless the code would violate the Simplicity & Clarity (from "The Practice of Programming" by Kernighan and Pike).

Caveat: In actual use this code will be extracting about 20 sets of url/id/title from a scalar variable holding the contents of an approx. 250kb HTML file fetched via LWP. Which means: the regex will include the 'g' modifier so the 'while' loop won't be present.

#! perl -w use strict; use Data::Dump qw(dump); my (@urls, @ids, @titles) = (); while (<DATA>) { my ($url, $id, $title) = ($_ =~ m|<h6 class="project-title"><a hre +f="(/projects/(\d+)/.+?\?ref=discovery)" target="">(.+?)</a></h6>|o ) +; push @urls, $url; push @ids, $id; push @titles, $title; } dump @urls, @ids, @titles; __END__ <h6 class="project-title"><a href="/projects/1956727289/how-to-build-a +-spaceship?ref=discovery" target="">How To Build A Spaceship</a></h6> +<p class="project-byline">Rohan Sinha</p>

Thank you for your time.

Searched for donut and crumpit. Found donate and stumbit instead.

In reply to What is Perl way to simultaneously assign to three separate arrays? by CoVAX

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.