The code below addreses itself solely to your question about how " the two captures can be sent to the arrays.." It is inappropriate and inadqequate for production use in a variety of ways:
- It offers no illustration of how to process multiple lines of your source data
- it makes no attempt to ensure that your customer can identify a particular IP with its associated MAC address (particularly when the source data is borked)
and, very important,
- its design is (intentionally) flawed, in that it has no plan to deal with incomplete data, failed matches, and the like, or numerous other problems which may challenge you
my $text='abc-123';
if ( $text =~ /(abc)-(\d{3})/) {
say "\$1 is $1"; # rather than printing the matches, as this doe
+s,
say "\$2 is $2"; # you could push the matches from each iteratio
+n
# over the full text to two arrays
}
# i.e., something like...
push @IPs, $1;
push @MACs, $2;
}
Almost all (good) introductions to Perl will teach you how to use push very early in the game (again, read the docs!). And had you taken the advice to read the docs on regexen, the code below should have been on the tip of your tongue (or fingertips).
I may be wrong, of course, but you seem to me to be trying to skip over the sometimes difficult but essential task of getting the basics down pat... so I say again, read the documents. This site has many very fine tutorials; so too, do may colleges and universities (and often those are accessible online at no charge). And if investing in a book is within your means, run -- don't walk -- to your nearest good bookstore and buy a copy of learning Perl.
Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
- code
- verbatim error and/or warning messages
- a coherent explanation of what "doesn't work actually means.
| [reply] [d/l] [select] |