[18180] in Perl-Users-Digest
Perl-Users Digest, Issue: 348 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 24 09:07:31 2001
Date: Sat, 24 Feb 2001 06:05:13 -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: <983023513-v10-i348@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 24 Feb 2001 Volume: 10 Number: 348
Today's topics:
testing <cryofan@msn.com>
Can I use Excel as a data source <c.darlington@virgin.net>
Re: Difficult Split Question <ianb@ot.com.au>
Re: Difficult Split Question <bart.lateur@skynet.be>
Re: Difficult Split Question <bertilow@chello.se>
Re: flushing stdout (Erland Nylend)
Re: flushing stdout (Martien Verbruggen)
Re: flushing stdout (Erland Nylend)
Re: help with variables in my email <ja@nee.snee>
net::irc module <t3chfr3ak@hotmail.com>
Perl on a shell account: how to use UNIX commands in a <donkan7@yahoo.com>
Re: Perl on a shell account: how to use UNIX commands i <gtoomey@usa.net>
Re: Perl on a shell account: how to use UNIX commands i (Gwyn Judd)
Re: Perl on a shell account: how to use UNIX commands i (Martien Verbruggen)
Re: Perl on a shell account: how to use UNIX commands i <donkan7@yahoo.com>
Re: Perl on a shell account: how to use UNIX commands i <krahnj@acm.org>
Re: Perl on a shell account: how to use UNIX commands i egwong@netcom.com
Re: Perl on a shell account: how to use UNIX commands i <donkan7@yahoo.com>
Re: Perl on a shell account: how to use UNIX commands i <flavell@mail.cern.ch>
Re: Problem: Perl cgi calling Excel via OLE on Win2000 <bart.lateur@skynet.be>
Re: Question.about s/// <bart.lateur@skynet.be>
regex help needed <cryofan@msn.com>
Re: regex help needed <krahnj@acm.org>
Re: regex help needed egwong@netcom.com
Search/Crawler Indexing with Perl? <georgebailey@my-deja.com>
Re: Search/Crawler Indexing with Perl? <tom_perkin@nospamplease.hotmail.com>
Send HTML with mail? <ja@nee.snee>
Re: Send HTML with mail? <krahnj@acm.org>
SHARE / TRADE costly perl programs <bizygal@earthlink.net>
Re: SHARE / TRADE costly perl programs (Martien Verbruggen)
Re: stock trading <comdog@panix.com>
Re: testing <uri@sysarch.com>
Why two different class concepts? <Grandulo@MailAndNews.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 23 Feb 2001 22:12:45 -0600
From: "cryofan" <cryofan@msn.com>
Subject: testing
Message-Id: <uJkjOjhnAHA.176@cpmsnbbsa09>
test
------------------------------
Date: Sat, 24 Feb 2001 09:55:34 -0000
From: "Virgin News" <c.darlington@virgin.net>
Subject: Can I use Excel as a data source
Message-Id: <dxLl6.19798$5n4.397129@news6-win.server.ntlworld.com>
I have a list of stockists written in an Excel spreadsheet which is
basically an address book.
I want someone to be able to query the spreadsheet via a webpage and then
produce a list which matches the query.
Can I use the spreadsheet as it stands, or will i have to convert it to a
flat file?
Any suggestions?
Many Thanks
Chris Darlington
------------------------------
Date: Sat, 24 Feb 2001 23:11:38 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: Difficult Split Question
Message-Id: <3A97A4F9.950EF83@ot.com.au>
Well, I feel suitably chastised and probably won't sink into another
benchmarkathon for a while (come to think of it, I never have before - must have
been a moment of weakness).
Joe Schaefer wrote:
> Ian Boreham <ianb@ot.com.au> writes:
>
> > that's pretty impressive.
>
> On the contrary, it's rather *unimpressive*, and it only serves
> to further confuse people regarding the relevance of the troll's
> advice.
This was actually just a build-up so I could make the following smart-ass comment.
I'd already posted my other solutions previously, and just thought I'd see how the
simple case version compared, considering I hadn't benchmarked it before.
> Please don't feed off the troll's code. Ever.
> *You* should know better.
Sheer bad (false?) laziness. I won't try to explain most of what's in the script
since it isn't mine.
> > 'name4' =>
> > '$_ = q!a,b,c,def(g,h,i),j,k,lmn(o,p,q),r,stu(v,w),xyz!;
> > $_ .= ",";
> ^^^^^^^^^
> Completely unnecessary.
Didn't even see it there in my haste. It was a leftover from name3, which I
copied. That means my solution would be even faster! Whoo-hoo! Where did I put
that script?
> > (@Array) = split /,(?![\w,]*\))/;
>
> Since this is a split-derived solution, unlike name3
> (but like name1) it ignores trailing sequences of commas.
> I guess that's where the original disclaimer regarding
> assumptions fits in.
That and a whole lot more (including not worrying about escapes since the example
doesn't have any).
Should we give you a shiny star-shaped badge?
Regards,
Ian
------------------------------
Date: Sat, 24 Feb 2001 12:39:47 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Difficult Split Question
Message-Id: <tgaf9t8nqlr5lfahni6gr2ern41dn4mcf9@4ax.com>
Christopher Burke wrote:
>Gwyn Judd wrote:
>
>>I was shocked! How could Christopher Burke <craznar@hotmail.com>
>>say such a terrible thing:
>>>I have input lines of the form :
>>>
>>>a,b,c,xyz(p,q,r),d
>>>a,def(x,y,z),b,pqr(m,n)
>>>
>>>I wish to split the line based on all ',' characters that are not
>>>between '(' and ')'.
>>
>>This is in the FAQ.
>>
>>perldoq -q split
>>
>
>No its not, because I want to keep the stuff outside the quotes and the
>quotes.
It is.
How can I split a [character] delimited string except when inside
[character]? (Comma-separated files)
But you shouldn't have expected a full solution there. Get the code from
the FAQ, and try and understand it. It's not that much. Once you
understand how it works, adapting it to this particular case is easy.
Look, what you want to match is either of the form:
bareword
or of the form
func(par,par,par)
So you should provide alternatives for those. For example:
\w+(?:\(\w+(?:,\w+)*\))?
Note that the stuff between parens is optional.
So the whole code can become:
@matches = /(\w+(?:\(\w+(?,\w+)*\))?)/g;
It's that easy.
--
Bart.
------------------------------
Date: Sat, 24 Feb 2001 14:05:15 GMT
From: "Bertilo Wennergren" <bertilow@chello.se>
Subject: Re: Difficult Split Question
Message-Id: <vcPl6.932$bX.11580@nntp1.chello.se>
Bart Lateur:
> So the whole code can become:
> @matches = /(\w+(?:\(\w+(?,\w+)*\))?)/g;
> It's that easy.
Except that your code gives an error when I try to run it:
Sequence (?,...) not recognized before HERE mark in
regex m/(\w+(?:\(\w+(?, << HERE \w+)*\))?)/
--
#####################################################################
Bertilo Wennergren
<http://purl.oclc.org/net/bertilo>
<bertilow@chello.se>
#####################################################################
------------------------------
Date: Sat, 24 Feb 2001 10:12:04 GMT
From: nylend@nextra.com (Erland Nylend)
Subject: Re: flushing stdout
Message-Id: <3a97860d.70322778@news.online.no>
On Sat, 24 Feb 2001 11:15:46 +1000, "Gregory Toomey" <gtoomey@usa.net>
wrote:
>The only way would be to close stdout and stderr,
>then do a fork system call and make sure the original process exits.
I know how to fork, but the parent seems to wait for the child to
complete. How do I execute a fork-command while I still want the
parent to complete before the child???
Theres a script at http://www.w3.org that works the way I want. (the
linkchecker-script). Ill see if I can break it down ...
Regards,
Erland Nylend
------------------------------
Date: Sat, 24 Feb 2001 21:45:25 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: flushing stdout
Message-Id: <slrn99f465.eoa.mgjv@martien.heliotrope.home>
On Sat, 24 Feb 2001 10:12:04 GMT,
Erland Nylend <nylend@nextra.com> wrote:
> On Sat, 24 Feb 2001 11:15:46 +1000, "Gregory Toomey" <gtoomey@usa.net>
> wrote:
>
>>The only way would be to close stdout and stderr,
>>then do a fork system call and make sure the original process exits.
>
>
> I know how to fork, but the parent seems to wait for the child to
The parent only waits when you tell it to.
$ cat foo.pl
#!/usr/local/bin/perl -w
use strict;
my $pid = fork;
die "Can't fork: $!" unless defined $pid;
if ($pid)
{
print "I'm the parent, exiting now\n";
exit 0;
}
else
{
sleep 2;
print "I'm the child, exiting now\n";
exit 0;
}
$ ./foo.pl
I'm the parent, exiting now
$ I'm the child, exiting now
> complete. How do I execute a fork-command while I still want the
> parent to complete before the child???
See above.
The problem you described in your original setup has nothing to do with
this, most likely. It may be due to the external program's output being
buffered. It may be due to the web server or something in your
environment buffering output. It may be something else.
Try all of this _outside_ of the web environment first. Then complicate
issues by running it as a CGI program. For external programs: You may
need to make sure you fool them into thinking they're attached to a
terminal.
Martien
--
Martien Verbruggen |
Interactive Media Division | Think of the average person. Half of
Commercial Dynamics Pty. Ltd. | the people out there are dumber.
NSW, Australia |
------------------------------
Date: Sat, 24 Feb 2001 11:51:11 GMT
From: nylend@nextra.com (Erland Nylend)
Subject: Re: flushing stdout
Message-Id: <3a979f7e.76835012@news.online.no>
On Sat, 24 Feb 2001 21:45:25 +1100, mgjv@tradingpost.com.au (Martien
Verbruggen) wrote:
>#!/usr/local/bin/perl -w
>use strict;
>
>my $pid = fork;
>die "Can't fork: $!" unless defined $pid;
>if ($pid)
>{
> print "I'm the parent, exiting now\n";
> exit 0;
>}
>else
>{
> sleep 2;
> print "I'm the child, exiting now\n";
> exit 0;
>}
>
>$ ./foo.pl
>I'm the parent, exiting now
>$ I'm the child, exiting now
Hey, that worked just fine!!
Thanks for all help!!
Regards,
Erland Nylend
------------------------------
Date: Sat, 24 Feb 2001 12:13:40 -0800
From: "Me" <ja@nee.snee>
Subject: Re: help with variables in my email
Message-Id: <K6Do#GlnAHA.379@asd24-aux-005.raketnet.nl>
NO NO NO
Just substitude the "variable" containing current date./ Much easier and
works flawlesly.
Let the text contain $put_date_here somewhere (as a plain word.
Then read text from file into $a
Let $b contain the current date.
Then:
$a=~s/\$put_date_here/$b/g;
Voila.... have fun :)
Regards,
Me
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:975ig6$8c$2@mamenchi.zrz.TU-Berlin.DE...
> According to Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>:
> > "John T." <j2lab.nospam@my-deja.com> writes:
> >
> > > I currently have a script that opens a text file then emails the
content
> > > of the text file line by line. I would like to enter the current date
> > > into the email. I tried assigning the current date to a variable and
> > > added the variable within the text file. All I seem to get back is
the
> > > $variablename in the email. What is it that I'm doing wrong?
> >
> > Umm... eval? (See perldoc -f eval)
> >
> > $ perl -ne '$_ = eval $_;print "$_\n"'
> > $0
> > -e
> > $^O
> > cygwin
> > $]
> > 5.006001
>
> This is nonsense! Refer to my reply to Rick Meldrum's posting who
> gave similarly useless and dangerous advice.
>
> Anno
------------------------------
Date: Sat, 24 Feb 2001 13:07:30 +0200
From: "T3chFr3aK" <t3chfr3ak@hotmail.com>
Subject: net::irc module
Message-Id: <983012863.424529@athnrd02.forthnet.gr>
does anyone know where i can find a guide for the net::irc module (not
perldoc) . Or a doc that explains all the methods and how to use them ...
thanx
------------------------------
Date: Sat, 24 Feb 2001 01:53:07 -0800
From: "Dick" <donkan7@yahoo.com>
Subject: Perl on a shell account: how to use UNIX commands in a perl script?
Message-Id: <0wLl6.1128$GE3.136363@news03.micron.net>
I'm learning Perl on a dial-up shell account, which has version 5.004_04.
How can I execute a UNIX command from within a perl script? Right now I'd
like to execute "uptime" and print the result.
Sorry for what is probably a basic question, but I don't know where else to
go for the answer..
Don't know if it's relevant, but my shell is the TC shell (tcsh).
Thanks,
Dick
------------------------------
Date: Sat, 24 Feb 2001 20:28:17 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: Perl on a shell account: how to use UNIX commands in a perl script?
Message-Id: <ePLl6.2456$v5.8161@newsfeeds.bigpond.com>
Try someting like $var=system('uptime').
You may need to use substr to get the value you need.
gtoomey
---------------
"Dick" <donkan7@yahoo.com> wrote in message
news:0wLl6.1128$GE3.136363@news03.micron.net...
> I'm learning Perl on a dial-up shell account, which has version 5.004_04.
> How can I execute a UNIX command from within a perl script? Right now I'd
> like to execute "uptime" and print the result.
>
> Sorry for what is probably a basic question, but I don't know where else
to
> go for the answer..
>
> Don't know if it's relevant, but my shell is the TC shell (tcsh).
>
> Thanks,
>
> Dick
>
>
------------------------------
Date: Sat, 24 Feb 2001 11:07:40 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Perl on a shell account: how to use UNIX commands in a perl script?
Message-Id: <slrn99f5fr.er.tjla@thislove.dyndns.org>
I was shocked! How could Gregory Toomey <gtoomey@usa.net>
say such a terrible thing:
>Try someting like $var=system('uptime').
>You may need to use substr to get the value you need.
Just out of curiosity, what value would you be using substr on? $var? I
doubt it, because that only holds the return value from system(), which
is the return value from the uptime program, which is an integer. I
think you are confusing the output of a program from its return value.
To grab the output you would use backticks or some other method.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
:urchin: n. See {munchkin}.
From "The New Hackers Dictionary", version 4.2
------------------------------
Date: Sat, 24 Feb 2001 21:55:17 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Perl on a shell account: how to use UNIX commands in a perl script?
Message-Id: <slrn99f4ok.eoa.mgjv@martien.heliotrope.home>
[Please, in the future, post your reply _after_ the suitably trimmed
text you reply to. It's the commonly accepted quoting style on this
newsgroup, and Usenet in general]
On Sat, 24 Feb 2001 20:28:17 +1000,
Gregory Toomey <gtoomey@usa.net> wrote:
> "Dick" <donkan7@yahoo.com> wrote in message
> news:0wLl6.1128$GE3.136363@news03.micron.net...
>> I'm learning Perl on a dial-up shell account, which has version 5.004_04.
>> How can I execute a UNIX command from within a perl script? Right now I'd
>> like to execute "uptime" and print the result.
>>
>> Sorry for what is probably a basic question, but I don't know where else to
>> go for the answer..
>>
>> Don't know if it's relevant, but my shell is the TC shell (tcsh).
>
> Try someting like $var=system('uptime').
Nonsense. And if you had consulted the documentation, you would have
found the following (very explicit) text about that:
$ man perlfunc
[snip]
system PROGRAM LIST
Does exactly the same thing as `exec LIST', except
that a fork is done first, and the parent process
waits for the child process to complete. Note
[snip]
elsewhere in this document. This is not what you
want to use to capture the output from a command,
for that you should use merely backticks or
`qx//', as described in the section on "`STRING`"
in the perlop manpage. Return value of -1 indi
[snip]
So, to answer the original question: To execute an external program, and
to capture the output, you use qx// or backticks. They are both
described in the perlop documentation, which you can read using the man
command, or with perldoc.
$ man perlop
$ perldoc perlop
> You may need to use substr to get the value you need.
Why? There are many ways to extract information from a string. substr is
only useful for fixed width output, which uptime hardly is (it may be on
_your_ system, but that doesn't mean anything).
Martien
PS. If you're command-line-phobic, ActiveState installs HTML versions of
the documentation. If you're on Mac, use Shuck. If you don't have Perl
installed on your own local computer yet, do so now.
--
Martien Verbruggen |
Interactive Media Division | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd. | you come to the end; then stop.
NSW, Australia |
------------------------------
Date: Sat, 24 Feb 2001 03:39:17 -0800
From: "Dick" <donkan7@yahoo.com>
Subject: Re: Perl on a shell account: how to use UNIX commands in a perl script?
Message-Id: <w3Nl6.1129$GE3.136988@news03.micron.net>
"Gregory Toomey" <gtoomey@usa.net> wrote in message
news:ePLl6.2456$v5.8161@newsfeeds.bigpond.com...
> Try someting like $var=system('uptime').
> You may need to use substr to get the value you need.
$var=system('uptime');
print $var, "\n";
gets me what I want, e.g.
"3:32am up 130 days, 58 min, 3 users, load average: 0.01, 0.04, 0.01".
Thanks very much.
But I also get a "0" on the next line. What's that, and how can I get rid of
it?
Also, strict yells at me that 'Global symbol "var" requires explicit package
name'.
Guess I've got a lot to learn..
Dick
> > I'm learning Perl on a dial-up shell account, which has version
5.004_04.
> > How can I execute a UNIX command from within a perl script? Right now
I'd
> > like to execute "uptime" and print the result.
> >
> > Sorry for what is probably a basic question, but I don't know where else
> to
> > go for the answer..
> >
> > Don't know if it's relevant, but my shell is the TC shell (tcsh).
> >
> > Thanks,
> >
> > Dick
------------------------------
Date: Sat, 24 Feb 2001 11:29:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl on a shell account: how to use UNIX commands in a perl script?
Message-Id: <3A979C3E.5CF52D19@acm.org>
Dick wrote:
>
> I'm learning Perl on a dial-up shell account, which has version 5.004_04.
> How can I execute a UNIX command from within a perl script? Right now I'd
> like to execute "uptime" and print the result.
>
> Sorry for what is probably a basic question, but I don't know where else to
> go for the answer..
my @uptime = `uptime`;
print @uptime;
John
------------------------------
Date: 24 Feb 2001 11:56:26 GMT
From: egwong@netcom.com
Subject: Re: Perl on a shell account: how to use UNIX commands in a perl script?
Message-Id: <9787h9$u1s$1@newssvr06-en0.news.prodigy.com>
Dick <donkan7@yahoo.com> wrote:
>
> "Gregory Toomey" <gtoomey@usa.net> wrote in message
> news:ePLl6.2456$v5.8161@newsfeeds.bigpond.com...
>> Try someting like $var=system('uptime').
>> You may need to use substr to get the value you need.
>
> $var=system('uptime');
> print $var, "\n";
>
> gets me what I want, e.g.
> "3:32am up 130 days, 58 min, 3 users, load average: 0.01, 0.04, 0.01".
> Thanks very much.
>
> But I also get a "0" on the next line. What's that, and how can I get rid of
> it?
This is excellent! I'm sure a lot of us made a similar mistake
when we started out too.
What's happening is that the "uptime" line is being printed when
system calls uptime -- it's *not* being captured by perl into the
variable $var. That's why $var prints out as "0" in the second
line. To see what I mean, compare these two from the command line:
perl -e 'my $var=system("uptime");'
perl -e 'my $var=`uptime`;'
Only in the second line (which uses the backticks) is the output
from uptime captured by perl. That's why adding a "print $var"
to the first line is essentially a no-op, whereas adding it to
the second line will actually print what you want. As has been
previously mentioned, see "Quote and Quote-like Operators" in
the perlop manpage.
I'm glad to hear that you're using strict. You're starting off
right :) What you need to do is to declare your package (global)
variables with 'use vars' or "our" (if you're using perl 5.6+),
or, declare the variables as a lexical with "my", as I did above
(see the strict, vars and perlfunc manpages).
HTH,
Eric
------------------------------
Date: Sat, 24 Feb 2001 05:02:28 -0800
From: "Dick" <donkan7@yahoo.com>
Subject: Re: Perl on a shell account: how to use UNIX commands in a perl script?
Message-Id: <vhOl6.1131$GE3.137291@news03.micron.net>
"John W. Krahn" <krahnj@acm.org> wrote in message
news:3A979C3E.5CF52D19@acm.org...
> Dick wrote:
> >
> > I'm learning Perl on a dial-up shell account, which has version
5.004_04.
> > How can I execute a UNIX command from within a perl script? Right now
I'd
> > like to execute "uptime" and print the result.
> >
> > Sorry for what is probably a basic question, but I don't know where else
to
> > go for the answer..
>
> my @uptime = `uptime`;
> print @uptime;
Yes! Thank you.
Dick
------------------------------
Date: Sat, 24 Feb 2001 14:18:46 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Perl on a shell account: how to use UNIX commands in a perl script?
Message-Id: <Pine.LNX.4.30.0102241415210.1576-100000@lxplus003.cern.ch>
On Sat, 24 Feb 2001, Martien Verbruggen wrote:
> [Please, in the future, post your reply _after_ the suitably trimmed
> text you reply to.
Opinions may of course differ on this topic, but wouldn't it be better
to persuade the hon. Usenaut, as a first priority, to post accurate
information, before persuading them to abandon this remarkably
accurate indicator of usenet bogosity?
------------------------------
Date: Sat, 24 Feb 2001 12:46:48 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Problem: Perl cgi calling Excel via OLE on Win2000
Message-Id: <17bf9tsde5utu295bg7n2h40a02qljd8u9@4ax.com>
Dave Fisher wrote:
>I'm porting a set of PERL scripts from Win98 (where they work fine) to
>Win2k IIS, and I'm having a problem getting a PERL script, running as
>a cgi, to start Excel and have it appear on the display.
*boggle*
You want a CGI script to open Excel and display a document on the
*server*? What on earth is that good for?
Besides, it would be dead easy to bring a server on its knees this way,
because you're starting a new copy of Excel every time the script is
run, and you leave it open when the script closes. A few tens of
visitors, and your server is out of memory.
--
Bart.
------------------------------
Date: Sat, 24 Feb 2001 12:43:20 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Question.about s///
Message-Id: <g1bf9t0tbkmfvmijgmdunfl6a0rsn4nafr@4ax.com>
snef wrote:
>I need te replace all accented characters (ö é .....) to their 'normal'
>characters.
>I wrote a little program in Windows with this line in it:
>
>$sometext =~ s/{ö|ó|ò|õ}/o/ig;
Wrong type of brackets. You want parens (but in this case, they're not
necessary). Or, your can use a character class, which matches ANY
character that is between these square brackets.
s/(ö|ó|ò|õ)/o/g;
or
s/[öóòõ]/o/g;
--
Bart.
------------------------------
Date: Fri, 23 Feb 2001 22:23:15 -0600
From: "cryofan" <cryofan@msn.com>
Subject: regex help needed
Message-Id: <OLBNHphnAHA.327@cpmsnbbsa09>
I am trying to kill the end of a string stored in an array.
This is what the string looks like:
http://biz.yahoo.com/rb/010223/business_spieker_merger_dc_5.html><b>Equityma
rket
.</small><p><a
The string is stored in array1[$num_words].
why doesn't this code work?
$array1[$num_words] =~ s/\>\<b\>.$//;
(note that I do have a hard-to-see period after "\>\<b\>" and before the
"$", which should represent everything after the "><b>." until the newline.)
What I want to do is get rid of everything after the "html". But it is not
working. I have tried many other more complicated substitution regexes with
no success. I was able to get rid of everything before the "http" with no
problem, but something weird is going on at the end.
Also, why won't this work?
$array1[$num_words] =~ s/\>\<b\>[a-zA-Z0-9]*//;
TIA
------------------------------
Date: Sat, 24 Feb 2001 11:25:23 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: regex help needed
Message-Id: <3A979B5F.49131137@acm.org>
cryofan wrote:
>
> I am trying to kill the end of a string stored in an array.
> This is what the string looks like:
> http://biz.yahoo.com/rb/010223/business_spieker_merger_dc_5.html><b>Equityma
> rket
> .</small><p><a
>
> The string is stored in array1[$num_words].
>
> why doesn't this code work?
>
> $array1[$num_words] =~ s/\>\<b\>.$//;
> (note that I do have a hard-to-see period after "\>\<b\>" and before the
> "$", which should represent everything after the "><b>." until the newline.)
If you had read perlre you would know that the period in a regular
expression matches _one_ of any character except newline.
> What I want to do is get rid of everything after the "html". But it is not
> working. I have tried many other more complicated substitution regexes with
> no success. I was able to get rid of everything before the "http" with no
> problem, but something weird is going on at the end.
>
> Also, why won't this work?
>
> $array1[$num_words] =~ s/\>\<b\>[a-zA-Z0-9]*//;
The asterisk matches _zero or more_ times and in this regex it will
match zero characters.
$array1[$num_words] =~ s/><b>.*$//;
John
------------------------------
Date: 24 Feb 2001 12:05:33 GMT
From: egwong@netcom.com
Subject: Re: regex help needed
Message-Id: <97882c$u1s$2@newssvr06-en0.news.prodigy.com>
cryofan <cryofan@msn.com> wrote:
> I am trying to kill the end of a string stored in an array.
> This is what the string looks like:
> http://biz.yahoo.com/rb/010223/business_spieker_merger_dc_5.html><b>Equityma
> rket
> .</small><p><a
>
>
> The string is stored in array1[$num_words].
>
> why doesn't this code work?
>
> $array1[$num_words] =~ s/\>\<b\>.$//;
[ cut ]
Is it because you're missing a '*'? ('.' is a single character, '.*'
is 0-or-more characters.)
$array1[$num_words] =~ s/\>\<b\>.*$//;
^
By the way, the not is not hard for me to see because I use a fixed-
width font when reading/posting news. If you're not, please consider
it. It's much easier to read code this way.
> Also, why won't this work?
>
> $array1[$num_words] =~ s/\>\<b\>[a-zA-Z0-9]*//;
Because the '.', '<', '/' and '>' which appear after the '<b>' aren't
included in your character class, so the regexp won't match to the
end of the string.
By the way, you don't need to escape '>' and '<'.
Read (or reread) the perlre manpage.
ERic
------------------------------
Date: Sat, 24 Feb 2001 19:20:21 +1000
From: George Bailey <georgebailey@my-deja.com>
Subject: Search/Crawler Indexing with Perl?
Message-Id: <georgebailey-D24FD8.19202124022001@news.connect.com.au>
I'd really appreciate some help with this.
I've been attempting to create a search-engine-type crawler which will
index a set of files on my site, partly as a useful tool, and also as
part of the process of learning Perl.
I based it on code from a tutorial on Webmonkey:
http://hotwired.lycos.com/webmonkey/97/16/index2a.html?tw=programming
(but my question's not to do with the specifics of it!) and I've got as
far as this:
The crawler successfully opens and indexes the contents of the set of
files, and this leaves me with an index in the form:
foo,1,3,5,7,8
bar,2,4,6,8
...
which means that the word "foo" is in documents 1,3,5,7 and 8, the word
"bar" in 2,4,6 and 8 and so on.
The search script can then open the index file, read the line for "foo"
and figure out which documents contain it.
What I'd like to do is go one step further and have the documents ranked
by how many times the word appears. It occurs to me to have a structure
like this:
foo,1:5,3:10,5:12
which would mean that the word appeared 5 times in document 1, 10 times
in document 3 and so on.
But what would I do then to actually rank them? Say I had a hash where
they key was the document number and the value the number of times the
word occured. That would not only work, but I'd be able to increment the
"score" if the search was for "foo" and "bar", so that document 5 got 12
points for 12 mentions of "foo" and later got another 10 points because
it contained 10 mentions of "bar" as well.
But now that I know that document 5 is the clear winner, with 12
mentions of that word, how do I put it to the top of the list?
I can't sort my hash by its values, can I?
I'm sure I'm missing something obvious/going about it all wrong. Any
help very gratefully received.
------------------------------
Date: Sat, 24 Feb 2001 13:28:05 -0000
From: "Tom Perkin" <tom_perkin@nospamplease.hotmail.com>
Subject: Re: Search/Crawler Indexing with Perl?
Message-Id: <978cnu$qhn$1@pegasus.csx.cam.ac.uk>
> I can't sort my hash by its values, can I?
>
Perl FAQ 5.57, which was automatically posted to this very newsgroup not
long ago, contains the following:
+
How do I sort a hash (optionally by value instead of key)?
Internally, hashes are stored in a way that prevents you from imposing
an order on key-value pairs. Instead, you have to sort a list of the
keys or values:
@keys = sort keys %hash; # sorted by key
@keys = sort {
$hash{$a} cmp $hash{$b}
} keys %hash; # and by value
Here we'll do a reverse numeric sort by value, and if two keys are
identical, sort by length of key, and if that fails, by straight ASCII
comparison of the keys (well, possibly modified by your locale -- see
the perllocale manpage).
@keys = sort {
$hash{$b} <=> $hash{$a}
||
length($b) <=> length($a)
||
$a cmp $b
} keys %hash;
--
Perhaps in future you should make at least a token effort to read the
documentation before you jump to usenet.
-Tom
--
Tom Perkin > Pembroke College > tom_perkin@NOSPAMPLEASEhotmail.com
"Freedom is the by-product of economic surplus" - Aneurin Bevan
------------------------------
Date: Sat, 24 Feb 2001 12:16:26 -0800
From: "Me" <ja@nee.snee>
Subject: Send HTML with mail?
Message-Id: <rb5BhIlnAHA.200@asd24-aux-005.raketnet.nl>
How can I send an HTML mail using perl.
please help.
My mail looks stupid now. Need TABLES in there.
Thank you!!
Michel
------------------------------
Date: Sat, 24 Feb 2001 11:43:36 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Send HTML with mail?
Message-Id: <3A979FA5.7B181ABB@acm.org>
Me wrote:
>
> How can I send an HTML mail using perl.
> please help.
> My mail looks stupid now. Need TABLES in there.
That is of course your opinion, IMHO HTML mail looks stupid. :-)
John
------------------------------
Date: Sat, 24 Feb 2001 08:12:55 GMT
From: Lisa Escott <bizygal@earthlink.net>
Subject: SHARE / TRADE costly perl programs
Message-Id: <3A976CA7.F2712A51@earthlink.net>
I have bought many perl / cgi programs in the past, and have also traded
several... Now I have a collection of 31 professional perl scripts to
share and trade with you. Have you bought any perl / cgi programs?
Lets help each other out, no strings. People helping people, the way it
ought to be. Contact bizygal@hotmail.com or ICQ# 12986879 ...
Awaiting replies, Lisa
------------------------------
Date: Sat, 24 Feb 2001 21:46:47 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: SHARE / TRADE costly perl programs
Message-Id: <slrn99f48n.eoa.mgjv@martien.heliotrope.home>
On Sat, 24 Feb 2001 08:12:55 GMT,
Lisa Escott <bizygal@earthlink.net> wrote:
> I have bought many perl / cgi programs in the past, and have also traded
> several... Now I have a collection of 31 professional perl scripts to
> share and trade with you. Have you bought any perl / cgi programs?
> Lets help each other out, no strings. People helping people, the way it
> ought to be. Contact bizygal@hotmail.com or ICQ# 12986879 ...
Apart from not havign a clue about what's appropriate in a comp.lang
group, you also don't seem to know what's appropriate on Usenet. Don't
post the same message twice independently. Crosspost. Read my reply on
clp.modules.
Now, FOAD, you spammer.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | Curiouser and curiouser, said Alice.
NSW, Australia |
------------------------------
Date: Sat, 24 Feb 2001 08:10:48 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: stock trading
Message-Id: <comdog-F324C8.08104824022001@news.panix.com>
In article <3A96C216.B928F722@datashaping.com>, Vincent Granville
<vincentg@datashaping.com> wrote:
> If you have any Perl routine of interest to stock traders, and if you
> want to publish the code, email me. I will publish interesting routines
> in my newsletter.
> http://www.datashaping.com/newsletter.shtml
#!/usr/bin/perl
print "Buy low, sell high\n";
__END__
:)
--
brian d foy <comdog@panix.com>
------------------------------
Date: Sat, 24 Feb 2001 08:32:17 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: testing
Message-Id: <x7pug8h46m.fsf@home.sysarch.com>
>>>>> "c" == cryofan <cryofan@msn.com> writes:
c> test
obviously failed your iq test. typical of msn lusers. now go home to
uncle bill.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sat, 24 Feb 2001 07:28:48 -0500
From: Daniel Pfeiffer <Grandulo@MailAndNews.com>
Subject: Why two different class concepts?
Message-Id: <3AC1EBB9@MailAndNews.com>
Yesterday there was a bit of discussion about overload vs. tie. In perldoc
overload we read:
The value for `"="' is a reference to a function with
three arguments, i.e., it looks like the other values in
`use overload'. However, it does not overload the Perl
assignment operator. This would go against Camel hair.
Apparently allowing a normal class to control assignment is bad, while the
very same thing realised through "tie" is all right. This doesn't make
sense!
While classes aren't normally concerned with lifecycle issues like
assignment
(i.e. storage in a variable) or destruction of objects, some are. And for
these Perl has a second mechanism, "tie" which -- even though it has to do
with the internal working of the class -- is not hidden from the user, who
has
to instantiate his objects differently.
I am thinking about a programme, which rather than doing some expensive
calculations internally, would let a much better suited external programme
do
them. Now this programme could also store the (huge) results internally,
and
only few operations like "" or bool would actually transfer the result
within
Perl. The Perl objects would only act as handles to the external
programme's
variables.
But since I have no control over the lifecycle, I neither know when the user
of my class wants to actually store a result, nor when it can be freed
again.
If I stored every intermediate result, I'd get the maximum possible memory
leak in the other programme.
But asking the user to use "tie" every time he wants to store a result in a
new variable is very un-object-like! As a workaround, I want to look at
having my objects be sub-refs somehow containing a closure to some variable
tied by my methods themselves. How complicated!
A few more overloadable operations which cover exactly the methods to be
provided for a tie interface would have been much cleaner.
------------------------------
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 V10 Issue 348
**************************************