line 1485 -- if ($rule =~ s/\s*\bonly\(([^\)]+)\)//) { ++ if ($rule =~ s/^((?:(?:no\s+)?content\s+)?by\s+(\S+))\s+only\(([^\)]+)\)$/$1/) { ++ my %only; ++ $only{$2} = undef; ++ @only{split /\s*,\s*/, $3} = (); ++ foreach (keys %$data) { ++ delete $data->{$_} unless exists $only{$_}; ++ } ++ } elsif ($rule =~ s/\s*\bonly\(([^\)]+)\)//) { #### Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Folder\shell\CmdHere] @="&Command Prompt Here" [HKEY_CLASSES_ROOT\Folder\shell\CmdHere\Command] @="C:\\WINNT\\system32\\cmd.exe /k cd \"%1\"" #### use strict; use XML::Rules; my $parser = XML::Rules->new( rules => [ _default => 'content', 'other, Author' => 'as array', AuthorList => sub { return Authors => $_[1]->{Author} }, PubmedArticle => 'pass', ], stripspaces => 7, handlers => { Start => sub { my ( $Parser, $Element , %Attr) = @_; print "$Element\n"; # you can modify the elements of @_ for(my $i = 2;$i <= $#_; $i+=2) { $_[$i] = lc($_[$i]) }; #print "(@_)\n"; # and even add attributes push @_, blah => 666; }, Comment => sub {my ($Parser, $String) = @_; print "Found a comment: $String\n"}, } ); my $data = $parser->parse( \*DATA); use Data::Dumper; print Dumper($data); print "Authors:\n"; foreach my $author (@{$data->{Authors}}) { print "$author->{ForeName} $author->{LastName}\n"; } __DATA__ van Beilen J B JB Penninga D D Witholt B B #### $string = "xxabgi"; $_ = "abcghis"; print "Orig: \$string='$string'\t\$_='$_'\n"; $string =~ (0 ? y/a-c/d-f/ : y/g-i/j-l/); print "Changed: \$string='$string'\t\$_='$_'\n"; print "\n"; $string = "xxabgi"; $_ = "abcghis"; print "Orig: \$string='$string'\t\$_='$_'\n"; $string =~ (1 ? y/a-c/d-f/ : y/g-i/j-l/); print "Changed: \$string='$string'\t\$_='$_'\n"; #### my $xml = <<'*END*'; Valka s mloky Karel Capek It's really something and I have to underline it. Predtucha Pujmanova It's really a stupid pointless book. Confront this one. And don't read this one please! *END* my $parser = new XML::Rules ( rules => [ _default => 'content', u => sub {my $str = $_[1]->{_content}; $str =~ tr/ /_/; return '_'.$str.'_'}, b => sub {my $str = $_[1]->{_content}; return '*'.$str.'*'}, link => sub { qq{$_->{_content}} }, book => sub { my $desc = $_[1]->{description}; $desc =~ s/\n/\n\t/g; print "Book: $_[1]->{name}\nAuthor: $_[1]->{author}\nDescription: $desc\n\n"; }, ], ); $parser->parsestring($xml); #### my $xml = <<'*END*'; Jane Luser JLuser@bogus.com
Washington st. Old Creek The US bleargh
123-456-7890 663-486-7890 663-486-7000
John Other JOther@silly.com
Grant's st. New Creek Canada sdrysdfgtyh degtrhy degtrhy werthywerthy drthyu
663-486-7891
*END* my $parser = new XML::Rules ( rules => [ _default => sub {$_[0] => $_[1]->{_content}}, 'fname,lname' => sub {$_[0] => $_[1]->{_content}}, bogus => undef, address => sub {address => "$_[1]->{street}, $_[1]->{city} ($_[1]->{country})"}, phone => sub {$_[1]->{type} => $_[1]->{_content}}, # let's use the "type" attribute as the key and the content as the value phones => sub {delete $_[1]->{_content}; %{$_[1]}}, # remove the text content and pass along the type => content from the child nodes person => sub { # lets print the values, all the data is readily available in the attributes print "$_[1]->{lname}, $_[1]->{fname} <$_[1]->{email}>\n"; print "Home phone: $_[1]->{home}\n" if $_[1]->{home}; print "Office phone: $_[1]->{office}\n" if $_[1]->{office}; print "Fax: $_[1]->{fax}\n" if $_[1]->{fax}; print "$_[1]->{address}\n\n"; return; # the tag is processed, no need to remember what it contained }, ] ); $parser->parsestring($xml);