in reply to Re^4: Slurping file using regular expressions for array or variables
in thread Slurping file using regular expressions for array or variables
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.
|
|---|