PUSH? We don't need no stinkin' PUSH!

#!/usr/bin/perl use strict; use warnings; $_ = do { local $/; <DATA> }; my @AoH = map +{ interface => /^(\w+):\s+(flags)=(\S+)/, /(inet|ether|media|status):? (\S+)/g }, /.+?(?=^\w|\z)/gms; use Data::Dump 'pp'; pp \@AoH; __DATA__ lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP> inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 nd6 options=201<PERFORMNUD,DAD> gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether f4:0f:24:29:df:4d inet6 fe80::1cb5:1689:1826:cc7b%en0 prefixlen 64 secured scopeid 0 +x4 inet 10.176.85.19 netmask 0xffffff00 broadcast 10.176.85.255 nd6 options=201<PERFORMNUD,DAD> media: autoselect status: active en1: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500 options=60<TSO4,TSO6> ether 06:00:58:62:a3:00 media: autoselect <full-duplex> status: inactive p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304 ether 06:0f:24:29:df:4d media: autoselect status: inactive

Outputs:

[ { flags => "8049<UP,LOOPBACK,RUNNING,MULTICAST>", inet => "127.0.0.1", interface => "lo0", }, { flags => "8010<POINTOPOINT,MULTICAST>", interface => "gif0" }, { ether => "f4:0f:24:29:df:4d", flags => "8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST>", inet => "10.176.85.19", interface => "en0", media => "autoselect", status => "active", }, { ether => "06:00:58:62:a3:00", flags => "963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX>", interface => "en1", media => "autoselect", status => "inactive", }, { ether => "06:0f:24:29:df:4d", flags => "8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST>", interface => "p2p0", media => "autoselect", status => "inactive", }, ]

( I like Data::Dump better :)


In reply to Re: Generation of Array of hashes by reading a file by tybalt89
in thread Generation of Array of hashes by reading a file by pr33

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.