[26676] in Perl-Users-Digest
Perl-Users Digest, Issue: 8783 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 21 03:05:35 2005
Date: Wed, 21 Dec 2005 00:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 21 Dec 2005 Volume: 10 Number: 8783
Today's topics:
My Regexp XML Parser -> Structured Perl Data, Cut & Pa robic0
Re: newbie ques <sdn.girths00869@zoemail.net>
Re: Picking Up Perl <comdog@panix.com>
Re: Recursively Parsing through multipart messages use <admin@ycdemocrats.org>
Re: split by word using | as delimiter <someone@example.com>
Re: split by word using | as delimiter <sdn.girths00869@zoemail.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Dec 2005 23:59:06 -0800
From: robic0
Subject: My Regexp XML Parser -> Structured Perl Data, Cut & Paste Version, No Module's (Vol I)
Message-Id: <a51iq19s2dudmp4adosvp1u19otjhf3ete@4ax.com>
This post is in response to someone who asked for help trying to
parse xml into a data structure. The poster couldn't install
XML::Parser or XML::Simple. I replied a few times with some
partial code. Good to my word, here is the core of a cut & paste
non-Perl-module based, raw, robust data xml parser into Perl
data structures. Its about 140 lines of code. I imagine its
about 3 times faster than the XML parsers out there, didn't time
it. It doesen't use the overhead of SAX or nodes.
This installment is released prematurely without the fancy
XML::Simple options yet. This is a typical "force array"
version (see the sub's below). I wanted to wait until tommorow
to post this but, I already know how to do it but don't have the
time tonight, however this is fairly final, and so I release
it with the understanding that its shortcomings will be fixed
in a day or so.
I've spent 4 days on this. You have to read between the lines
to insert your xml file open or just cut and paste your xml
to $gabage1. I've left that part up to you. The output
and data are legitimate. It won't look like XML:Simple
in the default settings. I maintaine a root here and some other
things. However, I will post a mod tommorow. The output and
parsing is completely legitimate. The parsing is probably
much faster than the modules on CPAN.
Let me know if you have any suggestions for improvement.
I want to keep it under 200 lines for a complete cut & paste
solution. It doesen't use any parser out there. Its parser
is built in. I don't think this method is used anywhere
in the XML world, you may want to check for possible multiple
speed enhancement.
Posting changes tommorow on this.
Contact info:
email: robic0-AT-yahoo.com
========================================================
use strict;
use warnings;
use Data::Dumper;
open DATA "datafile" or die "can't open datafile...";
my $gabage1 = <DATA>;
close DATA;
my @xml_files = ($gabage1);
my $debug = 0;
my $rmv_white_space = 1;
## -- XML start & end regexp substitution delimeter chars --
## match side , substitution side
## -----------------------/-------------------------
my @S_dlim = ('\[' , '['); # use these for reading (debug)
my @E_dlim = ('\]' , ']');
#my @S_dlim = (chr(140) , chr(140)); # use these for production
#my @E_dlim = (chr(141) , chr(141));
for (@xml_files)
{
if ($rmv_white_space) {
s/>[\s]+</></g;
s/[\s]+</</g;
s/>[\s]+/>/g;
}
print "\n",'='x30,"\n$_\n\n" if ($debug);
my $ROOT = {}; # container
my ($last_cnt, $cnt, $i) = (-1, 1, 0);
# should only need 2 iterations max, but wth
while ($cnt != $last_cnt && $i < 20)
{
$last_cnt = $cnt;
## <?XML-Version ?> , have to check the format of '<?'
while (s/<\?([^<>]*)\?>//i) {} # to void xml
versioning
# while (s/<\?([^<>]*)\?>/$S_dlim[1]$cnt$E_dlim[1]/i) {
print "$cnt <$1> = \n" if ($debug); $cnt++}
## <!-- Comments -->
# while (s/<!--([^<>]*)-->//i) {} # to void comments
while (s/<!--([^<>]*)-->/$S_dlim[1]$cnt$E_dlim[1]/i) {
print "$cnt <!-- --> = $1\n" if ($debug);
$ROOT->{$cnt} = { comment => $1 };
$cnt++;
}
# Comments, need to have "anything but <!-- nor -->
here" (revisit)
# while
(s/<!--([^(<!--)^(-->)]*)-->/$S_dlim[1]$cnt$E_dlim[1]/i) { print "$cnt
<!-- --> = $1\n" if ($debug); $cnt++}
## <Tag/> , no content
while
(s/<([0-9a-zA-Z]+)\/>/$S_dlim[1]$cnt$E_dlim[1]/i) {
print "$cnt <$1> = \n" if ($debug);
$ROOT->{$cnt} = { $1 => '' };
$cnt++;
}
## <Tag Attributes/> , no content
while (s/<([0-9a-zA-Z]+)([ ]+[0-9a-zA-Z]+[ ]*=[
]*"[^<]*")+[ ]*\/>/$S_dlim[1]$cnt$E_dlim[1]/i) {
print "$cnt <$1> = attr: $2\n" if ($debug);
$ROOT->{$cnt} = { $1 => getAttrHash($2) };
$cnt++;
}
## <Tag> Content </Tag>
while
(s/<([0-9a-zA-Z]+)>([^<]*)<\/\1>/$S_dlim[1]$cnt$E_dlim[1]/i) {
print "$cnt <$1> = $2\n" if ($debug);
my $unknown = '';
if (length($2) > 0) {
my ($key); my $hcontent =
getContentHash($2, $ROOT);
if (keys (%{$hcontent}) > 1) {
$unknown = $hcontent;
}
else { ($key,$unknown) = each
(%{$hcontent}); }
}
$ROOT->{$cnt} = { $1 => $unknown };
$cnt++;
}
## <Tag Attributes> Content </Tag>
while (s/<([0-9a-zA-Z]+)([ ]+[0-9a-zA-Z]+[ ]*=[
]*"[^<]*")+[ ]*>([^<]*)<\/\1>/$S_dlim[1]$cnt$E_dlim[1]/i) {
print "$cnt <$1> = attr: $2, content: $3\n" if
($debug);
my $hattrib = getAttrHash($2);
my $hcontent = getContentHash($3, $ROOT);
while (my ($key,$val) = each (%{$hcontent})) {
$hattrib->{$key} = $val;
}
$ROOT->{$cnt} = { $1 => $hattrib };
$cnt++;
}
$i++ if ($last_cnt != $cnt);
}
if (/<|>/) {
print "($i) XML problem, malformed, syntax or tag
closure:\n$_";
} else {
print "$i itterations\n\n";
#print Dumper($ROOT);
my $outer_element = $cnt-1;
if (exists $ROOT->{$outer_element}) {
my $tmp = {};
%{$tmp} = %{$ROOT->{$outer_element}};
print Dumper($tmp);
}
}
}
##
sub getAttrHash
{
my $attstr = shift;
my $ahref = {};
return $ahref unless (defined $attstr);
while ($attstr =~ s/[ ]*([0-9a-zA-Z]+)[ ]*=[ ]*"([^=]*)"[
]*//i) {
$ahref->{$1} = $2;
}
return $ahref;
}
##
sub getContentHash
{
my ($attstr,$hStore) = @_;
my $ahref = {};
return $ahref unless (defined $attstr && defined $hStore);
my @ary = ();
while ($attstr =~
s/([^<$S_dlim[0]$E_dlim[0]]+)|$S_dlim[0]([\d]+)$E_dlim[0]//i) {
if (defined $1) {
push (@ary, $1);
}
elsif (defined $2 && exists $hStore->{$2}) {
my ($key,$val) = each (%{$hStore->{$2}});
# here, force array is in effect (aka: simple)
# (this will be modified in a day or so)
################
if (exists $ahref->{$key})
{
#print "getChash - $key\n";
push (@{$ahref->{$key}}, $val);
} else {
$ahref->{$key} = [$val];
# $ahref->{$key} = $val;
}
################
}
}
if (scalar(@ary) == 1) {
$ahref->{'content'} = $ary[0];
} elsif (scalar(@ary) > 1) {
$ahref->{'content'} = [@ary];
}
return $ahref;
}
__END__
$VAR1 = {
'document' => {
'WMSNameSpaceVersion' => '2.0',
'comment' => [
' Control Protocol ',
' Data Protocol ',
' Feedback Protocol ',
' Network Source '
],
'node' => [
{
'opcode' => 'create',
'comment' => [
' Object Store
'
],
'name' => 'Control Protocol',
'node' => [
{
'opcode' =>
'create',
'comment' => [
'
RTSP ',
'
Sessionless Multicast '
],
'name' =>
'Object Store',
'node' => [
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'RTSP',
'node' => [
{
'opcode' => 'create',
'value' => '{308786f0-8b15-11d2-b25f-006097d2e41e}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'RTSP,RTSPA,RTSPT,RTSPU,RTSPM',
'name' => 'Protocol',
'type' => 'string'
}
]
}
]
},
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'Sessionless Multicast',
'node' => [
{
'opcode' => 'create',
'value' => '{f9377800-f38d-11d2-b26c-006097d2e41e}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'MCAST,RTP',
'name' => 'Protocol',
'type' => 'string'
}
]
}
]
}
]
},
{
'opcode' =>
'create',
'name' =>
'Shared Properties'
}
]
},
{
'opcode' => 'create',
'comment' => [
' Object Store
'
],
'name' => 'Data Protocol',
'node' => [
{
'opcode' =>
'create',
'comment' => [
'
RTP ',
'
RTP/ASF ',
'
RTP/AVP ',
'
RTP/FEC ',
'
RTP/WMS-FEC '
],
'name' =>
'Object Store',
'node' => [
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'RTP',
'node' => [
{
'opcode' => 'create',
'value' => '{cbfb2e20-ab7b-11d2-b261-006097d2e41e}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'x-asf-pf',
'name' => 'Format',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => 'RTP/AVP',
'name' => 'Protocol',
'type' => 'string'
}
]
}
]
},
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'RTP/ASF',
'node' => [
{
'opcode' => 'create',
'value' => '{149a44be-dc14-4e94-9cb0-c0268e77df9e}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'x-asfv2-pf,x-asfv2-grp-pf,x-asfv2-frag-pf',
'name' => 'Format',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => 'RTP/AVP',
'name' => 'Protocol',
'type' => 'string'
}
]
}
]
},
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'RTP/AVP',
'node' => [
{
'opcode' => 'create',
'value' => '{d7335e2e-62eb-4ad0-96cd-b31c9d0f9f85}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'PCMU,L8,L16,MPA,G726-24,G726-40',
'name' => 'Format',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => 'RTP/AVP',
'name' => 'Protocol',
'type' => 'string'
}
]
}
]
},
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'RTP/FEC',
'node' => [
{
'opcode' => 'create',
'value' => '{02DEFE42-F8FC-11d2-8670-00C04F6890ED}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'parityfec',
'name' => 'Format',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => 'RTP/AVP',
'name' => 'Protocol',
'type' => 'string'
}
]
}
]
},
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'RTP/WMS-FEC',
'node' => [
{
'opcode' => 'create',
'value' => '{EDAB8E6B-746C-40db-A885-9E4A9EEF27A2}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'wms-fec',
'name' => 'Format',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => 'RTP/AVP',
'name' => 'Protocol',
'type' => 'string'
}
]
}
]
}
]
},
{
'opcode' =>
'create',
'name' =>
'Shared Properties'
}
]
},
{
'opcode' => 'create',
'comment' => [
' Object Store
'
],
'name' => 'Feedback Protocol',
'node' => [
{
'opcode' =>
'create',
'comment' => [
'
RTCP '
],
'name' =>
'Object Store',
'node' => [
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'RTCP',
'node' => [
{
'opcode' => 'create',
'value' => '{ecfddc81-184e-11d3-ae84-00a0c95ec3f0}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'x-wms-rtx',
'name' => 'Format',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => 'RTP/AVP',
'name' => 'Protocol',
'type' => 'string'
}
]
}
]
}
]
},
{
'opcode' =>
'create',
'name' =>
'Shared Properties'
}
]
},
{
'opcode' => 'create',
'comment' => [
' Object Store
',
' Shared
Properties '
],
'name' => 'Network Source',
'node' => [
{
'opcode' =>
'create',
'comment' => [
'
WMS Http Network Source ',
'
WMS Mms Network Source ',
'
WMS Msbd Network Source ',
'
WMS Network Source '
],
'name' =>
'Object Store',
'node' => [
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'WMS Http Network Source',
'node' => [
{
'opcode' => 'create',
'value' => '{566A2EFF-5651-4020-AC1A-EB48E4571EA3}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'HTTP',
'name' => 'Source Type',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x50',
'name' => 'DefaultHttpServerPort',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x1bb',
'name' => 'DefaultHttpServerSSLPort',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x8',
'name' => 'PacketBuffers',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'EnableHTTP1_1',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x1e',
'name' => 'OpenTimeout',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x64',
'name' => 'SecondSegmentTimeout',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '',
'name' => 'ControlAdapter',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x55',
'name' => 'PercentBWUsageForAccelStreaming',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x3',
'name' => 'Proxy Setting',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '',
'name' => 'ProxyHostName',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x50',
'name' => 'ProxyPort',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'ProxyBypassForLocal',
'type' => 'int32'
}
]
}
]
},
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'WMS Mms Network Source',
'node' => [
{
'opcode' => 'create',
'value' => '{DCF6C8B2-F6C0-461b-82DA-35945EADF54A}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'MMS,MMST,MMSU',
'name' => 'Source Type',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x6db',
'name' => 'DefaultServerPort',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x4',
'name' => 'MaxReadHeaderRetries',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x8',
'name' => 'PacketBuffers',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'DropProb',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'DropGracePeriod',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'FirstDropGracePeriod',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'DropBurstDuration',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'PacketPairDropProb',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x2',
'name' => 'NackAlgorithm',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'NackRateMultiplier',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x5dc',
'name' => 'NackBurst',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x3e8',
'name' => 'NackTraceInterval',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'NackRetry',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'IgnoreServerVersion',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'EnableMmsDistribution',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'AssertStrangeErrors',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x5a',
'name' => 'InactivityTimeout',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x20',
'name' => 'OpenTimeout',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x55',
'name' => 'PercentBWUsageForAccelStreaming',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '',
'name' => 'FunnelAdapter',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '',
'name' => 'ControlAdapter',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'Proxy Setting',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '',
'name' => 'ProxyHostName',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x6db',
'name' => 'ProxyPort',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'ProxyBypassForLocal',
'type' => 'int32'
}
]
}
]
},
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'WMS Msbd Network Source',
'node' => [
{
'opcode' => 'create',
'value' => '{FB74F625-7D25-4455-B840-7B870B5B9322}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'ASFM',
'name' => 'Source Type',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x8',
'name' => 'PacketBuffers',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'DropProb',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'DropGracePeriod',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'FirstDropGracePeriod',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'DropBurstDuration',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x3a98',
'name' => 'McastTimeout',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'EnableIGMPv3',
'type' => 'int32'
}
]
}
]
},
{
'opcode' => 'create',
'comment' => [
' Properties '
],
'name' => 'WMS Network Source',
'node' => [
{
'opcode' => 'create',
'value' => '{ad763fa6-3b90-41ab-bd44-4f832beee55f}',
'name' => 'CLSID',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'Enabled',
'type' => 'int32'
},
{
'opcode' => 'create',
'name' => 'Properties',
'node' => [
{
'opcode' => 'create',
'value' => 'RTSP,XSDP,RTP,RTSPA,RTSPT,RTSPU,RTSPM',
'name' => 'Source Type',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'EnableATM',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'MaximumMTU',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x14',
'name' => 'FirewallTimeout',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x1e',
'name' => 'OpenTimeout',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'RtxDropProb',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'DropProb',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'DropGracePeriod',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'FirstDropGracePeriod',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'DropBurstDuration',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'PacketPairDropProb',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x2',
'name' => 'NackAlgorithm',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'NackRateMultiplier',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x5dc',
'name' => 'NackBurst',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x3e8',
'name' => 'NackTraceInterval',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x1',
'name' => 'NackRetry',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'BurstProtection',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'EmulateNetworkDisconnect',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'AssertStrangeErrors',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x55',
'name' => 'PercentBWUsageForAccelStreaming',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'Proxy Setting',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '',
'name' => 'ProxyHostName',
'type' => 'string'
},
{
'opcode' => 'create',
'value' => '0x22a',
'name' => 'ProxyPort',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x0',
'name' => 'ProxyBypassForLocal',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x3e8',
'name' => 'PktGracePeriodAtEOSForBPP',
'type' => 'int32'
},
{
'opcode' => 'create',
'value' => '0x9c4',
'name' => 'PktGracePeriodAtEOSForODP',
'type' => 'int32'
}
]
}
]
}
]
},
{
'opcode' =>
'create',
'name' =>
'Shared Properties',
'node' => [
{
'opcode' => 'create',
'name' => 'Local'
}
]
}
]
}
]
}
};
__DATA__
<document WMSNameSpaceVersion="2.0">
<node name="Control Protocol" opcode="create" >
<node name="Object Store" opcode="create" >
<node name="RTSP" opcode="create" >
<node name="CLSID" opcode="create" type="string"
value="{308786f0-8b15-11d2-b25f-006097d2e41e}" />
<node name="Enabled" opcode="create" type="int32" value="0x1"
/>
<node name="Properties" opcode="create" >
<node name="Protocol" opcode="create" type="string"
value="RTSP,RTSPA,RTSPT,RTSPU,RTSPM" />
</node> <!-- Properties -->
</node> <!-- RTSP -->
<node name="Sessionless Multicast" opcode="create" >
<node name="CLSID" opcode="create" type="string"
value="{f9377800-f38d-11d2-b26c-006097d2e41e}" />
<node name="Enabled" opcode="create" type="int32" value="0x1"
/>
<node name="Properties" opcode="create" >
<node name="Protocol" opcode="create" type="string"
value="MCAST,RTP" />
</node> <!-- Properties -->
</node> <!-- Sessionless Multicast -->
</node> <!-- Object Store -->
<node name="Shared Properties" opcode="create" />
</node> <!-- Control Protocol -->
<node name="Data Protocol" opcode="create" >
<node name="Object Store" opcode="create" >
<node name="RTP" opcode="create" >
<node name="CLSID" opcode="create" type="string"
value="{cbfb2e20-ab7b-11d2-b261-006097d2e41e}" />
<node name="Enabled" opcode="create" type="int32" value="0x1"
/>
<node name="Properties" opcode="create" >
<node name="Format" opcode="create" type="string"
value="x-asf-pf" />
<node name="Protocol" opcode="create" type="string"
value="RTP/AVP" />
</node> <!-- Properties -->
</node> <!-- RTP -->
<node name="RTP/ASF" opcode="create" >
<node name="CLSID" opcode="create" type="string"
value="{149a44be-dc14-4e94-9cb0-c0268e77df9e}" />
<node name="Enabled" opcode="create" type="int32" value="0x1"
/>
<node name="Properties" opcode="create" >
<node name="Format" opcode="create" type="string"
value="x-asfv2-pf,x-asfv2-grp-pf,x-asfv2-frag-pf" />
<node name="Protocol" opcode="create" type="string"
value="RTP/AVP" />
</node> <!-- Properties -->
</node> <!-- RTP/ASF -->
<node name="RTP/AVP" opcode="create" >
<node name="CLSID" opcode="create" type="string"
value="{d7335e2e-62eb-4ad0-96cd-b31c9d0f9f85}" />
<node name="Enabled" opcode="create" type="int32" value="0x1"
/>
<node name="Properties" opcode="create" >
<node name="Format" opcode="create" type="string"
value="PCMU,L8,L16,MPA,G726-24,G726-40" />
<node name="Protocol" opcode="create" type="string"
value="RTP/AVP" />
</node> <!-- Properties -->
</node> <!-- RTP/AVP -->
<node name="RTP/FEC" opcode="create" >
<node name="CLSID" opcode="create" type="string"
value="{02DEFE42-F8FC-11d2-8670-00C04F6890ED}" />
<node name="Enabled" opcode="create" type="int32" value="0x1"
/>
<node name="Properties" opcode="create" >
<node name="Format" opcode="create" type="string"
value="parityfec" />
<node name="Protocol" opcode="create" type="string"
value="RTP/AVP" />
</node> <!-- Properties -->
</node> <!-- RTP/FEC -->
<node name="RTP/WMS-FEC" opcode="create" >
<node name="CLSID" opcode="create" type="string"
value="{EDAB8E6B-746C-40db-A885-9E4A9EEF27A2}" />
<node name="Enabled" opcode="create" type="int32" value="0x1"
/>
<node name="Properties" opcode="create" >
<node name="Format" opcode="create" type="string"
value="wms-fec" />
<node name="Protocol" opcode="create" type="string"
value="RTP/AVP" />
</node> <!-- Properties -->
</node> <!-- RTP/WMS-FEC -->
</node> <!-- Object Store -->
<node name="Shared Properties" opcode="create" />
</node> <!-- Data Protocol -->
<node name="Feedback Protocol" opcode="create" >
<node name="Object Store" opcode="create" >
<node name="RTCP" opcode="create" >
<node name="CLSID" opcode="create" type="string"
value="{ecfddc81-184e-11d3-ae84-00a0c95ec3f0}" />
<node name="Enabled" opcode="create" type="int32" value="0x1"
/>
<node name="Properties" opcode="create" >
<node name="Format" opcode="create" type="string"
value="x-wms-rtx" />
<node name="Protocol" opcode="create" type="string"
value="RTP/AVP" />
</node> <!-- Properties -->
</node> <!-- RTCP -->
</node> <!-- Object Store -->
<node name="Shared Properties" opcode="create" />
</node> <!-- Feedback Protocol -->
<node name="Network Source" opcode="create" >
<node name="Object Store" opcode="create" >
<node name="WMS Http Network Source" opcode="create" >
<node name="CLSID" opcode="create" type="string"
value="{566A2EFF-5651-4020-AC1A-EB48E4571EA3}" />
<node name="Enabled" opcode="create" type="int32" value="0x1"
/>
<node name="Properties" opcode="create" >
<node name="Source Type" opcode="create" type="string"
value="HTTP" />
<node name="DefaultHttpServerPort" opcode="create"
type="int32" value="0x50" />
<node name="DefaultHttpServerSSLPort" opcode="create"
type="int32" value="0x1bb" />
<node name="PacketBuffers" opcode="create" type="int32"
value="0x8" />
<node name="EnableHTTP1_1" opcode="create" type="int32"
value="0x1" />
<node name="OpenTimeout" opcode="create" type="int32"
value="0x1e" />
<node name="SecondSegmentTimeout" opcode="create"
type="int32" value="0x64" />
<node name="ControlAdapter" opcode="create" type="string"
value="" />
<node name="PercentBWUsageForAccelStreaming" opcode="create"
type="int32" value="0x55" />
<node name="Proxy Setting" opcode="create" type="int32"
value="0x3" />
<node name="ProxyHostName" opcode="create" type="string"
value="" />
<node name="ProxyPort" opcode="create" type="int32"
value="0x50" />
<node name="ProxyBypassForLocal" opcode="create"
type="int32" value="0x0" />
</node> <!-- Properties -->
</node> <!-- WMS Http Network Source -->
<node name="WMS Mms Network Source" opcode="create" >
<node name="CLSID" opcode="create" type="string"
value="{DCF6C8B2-F6C0-461b-82DA-35945EADF54A}" />
<node name="Enabled" opcode="create" type="int32" value="0x1"
/>
<node name="Properties" opcode="create" >
<node name="Source Type" opcode="create" type="string"
value="MMS,MMST,MMSU" />
<node name="DefaultServerPort" opcode="create" type="int32"
value="0x6db" />
<node name="MaxReadHeaderRetries" opcode="create"
type="int32" value="0x4" />
<node name="PacketBuffers" opcode="create" type="int32"
value="0x8" />
<node name="DropProb" opcode="create" type="int32"
value="0x0" />
<node name="DropGracePeriod" opcode="create" type="int32"
value="0x0" />
<node name="FirstDropGracePeriod" opcode="create"
type="int32" value="0x0" />
<node name="DropBurstDuration" opcode="create" type="int32"
value="0x0" />
<node name="PacketPairDropProb" opcode="create" type="int32"
value="0x0" />
<node name="NackAlgorithm" opcode="create" type="int32"
value="0x2" />
<node name="NackRateMultiplier" opcode="create" type="int32"
value="0x1" />
<node name="NackBurst" opcode="create" type="int32"
value="0x5dc" />
<node name="NackTraceInterval" opcode="create" type="int32"
value="0x3e8" />
<node name="NackRetry" opcode="create" type="int32"
value="0x1" />
<node name="IgnoreServerVersion" opcode="create"
type="int32" value="0x0" />
<node name="EnableMmsDistribution" opcode="create"
type="int32" value="0x0" />
<node name="AssertStrangeErrors" opcode="create"
type="int32" value="0x0" />
<node name="InactivityTimeout" opcode="create" type="int32"
value="0x5a" />
<node name="OpenTimeout" opcode="create" type="int32"
value="0x20" />
<node name="PercentBWUsageForAccelStreaming" opcode="create"
type="int32" value="0x55" />
<node name="FunnelAdapter" opcode="create" type="string"
value="" />
<node name="ControlAdapter" opcode="create" type="string"
value="" />
<node name="Proxy Setting" opcode="create" type="int32"
value="0x0" />
<node name="ProxyHostName" opcode="create" type="string"
value="" />
<node name="ProxyPort" opcode="create" type="int32"
value="0x6db" />
<node name="ProxyBypassForLocal" opcode="create"
type="int32" value="0x0" />
</node> <!-- Properties -->
------------------------------
Date: Tue, 20 Dec 2005 22:34:04 -0600
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: newbie ques
Message-Id: <Xns9732F018F4282sdn.comcast@216.196.97.136>
BZ <BZ@caradhras.net> wrote in
news:slrndq3e8f.oe2.BZ@ophelia.vpn.zoetekouw.net:
> That's because \< and \> match word boundaries, not < and >
> characters.
Not in Perl.
Perhaps you're thinking about some other regexp syntax?
--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
------------------------------
Date: Tue, 20 Dec 2005 21:35:50 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: Picking Up Perl
Message-Id: <201220052135508053%comdog@panix.com>
In article <GX%pf.1626$1Y4.151250@news20.bellglobal.com>, Matt Garrish
<matthew.garrish@sympatico.ca> wrote:
> "rbt" <rbt@athop1.ath.vt.edu> wrote in message
> news:do9odi$5pg$1@solaris.cc.vt.edu...
> >
> > What books (if any) target Perl on Windows? I need info on accessing the
> > Windows API, creating services, managing processes, etc and I prefer
> > proper books over online only material.
>
> Learning Perl on Win32
There's not much point in getting "Learning Perl on Win32" anymore.
We worked hard to remove the unix-bias from "Learning Perl" so you
can get the latest version and use it no matter which platform you
decide to use. :)
--
brian d foy, bdfoy@cpan.org
Subscribe to The Perl Review: http://www.theperlreview.com
------------------------------
Date: Wed, 21 Dec 2005 04:53:13 GMT
From: Bloch <admin@ycdemocrats.org>
Subject: Re: Recursively Parsing through multipart messages use Mail::Box::Manager;
Message-Id: <Zc5qf.6176$vJ4.3186@trnddc07>
GEEEEEEYYYYYAAAARGH!!!
foreach my $part($_->body->parts('RECURSE'))
was the option that I was looking for. Missed it in the documentation
(several times, I might add).
For what it's worth, I place the blame entirely on Mark Overmeer, who
spent godknowshowlong writing and documenting this excellent module.
Mark, if you hadn't been so thorough, I would never have missed such an
important, easily-spotted detail. No, no, this has nothing to do with the
fact that I'm an American, weaned on television and raised in the age of
instant gratification. Nor with the fact that my iq is roughly 200 points
lower than a sponge -- and not one of those real sponges either, I'm
talking a sponge made by 3M or Dow or someone. No, it's your fault.
And that goes for the lot of you Perl mongers who have contributed to
developing Perl, and in so-doing, have helped to build the modern
internet, or rather, "internets" as our President so eloquently puts it.
You owe me something. I could be using Smalltalk, or Eiffel, or Scheme or
Visual Basic or something, but I chose Perl. Okay, admittedly, Perl
*might* be slightly better than those languages for the problem domains
that I usually look at -- parsing textfiles and playing around with *nixy
stuff and so on. But many of my former CS professors *insist* that it's
ugly -- so it must be true -- so, again, you owe me for giving me such a
cool language to play with for for free -- as in free beer and free
speech.
;-)
On Wed, 21 Dec 2005 01:06:35 +0000, Bloch wrote:
> I've written a little script that uses mailbox manager to parse an mbox
> file, strip off most of the headers, decode the body, and eventually
> print the data that is encoded as text/plain. It works fine for
> messages that are flat (i.e., multipart/alternative on the top level)
> and it can just grab the plaintext attachments from 1 level down.
>
> I run into problems when I hit multipart/mixed messages and I have to
> descend down a level. I've been reading through the groups.google.com
> archives and and the man pages of these modules and see that applying
> these items recursively is tricky for inexperienced programmers -- which
> I claim to be. Can someone recommend a better way of getting to my
> desired endpoint, or help me sort out how to get there using my existing
> approach?
>
> I've attached the relevent portion of my code and the output of
> printStructure to give a better idea of the problem domain.
>
> #!/usr/local/bin/perl
>
> use Mail::Box::Manager;
> use Date::Parse;
> use warnings;
> use strict;
> my $mgr = Mail::Box::Manager->new;
> #my $folder_file = "/home/salvador/mail/releases"; my $folder_file =
> "/home/salvador/mail/releases.old"; my $folder = $mgr->open(folder =>
> $folder_file) or die "Could not open folder $!n";
> my(@subject,@sender,@body,@time);
> my $x = 0;
> for ($folder->messages) {
> $subject[$x] = $_->subject;
> $sender[$x] = $_->sender->address;
> $time[$x] = $_->get('Date');
> #body[$x] = $decode = $_->decoded;
> #$_->printStructure;
>
> if($_->isMultipart) {
> foreach my $part($_->body->parts) {
> my $attached_head = $part->head;
> my $attached_body = $part->decoded;
> if($attached_head =~ /text\/plain/) {
> # print "$attached_head\n";
> # print "OK\n";
> }elsif($attached_head =~ /multipart\/alternative/i) {
> print "$attached_head\n";
> print "Crap\! How do I parse the next batch of headers?\n";
> print "$attached_body";
> }
> }
> }
> $x++;
> }
>
> PARTIAL OUTPUT OF MESSAGE STRUCTURES:
>
> OK:
> multipart/alternative: KENNEDY: AMERICANS DESERVE BETTER THAN A
> REPUBLICAN BUDGET THAT LEAVES THEM BEHIND (111850 bytes)
> text/plain (47689 bytes)
> text/html (62436 bytes)
>
> OK:
> multipart/alternative: Boxer Asks Legal Scholars on Dean's 'Impeachable
> Offense' Comment (10116 bytes)
> text/plain (2647 bytes)
> text/html (5495 bytes)
>
> OK:
> multipart/alternative: Sen. Jeffords' Statement on ANWR/Defense Spending
> Bill (8876 bytes)
> text/plain (1030 bytes)
> text/html (5864 bytes)
>
> FAILS TO PARSE PROPERLY:
> multipart/mixed: KENNEDY: REPUBLICANS BLOCK INTELLIGENCE BILL TO AVOID
> THE TRUTH OF THE WAR (202224 bytes)
> multipart/alternative (146945 bytes)
> text/plain (54877 bytes)
> text/html (91778 bytes)
> application/msexcel (53598 bytes)
>
> ...
------------------------------
Date: Wed, 21 Dec 2005 04:03:16 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: split by word using | as delimiter
Message-Id: <8u4qf.30875$h86.3058@edtnps89>
William wrote:
> input file - dummylist.txt:
> |ZZ_JEN|1|0|0|0|name@uwaterloo.ca
>
> expected output:
> 6
> ZZ_JEN
But you have seven fields there, not six.
> current output:
> 35
> Z
>
> code in question:
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my $dummy_list = "/mkapp/webapps/mxrt-cgi/upload_vol/dummylist.txt";
>
> open ( DUMMY_FD , $dummy_list ) || die "Cannot open file $dummy_list\n";
You should include the $! variable in the error message so you know *why* it
failed to open.
> my @lines = <DUMMY_FD>;
> foreach my $currentLine ( @lines ) {
Is there a valid reason to read the entire file into an array first? (Instead
of just reading one line at a time?)
> my @instrumentEntries = ( split(/|/, $currentLine) );
As has been explained by others, certain characters serve a special purpose in
a regular expression (and | is one of them.)
> my $numEntries = @instrumentEntries;
> print $numEntries . "\n";
>
> print $instrumentEntries[1] . "\n";
> }
> close ( DUMMY_FD );
>
>
> for the line
> my @instrumentEntries = ( split(/|/, $currentLine) );
>
> what is the correct way to split $currentLine of the input file?
>
>
>
> P.S. i already checked perldoc -f split and perldoc -q split.
The first argument to split() is a regular expression so the regular
expression man page(s) should be consulted. :-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 20 Dec 2005 22:44:00 -0600
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: split by word using | as delimiter
Message-Id: <Xns9732F1CB26D35sdn.comcast@216.196.97.136>
William <wh2leung@student.cs.uwaterloo.ca> wrote in
news:Pine.GSO.4.64.0512201657090.25492@cpu02.student.cs.uwaterloo.ca:
Others have answered your primary question. I just have a couple of
comments; hope you don't mind.
> open ( DUMMY_FD , $dummy_list ) || die "Cannot open file $dummy_list
\n";
If 'open' (or many other functions) fails, the reason is stored in the
variable $! -- it is a good idea to include that in your error message.
> my @lines = <DUMMY_FD>;
> foreach my $currentLine ( @lines ) {
Strictly speaking, it is not wrong to do the above. But it generally
makes more sense to write the above as:
while (my $currentLine = <DUMMY_FD>) {
Why read the entire file into memory, when you're only dealing with one
line at a time? For small files, the difference is trivial. I
personally regularly deal with files and database tables whose sizes
range in the tens of gigabytes. Reading files one line at a time is a
good habit to get into.
> my @instrumentEntries = ( split(/|/, $currentLine) );
As others have pointed out, | is special within regular expressions, and
must be escaped to be treated as a literal.
>
> P.S. i already checked perldoc -f split and perldoc -q split.
Very good. This alone puts you ahead of 90% of posters to
comp.lang.perl.misc.
--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8783
***************************************