[17426] in Perl-Users-Digest
Perl-Users Digest, Issue: 4846 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 8 14:06:45 2000
Date: Wed, 8 Nov 2000 11:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973710311-v9-i4846@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 8 Nov 2000 Volume: 9 Number: 4846
Today's topics:
Re: bad printf field width handling <fulko@wecan.com>
Re: cleaning up user input <--www forms (Anno Siegel)
Re: DBI and mysql <hartleh1@westat.com>
Re: Detecting socket closure <fulko@wecan.com>
Re: Detecting socket closure <fulko@wecan.com>
Files on NFS <ildar@mera.ru>
Re: garbage collecting hashes are slow <fulko@wecan.com>
Re: getgrgid does not work with nis (perl 5.6.0) <elaine@chaos.wustl.edu>
Re: getgrgid does not work with nis (perl 5.6.0) <Olivier.Lacroix@ciril.fr>
Re: getgrgid does not work with nis (perl 5.6.0) <ren.maddox@tivoli.com>
Re: getgrgid does not work with nis (perl 5.6.0) (Garry Williams)
Re: Google module help <jpmcg@smi.ucd.ie>
Handling telnet session termination (malgosia askanas)
Re: HELP HOMEWORK!!! <bill.kemp@wire2.com>
how to wait for a child to end <ghwen@infonie.fr>
Is this procedure called parsing? (Newbie) <support@bedroomisp.co.uk>
Re: Is this procedure called parsing? (Newbie) nobull@mail.com
Re: Is this procedure called parsing? (Newbie) (Michel Dalle)
Module Unicode::Map8 from CPAN schnurmann@my-deja.com
Re: OOP and information hiding (Richard J. Rauenzahn)
Re: Passing args as references <ren.maddox@tivoli.com>
Perl vs. ActivePerl (newbie) (LK)
Re: Perl vs. ActivePerl (newbie) <kstep@pepsdesign.com>
Re: Problem reading a binary file <flavell@mail.cern.ch>
Re: returning a true value is FUN! (was Re: Log.pm did <ren.maddox@tivoli.com>
Re: Searching for many words in large string (Rafael Garcia-Suarez)
Re: Searching for many words in large string (Anno Siegel)
Text::Wrap and cgi-bin programming <david@nucleus.chem.uconn.edu>
Re: Text::Wrap and cgi-bin programming <tony_curtis32@yahoo.com>
Re: Text::Wrap and cgi-bin programming <david@nucleus.chem.uconn.edu>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 08 Nov 2000 13:19:54 -0500
From: Fulko Hew <fulko@wecan.com>
Subject: Re: bad printf field width handling
Message-Id: <3A09994A.794B@wecan.com>
Ren Maddox wrote:
> > I have also just submitted a 'perlbug' on this item.
>
> Too bad you didn't check here first....
Very, unfortunately true.
But at least via perlbug I got an answer within 60 seconds.
Now thats IMPRESSIVE support! Take that you commercial outfits!
Unfortunately it is a "C" gotcha, and even though I've been
writting "C" code for over 20 years now, it still didn't twig
in my brain, until someone else shook it a bit.
Its amazing that I even sucked _all_ of my other cohorts at
work down the same garden path, as I travelled. Actually
they walked it by themselves... I didn't have to push.
------------------------------------------------------------------------
Fulko Hew, Voice: 905-333-6000 x 6010
Senior Engineering Designer, Direct: 905-333-6010
Northrop Grumman-Canada, Ltd. Fax: 905-333-6050
777 Walkers Line, Home: fulko%fkhew@wecan.com
Burlington, Ontario, Canada, L7N 2G1 Work: fulko@wecan.com
------------------------------
Date: 8 Nov 2000 16:39:11 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: cleaning up user input <--www forms
Message-Id: <8ubvjg$1rm$1@lublin.zrz.tu-berlin.de>
eyoung <eyoung@noway.com> wrote in comp.lang.perl.misc:
>Sometimes an idiot will enter tons of garbage into a text area, such as
>in a message
>board. If they keep typing without any spaces...the end result is a very
>long line in the next web page. The following code will look for a word
>that is over 80 characters and divide it into two pieces. However if the
>evil user types 180 characters the fist line will end up with 80
>characters and the remaining 100 will be on the next line not to mention
>if the 180 characters start at the end of the section....how do I change
>my to make it so that after 80 charaters a new line will be started. I
>tried doing it in the html by using the width and size settings on
>objects but that does not work either.
>
>$messagetext =~ s/(\b[a-zA-Z]{80})([a-zA-Z]+\b/ "$1­ $2" /ge;
The Text::Wrap module (in the standard distribution) does this.
Anno
------------------------------
Date: Wed, 08 Nov 2000 11:10:51 -0500
From: Henry Hartley <hartleh1@westat.com>
Subject: Re: DBI and mysql
Message-Id: <3A097B0B.88E23D07@westat.com>
HappyHippo wrote:
>
> SELECT id
> FROM items
> WHERE description LIKE $query
> OR title LIKE $query
> LIMIT 0,20
>
> I've used the AND, but I dont want to find the id's where both
> cases exist, I need to get them where either cases exist. Does
> anyone know how I can do this?
The SQL statement you have there will return the records where either of
the cases exist. That is, where description is LIKE $query or where
title is LIKE $query (including where they are BOTH LIKE $query).
What's the problem? Do you want to exclude those where they are both
true?
--
Henry Hartley
Westat
Rockville, Maryland, USA
------------------------------
Date: Wed, 08 Nov 2000 12:41:58 -0500
From: Fulko Hew <fulko@wecan.com>
Subject: Re: Detecting socket closure
Message-Id: <3A099066.167E@wecan.com>
Charles DeRykus wrote:
>
> In article <3A06D7AF.41C6@wecan.com>, Fulko Hew <fulko@wecan.com> wrote:
> >> Just curious but with your signal handler installed, what
> >> do you now see with:
> >>
> >> defined( send(...) ) || die "send $host: $!";
> >>
> >> Also, what does your handler look like?
> >
> >
> >send now unblocks and returns undef.
> >
>
> Right, but if the call returns undef, you'll
> get a $! return which is what I was curious
> about.
Sorry, don't know what that returns.
Fortunately, unfortunately, I've substantially changed the
code by now.
> >the handler:
> >
> >use POSIX qw(:sys_wait_h);
> >sub closer {
> > waitpid(-1, &WNOHANG);
> > $SIG{PIPE} = \&closer; # this enables send() to be interrupted
> >} # when the socket is closed
> >
>
> Partly what baffled me was that the usual idiom
> for checking C<send> returns is the code below:
>
> defined( send(...) ) || die "send $host: $!";
>
> You didn't use this which I would have expected
> to have revealed the SIGPIPE.
Unless you install the signal handler, send() never returns.
> So, I speculated
> that your error checking might be the culprit
> and wanted to eliminate that possibility.
>
> Sorry if I'm missing some key ingredient here.
If you are asking why I don't invoke || die
is because failure to send, because the other
side closed should NOT be considered catastrophic
as a lot of IO::Socket assumes. It should be
up to the programmer to decide what to do under
those circumstances. Unless I'm reading the POD
wrong, I don't think it'll let you do that. I
ended up subclassing it, and doing a more friendly
thing in my version... ie. return undef instead
of calling die.
------------------------------
Date: Wed, 08 Nov 2000 12:51:56 -0500
From: Fulko Hew <fulko@wecan.com>
Subject: Re: Detecting socket closure
Message-Id: <3A0992BC.2781@wecan.com>
Charles DeRykus wrote:
>
> In article <G3oo13.1u0@news.boeing.com>,
> Charles DeRykus <ced@bcstec.ca.boeing.com> wrote:
> >In article <3A06D7AF.41C6@wecan.com>, Fulko Hew <fulko@wecan.com> wrote:
> >>> Just curious but with your signal handler installed, what
> >>> do you now see with:
> >>>
> >>> defined( send(...) ) || die "send $host: $!";
> >>>
> >>> Also, what does your handler look like?
> >>
> >>
> >>send now unblocks and returns undef.
> >>
> >
> >Right, but if the call returns undef, you'll
> >get a $! return which is what I was curious
> >about.
> >
> >>the handler:
> >>
> >>use POSIX qw(:sys_wait_h);
> >>sub closer {
> >> waitpid(-1, &WNOHANG);
> >> $SIG{PIPE} = \&closer; # this enables send() to be interrupted
> >>} # when the socket is closed
> >>
> >
> >Partly what baffled me was that the usual idiom
> >for checking C<send> returns is the code below:
> >
> > defined( send(...) ) || die "send $host: $!";
> >
> >You didn't use this which I would have expected
> >to have revealed the SIGPIPE. So, I speculated
> >that your error checking might be the culprit
> >and wanted to eliminate that possibility.
See my previous reply to this.
> Actually, after checking DejaNews, I suspect you were
> correct in installing a SIGPIPE handler but something
> more like this would be a better IMO:
>
> { local $SIG{PIPE} = 'IGNORE';
> defined( send(...) ) || die "send $host: $!";
> }
>
> Unless I missed the boat, that'll prevent the SIGPIPE from
> terminating your program and instead C<send> will return -1
> with $! set to EPIPE ("broken pipe"). You shouldn't have to
> do any other error checking contortions.
Keep in mind that the program wasn't terminating, it was blocking
in send().
I suspect if you set it to ignore (I haven't tried it) then
the signal won't be delivered, and the send() won't get interrupted.
and I'm back to being blocked.
-----------------------------------------------------------------------
Fulko Hew, Voice: 905-333-6000 x 6010
Senior Engineering Designer, Direct: 905-333-6010
Northrop Grumman-Canada, Ltd. Fax: 905-333-6050
777 Walkers Line, Home: fulko%fkhew@wecan.com
Burlington, Ontario, Canada, L7N 2G1 Work: fulko@wecan.com
------------------------------
Date: Wed, 8 Nov 2000 19:45:37 +0300
From: "Ildar Gabdullin" <ildar@mera.ru>
Subject: Files on NFS
Message-Id: <8ubvvj$10q5$1@news.kis.ru>
Hello, all.
How I can determine from perl script whether the file reside on NFS or not ?
Any help very appreciated.
Ildar.
------------------------------
Date: Wed, 08 Nov 2000 13:05:41 -0500
From: Fulko Hew <fulko@wecan.com>
Subject: Re: garbage collecting hashes are slow
Message-Id: <3A0995F5.446B@wecan.com>
Gwyn Judd wrote:
>
> I was shocked! How could Fulko Hew <fulko@wecan.com>
> say such a terrible thing:
> >Gwyn Judd wrote:
> >>
> >> I was shocked! How could Fulko Hew <fulko@wecan.com>
> >> say such a terrible thing:
> >
> >I didn't want to say it!
>
> :) Oh by the way, it's considered rude to send someone an emailed reply
> and post the same reply to usenet without mentioning that fact.
My appologies. I've never heard such a rule before. Unless you
mean the private mail should have mentioned that it was posted too?
cause anyone reading the posting wouldn't care if it was privately
mailed.
I just think it convenient to receive it personally, since you were
involved in the discussion, and to have it posted too for posterity
so that others could benefit.
> >> >My app generates and clears a large number of hashes.
> >>
> >> >If you do the single sets, (on my machine) each set takes about
> >> >55 usec. Adding the clear statement ups the loop time to 800 usec.
> >>
> >> I don't get the same results as you with virtually the same code.
> >
> >Remember its a sample, and the speed _really_ depends on whats been
> >happening before that sample code. Basically I generate a hash that
> >has a few thousand items, a few dozen times. Then I generate a few
> >hundreds of thousand hashes that contain one or two items. Clearing
> >those small hashes sometimes takes a long time, but they are quick if
> >I skip that code that created and destroyed the big hashes.
> >So go figure?
>
> Beats me. What if you store all the little hashes in an array and just
> clear the array instead of clearing them one at a time? Are you sure you
> aren't running out of memory (when givin the choice of memory or speed,
> Perl tends to throw memory at the problem :) )
Ahh, I think I confused you. There is only ever a single hash.
Sometimes small, sometimes large. The reason for the "thousands of
times"
is to make a loop big enough to have its time measured.
No I'm not running out of memory, although I suppose it could have
started
paging under some of the test conditions. The box isn't within ear shot
so I couldn't hear it paging if it was.
More recent (slightly different) tests have given me different answers
so I'm beginning to suspect the paging effect was causing it.
> >> Can you post the script you use the do the benchmarking?
> >
> >Unfortunately not. Its propriatary code. It will take me some time
> >to build a test case that re-creates the same symptoms without the
> >special functionality. If you are interested (privately) I might
> >be able to send you the code, but I can't post it "as is".
>
> Well you'd be much better off posting it to usenet. I doubt I'd be able
> to find and fix your problem by myself but there are a number of experts
> here who probably can. Besides the end of year is coming up so I
> probably don't have time. See if you can reduce the problem to an example
> that has the behaviour and doesn't give away your proprietary secrets
> and post it here?
Alas, I know that. If I could have reduced the problem, I would have
already posted it. :-(
-------------------------------------------------------------------------------
Fulko Hew, Voice: 905-333-6000 x 6010
Senior Engineering Designer, Direct: 905-333-6010
Northrop Grumman-Canada, Ltd. Fax: 905-333-6050
777 Walkers Line, Home: fulko%fkhew@wecan.com
Burlington, Ontario, Canada, L7N 2G1 Work: fulko@wecan.com
------------------------------
Date: Wed, 08 Nov 2000 16:16:32 GMT
From: "Elaine Ashton" <elaine@chaos.wustl.edu>
Subject: Re: getgrgid does not work with nis (perl 5.6.0)
Message-Id: <A%eO5.13868$AM5.260562@news1.nokia.com>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:8ubs9s$1ld$1@lublin.zrz.tu-berlin.de...
> Olivier LACROIX <Olivier.Lacroix@ciril.fr> wrote in
comp.lang.perl.misc:
> >Hello.
> >I have a problem with getgrgid (and with all commend getgr*). It
returns
> >the correct value for all local groups, but returns NULL value for all
> >groups in the NIS database. I think there is a bug, because all
commands
> >getpw* work (even with NIS).
>
> I'd rather suspect a malfunction of the NIS system. Does niscat
> (or whatever you use for the purpose) show you the missing groups?
I use NIS with Perl 5.005_03 and 5.6.0 on Solaris 2.5, 2.6, 7 and HP-UX
10.20 and have no problems with getgrgid at all. Perhaps you would be
willing to show us your code. NIS generally either works or it doesn't.
e.
------------------------------
Date: Wed, 08 Nov 2000 18:07:01 +0100
From: Olivier LACROIX <Olivier.Lacroix@ciril.fr>
Subject: Re: getgrgid does not work with nis (perl 5.6.0)
Message-Id: <3A098834.3658372B@ciril.fr>
Elaine Ashton a écrit :
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:8ubs9s$1ld$1@lublin.zrz.tu-berlin.de...
> > Olivier LACROIX <Olivier.Lacroix@ciril.fr> wrote in
> comp.lang.perl.misc:
> > >Hello.
> > >I have a problem with getgrgid (and with all commend getgr*). It
> returns
> > >the correct value for all local groups, but returns NULL value for all
> > >groups in the NIS database. I think there is a bug, because all
> commands
> > >getpw* work (even with NIS).
> >
> > I'd rather suspect a malfunction of the NIS system. Does niscat
> > (or whatever you use for the purpose) show you the missing groups?
>
> I use NIS with Perl 5.005_03 and 5.6.0 on Solaris 2.5, 2.6, 7 and HP-UX
> 10.20 and have no problems with getgrgid at all. Perhaps you would be
> willing to show us your code. NIS generally either works or it doesn't.
>
> e.
I have tried the getgrgid in a C program and it works fine with NIS. I have
only this problem with my new PERL version.
--
Olivier LACROIX
C.I.R.I.L.
Cellule Réseau StanNet
Chateau du Montet | Tel : +33 3.83.44.74.29
Rue du Doyen Roubault | Fax : +33 3.83.44.02.62
F - 54500 VANDOEUVRE | email : Olivier.Lacroix@ciril.fr
------------------------------
Date: 08 Nov 2000 11:07:29 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: getgrgid does not work with nis (perl 5.6.0)
Message-Id: <m3d7g6o0j2.fsf@dhcp11-177.support.tivoli.com>
Olivier LACROIX <Olivier.Lacroix@ciril.fr> writes:
> Hello.
>
> I have a problem with getgrgid (and with all commend getgr*). It returns
> the correct value for all local groups, but returns NULL value for all
> groups in the NIS database. I think there is a bug, because all commands
> getpw* work (even with NIS).
Check the /etc/group file for the + line at the bottom. If that is
missing then NIS will not be used for group resolution. (At least,
that's the way I remember it, it's been several years since I've used
NIS.)
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 08 Nov 2000 18:42:02 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: getgrgid does not work with nis (perl 5.6.0)
Message-Id: <_7hO5.1039$FG.56629@eagle.america.net>
On 08 Nov 2000 11:07:29 -0600, Ren Maddox <ren.maddox@tivoli.com>
wrote:
>Olivier LACROIX <Olivier.Lacroix@ciril.fr> writes:
>> I have a problem with getgrgid (and with all commend getgr*). It returns
>> the correct value for all local groups, but returns NULL value for all
>> groups in the NIS database. I think there is a bug, because all commands
>> getpw* work (even with NIS).
>
>Check the /etc/group file for the + line at the bottom. If that is
>missing then NIS will not be used for group resolution. (At least,
>that's the way I remember it, it's been several years since I've used
>NIS.)
That may not be necessary. Here's the configuration I use on my
Solaris workstation (/etc/nsswitch.conf that came with Solaris):
# the following two lines obviate the "+" entry in /etc/passwd and
# /etc/group.
passwd: files nisplus
group: files nisplus
I don't configure any local groups in my local /etc/group file, so the
getgrgid() result does lall over to the NIS+ database:
$ cat /etc/group
root::0:root
other::1:
bin::2:root,bin,daemon
sys::3:root,bin,sys,adm
adm::4:root,adm,daemon
uucp::5:root,uucp
mail::6:root
tty::7:root,tty,adm
lp::8:root,lp,adm
nuucp::9:root,nuucp
staff::10:root
daemon::12:root,daemon
sysadmin::14:
nobody::60001:
noaccess::60002:
nogroup::65534:
$ perl -wle 'print getgrgid 43'
sysdev43bancroft garry csaunder mwilliam cpowers loget
$ perl -v
This is perl, v5.6.0 built for sun4-solaris
$ uname -a
SunOS ifr 5.8 Generic_108528-01 sun4u sparc SUNW,Ultra-5_10
$
--
Garry Williams
------------------------------
Date: 8 Nov 2000 17:46:11 GMT
From: John Paul McGowan <jpmcg@smi.ucd.ie>
Subject: Re: Google module help
Message-Id: <newscache$23tp3g$mgm$1@weblab.ucd.ie>
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> On Mon, 6 Nov 2000 12:02:23 -0000 jp wrote:
>> Hi,
>> I'm wondering if anyone who has used the Google.pm
>>
> OK Maybe I'm going blind but there doesnt appear to be a Google module
> on CPAN - well not on monday anyhow ... maybe you could be more specific.
I finally figured out the problem...the regular expression within the Google module to find the "next" button did not match the format in the Google results page. I then noticed there was a newer version of the Google module, so I checked the regexp in that and it matched - Google must have simply changed their format between July and September.
The Google module *is* detailed on CPAN, by the way, at
http://search.cpan.org/doc/JSMYSER/WWW-Search-Google-2.21/Google.pm .
JP
------------------------------
Date: 8 Nov 2000 11:12:21 -0500
From: askanas@panix.com (malgosia askanas)
Subject: Handling telnet session termination
Message-Id: <8ubu15$dic$1@panix6.panix.com>
I have an interactive Perl program which has the following bug: if the telnet
session goes down while the user is running the program, the program continues
to run and consumes a large amount of system resources. I tried to put in
signal handlers for "HUP" and "INT", but that didn't help. Can anybody
advise me on how to fix this? Many thanks in advance.
-malgosia
------------------------------
Date: Wed, 8 Nov 2000 17:04:20 -0000
From: "W Kemp" <bill.kemp@wire2.com>
Subject: Re: HELP HOMEWORK!!!
Message-Id: <973703408.25792.0.nnrp-08.c3ad6974@news.demon.co.uk>
<SNIP>
> {
> my($string) = "brad<hello>3hello";
> $string =~ /^[^\d]{2,4}<([^>]+)>\d?\1$/;
> if( defined($1) ) {
Isn't that a bit duff?- see below
> print "$1\n";
> } else {
> print "not found\n";
> }
> }
Surely $1 could be from a previous pattern match that worked, and so be
defined.
Although I suspect that the blocking would make sure that this was not the
case.
I would have thought that this wasn't really a good thing to be teaching
people.
(answer myself- yes) compare:-
perl -e 'while(<>){ {/(a.a)/; if ( defined ($1) ){print
"yes\n"}else{print"no\n"} }}'
with
perl -e 'while(<>){ /(a.a)/; if ( defined ($1) ){print
"yes\n"}else{print"no\n"}}'
------------------------------
Date: Wed, 8 Nov 2000 17:25:13 +0100
From: "ghwen" <ghwen@infonie.fr>
Subject: how to wait for a child to end
Message-Id: <973701077.624221@remus.infonie.fr>
My script executes a ftp script in nohup mode and I'd like the first script
to wait the end of transfert or kill the process after a delay.
Thank you for your help
------------------------------
Date: Wed, 8 Nov 2000 17:26:18 -0000
From: "Phil Latio" <support@bedroomisp.co.uk>
Subject: Is this procedure called parsing? (Newbie)
Message-Id: <XXfO5.1800$y94.46280@stones>
Is it possible to write a small perl program that will do the following:
1. Go to a text based file (no HTML in the document) on a web server
2. Find a particular text string
3. Start capturing the text directly after this string
4. Stop capturing text before another specified text string
5. Display this captured text on a webpage as an SSI
I reckon this should be quite a simple task but I have searched the web
under "parsing" and not found any relevant help. It could be that I am using
the wrong terminology for this procedure.
I would be grateful if for any assistance or pointers.
Many thanks
Phil
(a newbie for the last 10 months)
------------------------------
Date: 08 Nov 2000 18:11:46 +0000
From: nobull@mail.com
Subject: Re: Is this procedure called parsing? (Newbie)
Message-Id: <u9vgtybafx.fsf@wcl-l.bham.ac.uk>
"Phil Latio" <support@bedroomisp.co.uk> writes:
> Is it possible to write a small perl program that will do the following:
>
> 1. Go to a text based file (no HTML in the document) on a web server
LWP
> 2. Find a particular text string
> 3. Start capturing the text directly after this string
> 4. Stop capturing text before another specified text string
Pattern match
> 5. Display this captured text on a webpage as an SSI
CGI
It would definitely straining the definition of parsing to consider
steps 2-4 "ignore everything upto token1 then capture everything upto
token2" to be parsing. However strictly speaking it is parsing.
> I reckon this should be quite a simple task but I have searched the web
> under "parsing" and not found any relevant help. It could be that I am using
> the wrong terminology for this procedure.
You are. Parsing usually refers to a much more rigerous process of
understanding the grammer on the input.
The better thing to look for in such a simple case is "pattern matching".
Of course another approach if you can't guess a suitable set of
keywords is to manually look at _all_ the questions (not the answers)
in the Perl FAQ and see if your question is "frequently asked".
Admitedly, more often than not this won't find the solution, but even
so you'll only have spent 5-10 minuites and this will be a valuable
investment for the future. In this particualar case you'll also find
your question _is_ "frequently asked"
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 08 Nov 2000 18:29:24 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Is this procedure called parsing? (Newbie)
Message-Id: <8uc663$gne$1@news.mch.sbs.de>
In article <XXfO5.1800$y94.46280@stones>, "Phil Latio" <support@bedroomisp.co.uk> wrote:
>Is it possible to write a small perl program that will do the following:
>
>1. Go to a text based file (no HTML in the document) on a web server
>2. Find a particular text string
>3. Start capturing the text directly after this string
>4. Stop capturing text before another specified text string
>5. Display this captured text on a webpage as an SSI
>
>I reckon this should be quite a simple task but I have searched the web
>under "parsing" and not found any relevant help. It could be that I am using
>the wrong terminology for this procedure.
Here's a code snippet to grab a webpage or textfile and
extract part of the text with a regular expression :
use LWP::Simple;
my $text = get('http://www.someserver.com/sometext.txt');
print 'www.someserver.com tells me : ';
if ($text =~ /a particular string(.*?)another specified string/) {
print $1;
}
else {
print 'nothing';
}
If you intend to use this in an SSI context, you're probably
better off using the mirror($url,$file) function as described
in the LWP::Simple documentation. That way, you won't
have to download the whole textfile each time your SSI gets
executed.
If you have permission to display that information, it's
sometimes called syndication. If you don't, it's probably
called theft of copyrighted information or something like
that...
Michel.
------------------------------
Date: Wed, 08 Nov 2000 16:43:42 GMT
From: schnurmann@my-deja.com
Subject: Module Unicode::Map8 from CPAN
Message-Id: <8ubvrr$qof$1@nnrp1.deja.com>
Has anyone had problems compiling the Unicode::Map8 module under Win 2K
and VC++ 6?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 8 Nov 2000 17:12:53 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: OOP and information hiding
Message-Id: <973703572.623767@hpvablab.cup.hp.com>
damian@cs.monash.edu.au (Damian Conway) writes:
>nospam@hairball.cup.hp.com (Richard J. Rauenzahn) writes:
>
> > As I think Abigail alluded to, I could write OO conventions in C similar
> > to those in Perl -- does that make C OO?
>
>That's not a meaningful question. It depends entirely by what one means
>by "object-oriented":
Agreed.
> * If you mean [that OO means] "permits OO styles of programming" then the
> answer is "yes".
>
> * If you mean [that OO means] "supports OO styles of programming" then the
> answer is "maybe".
>
> * If you mean [that OO means] "mandates OO styles of programming" then the
> answer is "no".
I think Perl falls into category one, with a slight leaning to two
because of the syntactic sugar. C++ falls in between two and three.
[btw, I've added the bracketed text to make the above less confusing
when out of context.]
> > I think part of the argument lies in where you draw the line at "Perl
> > -- The Language." I don't consider the modules that provide OO
> > conventions to be part of "The Language."
>
>Then C++ has no I/O,
The language doesn't. That's part of the runtime environment/C++
standard libraries, and by convention >> and << are overloaded for those
purposes.
>nor any RTTI mechanism, nor standard exceptions.
These I'd have to think about -- and may not be able to comment on since
I don't have experience with any other languages that integrate those
better into the language. Since try and catch are part of the syntax,
I'm curious why you would say C++ wouldn't have them under my
definition.
>There is no "line"; there is only the question of whether a language
>supports a give feature set that may be considered useful in OO
>programming. All languages do to some extent (one could programm in an OO
>style in assembler, though it wouldn't be much fun!), but the point is
>that it's a continuum.
White exists and black exists, but in between there is a continuum and
we certainly call colors within that continuum 'white' and 'black' -
others we call grey. And for some we wait for Florida =-)
>OO is a mindset and a way of structuring code. There are no "OO
>languages", only languages that allow (and sometimes help) one to do OO
>programming. Perl is indisputably one of those.
OO is a mindset of structuring code. It's also a way to design a
language. Because you can write OO in a non OO language doesn't make
that language OO.
One feature of OO languages is that they encourage and facilitate OO
design. I don't feel that Perl does this. It feels like some syntactic
sugar was added to the language to allow some cool OO stuff to be
written, but that doesn't make the language OO. [And I also subscribe
to the all objects should be Lego Bricks not Velcro and Legos and K'nex
and outside-the-language-implementation-du-juor theory being discussed
in a parallel thread.]
Rich
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: 08 Nov 2000 11:22:57 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Passing args as references
Message-Id: <m38zqunzta.fsf@dhcp11-177.support.tivoli.com>
[Jeopardectomy]
"John" <gods-apollo@home.com> writes:
[Missing attribution for MJD]
> >In Perl, function arguments are always passed by reference.
> >
> > sub set_to_37 {
> > $_[0] = 37;
> > }
> >
> > $x = 19;
> > set_to_37($x);
> > print $x, "\n"; # Prints 37
>
>
>
> Yes.. if you declare the variable outside the function:
>
> my $chub;
> $yourfawn = 1;
>
> chubby();
>
> If you write a function that:
>
> sub chubby ()
Unrelated to the current topic, but including those parens there is
not standard for a subroutine definition and has the effect of
defining an empty prototype for this function. See the "Prototypes"
section of perlsub(1).
> {
> my $temp = $yourfawn;
> $chub = temp;
> }
Um... I think you should re-read what MJD wrote. He didn't do at all
what you are doing.
> There is no point in returning anythinga s you are directly accessing the
> variable as you have already changed it. What if I need to use this
> function more than once for different variables. Sure.. this does solve my
> problem for what I need to do.. for one variable. And this is what I have
> used. But what happens when I need the function to do the same with $hat
> and $cat or $blue and $nosedive? I'm stuck.
His code handles this fine. You need to think about what it's doing
some more. In particular, realize that the syntax $_[0] refers to the
first element of the @_ array, which is the array of arguments to the
function. His point was that this array is *always* passed by
reference and it is not until you explicitly copy things out of this
array that a copy occurs.
The relevant portion of perlsub(1) is:
Any arguments passed to the routine come in as the array
@_. Thus if you called a function with two arguments,
those would be stored in $_[0] and $_[1]. The array @_ is
a local array, but its elements are aliases for the actual
scalar parameters. In particular, if an element $_[0] is
updated, the corresponding argument is updated (or an
error occurs if it is not updatable). If an argument is
an array or hash element which did not exist when the
function was called, that element is created only when
(and if) it is modified or if a reference to it is taken.
(Some earlier versions of Perl created the element whether
or not it was assigned to.) Note that assigning to the
whole array @_ removes the aliasing, and does not update
any arguments.
Note that for arrays it is only the elements themselves that are
passed this way, so while the individual elements can be modified,
elements cannot be added to or deleted from the array.
The situation is even worse for hashes, which are copied on flatten.
The elements of the hash cannot be modified in this way.
So for arrays and hashes, it is usually best to simply pass in a
reference as described in the other posts in this thread.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 08 Nov 2000 16:55:16 GMT
From: lkenny@fisheries.org (LK)
Subject: Perl vs. ActivePerl (newbie)
Message-Id: <3a098567.18237417@news.volocom.net>
What are the differences and benefits of these two over each other. I
am using a windows machine and do not have a C compiler. Therefore I
downloaded ActivePerl so I could work with perl.
But I don't want to be missing out on anything when learning perl that
may come back to haunt me down the road.
Which way do you perl veterans suggest?
Plus I don't know how to or where to actually write and execute the
programs. I assume I can write them in notepad. But where do I
execute?
Thanks,
LK
------------------------------
Date: Wed, 8 Nov 2000 13:02:27 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: Perl vs. ActivePerl (newbie)
Message-Id: <8uc4fm$p37$1@slb0.atl.mindspring.net>
Hi LK,
I may be asking for flames form the purists, but if you're running Perl on
NT, ActiveState is the way to go. Most of the (Unix vs NT) compatibility
issues have been fixed, and without a C compiler, this is about the only way
to get some modules to install. As far as limitations go, there are many
modules available on CPAN that do not have PPM-installable packages
available. As you are just getting started with Perl, you can probably get
along without Damian Conway's Parse::RecDescent for a while ;).
You can certainly get started writing your scripts in NotePad and running
them from the command line, however you will probably want to find a good
programmer's editor. Not just for Perl, but for all text files. All of the
time. I personally use TextPad (http://www.textpad.com) - it's good, it's
cheap and you can run your scripts directly in the editor and then jump
directly to the offending line when your program bombs. It also displays
your code in lots of fancy, syntax-dependent colors, which is a lot more
than NotePad can do. Of course, any good programmer's editor will do these
things just as well.
"LK" <lkenny@fisheries.org> wrote in message
news:3a098567.18237417@news.volocom.net...
> What are the differences and benefits of these two over each other. I
> am using a windows machine and do not have a C compiler. Therefore I
> downloaded ActivePerl so I could work with perl.
> But I don't want to be missing out on anything when learning perl that
> may come back to haunt me down the road.
> Which way do you perl veterans suggest?
> Plus I don't know how to or where to actually write and execute the
> programs. I assume I can write them in notepad. But where do I
> execute?
>
>
> Thanks,
>
> LK
------------------------------
Date: Wed, 8 Nov 2000 19:36:04 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Problem reading a binary file
Message-Id: <Pine.GHP.4.21.0011072309480.3718-100000@hpplus03.cern.ch>
On Tue, 7 Nov 2000, Michael Carman wrote:
> > > > > In reality, "\n" is *not* a character.
^^^^^^^^^^^^^^^^^^^^^^^^^
> > Yes, well that's the problem when you say "in reality" - when you
> > meant "in principle".
>
> Heh. Maybe I'm perverse, but I meant it the way I said it. In reality,
> there is no "\n" character
^^^^^^^^^^^^^^^^^^^^^^^^^^
Ah, but that's a very different statement from the one you made
before (and is quoted above).
I'm off the case now - at risk of counting angels on pinheads.
------------------------------
Date: 08 Nov 2000 10:30:50 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: returning a true value is FUN! (was Re: Log.pm did not return a true value)
Message-Id: <m3n1fao285.fsf@dhcp11-177.support.tivoli.com>
tadmc@metronet.com (Tad McClellan) writes:
> ()=0;
>
> is a list assignment.
>
> So Perl DWIMs the zero into a list
>
> ()=(0);
The problem I have with this explanation is that it implies that those
parens around the 0 have something to do with creating a list -- but
they most certainly do NOT.
In particular, a scalar assignment works fine even if there are parens
on the right:
$x = (0); # $x gets 0
The normal multiple element list assignment does require the parens,
but only because "=" binds tighter than ",". So the parens are
required to override the precedence. Another way to do the same thing
is via "do":
@x = do { 1, 2, 3 }; # @x gets the three elements 1, 2, 3
I haven't seen that example before, but I like it. I hope it helps to
clarify the situation. This clearly shows that the parens are NOT
required to make a list, only to override the higher precedence of the
assignment.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 08 Nov 2000 16:23:12 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Searching for many words in large string
Message-Id: <slrn90ivsa.dkr.rgarciasuarez@rafael.kazibao.net>
Tony Mountifield wrote in comp.lang.perl.misc:
>Hi, I wonder if anyone can improve on this.
>
>I have a potentially long list of words, and need to know which, if any,
>appear in a large string. Assume the string and the list of words are
>already folded to lower case.
>
>My idea:
>
>study $string;
>@found = grep {$string =~ /\b$_\b/} @wordlist;
>
>Can this be improved upon, for speed?
Your method performs one search per word in @wordlist.
This one may be more efficient (but, of course, this depends on the
data) :
my $rx = join '|', map "\\b$_\\b", @wordlist; # Construct a big regexp
my %found = ();
my $found{$_} = 1 for $string =~ /$rx/go; # use /o if @wordlist does not
# change
print "$_\n" for keys %found;
BTW, the Benchmark module is most useful to compare efficiency of code
segments.
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 8 Nov 2000 16:30:33 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Searching for many words in large string
Message-Id: <8ubv39$1q7$1@lublin.zrz.tu-berlin.de>
Tony Mountifield <tony@softins.clara.co.uk> wrote in comp.lang.perl.misc:
>Hi, I wonder if anyone can improve on this.
>
>I have a potentially long list of words, and need to know which, if any,
>appear in a large string. Assume the string and the list of words are
>already folded to lower case.
>
>My idea:
>
>study $string;
>@found = grep {$string =~ /\b$_\b/} @wordlist;
>
>Can this be improved upon, for speed?
Yes, probably. You are basically looking for fixed substrings,
which is usually a job for index(). If you don't need the full
functionality of \b, but can do with blank separated words,
surround $string and every word in @wordlist with blanks, and
grep for { -1 + index $string, $_}.
On the other hand, a hash may perform even better. Store the
wordlist as keys of a hash: @wordset{ @wordlist} = (); Then,
supposing you can isolate one word of $string after the other
in $word, "exists $wordset{ $word}" does the test in a single
hash access. As for accessing each word in $string, this can be
as simple as a split() if you can afford to double the space used
for $string. Otherwise some fiddling with index and substr may
be needed, or even a regex which will now only have to pass the
string once.
Anno
------------------------------
Date: Wed, 08 Nov 2000 10:58:22 -0500
From: Carl David <david@nucleus.chem.uconn.edu>
Subject: Text::Wrap and cgi-bin programming
Message-Id: <3A09781E.43C7BC51@nucleus.chem.uconn.edu>
I'm not understanding how to use the text modules in
a perl program which runs as a cgi program. Using
the documentation, the output line is swallowed up,
i.e., disappears.
Can someone help me?
Thanks
Carl David
------------------------------
Date: 08 Nov 2000 10:16:57 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Text::Wrap and cgi-bin programming
Message-Id: <87snp2sakm.fsf@limey.hpcc.uh.edu>
>> On Wed, 08 Nov 2000 10:58:22 -0500,
>> Carl David <david@nucleus.chem.uconn.edu> said:
> I'm not understanding how to use the text modules in a
> perl program which runs as a cgi program. Using the
> documentation, the output line is swallowed up, i.e.,
> disappears. Can someone help me?
CGI is just an interface specification. It doesn't affect
the use of other modules such as text-wrapping, so this is
almost certainly a red-herring.
If you want people to help you, post your code, otherwise
it's impossible to know what is wrong.
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Wed, 08 Nov 2000 13:11:30 -0500
From: Carl David <david@nucleus.chem.uconn.edu>
Subject: Re: Text::Wrap and cgi-bin programming
Message-Id: <3A099752.15C12C4B@nucleus.chem.uconn.edu>
Thanks, you were right, I was stupid, RTFM should be
engraved on my forehead.
Carl David
Tony Curtis wrote:
>
> >> On Wed, 08 Nov 2000 10:58:22 -0500,
> >> Carl David <david@nucleus.chem.uconn.edu> said:
>
> > I'm not understanding how to use the text modules in a
> > perl program which runs as a cgi program. Using the
> > documentation, the output line is swallowed up, i.e.,
> > disappears. Can someone help me?
>
> CGI is just an interface specification. It doesn't affect
> the use of other modules such as text-wrapping, so this is
> almost certainly a red-herring.
>
> If you want people to help you, post your code, otherwise
> it's impossible to know what is wrong.
>
> hth
> t
> --
> Eih bennek, eih blavek.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4846
**************************************