Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: multiple matches per line *AND* multiple capture groups per match by johngg
in thread multiple matches per line *AND* multiple capture groups per match by Special_K

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2024-04-18 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found