[26550] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8692 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 21 09:05:32 2005

Date: Mon, 21 Nov 2005 06: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           Mon, 21 Nov 2005     Volume: 10 Number: 8692

Today's topics:
    Re: FAQ 9.10 How do I decode or create those %-encoding <rvtol+news@isolution.nl>
        problem using evaluations in vars <dont_w@nt_spam.org>
    Re: problem using evaluations in vars <joe@inwap.com>
    Re: problem using evaluations in vars (Anno Siegel)
        query status of STDIN (See Website For Email)
    Re: query status of STDIN (See Website For Email)
    Re: query status of STDIN <joe@inwap.com>
    Re: query status of STDIN brianr@liffe.com
    Re: XML Parsing too slow with XML::Simple <mirod@mirod.org>
    Re: XML Parsing too slow with XML::Simple <bart.lateur@pandora.be>
    Re: XML Parsing too slow with XML::Simple <mirod@mirod.org>
    Re: XML Parsing too slow with XML::Simple <matthew.garrish@sympatico.ca>
    Re: XML Parsing too slow with XML::Simple <mirod@mirod.org>
    Re: XML Parsing too slow with XML::Simple <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 21 Nov 2005 11:33:01 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: FAQ 9.10 How do I decode or create those %-encodings on the web?
Message-Id: <dlsbei.1d4.1@news.isolution.nl>

PerlFAQ Server schreef:

>     s/%([A-Fa-f\d]{2})/chr hex $1/eg;            # decode


Alternative:

      s/%([[:xdigit:]]{2})/chr hex $1/eg;            # decode

-- 
Affijn, Ruud

"Gewoon is een tijger."


------------------------------

Date: Mon, 21 Nov 2005 02:56:48 GMT
From: Mike Ballard <dont_w@nt_spam.org>
Subject: problem using evaluations in vars
Message-Id: <m2oe4eyaf1.fsf@west_f1.net>


Probably didn't word title right but I have these:

  $1 ne $3 && $2 ne $4
  $1 ne $3 && $2 eq $4
  $1 ne $3

and want to do this:

  $filter = "\$1 ne \$3 && \$2 ne \$4";

or
  
  $filter = "\$1 ne \$3 && \$2 eq \$4";

etc., depending on argv, right at the start of my code.

I want to define $filter based on argv so that instead of having 3
distinct/explicit "if ()" deeper in my code, I can have 1 "if ($filter)"
loaded with the argv-defined filter.

As I step through the code I can see that the correct filter gets selected
for "if ()" but the problem is it doesn't seem to be doing any evaluating
once there.  I've tried all manner of escaping/quoting when defining
$filter but in the "if ()" it always evaluates the same way (and
incorrectly).

Is this some issue with the stmt evaluating only when $filter is defined,
and then later in the "if ()" it's going to remain static?  Or is it just
how I'm trying to "protect" it from doing that when assigning it initially
to $filter?

If I'm allowed to do this, what do I have to do to make it work (I looked
at "eval" but gave up kinda quick on it)?

Mike  
-- 




------------------------------

Date: Sun, 20 Nov 2005 20:23:31 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: problem using evaluations in vars
Message-Id: <boqdnYmHNJd41hzeRVn-vA@comcast.com>

Mike Ballard wrote:
> Probably didn't word title right but I have these:
> 
>   $1 ne $3 && $2 ne $4
>   $1 ne $3 && $2 eq $4
>   $1 ne $3

@m = $string =~ /(a.*)(b.*)(c.*)(d.*)/	; Put $1,$2,$3,$4 into array

sub filter1 { $_[1] ne $_[3] and $_[2] ne $_[4]; }
sub filter2 { $_[1] ne $_[3] and $_[2] eq $_[4]; }
sub filter3 { $_[1] ne $_[3]; }

> I can have 1 "if ($filter)"

   if (filter1(undef,@m)) { ... }
   if (filter2(undef,@m)) { ... }
   if (filter3(undef,@m)) { ... }

	-Joe


------------------------------

Date: 21 Nov 2005 10:01:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: problem using evaluations in vars
Message-Id: <dls5ta$1d1$1@mamenchi.zrz.TU-Berlin.DE>

Mike Ballard  <dont_w@nt_spam.org> wrote in comp.lang.perl.misc:
> 
> Probably didn't word title right but I have these:
> 
>   $1 ne $3 && $2 ne $4
>   $1 ne $3 && $2 eq $4
>   $1 ne $3
> 
> and want to do this:
> 
>   $filter = "\$1 ne \$3 && \$2 ne \$4";
> 
> or
>   
>   $filter = "\$1 ne \$3 && \$2 eq \$4";
> 
> etc., depending on argv, right at the start of my code.
> 
> I want to define $filter based on argv so that instead of having 3
> distinct/explicit "if ()" deeper in my code, I can have 1 "if ($filter)"
> loaded with the argv-defined filter.
> 
> As I step through the code I can see that the correct filter gets selected
> for "if ()" but the problem is it doesn't seem to be doing any evaluating
> once there.  I've tried all manner of escaping/quoting when defining
> $filter but in the "if ()" it always evaluates the same way (and
> incorrectly).

You are entitled to your view, but I'd say the evaluation is correct,
your expectations aren't.

> Is this some issue with the stmt evaluating only when $filter is defined,
> and then later in the "if ()" it's going to remain static?  Or is it just
> how I'm trying to "protect" it from doing that when assigning it initially
> to $filter?

Exactly.  $filter is a string and takes its value when you assign it.
It won't change later just because you have evaluated another pattern
match.

> If I'm allowed to do this, what do I have to do to make it work (I looked
> at "eval" but gave up kinda quick on it)?

You gave up too soon.  While there are other methods, eval() is the
simplest way to compile a bit of code that has been handed in as an
argument:

    my $filter_code = shift;
    eval "sub filter { $filter_code }";
    die "Invalid filter code '$filter_code': $@" if $@;

    while ( <DATA> ) {
        /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+/;
        print filter() ? "yes " : "no  ", $_;
    }

    __DATA__
    a b c d
    a a a a
    a b a b
    a a c c

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


------------------------------

Date: Sun, 20 Nov 2005 18:13:49 -0800
From: "Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail@moderncppdesign.com>
Subject: query status of STDIN
Message-Id: <IqA8v2.391@beaver.cs.washington.edu>

Hello,


Here's a tricky one. I have a perl script that most of the time is 
invoked like this:

$ some_command | my_perl_script

Now, inside my_perl_script, when reading STDIN through end-of-file, I 
want to look at the exit status of the "upstream" command, that is, 
some_command. If that command has a nonzero exit status, I deem the 
input as incomplete.

How can I do that in perl? Is there a way of figuring out the exist 
status of STDIN, in case that came as a pipe?


Thanks,

Andrei


------------------------------

Date: Sun, 20 Nov 2005 18:20:30 -0800
From: "Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail@moderncppdesign.com>
Subject: Re: query status of STDIN
Message-Id: <IqA966.3FI@beaver.cs.washington.edu>

Andrei Alexandrescu (See Website For Email) wrote:
> How can I do that in perl? Is there a way of figuring out the exist 
> status of STDIN, in case that came as a pipe?

s/exist/exit/

Andrei


------------------------------

Date: Sun, 20 Nov 2005 20:57:28 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: query status of STDIN
Message-Id: <tvednQsyVb5GzhzeRVn-uQ@comcast.com>

Andrei Alexandrescu (See Website For Email) wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
> 
>> How can I do that in perl? Is there a way of figuring out the exit 
>> status of STDIN, in case that came as a pipe?

STDIN does not have an exit value.

You'll need to create the pipe yourself, and check the value
returned from close().

linux% perl -e 'open P,shift()."|" or die; while(<P>){print;} $e=close 
P; print "Pipe close = ",0+$e,"\n"' false
Pipe close = 0
linux% perl -e 'open P,shift()."|" or die; while(<P>){print;} $e=close 
P; print "Pipe close = ",0+$e,"\n"' true
Pipe close = 1
linux% perl -e 'open P,shift()."|" or die; while(<P>){print;} $e=close 
P; print "Pipe close = ",0+$e,"\n"' date
Sun Nov 20 20:54:51 PST 2005
Pipe close = 1

The value of close(P) is true if the process feeding the pipe exited
without an error code.
	-Joe


------------------------------

Date: Mon, 21 Nov 2005 13:58:47 +0000
From: brianr@liffe.com
Subject: Re: query status of STDIN
Message-Id: <vtek5aksq0.fsf@ssdevws28.admin.liffe.com>

"Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail@moderncppdesign.com> writes:

> Hello,
>
>
> Here's a tricky one. I have a perl script that most of the time is
> invoked like this:
>
> $ some_command | my_perl_script
>
> Now, inside my_perl_script, when reading STDIN through end-of-file, I
> want to look at the exit status of the "upstream" command, that is,
> some_command. If that command has a nonzero exit status, I deem the
> input as incomplete.
>
> How can I do that in perl? Is there a way of figuring out the exist
> status of STDIN, in case that came as a pipe?

The exit status of a program is generally only available to its
parent, which in this case would have to be my_perl_script. Your Perl
script could execute some_command itself, and replace its STDIN with
the piped output. For example:

----------------------------------------------------------------------
use strict;
use warnings;

use Getopt::Std;

my %opts;
getopts("c:", \%opts) or die "Bad switch\n";

if (defined $opts{c}) {
    open STDIN, "$opts{c} |"
	or die "Failed to start command '$opts{c}': $!\n";
}

while (<>) {
    print "IN: $_";
}

if (defined $opts{c}) {
    close STDIN;
    print "Incomplete\n" if $?;
}
----------------------------------------------------------------------

This could then be executed as

$ my_perl_script -c "some_command arg1 arg2"

For more info see:

perldoc perlopentut
perldoc -f open
perldoc perlvar

HTH

-- 
Brian Raven

It's easy to solve the halting problem with a shotgun.   :-)
             -- Larry Wall in <199801151836.KAA14656@wall.org>


------------------------------

Date: Mon, 21 Nov 2005 11:32:38 +0100
From: Michel Rodriguez <mirod@mirod.org>
Subject: Re: XML Parsing too slow with XML::Simple
Message-Id: <4381a247$0$8480$5fc30a8@news.tiscali.it>

Todd W wrote:

> For high performance XML parsing I use SAX. SAX is a language independent
> light weight XML interface. As with all XML interfaces, it has somewhat of a
> learning curve.

Just to get the record straight: the last time I checked, SAX was NOT 
fast. At least in Perl.

See http://www.xmltwig.com/article/simple_benchmark/ The last test is 
especially telling: for a multi-step process, it is basically twice as 
fast to use XML::LibXML and temporary XML files between steps than to 
pass SAX events around.

You are welcome to run the tests again, BTW.

-- 
mirod



------------------------------

Date: Mon, 21 Nov 2005 10:53:52 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: XML Parsing too slow with XML::Simple
Message-Id: <gp93o19tml8ancntd3ab6eduea2bvld6ps@4ax.com>

Michel Rodriguez wrote:

>Just to get the record straight: the last time I checked, SAX was NOT 
>fast. At least in Perl.

Maybe because you used the (default) Pure Perl driver?

-- 
	Bart.


------------------------------

Date: Mon, 21 Nov 2005 12:09:07 +0100
From: Michel Rodriguez <mirod@mirod.org>
Subject: Re: XML Parsing too slow with XML::Simple
Message-Id: <4381aad3$0$8490$5fc30a8@news.tiscali.it>

Bart Lateur wrote:
> Michel Rodriguez wrote:
> 
>>Just to get the record straight: the last time I checked, SAX was NOT 
>>fast. At least in Perl.
> 
> Maybe because you used the (default) Pure Perl driver?
> 

Did I?

The code is available, have a look at it. It seems to me that pushing 
XML::LibXML::SAX as the first filter in the pipeline would call the 
XML::LibXML driver. The pure Perl driver takes A LOT more time, as shown 
in the other tests.

I am not trying to be negative here. Just to correct the "SAX is fast" 
line that is saddly unsupported by benchmarks.

-- 
mirod


------------------------------

Date: Mon, 21 Nov 2005 08:03:21 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: XML Parsing too slow with XML::Simple
Message-Id: <ZAjgf.754$e43.97618@news20.bellglobal.com>


"Michel Rodriguez" <mirod@mirod.org> wrote in message 
news:4381aad3$0$8490$5fc30a8@news.tiscali.it...
> Bart Lateur wrote:
>> Michel Rodriguez wrote:
>>
>>>Just to get the record straight: the last time I checked, SAX was NOT 
>>>fast. At least in Perl.
>>
>> Maybe because you used the (default) Pure Perl driver?
>>
>
> Did I?
>
> The code is available, have a look at it. It seems to me that pushing 
> XML::LibXML::SAX as the first filter in the pipeline would call the 
> XML::LibXML driver. The pure Perl driver takes A LOT more time, as shown 
> in the other tests.
>
> I am not trying to be negative here. Just to correct the "SAX is fast" 
> line that is saddly unsupported by benchmarks.
>

That has nothing to do with SAX parsing and everything to do with the pure 
perl parser. It is well documented that it is ridiculously slow. SAX is fast 
if you do it right...

Matt 




------------------------------

Date: Mon, 21 Nov 2005 14:25:31 +0100
From: Michel Rodriguez <mirod@mirod.org>
Subject: Re: XML Parsing too slow with XML::Simple
Message-Id: <4381cacb$0$8492$5fc30a8@news.tiscali.it>

Matt Garrish wrote:
> "Michel Rodriguez" <mirod@mirod.org> wrote in message 
> news:4381aad3$0$8490$5fc30a8@news.tiscali.it...
> 
>>Bart Lateur wrote:
>>
>>>Michel Rodriguez wrote:
>>>
>>>
>>>>Just to get the record straight: the last time I checked, SAX was NOT 
>>>>fast. At least in Perl.
>>>
>>>Maybe because you used the (default) Pure Perl driver?
>>>
>>
>>Did I?
>>
>>The code is available, have a look at it. It seems to me that pushing 
>>XML::LibXML::SAX as the first filter in the pipeline would call the 
>>XML::LibXML driver. The pure Perl driver takes A LOT more time, as shown 
>>in the other tests.
>>
>>I am not trying to be negative here. Just to correct the "SAX is fast" 
>>line that is saddly unsupported by benchmarks.
>>
> 
> 
> That has nothing to do with SAX parsing and everything to do with the pure 
> perl parser. It is well documented that it is ridiculously slow. SAX is fast 
> if you do it right...

Once again, the code is available, did you read it? Did I make a mistake 
and use the pure perl parser instead of XML::LibXML::SAX?

As far as I can tell I used the fastest SAX driver available.

I am sure there are good reasons to use SAX, but as far as I can tell, 
speed is not one of them.

<rant mode="on">I don't really know how to say that nicely, but I am 
starting to get a little annoyed at some SAX advocates refusing tho face 
reality. If you like SAX and don't have performave issues with it, then 
use it. If you think that my benchmark is flawed, then point the flaws. 
Or write a different benchmark. Just don't pretend that SAX is faster 
than the alternatives when it isn't. I personaly couldn't care less 
whether SAX is fast or not, I just don't appreciate having taken the 
time to write a  benchmark, only for its results to be dismissed by 
people who don't seem to have taken the time to even read it.</rant>

-- 
mirod


------------------------------

Date: Mon, 21 Nov 2005 13:58:17 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: XML Parsing too slow with XML::Simple
Message-Id: <Xns97155B446FD43asu1cornelledu@127.0.0.1>

Michel Rodriguez <mirod@mirod.org> wrote in
news:4381cacb$0$8492$5fc30a8@news.tiscali.it: 

> Matt Garrish wrote:
>> "Michel Rodriguez" <mirod@mirod.org> wrote in message 
>> news:4381aad3$0$8490$5fc30a8@news.tiscali.it...
>> 
>>>Bart Lateur wrote:
>>>
>>>>Michel Rodriguez wrote:
>>>>
>>>>
>>>>>Just to get the record straight: the last time I checked, SAX was
>>>>>NOT fast. At least in Perl.
>>>>
>>>>Maybe because you used the (default) Pure Perl driver?

 ...
> I just don't appreciate having taken the time to write a  
> benchmark, only for its results to be dismissed by people 
> who don't seem to have taken the time to even read
> it.</rant> 

Well, after seeing this, I became curious, and downloaded 
your benchmark code at 

<URL:http://www.xmltwig.com/article/simple_benchmark/simple_benchmark.tar.gz>

Tried to run the script run_all, but:

D:\Dload\simple_benchmark> perl run_all
Can't find string terminator "'" anywhere before EOF at -e line 1.
-uThe system cannot find the file specified.
Module versions:
Can't find string terminator "'" anywhere before EOF at -e line 1.
-uThe system cannot find the file specified.
Can't call method "size" on an undefined value at run_all line 41.

is all I get.

I am on Windows XP SP2 with Perl 5.8.7

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

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 8692
***************************************


home help back first fref pref prev next nref lref last post