I wanted to populate an anon array with stat from a file, with labels.... so..

#!/usr/bin/perl -w use strict; use List::MoreUtils qw(:all); use Smart::Comments; my @labels =qw(dev ino mode nlink uid gid rdev size atime mtime ctime +blksize blocks); my @stat = stat "/tmp"; my $stat = { zip @labels, @stat}; ### $stat

That works great. Prints out :

### $stat: {
###          atime => 1156789541,
###          blksize => 4096,
###          blocks => 32,
###          ctime => 1156791103,
###          dev => 64768,
###          gid => 0,
###          ino => 2684353,
###          mode => 17407,
###          mtime => 1156791103,
###          nlink => 15,
###          rdev => 0,
###          size => 12288,
###          uid => 0
###        }

But why declare the arrays in the fist place? ...

#!/usr/bin/perl -w use strict; use List::MoreUtils qw(:all); use Smart::Comments; my $stat = { zip qw(dev ino mode nlink uid gid rdev size atime mtime ctime blksize bl +ocks), ( stat '/tmp' ) }; # No! Don't like that! ### $stat

gives:

Type of arg 1 to List::MoreUtils::mesh must be array (not list) at tmp +.pl line 16, near "} }"

I can't figure out the correct way/syntax to have zip/mesh interpret these as arrays :( - Array? Not list? does this mean we must predeclare as an array?


In reply to using List::MoreUtils::zip with anon arrays ? by leocharre

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.