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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|