amazotron has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use Benchmark; my $testline = '<someelement a="123" bbb="rrr sss ttt" cccc="14 or 15" +>'; my $xmlregex = qr/(?:\s+(\w+)=\"(.*?)\")|(?:^\s*<(\w+))|(?:>\s*$)/; my $xmlregex1 = qr/^\s*<([^\s]+)(.*)>\s*$/; my $xmlregex2 = qr/\s+(\w+)="([^"]+)"/; my @lines = ($testline) x 5000; my @example = (); sub useregex2 { my @items = (); foreach my $line (@lines) { if ($line =~ /$xmlregex1/o) { my ($element,$attribs) = ($1,$2); @items = grep length, split(/$xmlregex2/, $attribs); } else { print "useregex2: malmformed XML in $line\n"; exit; } } } sub usesplit { foreach my $line (@lines) { my @items = split(/\s+/,$line); } } timethese (500, { 'useregex2' => \&useregex2, # 'useregex' => \&useregex, 'usesplit' => \&usesplit, });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: quickest way to parse pidgeon XML?
by CountZero (Bishop) on May 28, 2004 at 16:37 UTC | |
|
Re: quickest way to parse pidgeon XML?
by samtregar (Abbot) on May 28, 2004 at 18:31 UTC | |
by amazotron (Novice) on May 31, 2004 at 21:23 UTC | |
by samtregar (Abbot) on Jun 01, 2004 at 03:28 UTC | |
by amazotron (Novice) on Jun 01, 2004 at 14:24 UTC |