[26374] in Perl-Users-Digest
Perl-Users Digest, Issue: 8546 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 20 03:05:33 2005
Date: Thu, 20 Oct 2005 00:05:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 20 Oct 2005 Volume: 10 Number: 8546
Today's topics:
Re: Case Sensitive Regex <tadmc@augustmail.com>
Re: getElementsByTagName, tag does not exist robic0@yahoo.com
Re: Whats the most complicate RegEX that can be done? robic0@yahoo.com
Re: why the perl docs suck robic0@yahoo.com
Re: why the perl docs suck robic0@yahoo.com
Re: why the perl docs suck robic0@yahoo.com
Re: why the perl docs suck robic0@yahoo.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 19 Oct 2005 23:43:59 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Case Sensitive Regex
Message-Id: <slrndle84f.5d8.tadmc@magna.augustmail.com>
Robert <rbutcher.nospam@hotmail.com> wrote:
> I am trying to secure my mailer script
Then you should have taint checking turned on.
perldoc perlsec
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 19 Oct 2005 23:54:53 -0700
From: robic0@yahoo.com
Subject: Re: getElementsByTagName, tag does not exist
Message-Id: <cmfel1pas2i6b65oadd4ub42u9dvmt6cf8@4ax.com>
On Tue, 11 Oct 2005 23:11:25 -0700, robic0@yahoo.com wrote:
You know, I'm gonna go one step further here and say:
If you use nodes your some kind of a dumb ass. Not the
modern thinking at all !!
>On Tue, 11 Oct 2005 10:28:01 -0500, hymie_@_lactose.homelinux.net
>(hymie!) wrote:
>
>>Greetings. I'm just starting to dabble in XML, and I've run across a
>>problem.
>>
>>I'm going through my XML document using this construct:
>>
>>use XML::DOM;
>>my $parser = new XML::DOM::Parser
>> or bail ("Unable to create XML parser");
>>my $story = $parser->parse($data);
>>$out{"SOURCE"} = $story->getElementsByTagName("Source")->
>> item(0)-> getFirstChild->getData;
>>$out{"DATE"} = $story->getElementsByTagName("Publication_Date")->
>> item(0)-> getFirstChild->getData;
>>$out{"TEXT"} = $story->getElementsByTagName("Body_Text")->
>> item(0)-> getFirstChild->getData or die "$!";
>>
>>Everything works fine, until I get to a $story where Body_Text doesn't
>>exist. I've looked through all of the XML::DOM docs that I can find,
>>but I can't find either a way to test if Body_Text exists, or what happens
>>when Body_Text doesn't exist. The script stops with no obvious
>>diagnostic output -- it appears that the "die" never happens.
>>
>>Can somebody show me the light?
>>
>>hymie! http://www.smart.net/~hymowitz hymie_@_lactose.homelinux.net
>>===============================================================================
>>I've got an answer. I'm going to fly away. What have I got to lose?
>> --Crosby, Stills, and Nash
>>===============================================================================
>The alternative to DOM is SAX, widely used in modern code.
>Its basically a simple event driven model, calling handlers
>when the basic structured xml components are encountered. This
>allows you to control going from xml to internal data structures
>and/or back out to xml. Expat provides hooking handlers to most
>of the current W3c constructs. These are just the basic ones.
>Its up to you to extract the data into internal structures.
>For that XML:Simple is a good tool. With Expat you can accumulate
>nested data in a single string. Then Simple will create nested
>Perl structures using tag names. Then you can Dumper it.
>But, nobody uses Xml that doesen't know ahead of time what those
>structures are both out and in. This is a way to control/validate/
>populate them. SAX gives you a much simpler model and allows
>much better control of the data. If you need more information
>let me know. Getting Xerces working is a chore (you could do
>without it for now, its only being used for schema checking here).
>This code chunk sample is from 7,000 line code I wrote that was
>converted
>to a binary with Perl2Exe (including Xerces). I've chopped it up,
>you can't see or know what it does so it will look nasty but
>all the clues are there for you to investigate SAX and thats enough.
>-gluck
>
>
>---
>This code is chopped out of a large practical xml code base and is NOT
>cut & paste workable. Its just for instructional purposes
>for the poster to give a flavor of SAX: Simple Api Xml.
>
>use XML::Xerces;
>
>use XML::Parser::Expat;
>use XML::Simple;
>
>## main
>{
> ## Initialize program / build list of xml files (ie: glob)
> for (@XmlFiles)
> {
> /.+$dlimsep(.+)$/; (defined elsewhere for win/unix os)
> $XML_File = $1;
> Log ($XML_File);
>
> ## Validate Schema with Xerces
> ## note: Xerces is being used for schema validation
>and
> ## as backup xml integrity (done elsewhere)
> next if (!ValidateSchema ($_));
>
> if (!open(SAMP, $_)) {
> Log (...);
> next;
> }
>
> ## Parse xml and integrity check (Expat-SAX)
> my $parser = new XML::Parser::Expat;
> $parser->setHandlers('Start' => \&stag_h,
> 'End' => \&etag_h,
> 'Char' => \&cdata_h);
> $parser->setHandlers('Comment' => \&comment_h) if
>($hVars{'CommentLogging'});
>
> eval {$parser->parse(*SAMP)};
> if ($@) {
> ## xml integrity failed -log this error
> $@ =~ s/^[\x20\n\t]+//; $@ =~
>s/[\x20\n\t]+$//;
> # attempt strip off program line,col info at
>end
> $@ =~ s/(at line [0-9]+,.+)?at .+ line
>[0-9]+$/$1/;
> Log (...error...);
> }
> close(SAMP);
> $parser->release;
> }
>}
>
>########################################################
># EXPAT Event Handlers - start/end/content (defaults)
>########################################################
>##
>sub stag_h # -- Start Tag --
>{
> my ($p, $element, %atts) = @_;
> $element = uc($element);
> $last_content = '';
> $last_syntax_content = '';
>
> ## -- construct & Print start tag --
> my $tag = "\<$element\>";
> if ($XML_PRINT) {
> printf ("%3d", $p->current_line);
> print get_indent();
> print "$tag";
> print " Attr" if (keys %atts);
> foreach my $key (keys %atts) {
> print ", $key=".$atts{$key};
> }
> print "\n";
> }
> $tab_lev++;
>
> ## -- set Detached special content handler --
> if (exists ($Content_hash{$element}) &&
>$Content_hash{$element}->[1]) {
> $p->setHandlers('Char' =>
>$Content_hash{$element}->[0]);
> }
>
> ## do something with attributes
> ## start keying (populating) your data structures
> ## set flags, etc ...
>}
>
>##
>##
>sub etag_h # -- End Tag --
>{
> my ($p, $element) = @_;
> $element = uc($element);
>
> ## -- Construct & Print end tag --
> my $tag = "\</$element\>";
> $tab_lev--;
> if ($XML_PRINT) {
> printf ("%3d", $p->current_line);
> print get_indent();
> print "$tag\n";
> }
> ## -- store last Content in hash (do more stuff)
>
> ## then:
> $last_content = '';
>
> ## -- Restore default content handler --
> if (exists ($Content_hash{$element}) &&
>$Content_hash{$element}->[1]) {
> $p->setHandlers('Char' => \&cdata_h);
> my $last = (@Action) - 1;
> my $aref = $Action[$last];
> $Content_hash{$element}->[2]($last_syntax_content,
>$aref, $element);
> }
>}
>
>##
>##
>sub cdata_h # -- Default Content Data --
>{
> my ($p, $str) = @_;
> # use original for entities, incase reparse
> $str = $p->original_string;
> # remove leading/trailing space, newline, tab
> $str =~ s/^[\x20\n\t]+//; $str =~ s/[\x20\n\t]+$//;
> if (length ($str) > 0)
> {
> if ($XML_PRINT) {
> printf ("%3d", $p->current_line);
> print get_indent();
> print "$str (".length($str).")\n";
> }
> $last_content .= $str;
> }
>}
>
>##
>##
>sub comment_h # -- Default Comment Data --
>{
> my ($p, $str) = @_;
> # use original for entities, incase reparse
> $str = $p->original_string;
> # remove leading/trailing space, newline, tab
> $str =~ s/^[\x20\n\t]+//; $str =~ s/[\x20\n\t]+$//;
> if (length ($str) > 0)
> {
> printf (" %d,%d\n",
>$p->current_line,$p->current_column);
> }
>}
>
>##
>##
>sub cdata_x_h # -- Special Content Data --
>{
> my ($p, $str) = @_;
> cdata_h ($p, $str);
> # remove leading/trailing space, newline, tab
> $str =~ s/^[\x20\n\t]+//; $str =~ s/[\x20\n\t]+$//;
> $last_syntax_content .= $str if (length ($str) > 0);
>}
>
>########################################################
># Xerces - too much to explain
>########################################################
>#
>sub ValidateSchema {
> my ($xfile) = @_;
> #my $valerr = 0;
>
> # Docs:
>http://xml.apache.org/xerces-c/apiDocs/classAbstractDOMParser.html#z869_9
> my $Xparser = XML::Xerces::XercesDOMParser->new();
> $Xparser->setValidationScheme(1);
> $Xparser->setDoNamespaces(1);
> $Xparser->setDoSchema(1);
> #$Xparser->setValidationSchemaFullChecking(1); # full
>constraint (if enabled, may be time-consuming)
>
>
>$Xparser->setExternalNoNamespaceSchemaLocation($hVdef{'Schema'});
>
> my $ERROR_HANDLER = XLoggingErrorHandler->new(\&LogX_warn,
>\&LogX_error, \&LogX_ferror, );
> #my $ERROR_HANDLER = XML::Xerces::PerlErrorHandler->new();
> $Xparser->setErrorHandler($ERROR_HANDLER);
>
> # no need for eval on parse with handlers.. just insurance on
>die
> eval {$Xparser->parse
>(XML::Xerces::LocalFileInputSource->new($xfile));};
> if ($@) {
> }
> return 1;
>}
>
>## handlers (alot more not shown)
------------------------------
Date: Wed, 19 Oct 2005 23:37:10 -0700
From: robic0@yahoo.com
Subject: Re: Whats the most complicate RegEX that can be done?
Message-Id: <pleel19p6hr9eemlus57qtc2u3a95ata9k@4ax.com>
On Sun, 9 Oct 2005 21:58:35 -0400, "Matt Garrish"
<matthew.garrish@sympatico.ca> wrote:
Dude, the re that will distroy us all is s///.
In Quantem Physics thats the end of the world man!
>
><robic0@yahoo.com> wrote in message
>news:ho8jk1pvmsoe960s49jb8fomehj6p5d9vq@4ax.com...
>> What is the most complicated Regular Expression possible?
>
>The regular expression that will destroy us all. But if you write it, you'll
>destroy us all and so never know that you succeeded.
>
>Matt
>
------------------------------
Date: Wed, 19 Oct 2005 23:45:56 -0700
From: robic0@yahoo.com
Subject: Re: why the perl docs suck
Message-Id: <68fel1dalc7d9mso7enc4j42psligcv6n8@4ax.com>
On Tue, 11 Oct 2005 21:22:27 -0500, "Fred@fred.net" <Fred@fred.net>
wrote:
>On Tue, 11 Oct 2005 10:26:25 +0300, "Veli-Pekka Tätilä"
><vtatila@mail.student.oulu.fi> wrote:
>
>>Fred@fred.net wrote:
>>> was helping a new programmer
>>> at work get used to perl. <snip>
>>> push ARRAY,LIST
>>>
>>> Treats ARRAY as a stack, and pushes the values of LIST onto the end of
>>> ARRAY. The length of ARRAY increases by the length of LIST. Has the
>>> same effect as
>>>
>>> for $value (LIST) {
>>> $ARRAY[++$#ARRAY] = $value;
>>> }
>>> <snip>
>>> That's like asking "Hows the weather" and someone begins talking about
>>> the big bang theory. It does not even use push.
>>Well if it used push to explain push, how would you explain how push works?
>>I find the sample code enlightning as it shows you briefly, clearly and
>>unambiguously the key idea behind push.
>>
>>> I don't fucking *want* to think, I wan't a fucking answer right now!
>>Could you please mind your Ps and Qs? I reckon not, this doesn't exactly
>>give a smart image of you.
>>
>>> what is the format specifier for printf... let's see it's just like c.
>>Ok me too, I wish that perldoc would go into more details here or at least
>>reference sprintf more clearly. I think the perldoc page for sprintf gives
>>you much more info, however, and prinf mentions that it works like sprintf.
>>But no docs are perfect. I like perldocs quite a bit the brief and rather
>>formal style somewhat reminds me of the K&R book plus the examples. Have you
>>ever browsed the PHP docs? Though the tone is nice and friendly, they often
>>leave a lot of behavior unspecified.
>>
>>> wanted someone to say "It's the percent sign you fucking idiot!!"
>>Howabout googling for perl printf example. It's actually faster than ranting
>>here.
>>
>>> Part 1 in a series.
>>I think I'll gladly skip the rest, unless you manage to be much more
>>objective and give useful feedback.
>
>No docs are perfect, so an admonition to "RTFM" should be given with
>more humility than is typical on this NG.
>
>Thanks...
WTF does RTFM mean?
------------------------------
Date: Wed, 19 Oct 2005 23:47:30 -0700
From: robic0@yahoo.com
Subject: Re: why the perl docs suck
Message-Id: <8bfel1515urbihbrl1gh683524mogcj8j6@4ax.com>
On Wed, 12 Oct 2005 15:27:34 -0000, "David K. Wall"
<darkon.tdo@gmail.com> wrote:
>Bernard El-Hagin <bernard.el-haginDODGE_THIS@lido-tech.net> wrote:
>
>>> Fucking idots.
>>
>>
>> We agree here. I hate idots even more than I hate icommas. Don't
>> even get me started on iquestionmarks and iMacs.
>
>What about iPod? Is that Perl documentation for an iMac?
What about iDick?
------------------------------
Date: Wed, 19 Oct 2005 23:50:45 -0700
From: robic0@yahoo.com
Subject: Re: why the perl docs suck
Message-Id: <2gfel1lf85kb2314a7g8qr4938lepm6e9r@4ax.com>
On Tue, 11 Oct 2005 08:39:41 -0500, Tad McClellan
<tadmc@augustmail.com> wrote:
Hey Tad can you explain just what a stack is for the dumb
folks here.
>Fred@fred.net <Fred@fred.net> wrote:
>
>> But I had to laugh when we found
>> this gem in the hallowed "docs";
>> looking for info on push() we find this helpful entry in
>> the help files:
>>
>> push ARRAY,LIST
>>
>> Treats ARRAY as a stack, and pushes the values of LIST onto the end of
>> ARRAY.
>
>
>If you don't know what a stack is, then you should ask what a stack is.
>
>
>> I don't fucking *want*
>
>
>This may come as a shock, but Perl does not exist to please you.
>
>
>> I wan't a fucking answer right now!
>
>
>You will get more responses to your job offer if you mention
>what compensation will be provided.
>
>
>> I did not need to be sent off into oblivion by a manual written by
>> idiots.
>
>
>Then choose some programming language whose manual is not written by idiots.
------------------------------
Date: Thu, 20 Oct 2005 00:11:42 -0700
From: robic0@yahoo.com
Subject: Re: why the perl docs suck
Message-Id: <gegel1l7jrma2so0no4o7c1hvcjocqs5km@4ax.com>
On Wed, 12 Oct 2005 11:42:56 -0700, Keith Keller
<kkeller-usenet@wombat.san-francisco.ca.us> wrote:
Hey Keith, I used emacs editor in the 1980's for a few years.
What ever happended to that? Anybody still use it with its
finger contorting gazzillion esc code, hilite, cut/past dual
screen keyboard bizzaro world? You can't be serious, 20 years
later its still used?
>On 2005-10-12, David K. Wall <darkon.tdo@gmail.com> wrote:
>>
>> What about iPod? Is that Perl documentation for an iMac?
>
>Probably written using eMacs.
>
>--keith
------------------------------
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 8546
***************************************