Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
"So in general, is it not possible to do a multi-array assignment in a single line, i.e.: (@a, @b) = <some_expression>"

That's correct with the syntax you're using there; however, you can do it with references. Here's a rather contrived example to demonstrate.

#!/usr/bin/env perl -l use strict; use warnings; my ($letters, $digits) = get_arrays(); print "Letters REF: $letters"; print "Letters: @$letters"; print for @$letters; print "Digits REF: $digits"; print "Digits: @$digits"; print for @$digits; sub get_arrays { my @three_letters = qw{A B C}; my @three_digits = qw{1 2 3}; return (\@three_letters, \@three_digits); }

Output:

Letters REF: ARRAY(0x7ff684047ad0) Letters: A B C A B C Digits REF: ARRAY(0x7ff684047938) Digits: 1 2 3 1 2 3

If you're unfamiliar with references, a good place to start is "perlreftut - Mark's very short tutorial about references". In the "The Rest" section, you'll find links to more detailed documentation on this topic.

-- Ken


In reply to Re^3: multiple matches per line *AND* multiple capture groups per match by kcott
in thread multiple matches per line *AND* multiple capture groups per match by Special_K

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 cooling their heels in the Monastery: (5)
As of 2024-04-19 20:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found