[12792] in Perl-Users-Digest
Perl-Users Digest, Issue: 202 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 20 14:17:17 1999
Date: Tue, 20 Jul 1999 11:10:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 20 Jul 1999 Volume: 9 Number: 202
Today's topics:
Re: Programming problem <emschwar@rmi.net>
Re: Programming problem <cassell@mail.cor.epa.gov>
reading sections of a file by markers (Steve .)
Re: regexp fun! (Tad McClellan)
Re: regular Expression <dgris@moiraine.dimensional.com>
Re: runs okay in shell, not in browser <martin@adoma.se>
Re: Seeking for a page maintainer for the Cetus Links <manfred.schneider@rhein-neckar.de>
Re: that great DNS lookup script <delete.the.nospam.kayec@gov.ns.ca>
Trapping Intr, Exec, Stty ben_hoyt@my-deja.com
Re: using perl to talk to a modem (Michael T Pins)
Re: weird getc behaviour <cassell@mail.cor.epa.gov>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Jul 1999 10:52:18 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Programming problem
Message-Id: <xkfk8rvmfgd.fsf@valdemar.col.hp.com>
merlyn@stonehenge.com (Randal L. Schwartz) writes:
> That's so scary that it works. And here's the old fortran "goto less
> equal greater":
>
> goto (qw(LESS EQUAL GREATER))[($a <=> $b)+1]
I've heard that FORTRAN programmers can write FORTRAN in any language,
but I've never (before) seen anybody writing Perl in FORTRAN in Perl. Or
something.
I think I need to go lie down now.
-=Eric
------------------------------
Date: Tue, 20 Jul 1999 10:35:40 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: "Randal L. Schwartz" <merlyn@stonehenge.com>
Subject: Re: Programming problem
Message-Id: <3794B36C.5379CBAF@mail.cor.epa.gov>
[cc email sent to poster]
Randal L. Schwartz wrote:
>
> >>>>> "Abigail" == Abigail <abigail@delanet.com> writes:
>
> Abigail> goto (qw(LABEL0 LABEL1 LABEL2 LABEL3
> Abigail> LABEL4 LABEL5 LABEL6)) [$count % 7];
>
> hey, let's optimize that computed goto:
>
> goto sprintf "LABEL%d", $count % 7;
>
> That's so scary that it works. And here's the old fortran "goto less equal greater":
>
> goto (qw(LESS EQUAL GREATER))[($a <=> $b)+1]
MOOOOOOOMMMMMM!!! Randal's scaring me again!
Boy, we already had Baby Perl this morning, and now Scary Perl.
What's next? Posh Perl?
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 20 Jul 1999 16:10:57 GMT
From: syarbrou@nospam.enteract.com (Steve .)
Subject: reading sections of a file by markers
Message-Id: <37949ec9.238778090@news.enteract.com>
Say I've got a text file that has something like this:
-- text file example snip --
<- start ->
bla bla
bla bla bla
bla bla
bla
<- e1 ->
<- start e2 ->
bla bls a sfd
sfd
ddfsf
df
<- end e2 ->
-- end text file example --
How would I basically say something like take everything starting
after <- start -> and before <- e1 -> and put it in variable $start,
and take everything after <- start e2 -> and before <- end e2 -> and
put it in variable $end ? Thanks.
Steve
------------------------------
Date: Tue, 20 Jul 1999 08:46:10 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: regexp fun!
Message-Id: <i2r1n7.qu5.ln@magna.metronet.com>
James Gerard Coleman (jgc5a@j2.mail.virginia.edu) wrote:
: i'm trying to match regexp, but not having too much success... actually,
: i'm trying to take a value out of a line of text that has one of the
: following two formats:
: "-1:-4:-4 HTTP.005: User 498004652 timed out authentication"
: "07:48:38 HTTP.001: User 498004652(38.11.249.163) authenticated"
: i'm trying to strip the time value (yes, i know there's no negative time..
: it's just what's being spit out to me, so i have to deal with it)
Those looked like _fixed width_ fields.
If so, then unpack() or substr() is the Right Tool, not pattern matching.
my $timeval = substr $_, 0, 8;
: i tried using
: $timeval = /{2}[0-9\-]:{2}[0-9\-]:{2}[0-9\-]\s/
^^^
1) Quantifiers go _after_ the thing they apply to, not before.
2) $timeval will get one of two possible values, zero or one,
likely not what you want.
3) You do not need to escape hyphens when they are first or last
in the character class.
4) You are not capturing the matched characters anywhere
my $timeval = $1 if /([0-9-]{2}:[0-9-]{2}:[0-9-]{2})\s/;
: to match two numberical digits (or a minus) colon, etc. but it didn't
: return a value.
I most certainly _did_ return a value, just not the one you wanted.
Go see what the return value from m// is when used in a scalar context.
: i also tried: /.*:.*:.*\s/
Due to greediness.
my $timeval = $1 if /(.*?:.*?:.*?)\s/;
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 20 Jul 1999 12:11:20 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: regular Expression
Message-Id: <m33dyj5gzb.fsf@moiraine.dimensional.com>
tadmc@metronet.com (Tad McClellan) writes:
> Stephan Pelikan (a9702466@unet.univie.ac.at) wrote:
>
> : I want to analyse an string on pairs of "(" and ")":
<snip>
> : I worked hard, but my knowledge of regular expressions is limited.
> That is obvious, since it is *mathematically impossible* to
> do what you want with regular expressions.
Fortunately for all of us, perl doesn't have _regular_ expressions
anymore. If you are using a non-obsolete version of perl matching
nested parens is trivial.
> They do not have enough power to handle arbitrarily nested constructs.
>
> (it _can_ be done, though it is often ugly, if you can live with
> a "maximum nesting depth" restriction.
> )
It can be done, without being ugly, to an arbitrary nesting
depth.
% cat re_test.pl
#!/home/dgris/bin/perl
use strict;
my $re;
# snipped straight from perlre
$re = qr{ \(
(?:
(?> [^()]+ ) # non-parens, no backtracking
|
(?p{$re}) # me, again
)*
\)}x;
while (<DATA>) {
if (/$re/) {
print "\$` = [$`]";
print "\$& = [$&]";
print "\$' = [$']";
}
}
__END__
this (is a (test) of (matching) (balanced)(parens in a(string)))
% perl re_test.pl
$` = [this ]
$& = [(is a (test) of (matching) (balanced)(parens in a(string)))]
$' = [
]
%
This technique generalizes to parsing any arbitrarily nested
construct. This makes it possible to write a regex that will
correctly parse HTML as well.
> : I hope someone of you knows how to formulate it.
> Anybody who checks the Perl FAQ before posting to the Perl
> newsgroup already knows that it cannot be done (with regexen):
Good thing I don't waste my time looking at the faq anymore. I
might have been so worried about the fact that this can't be done
that I wouldn't have any code doing it. :-)
dgris
--
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Tue, 20 Jul 1999 17:43:30 +0100
From: Martin Quensel <martin@adoma.se>
Subject: Re: runs okay in shell, not in browser
Message-Id: <3794A732.CF18470D@adoma.se>
lmoloch@my-deja.com wrote:
>
> Hello!
>
> I've been puzzling over this piece of code for some time now. It runs
> perfectly when I execute it by typing in its name (or when I type "perl
> userlog.cgi", but the script refuses to run if I call it via a web
> browser-- it displays only a small part of the middle of the expected
> output:
[cut...]
If it only displays a small part of the middle of the expected output
(you mean it does this in the browser right??) then the script doesent
refuse to run.
If you take a look at the HTML the script produces, everything should be
there.
(view source from the menu)
BestRegards
Martin Q
------------------------------
Date: Tue, 20 Jul 1999 18:12:07 +0200
From: "Manfred Schneider" <manfred.schneider@rhein-neckar.de>
Subject: Re: Seeking for a page maintainer for the Cetus Links
Message-Id: <7n274n$j7t$1@news-ma.rhein-neckar.de>
Hi,
> >Manfred Schneider <manfred.schneider@rhein-neckar.de> wrote
> >the Cetus Links ( http://www.cetus-links.org/ ) are a collection of
> >pointers to various information about Object-Orientation and
> >Component-Orientation.
> >
> >The web site contains 15,000+ links and 60+ page. During '98 the site
> >was visited more than 500,000 times. The collection is developed and
> >maintained by a team of several people from different countries
> >(please have a look at http://www.cetus-links.org/team.html ).
> >
> >To enhance and to improve the site we are currently looking for someone
> >who would like to take over the page
> >
> > Perl http://www.cetus-links.org/oo_perl.html
> >
> >If you are interested to join the Cetus Team and to maintain and
> >enhance this page for a longer period of time please let me know.
> >
> >The Cetus Team welcomes your help and support very much.
Marcel Grunauer <marcel.grunauer@lovely.net> wrote
> You might be better off at misc.jobs.offered, or
> perl-jobs-announce@happyfunball.pm.org
> (the perl-jobs-announce list on www.pm.org).
oops, maybe this is a misunderstanding. The Cetus Links are
maintained by a group of volunteers without any financial interest.
These people develop and maintain the pages of the Cetus Links
in their spare time.
Please have a look at
http://www.cetus-links.org/about.html
So we would be happy if someone is interested to join the Cetus Team
and to enhance and improve the Perl page :-)
Cheers, Manfred
+---------------+---------------------------------------------------+
| Cetus Links | Thousands of Links on Objects & Components |
+---------------+---------------------+-------------+---------------+
| Central site | www.cetus-links.org | 65 pages on | 18 mirrors in |
| German mirror | www.cetus-links.de | OO & CBD | 14 countries |
+---------------+---------------------+-------------+---------------+
------------------------------
Date: Tue, 20 Jul 1999 13:40:13 -0300
From: "kayec" <delete.the.nospam.kayec@gov.ns.ca>
Subject: Re: that great DNS lookup script
Message-Id: <BC1l3.896$6T3.40538@sapphire.mtt.net>
THANK YOU BENJAMIN !!!
Benjamin Franz wrote in message ...
>In article <bQ%k3.883$6T3.39627@sapphire.mtt.net>,
>kayec <delete.the.nospam.kayec@gov.ns.ca> wrote:
>>Sometime ago i was pointed to a very fast DNS lookup script that did
>>multiple lookups at a time... very fast, very impressive.
>>
>>Since then i've had a few problems and would like a copy of the
>>original script again...
>
><URL:http://www.deja.com/getdoc.xp?AN=455581292>
>
>--
>Benjamin Franz
------------------------------
Date: Tue, 20 Jul 1999 17:46:15 GMT
From: ben_hoyt@my-deja.com
Subject: Trapping Intr, Exec, Stty
Message-Id: <7n2cl2$2vu$1@nnrp1.deja.com>
Hi comp.lang.perl,
I have an interesting problem that I'm trying to
work through. I have a series of three perl
scripts that represent, basically, text-based
menus. A user moves from one menu to a sub menu
by choosing a option number. Once the input is
recieved, the "main" menu exec()s out into the new
submenu. In all the sub menus, I'm trapping INTR
to exec() back to the main menu. I have mapped
INTR to the escape key (^[) for user
friendliness. Here is the problem: I can leave
the main menu for a sub menu, play around in the
submenu, then I can escape (exec()) back to the
main menu. Then, I once again exec() into the
same sub menu that I just left. Now I'm in the
submenu for the second time. However, this time
when I SIG(INTR) (press escape), the submenu
script doesn't trap the signal, like it doesn't
see it.
I'm using perl4.036 (space constraints) on Linux
2.0.37 GLIBC. The main menu and the sub menu are
both separate scripts. The environment variables
all check out, and a system call to stty --all
from both the main menu and the sub menu show that
the INTR signal is still ^[ in all cases, even
where it fails to trap in the second running of
the sub menu.
Does anyone have any ideas? This has really been
bothering me for awhile! Or, does anyone have a
better, functional, method in 4.036 to exec from
one program to the next and be able to break out
of successive scripts back to the one that
exec()ed the sub menu, without leaving additional
Perl or shell processes running?
If anyone has some good ideas, please let me know
via email: ben@spectrumwireless.net
Thanks in advance!
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 20 Jul 1999 17:00:39 GMT
From: mtpins@visi.com (Michael T Pins)
Subject: Re: using perl to talk to a modem
Message-Id: <XW1l3.4492$U5.842721@ptah.visi.com>
rwadman@morgan.ucs.mun.ca (Ray Wadman) writes:
>hi, i hope someone can help. i need to to know the best way to
>to use perl to communicate with a modem on fbsd 2.2.7
>(what i have to do is use perl to talk to a modem and send out a
>page (the numvber is a pager system) and inform when a critcal host
>goes down.)
The best way to do this isn't with perl.
Install qpage and have bigbrother (or whatever you are using to monitor)
call qpage to do the actual paging.
--
**************************************************************************
* Michael T Pins | mtpins@visi.com *
* keeper of the nn sources | mtpins@icaen.uiowa.edu *
* ftp://ftp.visi.com/users/mtpins | #include <std.disclaimer> *
------------------------------
Date: Tue, 20 Jul 1999 10:39:30 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: weird getc behaviour
Message-Id: <3794B452.2250CCEF@mail.cor.epa.gov>
Anno Siegel wrote:
> [snip of useful explanation]
> Do you really need to process the file one character at a time?
> Or it that a vestige from former C programming. From what you say
> above, a loop like
>
> while ( $line = <INFILE> ) {
> if ( $line =~ /\\cite/ ) {
> # process line
> }
> }
>
> might serve you better.
My personal preference is to avoid nesting when possible, so
that my code is less incomprehensible.
while ( $line = <INFILE> ) {
next if ( $line !~ /\\cite/ );
# now process line
}
Just my $.02,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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 V9 Issue 202
*************************************