in reply to Re: Matching specific strings (are subs a good idea?)
in thread Matching specific strings (are subs a good idea?)
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $text_file = shift; open my $In, '<', $text_file or die $!; my $extract = join '\s+(.*?)\s*', qw( FirstName LastName Email BirthDa +te $ ); $extract = qr/$extract/; my %birthday; while (<$In>) { my ($first, $last, $email, $bdate) = /$extract/; $birthday{$email} = $bdate; } while (my $xml_file = shift) { my $dom = 'XML::LibXML'->load_xml(location => $xml_file); my $email = $dom->findvalue('/contractor/person/email'); unless (exists $birthday{$email}) { warn "No birthday for $email!\n"; next } my $person = $dom->find('/contractor/person'); my $bday = $person->[0]->addChild($dom->createElement('birthday')) +; $bday->appendText($birthday{$email}); $dom->toFile($xml_file); }
See XML::LibXML for documentation.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|