[27136] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8991 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 24 18:05:42 2006

Date: Fri, 24 Feb 2006 15:05:04 -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           Fri, 24 Feb 2006     Volume: 10 Number: 8991

Today's topics:
        Decimal equality question <a-no-spam@.invalid>
    Re: Implementing a "pull" (?) interface in perl xhoster@gmail.com
    Re: Implementing a "pull" (?) interface in perl <nomail@sorry.com>
    Re: read from file or from <DATA>? <brian.d.foy@gmail.com>
    Re: sharing variables-data perl-asp <matthew.garrish@sympatico.ca>
        Threads <rbcs@gmx.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 24 Feb 2006 11:48:11 -0800 (PST)
From: "a" <a-no-spam@.invalid>
Subject: Decimal equality question
Message-Id: <MTE0MDgxMDQ5MS5yb3J5Yg.1140810491@nulluser.com>

this is probably a dumb question, but i'm not seeing why perl is treating
these numbers as unequal. i've tried on a few different machines (intel and
sparc) and perl versions (5.8.7, 5.8.3) and get the same result.

perl -e 'if (361.35 == (72.27*5)) { print "EQUAL"; } else {print "NOT EQUAL";}'




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

Date: 24 Feb 2006 17:28:47 GMT
From: xhoster@gmail.com
Subject: Re: Implementing a "pull" (?) interface in perl
Message-Id: <20060224123138.286$NN@newsreader.com>

Arvin Portlock <nomail@sorry.com> wrote:
> > >
> > >I don't understand. You are describing exactly how I want the
> > >interface to act but not saying how you are doing it, i.e.,
> > >how exactly get_one() works. But yes, that's what I'm aiming for.
> >
> >
> > OK, now I don't understand.  If you give an example of how get_all()
> > would work, we could discuss how to make it work like get_one()
> > (assuming I can). But without seeing what you are currently doing, I
> > don't know to help you change it!
> >
> > Xho
>
> Right now I'm not object oriented but I want to move in that
> direction. This is a simplified example of what I'm doing.
> Assuming a file containing records like this:

OK, now I think I understand.  I had thought you wanted to write your own
parser, but you want to write an adapter module that takes an *existing*
call-back based XML-parser, and encapsulate it into a blocking parser
which returns control to the calling program directly rather than through
callbacks.  I thought about this a while ago but I gave up.  The only ways
I could think of involved either multiple threads or multiple processes
with IPC, and even if those parts worked perfectly it still wouldn't be all
that nice.

It was easier to just get comfortable with callbacks than to do that.  I'm
afraid you are in the same boat.  But it shouldn't be too hard to make
that transition.



> <record>
>    <author>Baum, L. Frank</author>
>    <title>The Wizard of Oz</title>
>    <date>1909</date>
> </record>
>
> The module works something like this:
>
> package FetchRecords;
> use Exporter;
> @ISA = Exporter;
> @EXPORT = qw(getRecords);
>
> my @records;

# change to:
my $callback;

> my $current_record = {};
>
> sub getRecords {
>     my $xmlfile = shift;
>
>     ## Parser setup and initialization here ...
>
>     return \@records;
> }

sub getRecords {
  $xmlfile=shift;
  $callback=shift;
  ## Parser setup and initialization here ...
};



>
> sub end_element {
>     my ($self, $e) = @_;
>     if ($e->{LocalName} eq 'author') {
>        $current_record->{author} = $e->{data};
>     } elsif ($e->{LocalName} eq 'title') {
>        $current_record->{author} = $e->{data};
>     } elsif ($e->{LocalName} eq 'date') {
>        $current_record->{date} = $e->{data};
>     } elsif ($e->{LocalName} eq 'record') {
>        push @records, $current_record;

         ##change previous line to:
         $callback->($current_record);

>        $current_record = {};
>     }
> }
>
> And the calling program works like this:
>
> use FetchRecords;
>
> my $records = getRecords('xmlfile.xml');
>
> foreach my $record (@$records) {
>     my $author = $record->{author};
>
>     ## etc...
> }

my $used_to_be_foreach = sub {
     my $record=$_[0];
     my $author = $record->{author};
     ## etc...
}

getRecords('xmlfile.xml',$used_to_be_foreach);


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Fri, 24 Feb 2006 12:06:20 -0800
From: Arvin Portlock <nomail@sorry.com>
Subject: Re: Implementing a "pull" (?) interface in perl
Message-Id: <dtnovu$811$1@agate.berkeley.edu>

xhoster@gmail.com wrote:

> Arvin Portlock  wrote:
>
> >>>I don't understand. You are describing exactly how I want the
> >>>interface to act but not saying how you are doing it, i.e.,
> >>>how exactly get_one() works. But yes, that's what I'm aiming for.
> >>
> >>
> >>OK, now I don't understand.  If you give an example of how get_all()
> >>would work, we could discuss how to make it work like get_one()
> >>(assuming I can). But without seeing what you are currently doing, I
> >>don't know to help you change it!
> >>
> >>Xho
> >
> >Right now I'm not object oriented but I want to move in that
> >direction. This is a simplified example of what I'm doing.
> >Assuming a file containing records like this:
>
>
> but you want to write an adapter module that takes an *existing*
> call-back based XML-parser, and encapsulate it into a blocking parser
> which returns control to the calling program directly rather than 
> through callbacks.

I couldn't have said it better myself. Seriously.

>
> >sub end_element {
> >    my ($self, $e) = @_;
> >    if ($e->{LocalName} eq 'author') {
> >       $current_record->{author} = $e->{data};
> >    } elsif ($e->{LocalName} eq 'title') {
> >       $current_record->{author} = $e->{data};
> >    } elsif ($e->{LocalName} eq 'date') {
> >       $current_record->{date} = $e->{data};
> >    } elsif ($e->{LocalName} eq 'record') {
> >       push @records, $current_record;
>
>
>          ##change previous line to:
>          $callback->($current_record);
>
>
> >       $current_record = {};
> >    }
> >}

You've just basically written my entire program for me.
All I have to do now is fill in the bits. My ideas in
regards to callbacks weren't quite as elegant. Yeah, threads
occurred to me as well but no way was I getting anywhere
near that. Callbacks aren't *exactly* the way I wanted to
handle this but they fulfill the design requirements.
It should work with arbitrarily large documents, and
the parsing details are completely hidden from the calling
application.

About performance. I have written these things directly in
the parsing program before, handling events as they were
encountered, and those applications have always been much
faster than storing up the events and processing them later
for large documents. I've never tried it with a DOM parser
though, which I imagine is much more efficient at storing up
events and iterating through them than I am. I've always
just assumed an 80 Mb file would bring it to its knees.

Thanks for you help!




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

Date: Fri, 24 Feb 2006 16:13:14 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: read from file or from <DATA>?
Message-Id: <240220061613142272%brian.d.foy@gmail.com>

In article <PysLf.2273$M52.1632@edtnps89>, John W. Krahn
<someone@example.com> wrote:

> You probably want to determine if STDIN is connected to a terminal or
> receiving data from redirection or a pipe.
> 
> perldoc -f -t

Heh, I'm surprised that perldoc sequence worked, considering that
perldoc has its own -t switch. :)
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***


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

Date: Fri, 24 Feb 2006 17:41:22 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: sharing variables-data perl-asp
Message-Id: <mYLLf.25636$%14.666814@news20.bellglobal.com>


"UkJay" <jay@cutmeukjay.com> wrote in message 
news:dtlcu0$pbn$1@news6.svr.pol.co.uk...
>
> "Todd W" <toddrw69@excite.com> wrote in message 
> news:gHnLf.59889$PL5.1320@newssvr11.news.prodigy.com...
>>
>> "UkJay" <jay@cutmeukjay.com> wrote in message
>> news:dtkhp3$4va$1@news6.svr.pol.co.uk...
>>> Is it possible to pass data between variables when using active server
>> pages
>>> and inserting some perl script in asp?
>>>
>>> Also how do you invoke a perl script from an active server page?
>>>
>>> Yes I want the best of both worlds ;-)
>>>
>>
>> The "pass data between variables" part I dont understand, but I think you
>> are looking for PerlScript. ASP in Perl. Here is a quickstart guide:
>>
>> http://www.4guysfromrolla.com/webtech/021100-1.shtml
>>
>> trwww
>>
>>
>
> I'm not looking for perl script
> I use it
>
> I want to use perl script in asp
> and share data
>

<%@ Language="PerlScript" %>

You're now using Perlscript in asp.

What exactly is "share data" supposed to mean? You want to store it in 
session: $Session->setVariable('key', 'value') or just write it back to 
hidden input fields in the next page's form? You'll have to elaborate if you 
expect any meaningful help.

Matt 




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

Date: Fri, 24 Feb 2006 14:47:49 +0100
From: RBCS <rbcs@gmx.net>
Subject: Threads
Message-Id: <pan.2006.02.24.13.47.49.149000@gmx.net>

Hello

Can someone tell me which module I should use to create tasks in windows
where I can run certain work in it. I used POE module, but this library
crashes when I load it with a lot of work and is not very happy with
ActiveState perl.

What do you recomend me?

Roman


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

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


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