[19660] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1855 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 2 09:05:46 2001

Date: Tue, 2 Oct 2001 06:05:10 -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: <1002027910-v10-i1855@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 2 Oct 2001     Volume: 10 Number: 1855

Today's topics:
        2 newlines after Headerlines in HTTP? <Rainer.Klier@erl.sbs.de>
    Re: Algorithm/Module for improving poor RegExps? <epa98@doc.ic.ac.uk>
    Re: Algorithm/Module for improving poor RegExps? <epa98@doc.ic.ac.uk>
    Re: Algorithm/Module for improving poor RegExps? (Mark Jason Dominus)
    Re: best regular expression (Eduardo Oliveros)
        Can't create NDBM database <gbeanery@hotmail.com>
    Re: Can't unlink file under Perl for NT (Rafael Garcia-Suarez)
    Re: Can't unlink file under Perl for NT <wyzelli@yahoo.com>
        Conditional regex substitution <marc.beyer@berlin.de>
    Re: Conditional regex substitution (Anno Siegel)
    Re: Conditional regex substitution nobull@mail.com
        delay in the loop - high CPU usage <andrey@flyg.kth.se>
    Re: delay in the loop - high CPU usage <ilya@martynov.org>
    Re: How to htmlize an email, for eg lynx? (David Combs)
        HTTP::Daemon::ClientConn <Rainer.Klier@erl.sbs.de>
    Re: IE vs. Netscape problems in perl <news@bim.be>
        my($a)=<> and strict <hermann@holzerath.de>
    Re: my($a)=<> and strict <joe+usenet@sunstarsys.com>
    Re: newbie question on objects and dereferencing <Thomas@Baetzler.de>
    Re: newbie question on objects and dereferencing <bart.lateur@skynet.be>
    Re: newbie question on objects and dereferencing (Miko O'Sullivan)
    Re: Perl 5.6.1 / IBM C compiler failure on pp_sys.c (Destiny's Lost Child)
    Re: Perl on CD-ROM <qvyht@removejippii.fi>
        reading unicode file/creating unicode dir  under w2k (Roland)
        Reduce "cell" where should I start (newbie) <08.363340@telia.com>
    Re: Reduce "cell" where should I start (newbie) <Thomas@Baetzler.de>
    Re: Sorting multidimensional arrays and MIN/MAX <s.warhurst@rl.ac.uk>
    Re: Sorting multidimensional arrays and MIN/MAX <s.warhurst@rl.ac.uk>
    Re: Sorting multidimensional arrays and MIN/MAX (Anno Siegel)
    Re: use RPC; (perl misk)
    Re: USEing modules in another directory (RoJo)
    Re: USEing modules in another directory (RoJo)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 02 Oct 2001 13:36:13 -0100
From: Rainer Klier <Rainer.Klier@erl.sbs.de>
Subject: 2 newlines after Headerlines in HTTP?
Message-Id: <3BB9D0DD.200BCD70@erl.sbs.de>

Hi,

to make visible, what a browser sends to a webserver,
I coded this tiny webserver, that shall bounce the
Requestheader back to the Browser.
Interesstingly it says, that the browser sent
2 newlines after the headerrequest. RFC 2616 says,
there should be one newline. Did I miss something?

Thanx, Rainer
------------------------------------------
#!/usr/bin/perl -wT

use HTTP::Daemon;
use HTTP::Response;

use constant PORT => 1234;

my $daemon = HTTP::Daemon->new(LocalPort => PORT)
  or die "Cannot open localport " . PORT .".\n$@";

while (my $clientconn = $daemon->accept()) {
  while (my $request = $clientconn->get_request()) {
    $requeststring = $request -> as_string();
    print $requeststring;
    $requeststring =~ s/^/-> /mg;
    $response = HTTP::Response->new();
    $response -> code(200);
    $response -> header('Content-type' => "text/plain");
    $response -> content($requeststring);
    $clientconn -> send_response($response);
  }
  $clientconn->close;
  undef($clientconn);
}


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

Date: 02 Oct 2001 09:47:09 +0100
From: Edward Avis <epa98@doc.ic.ac.uk>
Subject: Re: Algorithm/Module for improving poor RegExps?
Message-Id: <xn9y9mu5sz6.fsf@texel24.doc.ic.ac.uk>

"Markus Dehmann" <markus.cl@gmx.de> writes:

>Imagine I have the expressions:
>s/tree/x/g;
>s/fee/x/g;
>s/gee/x/g;
>
>Some tool should be able to convert it to:
>s/(?:tr|f|g)ee/x/;

It won't necessarily be faster.  I know that I have done tricks like
this and been surprised to find that the resulting match ran slower
than separate regexps: even with a pretty large number of things to
match against.  I don't have any examples and benchmarks to hand, but
I should have another look sometime.

Anyone else got measurements for separate regexps versus one big one?

-- 
Ed Avis <epa98@doc.ic.ac.uk>
Finger for PGP key


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

Date: 02 Oct 2001 09:49:59 +0100
From: Edward Avis <epa98@doc.ic.ac.uk>
Subject: Re: Algorithm/Module for improving poor RegExps?
Message-Id: <xn9u1xi5sug.fsf@texel24.doc.ic.ac.uk>

Jeff 'japhy' Pinyan <jeffp@crusoe.net> writes:

>>s/tree/x/g;
>>s/fee/x/g;
>>s/gee/x/g;
>>
>>Some tool should be able to convert it to:
>>s/(?:tr|f|g)ee/x/;
>
>Jarkko Hietniemi wrote Regex::PreSuf which takes a list of strings and
>converts them to an optimal regex to match any of them.

Why not just do

    s/(?:tree|fee|gee)/x/

and let Perl's regexp compiler optimize things?  It should combine
them into a single state machine and the 'ee's would get put together
into a single state (or two).

Is the regexp engine not that intelligent?

-- 
Ed Avis <epa98@doc.ic.ac.uk>
Finger for PGP key


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

Date: Tue, 02 Oct 2001 12:44:10 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Algorithm/Module for improving poor RegExps?
Message-Id: <3bb9b699.54ad$1df@news.op.net>

In article <xn9u1xi5sug.fsf@texel24.doc.ic.ac.uk>,
Edward Avis  <epa98@doc.ic.ac.uk> wrote:
>Why not just do
>
>    s/(?:tree|fee|gee)/x/
>
>and let Perl's regexp compiler optimize things?  

It doesn't perform the 'optimization' you are asking for.

Nor should it, since it would make the regex slower.

>It should combine them into a single state machine and the 'ee's
>would get put together into a single state (or two).

It should not.  (?:tr|f|g)ee has four states for 'tr', 'f', 'g', and
'ee', plus some for the |'s.  (?:tree|fee|gee) has three states for
'tree', 'fee', and 'gee', plus the same states for the |'s.  Also,
since the target strings are longer, the Boyer-Moore search is likely
to produce fewer false positives.

>Is the regexp engine not that intelligent?

In this case, it appears to be as intelligent as you want, since it
doesn't perform your defective 'optimization'.



-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 2 Oct 2001 04:00:27 -0700
From: eod_spam@yahoo.es (Eduardo Oliveros)
Subject: Re: best regular expression
Message-Id: <6a5611ae.0110020300.558cea96@posting.google.com>

Shan Ali Khan <shanali@singapura.singnet.com.sg> wrote in message news:<9p9pqv$8sp$1@violet.singnet.com.sg>...
> - regular expr to identify a 10 digit no. always beginning with 75 (7545632212, 7545632213 etc)
> - regular expr to strip 75 whenever it's received in a 10 digit no. and let the rest be 
>   selected (54632212 and 45632213 in the above case

Try this:

$nums="7512345678 7512332112";

@res = $nums=~/75(\d{8})/g;

print "res= @res \n"

output:
res= 12345678 12332112 

Regards,
  eod


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

Date: Tue, 02 Oct 2001 11:41:54 GMT
From: "Mike" <gbeanery@hotmail.com>
Subject: Can't create NDBM database
Message-Id: <6Khu7.108915$w7.13907287@news02.optonline.net>

I am a beginner, and am trying to learn how to create a database using NDBM.
Here is the code

#!/usr/bin/perl
use Fcntl;
use NDBM_File;

tie %dbhash, "NDBM_File", "dbdata", O_RDWR|O_CREAT, 0644;

$key='key1';
$value='value1';
$dbhash{$key}=$value;
untie %dbhash;

---------
This code creates a dbdata.db file, but apparently the book says I have to
create a dbdata.pag and dbdata.dir files.  Please help
Thanks





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

Date: 2 Oct 2001 07:49:30 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Can't unlink file under Perl for NT
Message-Id: <slrn9risbp.qea.rgarciasuarez@rafael.kazibao.net>

Glenn wrote in comp.lang.perl.misc:
} I can't seem to be able to delete a file via a Perl script under Win
} NT.  Have tried many things -- most recently this simple test...
} 
}     open (OUTFILE,"> e:/somedir/testfile.zzz");   #open it

You didn't test if the open succeeded.

}     printf OUTFILE "some test data\n";                # write something
}     close (OUTFILE);                                         # be sure
} to close it
}     unlink("e:/somedir/testfile.zzz") || print "could not delete  $!";
} # then delete it
} 
} The file gets created (it is there), but not deleted.  I get a
} "Permission denied" error.

What happens when you try to perform the same operation by hand ?
Does the filesystem grant you the permission to delete the file ?

} Don't ask why I am creating a file just to
} delete it -- my real use involves use of temporary files which I want to
} clean up when done. Any thoughts appreciated.  Thanks!

Have you tried the File::Temp module?

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Tue, 2 Oct 2001 18:14:42 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Can't unlink file under Perl for NT
Message-Id: <50fu7.2$xD5.267@wa.nnrp.telstra.net>

"Glenn" <glenn@surveystar.com> wrote in message
news:3BB91332.152A5049@surveystar.com...
> I can't seem to be able to delete a file via a Perl script under Win
> NT.  Have tried many things -- most recently this simple test...
>
>     open (OUTFILE,"> e:/somedir/testfile.zzz");   #open it
>     printf OUTFILE "some test data\n";                # write something
>     close (OUTFILE);                                         # be sure
> to close it
>     unlink("e:/somedir/testfile.zzz") || print "could not delete  $!";
> # then delete it
>
> The file gets created (it is there), but not deleted.  I get a
> "Permission denied" error.  Don't ask why I am creating a file just to
> delete it -- my real use involves use of temporary files which I want to
> clean up when done. Any thoughts appreciated.  Thanks!

I would guess it is a permissions problem then!

Try changing the permissions from 'Change' to 'Full Control' and see what
happens.

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Tue, 02 Oct 2001 10:25:44 +0100
From: Marc Beyer <marc.beyer@berlin.de>
Subject: Conditional regex substitution
Message-Id: <9pc15i$h996p$1@ID-80494.news.dfncis.de>

Hi,

I'm trying to remove some specific characters from a string like

s/=>|,|=|;| |"|'//g

but to exempt any characters enclosed by quotation marks. So that (for 
example):

Hello , => man=woman; "you, know=>";  'nothing;'

becomes

Hellomanwomanyou, know=>nothing;

Is there any way to do this with a single substitution or do I need to 
separately match the strings in quotation marks and substitute them after 
the special character have been removed from the rest of the string?

Any help would be muchly appreciated, thanks,

Marc


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

Date: 2 Oct 2001 10:00:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Conditional regex substitution
Message-Id: <9pc37n$d0r$1@mamenchi.zrz.TU-Berlin.DE>

According to Marc Beyer  <marc.beyer@berlin.de>:
> Hi,
> 
> I'm trying to remove some specific characters from a string like
> 
> s/=>|,|=|;| |"|'//g
> 
> but to exempt any characters enclosed by quotation marks. So that (for 
> example):
> 
> Hello , => man=woman; "you, know=>";  'nothing;'
> 
> becomes
> 
> Hellomanwomanyou, know=>nothing;
> 
> Is there any way to do this with a single substitution or do I need to 
> separately match the strings in quotation marks and substitute them after 
> the special character have been removed from the rest of the string?

If there is a single substitution, it is going to be complex.  A solution
in two or three steps is probably preferable.  You may want to take a
look at perldoc -q delimited.  It deals with treating characters within
quotes differently, though it's about splitting, not deleting.

Anno


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

Date: 02 Oct 2001 13:07:13 +0100
From: nobull@mail.com
Subject: Re: Conditional regex substitution
Message-Id: <u9bsjq1c0e.fsf@wcl-l.bham.ac.uk>

Marc Beyer <marc.beyer@berlin.de> writes:

> I'm trying to remove some specific characters from a string like
> 
> s/=>|,|=|;| |"|'//g
> 
> but to exempt any characters enclosed by quotation marks.

This is superfially similar to the FAQ "How can I split a [character]
delimited string except when inside [character]?"

> Hello , => man=woman; "you, know=>";  'nothing;'
> 
> becomes
> 
> Hellomanwomanyou, know=>nothing;
> 
> Is there any way to do this with a single substitution or do I need to 
> separately match the strings in quotation marks and substitute them after 
> the special character have been removed from the rest of the string?
> 
> Any help would be muchly appreciated, thanks,

It is _possible_ to do it with a s///eg:

s{([^'"]*)((["'])(.*?)\3)?}{
	my ($unquoted_bit, $quoted_bit) = ($1,$4);
	$unquoted_bit =~ s/=>|[,=; ]//g;
        no warnings 'uninitialized';
	$unquoted_bit . $quoted_bit;
}eg;

I really think it would aid readbility to do with an explicit while
loop:

my $out ='';
while (/([^'"]*)((["'])(.*?)\3)?/g) {
	my ($unquoted_bit, $quoted_bit) = ($1,$4);
	$unquoted_bit =~ s/=>|[,=; ]//g;
        no warnings 'uninitialized';
	$out .= $unquoted_bit . $quoted_bit;
}

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 02 Oct 2001 13:18:46 +0200
From: Andrey Shipsha <andrey@flyg.kth.se>
Subject: delay in the loop - high CPU usage
Message-Id: <3BB9A296.E3BBF660@flyg.kth.se>

Hello,

Last week I posted a question about a simple script which would monitor
a web page for me. I have received answers with a suitable algorithm for
that task.

Now I have implemented the algorithm and it seems to works great. The
only thing which is still annoying is that the CPU usage remains on 100%
while the script is running. Maybe it matters how one implements a loop
in the script?

I did it this way:

while (1>2)   #simple condition for forever loop
{
use POSIX ":sys_wait_h";
  { local($SIG{CHLD})=sub{wait};
    my $start = time;
    if (fork) { sleep } else { 1 while (time - $start < 60); exit }
  }
the body of my code which gets the page, derives MD5 signature, et.
}

The part of the code starting from "use POSIX" is meant to introduce a
delay of 60 sec. between the loops.

Is there any smarter way to delay or pause the script between the loops
so the CPU usage is not that heavy?

Cheers,

Andrey.

P.S. I attach my post from last week with an answer.


On Mon, 24 Sep 2001 15:29:36 +0200, Andrey Shipsha
<andrey@flyg.kth.se> wrote:

>Hello,
>
>I have no experience with Perl. However, I really want to have a script
>which will monitor a web page for me and, once the contents of the web
>page changed, send me a mail.
>
>Are there any available scripts which could do this task?

Probably.  

One can be knocked out trivially with a couple of modules.  Notably:
LWP::Simple (to get the page), Net::SMTP (to send the mail) and
Digest::MD5 (to boil the page down to a small string for comparison,
you can use CRC's or direct comparison if you want to also).

Read the page
Get the MD5 signature, store this
Loop forever
      sleep a while
      Read the page
      Compute the MD5 signature of this new page
      Compare this MD5 signature to the old one if they don't match
             send the mail message
             replace the stored MD5 signature with the new one
end of loop


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

Date: 02 Oct 2001 15:47:10 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: delay in the loop - high CPU usage
Message-Id: <873d52p8ld.fsf@abra.ru>

>>>>> On Tue, 02 Oct 2001 13:18:46 +0200, Andrey Shipsha <andrey@flyg.kth.se> said:

AS> Hello,
AS> Last week I posted a question about a simple script which would monitor
AS> a web page for me. I have received answers with a suitable algorithm for
AS> that task.

AS> Now I have implemented the algorithm and it seems to works great. The
AS> only thing which is still annoying is that the CPU usage remains on 100%
AS> while the script is running. Maybe it matters how one implements a loop
AS> in the script?

AS> I did it this way:

AS> while (1>2)   #simple condition for forever loop

Did you mean while (2>1) ? Anyway it can be just while (1)

AS> {
AS> use POSIX ":sys_wait_h";
AS>   { local($SIG{CHLD})=sub{wait};
AS>     my $start = time;
AS>     if (fork) { sleep } else { 1 while (time - $start < 60); exit }
AS>   }
AS> the body of my code which gets the page, derives MD5 signature, et.
AS> }

Why not just

    sleep 60

istead of this block?

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 2 Oct 2001 08:14:17 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: How to htmlize an email, for eg lynx?
Message-Id: <9pbt0p$l0s$1@news.panix.com>

In article <oESr7.649$Owe.318486016@news.frii.net>,
Chris Fedde <cfedde@fedde.littleton.co.us> wrote:
><SNIP>
>Good Luck
>
>BTW if you like lynx you might just take a quick look at w3m.

I just tried it -- AND GUESS WHAT?  -- IT DOES "TABLES"!

Pretty cool, tables, which lynx does NOT do.

Now, any way to (like in lynx) print to file
what you see now on w3m screen?

Or do you have do it via fresh command line?

(I have done "w3m -h", and man w3m, and "?"
 from inside w3m.)

(But lynx does seem *much* nicer as an interactive
program for web browsing -- except for the table
thing.)

Thanks for finally getting me to try w3m!

David

PS: And thanks to everyone else for their helps.



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

Date: Tue, 02 Oct 2001 12:30:53 -0100
From: Rainer Klier <Rainer.Klier@erl.sbs.de>
Subject: HTTP::Daemon::ClientConn
Message-Id: <3BB9C18D.9B08ADFD@erl.sbs.de>

Hi,

implemented a simple HTTP Daemon via HTTP::Daemon
and wanted to document it. The man page says,
that accept returns an object of type 
HTTP::Daemon::ClientConn, but I cannot find this
Module and no docu on it. Is the documentation
of HTTP::Daemon wrong?

Bye, Rainer


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

Date: Tue, 02 Oct 2001 11:40:00 GMT
From: Bart Mortelmans <news@bim.be>
Subject: Re: IE vs. Netscape problems in perl
Message-Id: <3BB9A751.9030309@bim.be>

David Linker wrote:

> I need some help. I wrote a download logging perl script. It keeps track
> of how many times a file has been downloaded, and who did it, in two
> separate files. It works perfectly now when accessed from within
> Netscape, but when I use Internet explorer, it downloads a link with the
> name of the script, and logs two downloads!


I had the same problem when giving a pdf-file back to the browser. I was 
adviced to use

===
$Response->AddHeader('Content-Disposition',qq[inline; filename="some.pdf"]);
===

and it worked for me.
I'm not sure if $Response->AddHeader is something that only works on 
Win32, but you'll probably get the idea about what can be done...

Sincerely,
Bart Mortelmans
www.YourName.be



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

Date: Tue, 02 Oct 2001 12:59:53 +0200
From: Hermann Fass <hermann@holzerath.de>
Subject: my($a)=<> and strict
Message-Id: <3BB99E29.7B3FC41A@holzerath.de>

The following is not a problem at all, but
it makes me curious.

#!/usr/bin/perl5 -w-
use strict;
my($a) = <>;
print $a;

This does not work as expected.
(Version 5.005 on Solaris 7 btw.)
When finalizing a line with a return, the script does not
go on, but waits for further input. Until ^D (EOF) is pressed.

But this one works fine:

#!/usr/bin/perl5 -w-
use strict;
my($a);
$a = <>;
print $a;

Localizing ("Mying" :-) the variable $a in advance, i.e. in
a different line, solves the problem. (Which is what I do
in larger scripts anyway.)

Anybody knowing what happened here?

Hermann



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

Date: 02 Oct 2001 07:23:12 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: my($a)=<> and strict
Message-Id: <m38zeumgkf.fsf@mumonkan.sunstarsys.com>

Hermann Fass <hermann@holzerath.de> writes:

> #!/usr/bin/perl5 -w-
> use strict;
> my($a) = <>;
> print $a;
> 
> This does not work as expected.
> (Version 5.005 on Solaris 7 btw.)
> When finalizing a line with a return, the script does not
> go on, but waits for further input. Until ^D (EOF) is pressed.

Right.  That's what happens when <> is in a list context.

> 
> But this one works fine:
> 
> #!/usr/bin/perl5 -w-
> use strict;
> my($a);
> $a = <>;
> print $a;
> 

Here <> is in a scalar context, so it only reads a single line.

> Localizing ("Mying" :-) the variable $a in advance, i.e. in
> a different line, solves the problem. (Which is what I do
> in larger scripts anyway.)
> 
> Anybody knowing what happened here?

It's not "my" that's the culprit- it's the magic parens around $a:

  my $a = <>;

should work just fine.  See the perlop manpage for
a description of <>, and also

  % perldoc -f readline

-- 
Joe Schaefer   "If you pick up a starving dog and make him prosperous, he will
               not bite you. This is the principal difference between a dog and
                                           a man."
                                               --Mark Twain



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

Date: Tue, 02 Oct 2001 10:38:22 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: newbie question on objects and dereferencing
Message-Id: <uauirt8trc8ogm8ebpp7tepqseempc1qe1@4ax.com>

On 1 Oct 2001 18:17:21 -0700, lsulky@home.com (Old Lars) wrote:

>I'm new to perl and even newer to OO programming (despite my age!).

Well, let's see if we can teach this old dog any new tricks :-)

>Here is a sample snippet I pulled from a nice tutorial page:
>
>my $Top_Ten_Times = $DOM_document->DocumentElement();  # assign the
>root node
>my $Events = $Top_Ten_Times->childNodes();             # assign child
>nodes
>
>Why do we not do this:
>
>	$Events = $DOM_document->childNodes() ;

Because this is not the same.

According to your sample, it should be something like:

my $Events = $DOM_document->DocumentElement()->childNodes();

>That is, why is the assignment indirect? 

I'm assuming
- that $Top_Ten_Times might be used again later on
- that the author didn't want to type a long indirection chain

Also, you're usually supposed to check each link of the chain you're
following - one of your intermediate functions might fail, and you'd
never know what hit you. So you do something like the above if you can
be certain that for example the DocumentElement() method never fails.

>Also, I've tried examining values of these objects like this:
>
>	print("\nEvents=" . "$Events") ;

This doesn't make much sense. Try print("\nEvents=$Events") ;

I mean, apart from the fact that this is an object handle where printing
doesn't make sense anyways.

>and of course I get HASH values like these:
>
>	Events=Win32::OLE=HASH(0x1838344)

Think of an object as of a black box that is identified by the value of
it's instance variable. You have no need to know what's inside because
you can manipulate the object throug the documented methods. Trying to
do anything else is considered Not Nice and also potentially dangerous,
because the inner workings of a module may well change from version to
version. I mean, the whole idea of objects is to hide the implementation
details from users so that they may be changed without impacting
existing code :-)

>...but I'm getting fuddled trying to dereference properly to see what
>I think of as "real" values. I can't show the values as arrays or
>hashes no matter what gonzo sequence of $@% I try. Can anyone take
>pity and help me :-) ?

Just don't do it.

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Tue, 02 Oct 2001 11:55:09 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: newbie question on objects and dereferencing
Message-Id: <r9ajrt0bdlfutf6pt5nedkl1gcousv951l@4ax.com>

Old Lars wrote:

>I'm new to perl and even newer to OO programming (despite my age!). I
>find myself wanting to "see" for myself values of objects, and am
>often confused by levels of object indirection.

>Here is a sample snippet I pulled from a nice tutorial page:
>
>my $Top_Ten_Times = $DOM_document->DocumentElement();  # assign the
>root node
>my $Events = $Top_Ten_Times->childNodes();             # assign child
>nodes
>
>Why do we not do this:
>
>	$Events = $DOM_document->childNodes() ;
>
>That is, why is the assignment indirect? 

Because it wouldn't work? childNodes() is a method belonging to
$Top_Ten_Times, i.e. the object returned by
$DOM_document->DocumentElement(), and not a method of $DOM_document
itself.

I think this ought to work:

my $Events = $DOM_document->DocumentElement()->childNodes();


>Also, I've tried examining values of these objects like this:
>
>	print("\nEvents=" . "$Events") ;
>
>and of course I get HASH values like these:
>
>	Events=Win32::OLE=HASH(0x1838344)
>
>...but I'm getting fuddled trying to dereference properly to see what
>I think of as "real" values. I can't show the values as arrays or
>hashes no matter what gonzo sequence of $@% I try. Can anyone take
>pity and help me :-) ?

You should start playing with Data::Dumper. It will do what you're
asking for.

	use Data::Dumper;
	print "Events=" . Dumper $Events;

-- 
	Bart.


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

Date: 2 Oct 2001 05:34:43 -0700
From: miko@idocs.com (Miko O'Sullivan)
Subject: Re: newbie question on objects and dereferencing
Message-Id: <db27ea77.0110020434.5e124d14@posting.google.com>

lsulky@home.com (Old Lars) wrote in message news:<4662e966.0110011717.4935cefb@posting.google.com>...

> Also, I've tried examining values of these objects like this:
> 
> 	print("\nEvents=" . "$Events") ;
> 
> and of course I get HASH values like these:
> 
> 	Events=Win32::OLE=HASH(0x1838344)
> 
> ...but I'm getting fuddled trying to dereference properly to see what
> I think of as "real" values. I can't show the values as arrays or
> hashes no matter what gonzo sequence of $@% I try. Can anyone take
> pity and help me :-) ?

Assuming you're used to working with hashes, you could create a hash
with the same values as the object like this:

 my %Events_hash = %{$Events};

Then you could iterate through the hash like normal:

 while (my($k, $v) = each(%Events_hash))
    {print $k, '=', $v, "\n"}

Of course, I'd choose to display the values w/o the holding hash:

 while (my($k, $v) = each(%{$Events}))
    {print $k, '=', $v, "\n"}

 ... but that might be more confusing.

Take heart, they're simplifying this whole reference/dereference thing
in Perl 6.  Larry got a huge round of applause when he announced it.


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

Date: 2 Oct 2001 02:34:07 -0700
From: destinyslostchild@theironpig.com (Destiny's Lost Child)
Subject: Re: Perl 5.6.1 / IBM C compiler failure on pp_sys.c
Message-Id: <786bcb1.0110020134.288ee78e@posting.google.com>

Mike Wood <acewood@texas.net> wrote in message news:<3BB4C4B6.25E0A8F8@texas.net>...
> Hello,
> 
> I'm fairly new to compiling software, and have run across a stumper (at
> least for me).  I'm using the IBM C compiler v5.0.2, and I am trying to
> compile the stable Perl 5.6.1.  sh Configure -de runs OK, but make fails
> on pp_sys.c with the following:
> -

Your problem is that the Configure script does lots of tests to determine
which C functions/libraries are already available and which ones need to
be emulated.  Unfortunately some of its choices are incorrect on AIX.

These choices are stored in the config.sh as d_name (for functions) and 
i_name (for libraries) with values of 'undef' (for not present) or 'define'
(for present).  This file is then used by the perl makefile to create the
config.h file. 


>     `sh  cflags libperl.a pp_sys.o`  pp_sys.c
>           CCCMD =  cc -DPERL_CORE -c -D_ALL_SOURCE -D_ANSI_C_SOURCE
> -D_POSIX_SOURCE -qmaxmem=16384 -q32 -D_LARGE_FILES -qlonglong -O
> "pp_sys.c", line 4356.14: 1506-068 (W) Operation between types "struct
> hostent*" and "int" is not allowed.
> ...
> "pp_sys.c", line 4388.21: 1506-285 (S) The indirection operator cannot
> be applied to a pointer to an incomplete struct or union.
>  ...

You'll probably find that the d_geth* values are set to 'undef' which would
mean that gethostbyname(), gethostbyaddr(), gethostname() aren't defined on
your system either though they exist within libc.a.

SO your options are:
1) go through every test done by sh Configure and double check its results
2) get the AIX perl freeware package from Bull

Good Luck


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

Date: Tue, 02 Oct 2001 10:31:14 GMT
From: Hessu <qvyht@removejippii.fi>
Subject: Re: Perl on CD-ROM
Message-Id: <3BB99621.7082E24A@removejippii.fi>



Kiaya wrote:
> 
> Anyone know how to put Perl on a CD-ROM so that you can run scripts
> off of it? I am making a CD-ROM that needs a search function
> implemented on it. We would like to combine HTML and cgi so that the
> CD-ROM will look exactly the same as the website archive. Thanks,
> Kiaya

I have been thinking that making platform-independed cd-rom-perl
would be nice for example as an installation software.
Gotta look this issue deeper...


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

Date: 2 Oct 2001 01:53:06 -0700
From: roland.buehler@gmx.de (Roland)
Subject: reading unicode file/creating unicode dir  under w2k
Message-Id: <f4691d60.0110020053.49a46940@posting.google.com>

Hi,
a lot of w2k tools generates unicode files (e.g. ldifde.exe). I want
to read a special line (e.g username: namewithlotofspecialchars) out
of such a file and create a directory with this username - until now I
have no success :(
How could I do this?
How can I read a unicode file with perl? 
 Now I simply `type` it to another file and get an ANSI version of the
content
How can I create a dir using win32api::file?

Thx for any hints :)
Roland.


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

Date: Tue, 02 Oct 2001 12:29:54 GMT
From: "Åke Wahlberg" <08.363340@telia.com>
Subject: Reduce "cell" where should I start (newbie)
Message-Id: <6riu7.3213$XO2.387769@newsb.telia.net>

Hi all.

I need to make this file more efficient, and I am very new to Perl, but I
belive that's
the language to use for this...

Below I have "pasted" a section of the file I need to reduce, and I will use
the "2nd and 4th" cell to explain what needs to happen.

This cell has to be compared with the next one, if they are the same, then
you need to add the other name to the first one, and so on...
see example below.


    Cell "SCK" U WFC1 {
        Data 3;
        Drive {
            Waveform { DriveOff @ "0s"; }
        }
    }


an other cell that are the same execpt "name"

    Cell "SIMRST" U WFC3 {
        Data 3;
        Drive {
            Waveform { DriveOff @ "0s"; }
        }
    }

So the result I am looking for is this.....


    Cell "SCK+SIMRST" U WFC1 {
        Data 3;
        Drive {
            Waveform { DriveOff @ "0s"; }
        }
    }

Where should I start ??, are there any "modules" functions that could help
"ease" the pain ??

Thanks, and I will be appreciate your help.
Sten.





-------------------------------------------------------a section of the
input file---------------------------------


    Cell "SCK" 0/1 WFC0 {
        Data 6/7;
        Drive {
            Waveform { DriveOn @ "0ns"; DriveData @ "0s"; }
        }
    }
    Cell "SCK" U WFC1 {
        Data 3;
        Drive {
            Waveform { DriveOff @ "0s"; }
        }
    }
    Cell "SCK" L/H WFC2 {
        Data 0/1;
        Drive {
            Waveform { DriveOff @ "0s"; }
        }
        Compare {
            Waveform { CompareData @ "95ns"; }
        }
    }
    Cell "SIMRST" U WFC3 {
        Data 3;
        Drive {
            Waveform { DriveOff @ "0s"; }
        }
    }
    Cell "SIMRST" L/H WFC4 {
        Data 0/1;
        Drive {
            Waveform { DriveOff @ "0s"; }
        }
        Compare {
            Waveform { CompareData @ "95ns"; }
        }
    }





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

Date: Tue, 02 Oct 2001 14:52:03 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Reduce "cell" where should I start (newbie)
Message-Id: <rsdjrtkasvk4af7f0db74bmm6l2b84bkir@4ax.com>

On Tue, 02 Oct 2001, "Åke Wahlberg" <08.363340@telia.com> wrote:
>I need to make this file more efficient, and I am very new to Perl, but I
>belive that's the language to use for this...
[...]
>Where should I start ??, are there any "modules" functions that could help
>"ease" the pain ??

You might want to look at Parse::RecDescent to parse your input into a
structure that's more manageable - unless your input file is huge, in
which case Parse::RecDescent is probably a sub-optimal choice.

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Tue, 2 Oct 2001 09:46:23 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Sorting multidimensional arrays and MIN/MAX
Message-Id: <9pbusu$ttq@newton.cc.rl.ac.uk>

"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
news:m1adzadfi6.fsf@halfdome.holdit.com...

> What groups have you read for over a decade that support upside-down
> quoting?

The point I was making though was that I wasn't quoting (or at least didn't
consider myself to be). One didn't need to read your kind offer of help when
reading my reply because it was self-explanatory, and the only quote I
thought I was making was regarding the previously suggested "@array = sort
{ $a->[1] <=> $b->[1] } @array" line, which I repeated anyway.

> I've been on Usenet for 20 years now.

Okay, you got 15 years on me there ;)

> I just can't see the point of having the answer before the question.
> It's just wrong.  Either don't quote the question, or quote it in
> context.  It's either relevant, or it isn't.

I suppose I kind of get what you mean. The way that I've been "brought up",
with regard to usenet, is to use discretion. If you need to reply to
individual points of a person's post then the quote 'n' response method is
best (like I'm doing now). Or if the reply would be particularly unclear
without reading the previous post then I would post below it. If the reply
doesn't require quoting of individual points then I see no harm in posting
above where you can see it immediately. The other argument is that if you've
been following a thread or if the reply is to your post, you don't need to
see what you posted and only need to see the reply. If it's at the top it
saves you having to scroll down.
All the newsgroups I've ever hung out on use a mixture of methods, but
perhaps as you say, they have all been full of Microsoft-generation users
(like me) ;-)

Regards
Spencer




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

Date: Tue, 2 Oct 2001 10:08:00 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Sorting multidimensional arrays and MIN/MAX
Message-Id: <9pc05g$o60@newton.cc.rl.ac.uk>

"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn9ric8e.t75.mgjv@martien.heliotrope.home...

> You'll find that on this group (and, amazingly, all groups I subscribe
> to) the quoting style I mentioned is the norm, and top-posting or
> jeopardy quoting are severly frowned upon.

In my post before the one you "policed" me over I replied in-line after
relevant quotes. It was only that one post, for reasons I described to
Randal above (or below.. or before.. or after as maybe you are not viewing
this thread in thread view ;) that I top-posted.

<snip>
>        grep BLOCK LIST
>        grep EXPR,LIST
>
>        print FILEHANDLE LIST
>        print LIST
>
> See the lack of a comma after the first 'argument' in some of these
> cases? Those syntactical oddities encourage a use without parentheses,
> at least they do in my case.

I think flexibility is good but, arguably, when you're learning a language
(and especially if that involves attemtping to understand other ppl's code)
I think it's easier if there is less flexibility. For me, seeing one person
write, for example -

@sorted = sort @array            and someone else write -
@sorted = sort(@array)           (that's probably a bad example)

add an element of confusion into matters because you start asking questions
that you wouldn't need to ask if there was only one correct way to write
it.. if you see what I mean.

> @s = sort({$a cmp $b} @names);
> or
> @s = sort {$a cmp $b}(@names); #yuck
> but _not_
> @s = sort({$a cmp $b}, @names);

They all look pretty yuck to me.. think I'll leave out the parentheses in
sort routines & the like from now on :)

> You don't need a site. All the doucmentation comes with Perl, and should
> be installed wherever Perl is installed. perldoc is a command, that you
> can use from a shell (or command, or cmd) prompt. If you are on MS win,
> and you installed the ActiveState distribution, then you also have the
> documentation installed as HTML, available from your start menu thingy.

Yes, I use the ActiveState distribution. I think I need to seriously swot up
on it :)

Regards
Spencer




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

Date: 2 Oct 2001 10:31:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Sorting multidimensional arrays and MIN/MAX
Message-Id: <9pc52a$d0r$2@mamenchi.zrz.TU-Berlin.DE>

According to S Warhurst <s.warhurst@rl.ac.uk>:
> "Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
 
[top posting]

> > I've been on Usenet for 20 years now.
> 
> Okay, you got 15 years on me there ;)
> 
> > I just can't see the point of having the answer before the question.
> > It's just wrong.  Either don't quote the question, or quote it in
> > context.  It's either relevant, or it isn't.
> 
> I suppose I kind of get what you mean. The way that I've been "brought up",
> with regard to usenet, is to use discretion.

You forget that your discretion is binding to those who follow you.
Even if top-posting looks semi-reasonable from your point of view,
it makes it hard for people who want to follow up to your reply.

There are times when I think people top-post just because you can
get away with saying some things that would be challenged if it
wasn't such a hassle to do so.

Anno


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

Date: 2 Oct 2001 04:16:42 -0700
From: perlmisk@yahoo.co.uk (perl misk)
Subject: Re: use RPC;
Message-Id: <7fe42fcd.0110020316.305b5b6f@posting.google.com>

Thomas Bätzler <Thomas@Baetzler.de> wrote in message news:<qgtgrtoeo8vbnj1q9f5jfcnmblhj2e5vnt@4ax.com>...
> On 1 Oct 2001 06:41:38 -0700, perlmisk@yahoo.co.uk (perl misk) wrote:
> 
> >Advanced Perl Programming
> >13.2.1 Using RPC
> >
> >mentions an RPC module:
> 
> I guess this is one of those books that are supposed to be read from
> front to back for convenience. In 13.2., it says "In this section, we
> use the Msg library to implement a Remote Procedure Call module,
> RPC.pm."
> 
> If you don't want to type it in yourself, grab the sample sources at
> http://examples.oreilly.com/advperl/.
> 
> HTH,

Yes, very much so, thank you.

There is no mention of using the portmapper with RPC under Perl. Is
this one of those cases, there is no mention because it has not been
implemented, and my time could be better spent implementing it instead
of moaning?

Can RPC handle multiple requests?  i.e. in Programming Perl there are
a variety of different servers for socket IPC, post forking,
pre-forking, etc.  From (trying to) read the RPC.pm code from Advanced
Perl (not my strong point) there is no mention of handling multiple
instances, is this correct?

If so, is this a feature and my poor understanding of RPC, i.e.
£ Synchronicity
£     The caller waits until the called procedure finishes. The RPC
module
£     invokes Msg::send_now and Msg::rcv_now to get this
£     blocking behavior.
to "hide" the fact that it is remote?

from reading Msg.pm, I can't tell how event_loop actually works, and
whether or not it can handle synchronous requests.

So if my daemon (one running on each server) wants to handle requests
from a menu and other peer daemons on remote servers, should I forget
RPC and stick to plain sockets whereby I would have more control over
the forking?

Regards

Andy


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

Date: Tue, 02 Oct 2001 07:14:02 GMT
From: rojo@mindspring.com (RoJo)
Subject: Re: USEing modules in another directory
Message-Id: <3bb968b0.45005764@news.mindspring.com>

Chas,

To ungarble that one statement, I'll embed some spaces:
use ..:     :..      ::rjapps      ::cgi      ::xml_methods    ;

I'll pursue the lib() recommendation.  Thanx.


On Mon, 01 Oct 2001 20:09:12 GMT, friedman@math.utexas.edu (Chas
Friedman) wrote:

>On Mon, 01 Oct 2001 19:24:42 GMT, rojo@mindspring.com (RoJo) wrote:
>
>>
>>I'm learning PERL with the help of a good book and your generous help.
>>I've succeeded in creating enterprise-level modules for my programs.
>>They work like a charm, as long as they're in the same directory as
>>the calling program.  Since these modules will relate to several
>>applications, I want to put them into their own directory. But I can't
>>figure out the syntax to do so.
>>
>>
>>The current application program under development is in:
>>C:\Web_Sites\rjassets\cgi
>>
>>The  enterprise-level modules are in:
>>C:\Web_Sites\rjapps\cgi
>>
>>I coded this command near the top of the calling program:
>>use ..::..::rjapps::cgi::xml_methods;
>What does this say? (It looks garbled in my newsreader.)
>>
>>But the PERL compiler says:
>>syntax error at file_maint_using_modules.pl line 6, near "use .."
>>
>>I also tried:
>>use Web_Sites::rjapps::cgii::xml_methods;
>>
>>But I then got:
>>Can't locate Web_Sites/rjapps/cgii/xml_methods.pm in @INC (@INC
>>contains: C:/Perl/lib C:/Perl/site/lib .) at
>>file_maint_using_modules.pl line 6.
>>
>>Can anyone help me with the correct syntax for the USE?
>>
>>Ron (rojo@mindspring.com)
>You probably need a statement like
>use lib 'path_to_lib';
>(This will add to @INC.)
>and then some
>use Module; 
>statements. (Note the quotes in the use lib statement. It is possible
>they should be double quotes for Windows.)
>                             chas



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

Date: Tue, 02 Oct 2001 07:14:43 GMT
From: rojo@mindspring.com (RoJo)
Subject: Re: USEing modules in another directory
Message-Id: <3bb96942.45152515@news.mindspring.com>

Brian,

Thanks.  I'll look up the lib() in the perldoc.


On Mon, 01 Oct 2001 16:13:21 -0400, brian d foy <comdog@panix.com>
wrote:

>In article <3bb8c2cd.2539121@news.mindspring.com>, rojo@mindspring.com 
>(RoJo) wrote:
>
>> They work like a charm, as long as they're in the same directory as
>> the calling program.  Since these modules will relate to several
>> applications, I want to put them into their own directory. But I can't
>> figure out the syntax to do so.
>
>    http://www.perldoc.com/perl5.6.1/lib.html
>
>-- 
>brian d foy <comdog@panix.com> - Perl services for hire
>CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
>Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.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.  

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


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