in reply to multiple matches per line *AND* multiple capture groups per match
You can use a ternary to push onto either the complete URL array or the filename array. To save space I have simplified the URLs and pattern but the principle would still hold for your data. Things would get more complicated if your URLs broke across lines.
$ perl -Mstrict -Mwarnings -MData::Dumper -e ' open my $xmlFH, q{<}, \ <<EOF or die $!; blarg http://a.b.co.uk/path/to/file.mp3 bloop http://x.y.com/stuff.mp3 blooble http://some.firm.com/downloads/glooble.mp3 sploffle EOF my $rx = qr{(?x) ( http:// .*? ( [^/]+ \.mp3 ) ) }; my( @comp, @fn ); my $xmlText = do { local $/; <$xmlFH>; }; push @{ $_ =~ m{^http://} ? \ @comp : \ @fn }, $_ for $xmlText =~ m{$rx}g; print Data::Dumper->Dumpxs( [ \ @comp, \ @fn ], [ qw{ *comp *fn } ] ); +' @comp = ( 'http://a.b.co.uk/path/to/file.mp3', 'http://x.y.com/stuff.mp3', 'http://some.firm.com/downloads/glooble.mp3' ); @fn = ( 'file.mp3', 'stuff.mp3', 'glooble.mp3' ); $
I hope this is helpful.
Update: Corrected unescaped dot in regex and added (?x) extended syntax to space things out for readability.
Cheers,
JohnGG
|
|---|