SPUG: Regex multi-line question

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Tue Aug 3 17:02:10 CDT 2004


> I can do it easily enough with a while<> loop (or a
> parser) but I figure there is a more obfuscated
> solution that one of you can propose using one line.

This uses a while loop... but, frankly, I think you'll 
wind up in obfuscation hell without one:

--
Charles DeRykus

use strict;
use warnings;

# FORE...!! : golf course use only...   

{ local $/;  $_ = <DATA>; }

while ( m{  \G .*? <media\stype="(.*?)" 
               .*? <path>        (.*?) </path> 
               .*? <tarname>     (.*?) </tarname>  }xsg )  {

        my( $type,$path,$tar ) = ( $1, $2, $3); 
        print join( ", " => $type,$path,$tar), "\n"; 
}
__END__
<?xml version="1.0" encoding="UTF-8" ?>
<transfer>
<media type="Record">
  <server>MUSIC</server>
  <path>/home/woody/vinyl/Migration</path>
  <tarname>JB_Migration.tar</tarname>
</media>
<media type="CD">
  <server>MUSIC</server>
  <path>/home/woody/cd/Migration</path>
  <tarname>JB_Migration.tar</tarname>
</media>
<media type="TAPE">
  <server>MUSIC</server>
  <path>/home/woody/cass/Migration</path>
  <tarname>JB_Migration.tar</tarname>
</media>
</transfer>



More information about the spug-list mailing list