[19332] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1527 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 15 06:10:57 2001

Date: Wed, 15 Aug 2001 03:10:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997870221-v10-i1527@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 15 Aug 2001     Volume: 10 Number: 1527

Today's topics:
        File of Records <asgar@tkusa.com>
    Re: File of Records <godzilla@stomp.stomp.tokyo>
    Re: File of Records <krahnj@acm.org>
    Re: File of Records <shutupsteve@awdang.no.thanks.com>
    Re: File of Records <krahnj@acm.org>
        Filehandle passed to function treated as scalar?? <miscellaneousemail@yahoo.com>
    Re: Filehandle passed to function treated as scalar?? (Tad McClellan)
    Re: Flock: Just to be sure ! (Anno Siegel)
        Freelance Perl Programmer <bob@thewebservice.com>
        Help with an HTML parsing problem (Dav Lam)
        How to call ISAPI dll from perl? <chch@kyokofukada.net>
    Re: Intermittent problems printing from perl <goldbb2@earthlink.net>
        Is $! a number or a string? (John Lin)
    Re: Is $! a number or a string? <pne-news-20010815@newton.digitalspace.net>
    Re: Is $! a number or a string? (John Lin)
    Re: Limit the number of child process <goldbb2@earthlink.net>
        make file's last field as first (PM Wong)
        Make-ing perl on Win98 <scheideg@mars.entic.net>
    Re: Make-ing perl on Win98 <wyzelli@yahoo.com>
        Need Perl module or regexp to slurp specific XML record <mel2000@hotmaildot.com>
    Re: Need Perl module or regexp to slurp specific XML re (Eric Bohlman)
    Re: Need Perl module or regexp to slurp specific XML re <godzilla@stomp.stomp.tokyo>
    Re: Not inserting duplicate elements into an array <ren@tivoli.com>
    Re: Not inserting duplicate elements into an array <gnarinn@hotmail.com>
        Perl and JVM (Ted)
    Re: Problem using the module Expect.pm <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 14 Aug 2001 23:40:22 -0400
From: "Asgar" <asgar@tkusa.com>
Subject: File of Records
Message-Id: <3b79ed72$0$150@wodc7nh6.news.uu.net>

I have a file of records in the form:

Today's File is:
00001 3423TG230 08/11/2001 NYC1
00002 3423TG231 08/12/2001 NYC2
00003 3423TG232 08/13/2001 NYC3
00004 3423TG233 08/14/2001 NYC4
00005 3423TG234 08/15/2001 NYC5
 ....
couple of hundreds of records.

I need to do the following:
1- skip the first line (header file)
2- in every record changed the date from mm/dd/yyyy format to mm/dd/yy.
3- at the end of each record have today's date in mm/dd/yy format appended.

I will appreciate any suggestions





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

Date: Tue, 14 Aug 2001 21:22:42 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: File of Records
Message-Id: <3B79F912.8066265D@stomp.stomp.tokyo>

Asgar wrote:

(snipped)
 
> I have a file of records in the form:
 
> I need to do the following:

> I will appreciate any suggestions


A suggestion would be to get off your
lazy butt and develop code to accomplish
what you expect others to serve you
upon a silver platter.


Godzilla!  Queen Of Plastic Picnic Utensils.


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

Date: Wed, 15 Aug 2001 04:25:31 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: File of Records
Message-Id: <3B79F9F5.ADB11B31@acm.org>

Asgar wrote:
> 
> I have a file of records in the form:
> 
> Today's File is:
> 00001 3423TG230 08/11/2001 NYC1
> 00002 3423TG231 08/12/2001 NYC2
> 00003 3423TG232 08/13/2001 NYC3
> 00004 3423TG233 08/14/2001 NYC4
> 00005 3423TG234 08/15/2001 NYC5
> ....
> couple of hundreds of records.
> 
> I need to do the following:
> 1- skip the first line (header file)
> 2- in every record changed the date from mm/dd/yyyy format to mm/dd/yy.
> 3- at the end of each record have today's date in mm/dd/yy format appended.
> 
> I will appreciate any suggestions


perl -pe 's|^(\d{5} \w{9} )(\d\d/\d\d/)\d\d(\d\d)( \w{4})$|$1$2$3$4
$2$3|' yourfile.txt



John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 14 Aug 2001 21:28:08 -0700
From: "Stephen Deken" <shutupsteve@awdang.no.thanks.com>
Subject: Re: File of Records
Message-Id: <tnjuhk9fu5k2c@corp.supernews.com>

#!/usr/bin/perl -wT

use strict;
use POSIX;

# asgar wrote:
# > I need to do the following:
# > 1- skip the first line (header file)

scalar <>;

# > 2- in every record changed the date from mm/dd/yyyy
#      format to mm/dd/yy.

foreach (<>)
{
  chomp;
  s- (\d{2})/(\d{2})/- $2/$1/-;

# > 3- at the end of each record have today's date in
#      mm/dd/yy format appended.

  $_ .= strftime( ' %m/%d/%Y', localtime( time() ) );

# > I will appreciate any suggestions

  print $_ . "\n";
}




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

Date: Wed, 15 Aug 2001 05:54:34 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: File of Records
Message-Id: <3B7A0F3A.2AB1C706@acm.org>

"John W. Krahn" wrote:
> 
> Asgar wrote:
> >
> > I have a file of records in the form:
> >
> > Today's File is:
> > 00001 3423TG230 08/11/2001 NYC1
> > 00002 3423TG231 08/12/2001 NYC2
> > 00003 3423TG232 08/13/2001 NYC3
> > 00004 3423TG233 08/14/2001 NYC4
> > 00005 3423TG234 08/15/2001 NYC5
> > ....
> > couple of hundreds of records.
> >
> > I need to do the following:
> > 1- skip the first line (header file)
> > 2- in every record changed the date from mm/dd/yyyy format to mm/dd/yy.
> > 3- at the end of each record have today's date in mm/dd/yy format appended.
> >
> > I will appreciate any suggestions
> 
> perl -pe 's|^(\d{5} \w{9} )(\d\d/\d\d/)\d\d(\d\d)( \w{4})$|$1$2$3$4
> $2$3|' yourfile.txt

Sorry, I misread part 3.

perl
-pe'BEGIN{@d=localtime}s|^(\S+\s\S+\s\d\d/\d\d/)\d\d(\d\d\s\S+)$|$1$2
sprintf"%02d/%02d/%02d",$d[4]+1,$d[3],$d[5]%100|e' yourfile.txt



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 15 Aug 2001 02:47:09 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Filehandle passed to function treated as scalar??
Message-Id: <MPG.15e390b18b4fb5e8989747@news.edmonton.telusplanet.net>

Hi everyone,

In the following code snippets...

print_contents(\*STDOUT, %h);

 ...

sub print_contents
{
  my ($FILE_HANDLE, %file_hash) = @_;
  my ($key, $value);
  while (($key, $value) = each %file_hash)
  { 
    print $FILE_HANDLE "$key -> $value\n"
  }
}

which seems to work just fine I was wondering why the $FILE_HANDLE in 
print_contents works when addressed as "print $FILE_HANDLE..."?  Since 
$FILE_HANDLE is technically a reference to a file handle (STDOUT) (I 
think) wouldn't it be more correct to say "print $$FILE_HANDLE..."?  

Why does a single "$FILE_HANDLE" work when in other cases such as 
addressing a reference to a hash one must use "$$" instead of "$"?  

I would appreciate someone's handle =:) on this.  

Thanks.

---
Carlos 
www.internetsuccess.ca
*NOTE*: Internet Success is NOT yet fully operational so although you are 
welcomed to visit and take a look, trying to subscribe will only be a 
frustration for you as your data will not be saved at this time.


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

Date: Wed, 15 Aug 2001 00:53:24 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Filehandle passed to function treated as scalar??
Message-Id: <slrn9nk024.c6u.tadmc@tadmc26.august.net>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:

> Subject: Filehandle passed to function treated as scalar??


Note that you are _not_ passing a "filehandle" to a function below.

You are passing a "reference to a typeglob" to a function.


>print_contents(\*STDOUT, %h);

>sub print_contents
>{
>  my ($FILE_HANDLE, %file_hash) = @_;

>    print $FILE_HANDLE "$key -> $value\n"


>which seems to work just fine I was wondering why the $FILE_HANDLE in 
>print_contents works when addressed as "print $FILE_HANDLE..."?  Since 
>$FILE_HANDLE is technically a reference to a file handle (STDOUT) (I 
                             ^^^^^^^^^^^

Ahh, but its a funky, special kind of reference...


>Why does a single "$FILE_HANDLE" work when in other cases such as 
>addressing a reference to a hash one must use "$$" instead of "$"?  


Magic. (seriously. That comes up from time to time with Perl)


>I would appreciate someone's handle =:) on this.  


from perlref.pod:

------------------------
It isn't possible to create a true reference to an IO handle (filehandle
or dirhandle) using the backslash operator.  The most you can get is a
reference to a typeglob, which is actually a complete symbol table entry.
But see the explanation of the C<*foo{THING}> syntax below.  However,
you can still use type globs and globrefs as though they were IO handles.
------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 15 Aug 2001 07:06:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Flock: Just to be sure !
Message-Id: <9ld70s$psj$1@mamenchi.zrz.TU-Berlin.DE>

According to John W. Krahn <krahnj@acm.org>:
> Anno Siegel wrote:
> > 
> > Instead of "1" you should use the constant LOCK_SH from the Ioctl
> > module.  Similar comments apply below.
> 
> $ perldoc Ioctl
> No documentation found for "Ioctl".
> 
> perldoc Fcntl

Yes.  Of course.
 
> 
> 
> >     open( FILE, "+>$file);
> > 
> > This will open for read/write, retaining the contents.  Then, after your
>                                  ^^^^^^^^^^^^^^^^^^^^^^
> 
> perldoc -f open
> 
> [snip]
>         You can put a `'+'' in front of the `'>'' or `'<''
>         to indicate that you want both read and write
>         access to the file; thus `'+<'' is almost always
>         preferred for read/write updates--the `'+>'' mode
>         would clobber the file first.
>               ^^^^^^^^^^^^^^^^^^^^^^

Yes.  Of course.

I should distribute a read-what-I-mean filter with my posts.

Anno


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

Date: Wed, 15 Aug 2001 05:12:45 GMT
From: "Bob Ruggeri" <bob@thewebservice.com>
Subject: Freelance Perl Programmer
Message-Id: <hxne7.135066$Cy.18968138@news1.rdc1.az.home.com>

Hello,

I am looking for a freelance Perl programmer to scrape information from 20
or so url's and insert into a database.  Please e-mail me
bob@thewebservice.com if you might be interested.  I do software
development, so I know per hour rates do not equate to low cost, but please
include pricing structure for general information.

Thanks,

Bob Ruggeri




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

Date: 15 Aug 2001 02:57:11 -0700
From: crud@hongkong.com (Dav Lam)
Subject: Help with an HTML parsing problem
Message-Id: <fc25f4f2.0108150157.1cca9167@posting.google.com>

I want to determine from an html that if it contains a hyperlink which
name--the text between the start and end tags of that hyperlink--is
"next", i've read the HTML::LinkExtor manpage and it seemds that it
can only parse out the attribute and what tag is it the link

Can anyone give me a clue how to do this task?

Thanks in advance


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

Date: Wed, 15 Aug 2001 14:29:48 +0700
From: "chch" <chch@kyokofukada.net>
Subject: How to call ISAPI dll from perl?
Message-Id: <9ld86j$jq6$1@chatta.samart.co.th>

Hi everybody. I'm new in here.
I'm also new perl developer. How I call my isapi dll from perl script?
that isapi link like as http://127.0.0.1/scripts/testisapi.dll?a=xx&b=yy
please help me.

thanks in advance.




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

Date: Wed, 15 Aug 2001 05:17:19 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Intermittent problems printing from perl
Message-Id: <3B7A3E1F.EEF9FDAB@earthlink.net>

Just a minor correction: each place I have unless( system ... ) should
be if( system ... ) since system returns a true value if the program
fails, and false if it succeeds.

-- 
I'm not a programmer but I play one on TV...


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

Date: 14 Aug 2001 19:18:38 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Is $! a number or a string?
Message-Id: <a73bcad1.0108141818.466d4f25@posting.google.com>

Dear all,

Who can explain this magic for me?

#!/usr/bin/perl -wl

$! = 5;
print $!;       #1: Input/output error
print $!+1;     #2: 6
print ++$!;     #3: No such device or address
print $!--;     #4: No such device or address

I guess there is a kind of variable that keeps a numeric value but
display differently when stringified.  This explains #1: #2: and #3:.

How about #4:?  The "--" performs a "return then decrement" operation.
So, what is printed is the "returned value", not the variable itself.
But it displays a string instead of a number.  Here the only guess I
can make is: the "returned value", one copy of the variable, is also
"this kind" of variable.

Yes, I can show my guess is right.  I copy it to a lexical variable:

# --- continued from the above program
my $x = $!;
print $x;       #5: Input/output error
print ++$x;     #6: 6

My questions are:

How many "this kind" of variables exist in Perl (built-in)?

Can I make this magic of my own?  (I believe the answer is "Yes".)
Thus, I can create an "iterator" to walk through my message table.

my $i = MessageTable::iterator(5);
print $i++;     # Message 5: Your email box is full
print $i++;     # Message 6: Fail to connection to mail server
print $i+1;     # 8

Thank you.
John Lin


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

Date: Wed, 15 Aug 2001 08:19:48 +0200
From: Philip Newton <pne-news-20010815@newton.digitalspace.net>
Subject: Re: Is $! a number or a string?
Message-Id: <ns4kntcvqi3apie87d64cj2hksq3r5qqu0@4ax.com>

On 14 Aug 2001 19:18:38 -0700, johnlin@chttl.com.tw (John Lin) wrote:

> I guess there is a kind of variable that keeps a numeric value but
> display differently when stringified.  This explains #1: #2: and #3:.

Precisely. It's even documented in the documentation, surprise surprise:

:  $OS_ERROR
:  $ERRNO
:  $!      If used in a numeric context, yields the current value of
:          errno, with all the usual caveats. (This means that you
:          shouldn't depend on the value of `$!' to be anything in
:          particular unless you've gotten a specific error return
:          indicating a system error.) If used in a string context,
:          yields the corresponding system error string.

> My questions are:
> 
> How many "this kind" of variables exist in Perl (built-in)?

I only know of $! having this dual nature.

> Can I make this magic of my own?  (I believe the answer is "Yes".)

Correct. You need XS code, however; you can't do it in pure Perl. The
Scalar::Util module gives you an interface to this functionality with
its dualvar subroutine:

:    dualvar NUM, STRING
:        Returns a scalar that has the value NUM in a numeric
:        context and the value STRING in a string context.
: 
:            $foo = dualvar 10, "Hello";
:            $num = $foo + 2;                    # 12
:            $str = $foo . " world";             # Hello world

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 15 Aug 2001 02:16:36 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: Is $! a number or a string?
Message-Id: <a73bcad1.0108150116.1205e87c@posting.google.com>

Philip Newton wrote
> On 14 Aug 2001 19:18:38 -0700, John Lin wrote:
> 
> > I guess there is a kind of variable that keeps a numeric value but
> > display differently when stringified.
> 
> Precisely. It's even documented in the documentation, surprise surprise:
> 
> :  $OS_ERROR
> :  $ERRNO

Thanks.  I did read this before I post.  But won't you feel curious about
this kind of behavior?

$! = 5;
my $x = $!;
print $x;       #5: Input/output error
print ++$x;     #6: 6

Now my question is: Is $x the same kind of variable as $! ?

If yes, why #6: doesn't print a message string (like #3: does)?
Why it lost its duality?

If no, then is $x a string or a number?
In #5: $x seems to be a string.
But if it is a string, then ++ on a string should be another string (like
++('AA') eq 'AB'), or 1 (like "A"+1 == 0+1 == 1), right?

Thank you.

John Lin


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

Date: Wed, 15 Aug 2001 04:27:02 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Limit the number of child process
Message-Id: <3B7A3256.77E71658@earthlink.net>

Cosmos Tong wrote:
> 
> Dear all,
> 
> I use the following code to create child process (copy from
> Programming Perl, 2nd Ed).  How can I know how many child process is
> running, and how can I limit them?

Knowing how many child processes are running is next to impossible,
except to keep track of how many you've created, and how many have died.

Limiting them is sortof easy -- just don't make that many!

> Also can anyone help explain the logic of the below code as I am
> confused.
> As the child will sleep 10 seconds, I can see 10 child
> processes.  And in the PARENT log I can see a list of 10 lines. 
> However, the CHILD log is not written until the 10 seconds is passed.
> And once the 10 seconds passed, the code that print the parent PID
> into PARENT LOG was run several times.  I am confused.

It's a buffering problem, I suspect.

The PARENT filehandle buffers the data it's writting.  With older perls,
filehandle buffers aren't flushed before a fork.  So you print some
stuff in the parent, then you fork.  After the fork, both the child and
the parent have the last thing the parent wrote in the buffer of their
PARENT filehandles.  When the child exits, it prints out whatever
unbuffered data it has [including that which is in the PARENT filehandle
buffer].  The solution is to upgrade to a newer perl, which will flush
handles before each fork, or else turn buffering off entirely.

> 
> Thanks very much.
> 
> Regards
> Cosmos
> 
> --
> 

#! /usr/bin/perl -w
use strict;

> open LOGFILE, ">/home/cosmos/devel/testing/log/rept.fork" ||
>   die "Cannot open log file\n";
> open CHILD, ">/home/cosmos/devel/testing/log/child"||
>   die "Cannot open log file\n";
> open PARENT, ">/home/cosmos/devel/testing/log/parent"||
>   die "Cannot open log file\n";

select( (
	select(LOGFILE), $|=1,
	select(CHILD  ), $|=1,
	select(PARENT ), $|=1,
	)[0] );

> sub REAPER {
>       $waitedpid=wait;
>       $SIG{CHLD} = \&REAPER;
> 
>       print LOGFILE "reaped $waitedpid\n";
> }
> 
> $SIG{CHLD} = \&REAPER;
> 
> print PARENT "-----$$-----\n";
> 
> while ( $x <= 100 ) {

If you only want 10 children, change this to 10.
Of course, better would be:
for my $x ( 1 .. 10 ) {

>     FORK: {
>         if ($pid=fork) {
>              print PARENT "$countp $$ $pid\n";
> 
>         }elsif (defined $pid) {
>             print CHILD "Child process $$ created\n";
>             sleep 10;
>             exit;
> 
>         }elsif ( $! =~ /No more process/ ){
>                 sleep 10;
>                 redo FORK;
>         }

You need another else here:
	else {
		die "Fork failed unexpectedly: $!";
	}

>      }
> 
>      $x++;

If you replace the while() with a for(), get rid of the above line.

> }

-- 
I'm not a programmer but I play one on TV...


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

Date: 16 Aug 2001 01:53:07 GMT
From: s11976@net1.hkbu.edu.hk (PM Wong)
Subject: make file's last field as first
Message-Id: <9lf923$ibg$1@net44p.hkbu.edu.hk>

Sorry for the trivial question.
I have a file with varying no. of fields (space delimited)
for each line
My objective is to make the last field become the first,
plus adding a tab character to delimit this field from the other
fields.
Any perl script could accomplish this ?



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

Date: 15 Aug 2001 01:14:33 GMT
From: Kent Scheidegger <scheideg@mars.entic.net>
Subject: Make-ing perl on Win98
Message-Id: <3b79ccf9$0$148@wodc7nh6.news.uu.net>

  On cpan.org, it blithely states that Windoze compatibility
is now built in, so you don't need to go get the binary "ports"
any more.  Just "make" your own.  My experience is somewhat 
different.

  I got the Borland C++ 5.5 compiler.  I got dmake.  I followed 
the README.WIN32 directions carefully.  It was a total failure.
No perl.exe was compiled.  A bunch of stuff flew by on the screen,
but nothing intelligible to tell me what the problem is.

  The README.WIN32 file has some disparaging remarks about Win98's
command.com shell.  Is that the problem?  Is the "make" process
just for NT and incompatible with 98?  Or is there some simple
trick I am missing here to actually do this on Win98?

  Any info would be appreciated.


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

Date: Wed, 15 Aug 2001 11:28:07 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Make-ing perl on Win98
Message-Id: <CBke7.62$1T.180114@wa.nnrp.telstra.net>

"Kent Scheidegger" <scheideg@mars.entic.net> wrote in message
news:3b79ccf9$0$148@wodc7nh6.news.uu.net...
>   On cpan.org, it blithely states that Windoze compatibility
> is now built in, so you don't need to go get the binary "ports"
> any more.  Just "make" your own.  My experience is somewhat
> different.
>
>   I got the Borland C++ 5.5 compiler.  I got dmake.  I followed
> the README.WIN32 directions carefully.  It was a total failure.
> No perl.exe was compiled.  A bunch of stuff flew by on the screen,
> but nothing intelligible to tell me what the problem is.
>
>   The README.WIN32 file has some disparaging remarks about Win98's
> command.com shell.  Is that the problem?  Is the "make" process
> just for NT and incompatible with 98?  Or is there some simple
> trick I am missing here to actually do this on Win98?
>
>   Any info would be appreciated.

Yep, go straight to www.activestate.com and download the binary.

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";





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

Date: Tue, 14 Aug 2001 19:39:55 -0700
From: "M.L." <mel2000@hotmaildot.com>
Subject: Need Perl module or regexp to slurp specific XML records
Message-Id: <9lcng3$8kog3$1@ID-19545.news.dfncis.de>

Given the following fixed XML records format:

<record id="0128">
  <name>John Doe</name>
  <address>123 Main St.</address>
  <city>Lake Elsinore</city>
  <state>CA</state>
  <phone>(123) 456-7890</phone>
  <zip>12345</zip>
  <email>jd@domain.com</email>
</record>

I don't want to slurp the entire database, just those records (and their
child elements) where, for example, <state> = NY

And I'd like to assign each record to a hash where:

$records{$id}{'id'} = ...
$records{$id}{'name'} = ...
$records{$id}{'address'} = ...
$records{$id}{'city'} = ...
$records{$id}{'state'} = NY
$records{$id}{'phone'} = ...
 ...

Which pure Perl (no C compiler needed) module or Perl regExp solution would
be best for this effort? The other modules I've looked at either needed a C
compiler, or required the entire XML database to be slurped before parsing.

Thanks




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

Date: 15 Aug 2001 02:57:21 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Need Perl module or regexp to slurp specific XML records
Message-Id: <9lcoeh$rjs$2@bob.news.rcn.net>

In comp.lang.perl.misc M.L. <mel2000@hotmaildot.com> wrote:
> Given the following fixed XML records format:

> <record id="0128">
>   <name>John Doe</name>
>   <address>123 Main St.</address>
>   <city>Lake Elsinore</city>
>   <state>CA</state>
>   <phone>(123) 456-7890</phone>
>   <zip>12345</zip>
>   <email>jd@domain.com</email>
> </record>

> I don't want to slurp the entire database, just those records (and their
> child elements) where, for example, <state> = NY

> And I'd like to assign each record to a hash where:

> $records{$id}{'id'} = ...
> $records{$id}{'name'} = ...
> $records{$id}{'address'} = ...
> $records{$id}{'city'} = ...
> $records{$id}{'state'} = NY
> $records{$id}{'phone'} = ...
> ...

> Which pure Perl (no C compiler needed) module or Perl regExp solution would
> be best for this effort? The other modules I've looked at either needed a C
> compiler, or required the entire XML database to be slurped before parsing.

If "pure Perl" still allows requiring XML::Parser to be installed, you 
could try XML::Records.



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

Date: Tue, 14 Aug 2001 21:57:43 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Need Perl module or regexp to slurp specific XML records
Message-Id: <3B7A0147.B9FD03DF@stomp.stomp.tokyo>

M.L. wrote:

(snipped)
 
> Given the following fixed XML records format:
 
> I don't want to slurp the entire database, just those records (and their
> child elements) where, for example, <state> = NY

Why would you consider using a module or consider
slurping a data base for a simple routine task?

 
> And I'd like to assign each record to a hash where:

I do not support use of a slow inefficient hash where
a quick efficient associative array can be used. Are
you a Perl 5 Cargo Cultist?

A presumption is made your data is precisely as you
state and, you will not be responding with,

  "Well...  uh... duh... my data is actually... duh...
  uhhh.. no.. actually I need to... duh... hmm..."


Research and read about the  $/  default record separator
along with the powerful and efficient local () function.

My $user_parameter represent user input criteria.

Replace my print function with whatever you want,
even an illogical slow inefficient hash routine.



You Perl 5 Cargo Cultists dictate local () is worthless
and should be removed from perl core? This is a classic
example of Perl 5 Cargo Cultists not having an ability
to think for themselves. You truly are Borg.


Godzilla!
--

#!perl

print "Content-type: text/plain\n\n";

$user_parameter = "ou812";

&Localize;

sub Localize
 {
  local ($/) = "<record id=\"";

  while (<DATA>)
   {
    if (/$user_parameter/i)
     {
      s/(\d+)">/ID $1:/;
      s/<\/.*>(\n)/$1/g;
      tr/>/:/;
      s/:/: /g;
      s/<([a-z])/\u$1/g;
      s/\n+$//;
      print;
     }
   }
 }


__DATA__
<record id="0127">
  <name>Kiralynne Schilitubi</name>
  <address>Oh My Big Butt Blvd.</address>
  <city>Riverside</city>
  <state>CA</state>
  <phone>(800) eat-fish</phone>
  <zip>12345</zip>
  <email>godzilla@stomp.stomp.tokyo</email>
</record>
<record id="0128">
  <name>Billyray</name>
  <address>Nine Inch Blvd.</address>
  <city>Riverside</city>
  <state>CA</state>
  <phone>(800) ou812</phone>
  <zip>12345</zip>
  <email>clydesdale@my.boyfriend.com</email>
</record>


PRINTED RESULTS:
________________

ID 0128: 
  Name: Billyray
  Address: Nine Inch Blvd.
  City: Riverside
  State: CA
  Phone: (800) ou812
  Zip: 12345
  Email: clydesdale@my.boyfriend.com


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

Date: 14 Aug 2001 18:37:39 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Not inserting duplicate elements into an array
Message-Id: <m3itfq5i2k.fsf@dhcp9-161.support.tivoli.com>

On Wed, 15 Aug 2001, Pcmann1@btinternet.com wrote:

Close...

>   my $page = new Page $uri; # Create a new Page object. Call the constructor
>   my $links = $page->links; # Now extract the links from the page
>   my %linksFromPage;                               # Create the hash
> 
>   for my $temp (@$links) { # Loop through all the links
>     if (exists $linksFromPage{$temp}) { # If its already in the hash then next link
>       next else { # Else link doesnt exist, hence add the link to the hash
>       $linksFromPage{$uri} = $temp;

Use this instead:

        $linksFromPage{$temp} = 1;

>     }
>   }

Since the hash isn't going to store duplicates anyway, there's really
no need to check.  I would use:

  $linksFromPage{$_}++ for @$links;

Which has the added benefit that you get a count of the occurrences
basically for free.  If you really don't need the count, you can get
even more clever by using a hash slice:

  @linksFromPage{@$links} = ();

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 15 Aug 2001 00:59:39 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Not inserting duplicate elements into an array
Message-Id: <997837179.101947403047234.gnarinn@hotmail.com>

In article <9lcat1$apg$1@neptunium.btinternet.com>,
Peter Mann <Pcmann1@btinternet.com> top-posted:

[
first of all, please do not top-post, that is, post a reply at the start of
the article, and then quote the whole of the article you are replying to.
]

>Ok, I looked up a Hash in my books and in theory it does what I need.
>But im not sure how to code it? A hash needs a value and a key right? But if
>I just have a list of links, what would be the key and what would be the
>content? The 'url' would effectively be unique, so is this the key?

the link would be the key, and anything you choose can be the value.
for example the value can be 1 (for exists) or it can be the count, if you
are interested in that.

>Anyway, I tried to implement what I think I need, but I cant get it to work.
>Does anyone have any suggestions?
>
>  my $page  = new Page $uri;       # Create a new Page object. Call the
>constructor
>  my $links = $page->links;          # Now extract the links from the page
>
>
>  my %linksFromPage;                               # Create the hash
>
>  for my $temp (@$links) {                        # Loop through all the
>links
>    if (exists $linksFromPage{$temp}) {      # If its already in the hash
>then next link
>      next
>    else {                                                     # Else link
>doesnt exist, hence add the link to the hash
>      $linksFromPage{$uri} = $temp;

no, replace it with:
       $linksFromPage{$temp}=1; # now it exists

>    }
>  }
>

now to your array of unique links
   my @links=keys %linksFromPage;

(snipped rest of top-posted article, along with whole thread)

gnari



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

Date: 14 Aug 2001 19:31:04 -0700
From: tsmandel@mediaone.net (Ted)
Subject: Perl and JVM
Message-Id: <42d0c841.0108141831.7de41780@posting.google.com>

We have an Web App Server that is written in Perl, I have a major
concern/problem.  When a client session is open, we want to call a
java client interface (wrapper) that allows connections between Web
App Server and our software.
 
My understanding that if I call this java client within Perl it will
instantiate the JVM for each client session that is open.  This will
be a huge problem.

Any ideas in dealing with Perl that calls a java app without creating
instance of the JVM for each client session.

Thanks


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

Date: Wed, 15 Aug 2001 05:29:38 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Problem using the module Expect.pm
Message-Id: <3B7A4102.7D177E5A@earthlink.net>

Daniel Wetzler wrote:
> 
> Hi,
> 
> I have a strange problem, using the perl module "Expect.pm".
> 
> I had no problems starting a program, normally running under console
> under Expect and automating the user input with my perl script.
> 
> The Program I want to operate via Expect.pm is written in Fortran and
> only asks the user several times for input, creates a data-file and
> writes the users data in a special format into it.
> 
> After the last input of the user it throws out a short message and
> stops automatically.
> My problem is, that if the program is called by Expect it doesn't want
> to stop.
> It runs further and further, producing tons of output in form of
> billions of the last message....
> The data file is written correctly so the program runs but doesn't
> stop at the time.
> 
> The perl script isn't further executed.So I don't have the possibility
> to send a
> 
> $program->hard_close();
> 
> to stop the program.
> 
> What's going wrong ?
> How can I handle this problem ?
> 
> I hope someone can help me.
> 
> Greetings, Daniel

Show us your perl/expect program, and maybe we can.


-- 
I'm not a programmer but I play one on TV...


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

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.  

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


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