[8972] in Perl-Users-Digest
Perl-Users Digest, Issue: 2590 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 14 01:07:52 1998
Date: Wed, 13 May 98 22:00:24 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 13 May 1998 Volume: 8 Number: 2590
Today's topics:
Automate connection w/ SB1000 <chamberl@magpage.com>
can you tell me how to subscribe perl digest? <jong@salt2.med.harvard.edu>
Re: CPAN & Module gripes (was Re: Ever Wonder...?) (Nicolas CABATOFF)
Re: Does Perl have a IDE?I don't like command line. (Leslie Mikesell)
Extracting duplicated entries ... (Chiu Chong-kan)
Re: Finding answers (Tad McClellan)
Get remote host dir using ftp.pl (Mr Chi Sang Cheng)
Re: How can you break out of a 'while... ' loop in a fu (Ronald J Kimball)
Re: how to create name for temporary file <igor.k@usa.net>
Re: Installing PERL on NT <rglick@liii.com>
Re: Is if ($a="something") a bad style? <dformosa@st.nepean.uws.edu.au>
Re: Nuclear bombing of NEW YORK! Small countries can ta <tmiley@spamsux.yakko.cs.wmich.edu>
Re: ODBC.pm: Is there a size limit to SQL statements? (Andy Lester)
Re: OO perl and speed <igor.k@usa.net>
Re: Question: Finding which element of a list a string (Martien Verbruggen)
Re: read file backwards (Craig Berry)
regex question (stripping html tags/text) <john_hong@Non-HP-USA-om42.om.hp.com>
Re: regex question (stripping html tags/text) (Tad McClellan)
REGEX Question (Gary Chambers)
Re: REGEX Question (Tad McClellan)
Re: Regular Expression Question (Ronald J Kimball)
Viterbi algorithm in Perl wanted <jong@salt2.med.harvard.edu>
Re: What does this do? <dfetter@shell4.ba.best.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 May 1998 01:58:47 GMT
From: James <chamberl@magpage.com>
Subject: Automate connection w/ SB1000
Message-Id: <6jdj4n$jhd$0@208.222.91.85>
Hi,
I have a GI SB1000 External Cable modem. It has a web interface to
bring the connection up & down. I would like the automate the process w/
a perl script or something. I have inspected the html page:
<BODY BGCOLOR = FFFFFF>
<TITLE>SURFboard TM Connection Manager</TITLE>
<HEAD><H3>Connection Manager</H3><HR>
<HTML>
<BODY BGCOLOR=FFFFFF>
<FORM METHOD="POST" ACTION="http:/"> <H2><BR><I>You are connnected
to the SURF
<INPUT TYPE=SUBMIT VALUE="Disconnect"></FORM>
<UL><UL>
<BR>
<P><LI><A HREF="/setup.html"><I><B>SETUP</B></I></A><P><LI><A
HREF="/diag.html"
</BODY>
</HTML>
<BR><BR><FONT SIZE = "-1"> <A HREF = "legal.html"> SURFboard
<SUP>TM</SUP><BR>C
</HTML>
I don't know how to write a script to POST to a url of ACTION="http:/"
Does anyone have any ideas or insight.
thanks,
James
chamberl@magpage.com
------------------------------
Date: Wed, 13 May 1998 22:06:33 -0400
From: Jong Park <jong@salt2.med.harvard.edu>
Subject: can you tell me how to subscribe perl digest?
Message-Id: <355A51A9.446B@salt2.med.harvard.edu>
Thanks,
email to my address please as the reason why
I want digest is because I have a difficulty
in accessing news group(I have to pay)
Cheers,
Jong
------------------------------
Date: 8 May 1998 14:31:18 GMT
From: ncc@@CS.McGill.CA (Nicolas CABATOFF)
Subject: Re: CPAN & Module gripes (was Re: Ever Wonder...?)
Message-Id: <6iv4vm$23a@sifon.cc.mcgill.ca>
Matija Grabnar (matija@rzenik.arnes.si) wrote:
> I am not a clueless newbie (in fact, I have a module on CPAN myself), but
> let's not pretend that everything on CPAN works smoothly.
> I wanted to install the Expect module. I knew it existed, because I
> read the announcement on c.l.p.a. However, when looking for it in
> modules/by-module, I couldn't find it. And I couldn't find it in
> 00modlist.long.html, either.
I installed it a month ago myself, and also had a bit of difficulty
finding it. So I will grant you that "[not] everything on CPAN works
smoothly." However, this was due (AFAIK) to a not-quite-current index,
which I don't see as a serious problem. I was just lazy and didn't feel
like looking up how to do a search, so I used the same means as you to
find the author and look in his directory.
> As if that wasn't enough, the Expect module installed silently, without
> tests, and without telling me that it required the IO::Pty module.
I don't know what version you installed, but here's the first of the two
paragraphs which comprise the v1.04 module's README:
To install Expect you will also need IO::Stty which will be in
the same directory as you found this package, currently at
ftp://ftp.habit.com/pub/perl. You will also need IO::Tty which
can be found in Graham Barr's directory on any CPAN site.
The two dependancies are stated upfront, and can be located exactly
where described.
> I searched the IO directory, and could find nothing. I did a 'find'
> across the CPAN tree, and nothing with 'Pty' in it's name that turned
> up was relevant. Finaly, the FAQ for Expect.pm suggested looking in
> Graham Barr's directory, where I found it, in a file called IO-Tty
> (NOT Pty). It turns out Tty also contains Tty, but that is not evident
> anywhere. BTW: the PTY module is listed in 00modlist.long.html, but
> there is no hint as to it's curious location.
If you'd just read the README (less than a screenful, browseable without
even downloading the module itself) you could have downloaded all the
required modules without ever leaving CPAN.
------------------------------
Date: 13 May 1998 22:28:26 -0500
From: les@MCS.COM (Leslie Mikesell)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jdocq$3i$1@Venus.mcs.net>
In article <6jbe9v$af0$1@mathserv.mps.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Tom Christiansen
><tchrist@mox.perl.com>],
>who wrote in article <6jap9f$enu$1@csnews.cs.colorado.edu>:
>> In comp.lang.perl.misc, ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
>> :it is *nix which is tool-challenged.
>>
>> Orwell was here.
>
>Name one *nix tool which is not available on my non-*nix machine.
>
>You are given 3 tries.
mknod (or even mkfifo)
ln
expect
Les Mikesell
les@mcs.com
------------------------------
Date: 14 May 1998 04:24:53 GMT
From: ckchiu@cs.cuhk.hk (Chiu Chong-kan)
Subject: Extracting duplicated entries ...
Message-Id: <6jdrml$ism@eng-ser1.erg.cuhk.edu.hk>
Hi folks,
I've got a file in the following format:
123;ABC;test0
324;BBC;test1
100;ABC;test2
324;AAA;test3
999;BBC;test4
.
.
What I want to do is to extract the rows with duplicated values on a
specific column and put them into a file. For example, if I treat
the second column as key, the output file should be:
123;ABC;test0
100;ABC;test2
324;BBC;test1
999;BBC;test4
If I treat the first column as key, the output should be:
324;BBC;test1
324;AAA;test3
Anyone idea ? Can anyone kindly give me a help ?
C.K.
--
Chong-kan Chiu Dept.of Computer Science & Engineering
E-mail : ckchiu@cs.cuhk.edu.hk The Chinese University of Hong Kong
Phone : (852) 2609-8422 Shatin, Hong Kong
------------------------------
Date: Wed, 13 May 1998 22:36:24 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Finding answers
Message-Id: <orodj6.oj8.ln@localhost>
Website Construction Company (websites@erols.com) wrote:
: I want to be independant as far as finding answers to questions.
Bravo!!
: I
: remember once seeing someone using grep to search all of the
: documentation to find answers. How did they do that? How would one do
: it for Win95 version?
I don't speak Win95, but I do speak Perl, so let's grep with perl:
perl -ne 'next unless /^=/; print if /My_Search_Term/' *.pod
Word searches only on the POD tag lines. Works suprisingly often.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 14 May 1998 03:13:21 GMT
From: chengcs@news.hk.super.net (Mr Chi Sang Cheng)
Subject: Get remote host dir using ftp.pl
Message-Id: <6jdngh$kn8$1@tst.hk.super.net>
Help!
I don't know how to obtain remote host dir contents using ftp'dir_open
in ftp.pl library.
It is urgent and any help would be appreciated.
Regards,
Griffin.
------------------------------
Date: Wed, 13 May 1998 21:57:30 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: How can you break out of a 'while... ' loop in a function?
Message-Id: <1d8zl21.1li6l0j4kcqeN@bay1-124.quincy.ziplink.net>
Stuart Wright <stu-w@usa.net.remove.everything.after.net> wrote:
> Ah well that explains it then - I've been programming in Perl for a
> year and I've never *had* perl - just a (bad) book and Wordpad.
What's the point of programming in Perl if you don't have perl? That's
like programming in C without a C compiler. You get a nice text file
that does absolutely nothing.
If you are able to execute your Perl programs, then you have perl.
And if you have perl, then you should have the documentation. Try
searching for files with 'perl' in the name.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 13 May 1998 21:51:43 -0700
From: "Igor Krivokon" <igor.k@usa.net>
Subject: Re: how to create name for temporary file
Message-Id: <6jdt35$ere$1@news.ncal.verio.com>
Zenin wrote in message <895109389.211748@thrush.omix.com>...
>No one mentioned the new_tmpfile() constructor of the IO::File module?
>Albeit probably only useful under Unix as I doubt NT/95's file system would
>be this cool.
1) It is useful, and not only under Unix
2) There's no such thing as "NT/95's file system".
Sounds not better then "unix/dos file system".
3) I'm not sure what did you mean by "cool". Nothing special:
#include <stdio.h>
FILE* tmpfile();
This worked on any system with C compiler ( even on MS-DOS 10 years ago :)
Regards,
Igor Krivokon
<igor.k@usa.net>
------------------------------
Date: 14 May 1998 02:29:19 GMT
From: "Ron Glick" <rglick@liii.com>
Subject: Re: Installing PERL on NT
Message-Id: <01bd7ee0$7f68f180$da1d1dd0@asdfasdf>
Hauk,
Make sure that you add the full to your Perl binaries to your system path.
I advise doing this through the Properties tab of My Computer, rather than
in a Command Prompt window. When you make changes to the path in a Command
Prompt window, they only take effect in that window, and are lost when that
window is closed. If you change the path in My Computer, it's global and
persistent.
Hope this helps,
Ron Glick
>
> > : Hauk Langlo wrote in message <3557F603.33C0D4B0@forumnett.no>...
> > : >Hi there. After using PERL at work for some weeks I have finally got
my
> > : >own PC at home. I'm pretty new to the PC format and have not managed
to
> > : >successfully install/build perl on my PC. I got a file called
> > : >perl5.00402-bindist04-bc. I have done the installation process but
my
> > : >perl programs will not work like they do at my job, they will not
work
> > : >at all really. Do anyone know exactly what kind of thins I will have
to
> > : >do in order to run PERL programs on my Win-NT PC? Any help would be
> > : >apprecuated. Thanks.
> > : >
> > : >Hauk Langlo (JAPH)
> > : >
> > : >
>
>
>
>
------------------------------
Date: 14 May 1998 03:37:15 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: Is if ($a="something") a bad style?
Message-Id: <895117035.456132@cabal>
In <1d8yu6g.tnav4y1vkjrksN@roxboro0-057.dyn.interpath.net> phenix@interpath.com (John Moreno) writes:
>Yong Huang <yong@shell.com> wrote:
>> Since I receive a couple of kind messages that misunderstood what I meant
>> (due to my fault!), I want to clarify my point.
>>
>> I want to do assignment and in the same step (at least at the programmer's
>> first sight), check to see if the string is null. The C style, that is,
>> if (!(fd=open("mydata.txt",r+)) { printf "Can't open the file "...
>> looks elegant and neat. That's why I want to know if this is thought of as
>> neat in Perl too.
>I understood what you meant - but that's NOT neat in C and it's not neat
>in Perl. It works (in both) and can occasionally be useful, but
>generally it's just a opportunity for a mistake to happen.
I would have to dissagry with you here.
$something = &somefuntion or die "Can't do somefuntion";
And this is a standard perl usage, thats even recomened.
--
I'm a perl programer; if you need perl programing, hire me.
Please excuse my spelling as I suffer from agraphia; see the url. Support NoCeM
http://www.cit.nepean.uws.edu.au/~dformosa/Spelling.html http://www.cm.org/
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: 13 May 1998 23:39:11 GMT
From: Tim Miley <tmiley@spamsux.yakko.cs.wmich.edu>
Subject: Re: Nuclear bombing of NEW YORK! Small countries can target with nukes!
Message-Id: <6jdauv$mcs$1@news.wmich.edu>
In comp.os.linux.misc gdw <gdw@yahoo.com> wrote:
> You are living, sleeping and walking on a planet which is a
> LIVE ATOM BOMB and a HUGE BAR MAGNET!!
You've broken your science teacher's heart with that kind of garbage. Tak a
trip to the library sometime. And, BTW, this is the Linux misc group. We
don't care to discuss politics, the bombs, etc., on this group. Just how cool
linux is.
--
* tmiley@spamsux.yakko.cs.wmich.edu *"What joy it is for leaders that *
* Computer Science Senior *men do not think!" - Adolf Hitler *
* Western Michigan University **Computer Club: Linux users since '93.
------------------------------
Date: 14 May 1998 03:38:56 GMT
From: petdance@maxx.mc.net (Andy Lester)
Subject: Re: ODBC.pm: Is there a size limit to SQL statements?
Message-Id: <6jdp0g$mdg$1@supernews.com>
: > It would appear that ODBC.pm has a limit on the size of SQL statements
: > (around 60K) that it can handle.
: Pardon my curiosity, but why are them statements *that* big?
I'm saving arbitrarily large web pages.
xoxo,
Andy
--
--
Andy Lester: <andy@petdance.com> http://tezcat.com/~andy/
Chicago Shows List: <shows@ChicagoMusic.com> http://ChicagoMusic.com/
------------------------------
Date: Wed, 13 May 1998 19:57:48 -0700
From: "Igor Krivokon" <igor.k@usa.net>
Subject: Re: OO perl and speed
Message-Id: <6jdmdi$bv0$1@news.ncal.verio.com>
Zenin wrote in message <895110589.306103@thrush.omix.com>...
>rdosser@my-dejanews.com wrote:
>: In man perltoot, Tom refers a couple of times to the speed of OO perl - that
>: direct hash lookups are an order of magnitude faster than method lookup, and
>: "if you wanted fast, you wouldn't be using objects at all." Can anybody point
>: me to a resource expanding on that? I want to know more about the tradeoffs.
>
> Methods (in any language) are inherently slower then function/subroutine
> calls because they must do at least two levels of lookup to find the
> method code pointer (They must lookup there first level package/class,
> then go looking for the method pointer). The greater the level of
> inheritance (ala "reuse") the greater the effect can be, depending
> (some compilers can cut this down, depending on the language).
In some languages - yes. But, of course, not "in any language".
Say, in C++ there's no runtime overhead for non-virtual function call.
If function declared as virtual, there's only one lookup in v-table.
That's pretty fast operation and it does not depend on level of inheritance
(and, imho, inheritance and reuse are weakly related terms)
Igor Krivokon
<igor.k@usa.net>
------------------------------
Date: 14 May 1998 03:09:38 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Question: Finding which element of a list a string corilates to
Message-Id: <6jdn9i$ere$1@comdyn.comdyn.com.au>
In article <6jd82c$d6k$4@comdyn.comdyn.com.au>,
mgjv@comdyn.com.au (Martien Verbruggen) writes:
> In article <6jcdfb$33l@hplntx.hpl.hp.com>,
> "Larry Rosler" <lr@hpl.hp.com> writes:
>
>> Is there an answer to this question better than the obvious and
>> mundane -- count up a loop?
>
> Maybe.. depending on how many times you have to look up an element. A
> hash table, with the array indices as values might be more efficient,
> but I'd have to benchmark that to be absolutely sure.
Ok, I couldn't resist. here's the benchmarking stuff.
#!/usr/local/bin/perl -w
use strict;
use Benchmark;
use vars qw ( @months %months );
my $count = 50_000;
@months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
for (my $i = 0; $i <= $#months; $i++) { $months{$months[$i]} = $i; }
print "loop for Jan: ";
timethis( $count, 'find_index_with_loop("Jan")' );
print "hash for Jan: ";
timethis( $count, 'find_index_from_hash("Jan")' );
print "loop for Jul: ";
timethis( $count, 'find_index_with_loop("Jul")' );
print "hash for Jul: ";
timethis( $count, 'find_index_from_hash("Jul")' );
print "loop for Dec: ";
timethis( $count, 'find_index_with_loop("Dec")' );
print "hash for Dec: ";
timethis( $count, 'find_index_from_hash("Dec")' );
print "loop for Ran: ";
srand(1234);
timethis( $count, '
my $m = $months[int(rand(12))];
find_index_with_loop($m);
');
print "hash for Ran: ";
srand(1234);
timethis( $count, '
my $m = $months[int(rand(12))];
find_index_from_hash($m);
');
print "build + hash for Ran: ";
srand(1234);
timethis( $count, '
for (my $i = 0; $i <= $#months; $i++) { $months{$months[$i]} = $i; }
my $m = $months[int(rand(12))];
find_index_from_hash($m);
');
sub find_index_with_loop
{
my $val = shift;
my $i;
for ($i = 0; $i <= $#months; $i++)
{
last if $val eq $months[$i];
}
return (($i <= $#months) ? $i : -1);
}
sub find_index_from_hash
{
my $val = shift;
return ((exists $months{$val}) ? $months{$val} : -1);
}
OUTPUT:
loop for Jan: timethis 50000: 2 secs ( 1.95 usr 0.00 sys = 1.95 cpu)
hash for Jan: timethis 50000: 1 secs ( 1.02 usr 0.00 sys = 1.02 cpu)
loop for Jul: timethis 50000: 4 secs ( 5.36 usr 0.01 sys = 5.37 cpu)
hash for Jul: timethis 50000: 2 secs ( 0.99 usr 0.00 sys = 0.99 cpu)
loop for Dec: timethis 50000: 8 secs ( 8.15 usr 0.00 sys = 8.15 cpu)
hash for Dec: timethis 50000: 1 secs ( 1.00 usr 0.00 sys = 1.00 cpu)
loop for Ran: timethis 50000: 6 secs ( 5.76 usr 0.00 sys = 5.76 cpu)
hash for Ran: timethis 50000: 2 secs ( 1.58 usr 0.00 sys = 1.58 cpu)
build + hash for Ran: timethis 50000: 11 secs (10.50 usr 0.00 sys = 10.50 cpu)
You'll note that especially if the month gets closer to the end of the
year, that the loop gets inefficient, which is obvious enough. The
last one merely illustrates how much less efficient it is to build the
hash for one lookup, compared to using the loop. Looks like two
lookups already warrants the use of the hash method.
Probably this could be more precise by eliminating the overhead of
calling subs etc., but since you normally would use a sub like this
anyway, I guess these numbers are valid enough. Both methods are
dealing with the same overhead anyway. The srands in there are to make
sure that the same set of pseudo-random numbers is used for all three
calls.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd. | make a better idiot.
NSW, Australia |
------------------------------
Date: 14 May 1998 01:58:25 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: read file backwards
Message-Id: <6jdj42$t1v$1@marina.cinenet.net>
Website Construction Company (websites@erols.com) wrote:
: I looked in many places, and I know I have seen the answer before but
: can't find it, so....
:
: How do you read from the bottom line up in a text file?
Presuming it's small enough to fit in memory all at once:
foreach my $line (reverse <FILE>) {
# ...process each line here...
}
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Wed, 13 May 1998 19:04:15 -0700
From: John Hong <john_hong@Non-HP-USA-om42.om.hp.com>
Subject: regex question (stripping html tags/text)
Message-Id: <355A511E.5069780B@Non-HP-USA-om42.om.hp.com>
I'm trying to strip all the script tags out of an html document.
I'm having trouble matching "everything up to </SCRIPT>"?
----------I've tried:-----------
$/ = ".\n"; #added we're spanning multiple lines
s/<SCRIPT>[^(<\/SCRIPT>]+<\/SCRIPT>//g;
#But the [^(\/SCRIPT>] isn't working.
----------I want:------------
<html>
blah. . . blah. . .
<SCRIPT>
<!-- hide script
function sitenav(f) {
var nav=f.urls.selectedIndex
location=f.urls.options[nav].value;
}
//-->
</SCRIPT>
blah. . . blah. . .
</html>
------------ to become ------------
<html>
blah. . . blah. . .
blah. . . blah. . .
</html>
Any help to this suffering newbie would be appreciated!
John H.
------------------------------
Date: Wed, 13 May 1998 22:45:27 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: regex question (stripping html tags/text)
Message-Id: <ncpdj6.8l8.ln@localhost>
John Hong (john_hong@Non-HP-USA-om42.om.hp.com) wrote:
: I'm trying to strip all the script tags out of an html document.
: I'm having trouble matching "everything up to </SCRIPT>"?
s#<SCRIPT>.*?</SCRIPT>##gs; # use an alternative pattern delimiter
: Any help to this suffering newbie would be appreciated!
This will work for the one example you provided.
There are lots of easy ways to break it though...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 14 May 98 02:35:46 GMT
From: gary@NOSPAM.netquarters.net (Gary Chambers)
Subject: REGEX Question
Message-Id: <slrn6lkm42.2gi.gary@flyfish.netquarters.net>
I'm having a problem with a REGEX.
Given the following text file:
abcd 113.70 Twice a year 06/17/98
jalalskdlin 113.70 Twice a year 11/05/98
uahld 24.95 Monthly 05/26/98
jsals 113.70 Twice a year 10/06/98
pll 65.85 Quarterly 06/15/98
And the following Perl script:
#!/usr/bin/perl -w
while (<>)
{
if (/\s*(\S*)\s*(\d+\.\d+)\s*(\S*){1,3}/)
{
$login = $1; $totalpmt = $2; $frequency = $3;
print "$login\t$totalpmt\t$frequency\n";
}
}
Why am I only extracting "Twice" in the "Twice a year" field? Should
I not be getting all three of the words with {1,3} in the regexp? Any
help is *GREATLY* appreciated...
--
Gary
//------------------------------------------
// Remove NOSPAM from address to reply
// NetQuarters, Inc., Brunswick, ME 04011
// 207-798-8400 (Voice) 207-798-8403 (Fax)
// Midcoast Maine's Total Internet Solution
//------------------------------------------
------------------------------
Date: Wed, 13 May 1998 23:00:17 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: REGEX Question
Message-Id: <h8qdj6.1o8.ln@localhost>
Gary Chambers (gary@NOSPAM.netquarters.net) wrote:
: I'm having a problem with a REGEX.
: Given the following text file:
: abcd 113.70 Twice a year 06/17/98
[snip]
: And the following Perl script:
: #!/usr/bin/perl -w
: while (<>)
: {
: if (/\s*(\S*)\s*(\d+\.\d+)\s*(\S*){1,3}/)
^^^^^^^^^^
[snip]
: Why am I only extracting "Twice" in the "Twice a year" field?
I don't get that in the output from your script... ??
: Should
: I not be getting all three of the words with {1,3} in the regexp?
No you should not.
There is a space (\s) between the words. Where have you provided
something to match it in your regex? (rhetorical, you haven't ;-)
if (/^\s*(\S+)\s+(\d+\.\d+)\s+(\S+(\s\S+)*)/)
I always prefer '+' over '*' if at all possible. Of course it depends
on your data and what you want to do.
: Any
: help is *GREATLY* appreciated...
Hope that did.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 13 May 1998 21:57:34 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Regular Expression Question
Message-Id: <1d8zlt9.ltd997xr957qN@bay1-124.quincy.ziplink.net>
Larry Rosler <lr@hpl.hp.com> wrote:
> As discussed in great detail in Friedl's masterly 'Mastering Regular
> Expressions', when you know what character you are looking for to
> terminate the match, you should be as specific as possible. In the
> first example, the 'non-greedy' pattern .*? eats up the entire string
> (to the new-line, if any) because it matches the pattern. Then it tries
> to match the next pattern \( and reluctantly backtracks, giving up
> characters all the way to the beginning, until it finds the *first* left
> parenthesis (if any). The second pattern [^(]* doesn't do any more work
> than is needed. It is much less greedy than the non-greedy .*) .
Whoa, you'd better read that book again, buddy. That's not how
non-greedy matching works at all! Non-greedy matching always tries the
*shortest* match first - hence "non-greedy".
Assuming a regex of /^(.*?)\(/ ...
First .*? matches 0 characters (not, as you suggested, the entire
string). Then the engine tries to match \(. If that fails, .*? matches
1 character and \( is attempted again. And so on. Thus, .*? backtracks
by trying to match more characters, not fewer. That's the difference
between greedy and non-greedy.
Note that matching all the way to the end of the string and then
back-tracking to the *first* \( would be not only ridiculously
inefficient, but also impossible. You can't find the first \( by
counting from the end of the string.
([^(]*) is *more* greedy than (.*?). The former has a greedy
quantifier, after all, and the latter has a non-greedy quantifier.
However, ([^(]*) is more efficient than (.*?). There are two reasons
for this.
First, ([^(]*) involves less backtracking; it matches right out to the
first \(, whereas (.*?) gets to the first \( only after stopping at
every preceding character along the way.
Second, ([^(]*) only involves one entry and exit into capturing
parentheses, whereas (.*?) exits and reenters the capturing parens for
every character up to the \(. And exiting and entering capturing parens
is expensive.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 13 May 1998 23:42:14 -0400
From: Jong Park <jong@salt2.med.harvard.edu>
Subject: Viterbi algorithm in Perl wanted
Message-Id: <355A6816.15FB@salt2.med.harvard.edu>
Thanks very much,
Jong
------------------------------
Date: 14 May 1998 04:04:54 GMT
From: David Fetter <dfetter@shell4.ba.best.com>
Subject: Re: What does this do?
Message-Id: <6jdqh6$dm6$1@nntp1.ba.best.com>
J1T1W1 <j1t1w1@aol.com> wrote:
> All,
> if someone could explain this line of code to me I would greatly appreciate
> it.
> read(STDIN, $buf, $ENV{'CONTENT_SIZE'});
<facetiousness level='high'>
1. Shows that you're asking a CGI question on a Perl newsgroup.
2. Demonstrates that somebody hasn't installed CGI.pm on your web server.
3. Perpetuates some unfortunate stereotypes about America On Line.
</facetiousness>
perldoc -f read :)
--
David Fetter 888 O'Farrell Street Apt E1205
shackle@ren.glaci.com San Francisco, CA 94109-7089 USA
http://www.best.com/~dfetter +1 415 567 2690 (voice)
print unpack ("u*",q+92G5S="!!;F]T:&5R(%!E<FP@2&%C:V5R"@``+)
A computer without Microsoft and IBM is like chocolate cake without
ketchup and mustard
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2590
**************************************