[8729] in Perl-Users-Digest
Perl-Users Digest, Issue: 2346 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 17 06:07:15 1998
Date: Fri, 17 Apr 98 03:00:26 -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 Fri, 17 Apr 1998 Volume: 8 Number: 2346
Today's topics:
'strict' and filehandles <heini@cheops.informatik.uni-osnabrueck.de>
Argument checking code in combination with GetOptions <hucka@eecs.umich.edu>
Re: Attempt to speed up rand() <rootbeer@teleport.com>
Re: Bill Gates should be invited to O'Reilly's "Free So <omegam@cmq.com>
Re: commenting a whole block? (Andy Wardley)
Re: commenting a whole block? <r.goeggel@atos-group.de>
Re: Easy way to count lines in a file <tkho@technologist.com>
Re: Embedding Perl in Java (Neil Briscoe)
Re: Filname into variable ( user Putt)
How can i see if a proc/prog is running <tor@kmd.dk>
Re: How to call an unix rsh in perl <zenin@archive.rhps.org>
Making E-mail with Perl <king_pellinore@hotmial.com>
Re: Multi-tasking/threading <gdc@xenetic.fi>
Re: Perl Oddity (Abigail)
Re: rand($.) (was wc-l in Perl) (Tom Mornini)
Re: Recursive Calls in Perl ? (Bart Lateur)
Re: regular expression question (Craig Berry)
Re: regular expression question <danboo@negia.net>
Re: regular expression question (David Oswald)
Re: regular expression question (David Oswald)
Searching PERL for SCO 3.2.v4 <mdegouttes@mail.pf>
Send Message to Event Viewer <curdin.vital@swisscom.com>
Re: unix commands in a perl <soetensi@se.bel.alcatel.be>
Re: unix commands in a perl <zenin@archive.rhps.org>
Re: unix commands in a perl (Neil Briscoe)
unpacking multiple binary shorts (WORDS) <dnac-db@rbgkew.org.uk>
Re: Wanna laugh? (My First cgi.pm Script) (Craig Berry)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 17 Apr 1998 11:15:37 +0200
From: Uwe Hein <heini@cheops.informatik.uni-osnabrueck.de>
Subject: 'strict' and filehandles
Message-Id: <35371DB9.15A7091@cheops.informatik.uni-osnabrueck.de>
With 'use strict' I am not able to call
'open ( FOO , $filename ) ;' anymore
(Bareword error).
Can anyone help?
Thanks
-uh
--
Uwe Hein
University of Osnabrueck
Albrechtstr. 28 Nobbenburger Str. 6
49076 Osnabrueck 49076 Osnabrueck
Germany Germany
Tel (49)541 969 2487 (49)541 67436
FAX (49)541 969 2770 (49)541 67456
email Uwe.Hein@informatik.Uni-Osnabrueck.DE
------------------------------
Date: 17 Apr 1998 03:58:43 -0400
From: Michael Hucka <hucka@eecs.umich.edu>
Subject: Argument checking code in combination with GetOptions
Message-Id: <824szsj2vg.fsf@robin.eecs.umich.edu>
This is probably a silly question, but I'm learning Perl and would like to
learn how this ought to be handled. I'm using GetOptions and have something
like this set up in a program:
&GetOptions("addpackage=s@", "addhost", "export=s@", "help", "host=s@",
"listexported", "listhosts", "listlocal", "listpackages",
"rmhost", "rmpackage=s@", "update", "verbose")
or &print_usage_and_exit();
Now, the thing is, some combinations of the options don't make sense
together. So I have code that looks like this:
if (defined($opt_host)) {
if (defined($opt_listhosts)) {
print "Using both --listhosts and --host does not make sense.\n";
&print_usage_and_exit();
} elsif (defined($opt_listpackages)) {
print "Using both --listpackages and --host does not make sense.\n";
&print_usage_and_exit();
} elsif (defined($opt_addpackage)) {
print "Using both --addpackage and --host does not make sense.\n";
&print_usage_and_exit();
} elsif (defined($opt_rmpackage)) {
print "Using both --rmpackage and --host does not make sense.\n";
&print_usage_and_exit();
}
.... other stuff ...
}
which is not very elegant. Seems like there should be a way of writing this
more compactly in a form such as
if (defined($opt_host)) {
if (defined($opt_listhosts) || defined($opt_listpackages)
|| defined($opt_addpackage) || defined($opt_rmpackage)) {
print "Using both $foo and --host does not make sense.\n";
&print_usage_and_exit();
}
...
}
where $foo is expanded to one of the option names. Problem: is there a way
of easily setting $foo to the right one (i.e., in this case, "listhosts",
"listpackages", etc.)?
--
Mike Hucka hucka@umich.edu http://www.eecs.umich.edu/~hucka University
PhD to be, computational models of human visual processing (AI Lab) of
UNIX systems administrator & programmer/analyst (EECS DCO) Michigan
------------------------------
Date: Fri, 17 Apr 1998 06:12:17 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Mark Waterous <mail@silas.hypermart.net>
Subject: Re: Attempt to speed up rand()
Message-Id: <Pine.GSO.3.96.980416225234.29515Q-100000@user2.teleport.com>
On Fri, 17 Apr 1998, Mark Waterous wrote:
> What I am attempting to do now, though I don't know if it's
> possible, is to speed up the process a bit. It delays for just over a
> second before returning a page, and though this isn't too much, if it
> can be gotten around, I would like to do it.
That's not rand's fault! That's just normal start-up time, and it sounds
as if you want to cut that down. One way to reduce a Perl CGI script's
start-up time (often to nearly zero) is to use Apache's mod_perl. Ask your
webmaster to help you to do that. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 16 Apr 1998 17:50:46 -0500
From: Omegaman <omegam@cmq.com>
Subject: Re: Bill Gates should be invited to O'Reilly's "Free Software Summit" (was Re: RMS should be invited to O'Reilly's "Free Software Summit")
Message-Id: <87vhs9v0s9.fsf@cmq.com>
Ben Bullock <ben@hayamasa.demon.co.uk> writes:
> Development of some linux free docs such as the Network guide
> apparently died off after the O'Reilly version came out.
So? There's nothing preventing anyone from updating the free Network
Guide. O'Reilly didn't kill the free version.
> In some cases the free version might have been just a half-written
> book that the author wanted to get debugged and then turn proprietory,
> such as the Tcl/Tk book by Ousterhout (no, it's not an O'Reilly book)
> instead of an actual free project, but in my opinion that's just
> as bad.
Again. so what? There's nothing stopping you or anyone else from
providing adequate free documentation. Instead of complaining about
the apparent superiority of O'Reilly's books, you should be producing
free documentation for the projects you care about.
There can be no more powerful argument for Free Software(and
documentation) then actual implemented proof.
--
-------------(( http://www.communique.net/~omegam ))-----------------
Omegaman<mailto:omegam@cmq.com> | "When they kick out your front door,
PGP Key fingerprint = | How are you gonna come?
6D 31 C3 00 77 8C D1 C2 | With your hands upon your head,
59 0A 01 E3 AF 81 94 63 | Or on the trigger of your gun?"
Send email with "get key" as the| -- The Clash, "Guns of Brixton"
"Subject:" to get my public key | _London_Calling_ , 1979
----------------------------------------------------------------------
------------------------------
Date: Fri, 17 Apr 1998 06:44:21 GMT
From: abw@cre.canon.co.uk (Andy Wardley)
Subject: Re: commenting a whole block?
Message-Id: <ErJpDy.IIG@cre.canon.co.uk>
Larry Rosler <lr@hpl.hp.com> wrote:
>With all respect, this is a glib and totally useless response. I
>followed your suggestion, and searched for "perl comment block", and
>got 19 totally irrelevant responses (only 7 of which were from "perl"
>groups, by the way). I don't want to waste more time refining the
>search (adding "entire" reduced it to 1 irrelevant response, about
>"Python").
Try it like this:
~g (comp.lang.perl.misc) & ~s (commenting)
Deja-News recognises ~g (group), ~s (subject), ~a (author) and a number
of other criteria which can be combined together as shown above. If you
can tie down one of the criteria (like group), then you'll get a much
better hit rate.
The above query returns (edited slightly for brevity):
1. 98/04/16 043 commenting a whole block? c.l.p.m Ji Huang
2. 98/04/16 043 Re: commenting a whole block c.l.p.m Jason Christian
3. 98/04/16 043 Re: commenting a whole block c.l.p.m Jason Christian
4. 98/04/16 043 Re: commenting a whole block c.l.p.m brian d foy
5. 98/04/16 043 Re: commenting a whole block c.l.p.m Craig Berry
6. 98/04/16 043 Re: commenting a whole block c.l.p.m Larry Rosler
7. 98/04/16 043 Re: commenting a whole block c.l.p.m Larry Rosler
8. 98/04/16 043 Re: commenting a whole block c.l.p.m Abigail
9. 98/04/16 043 Re: commenting a whole block c.l.p.m brian d foy
10. 98/04/16 043 Re: commenting a whole block c.l.p.m Andrew M. Langmead
11. 98/04/16 043 Re: commenting a whole block c.l.p.m Dan Boorstein
12. 98/04/16 043 Re: commenting a whole block c.l.p.m Larry Rosler
13. 98/04/16 042 creating pod - was Re: comme c.l.p.m Dan Baker
14. 98/04/16 042 Re: creating pod - was Re: c c.l.p.m brian d foy
15. 98/04/16 042 Re: creating pod - was Re: c c.l.p.m Dean Pentcheff
Looks like a fairly accurate hit for just one subject word.
A
--
Andy Wardley <abw@kfs.org> http://www.kfs.org/~abw
Signature lost in transit. We apologise for any inconvenience caused.
------------------------------
Date: Fri, 17 Apr 1998 10:04:35 +0200
From: "Ronald G\"oggel" <r.goeggel@atos-group.de>
Subject: Re: commenting a whole block?
Message-Id: <6h72fl$i85$1@news.pop-stuttgart.de>
Ji Huang schrieb in Nachricht ...
>Hi:
>
>I am a new user of perl and maybe i am not well informed but I really
>think it's extremely inconveniece in perl for me to bar a whole block
of
>codes from executing.
>, but in perl i have to put # sign at the beginning of each line of
the
>block.
>
>Is there any easier way for me to do it?
>
It depends on your editor.
emacs for example has block commands. So may set a mark at the
beginning of your block and then you put your cursor at the end of
your block, Type ^x-r-t ### to comment the block.
(and type ^x-r-k to uncomment the block).
HTH
Ronald
------------------------------
Date: Thu, 16 Apr 1998 23:26:09 -0700
From: Tommy <tkho@technologist.com>
Subject: Re: Easy way to count lines in a file
Message-Id: <3536F601.D9019BE4@technologist.com>
how about
@Lines= <ACCESS>
$NumOfLines= $#Lines;
> "Harold Reed" <hareed@bellsouth.net> writes:
>
> > Is there an easy way to count the number of lines a file has? I am working
> > with several access log files that are routinely larger than 300MB and I
> > have developed a crude update that lets the user know every 1000 lines that
> > are processed by the script - so you can get an idea of where the script is
> > in it duties (a stdout update, if you will). Is there a way that you can get
> > a readout of the number of lines in a file quickly? Currently I am using the
> > incredibly CPU-expensive
> >
> > while (<ACCESS>) {
> > counter++;
> > }
> > print "You have $counter lines in this file\n";
> >
> > This is chewing mountains of time on a huge file as previously decribed. I
> > have scoured for a way to count the number of lines - quickly (a la grep
> > perhaps?) - but can't seem to find any sort of clue. Any prompts from the
> > wizened?
> >
> > Harold Reed
Tommy Ho
tkho@technologist.com
------------------------------
Date: 17 Apr 1998 09:07:54 GMT
From: neilb@zetnet.co.uk (Neil Briscoe)
Subject: Re: Embedding Perl in Java
Message-Id: <memo.19980417100753.28605B@skep.compulink.co.uk.cix.co.uk>
In article <6h38pd$gjc$1@news.nanospace.com>, nawwar@kananews.com (Nawwar
Kasrawi) wrote:
> I'm wondering if anybody has successfully embedded Perl in Java. I'm
> struggling trying to figure out how to do it. Right now I'm think
> about how
> to call perl300.dll from Java using RNI.
>
> Any ideas?
>
Hmm - perl300.dll - that sounds rather win32-ish.
There has been some success in embedding Perl in Java on the Unix
platform. Its called JPL - its written by Larry Wall (remember him? ;-))
- and its available on the CD that comes with the Perl Resource Kit (Unix
Edition).
There is supposed to be a Perl Resource Kit (Win32 Edition) out shortly -
I don't think its released yet - since it certainly wasn't in the bookshop
when I bought the Unix version on Monday.
As an aside - to anyone wondering if the Perl Resource Kit is worth the
money - the answer is a definitive yes. I havn't even started reading the
docs yet - however - whats on the CD alone has already paid for itself -
despite the fact it cost #109.95 Sterling - as against $147 in the States
- and being as the Pound is currently so strong - the importer is making a
bucket load.
Regards
Neil
------------------------------
Date: 17 Apr 1998 08:21:34 GMT
From: szhpta@ubs.ch ( user Putt)
Subject: Re: Filname into variable
Message-Id: <6h73ee-1u6@svusenet.ubs.ch>
Mike Wescott (wescott@cygnus.ColumbiaSC.NCR.COM) wrote:
: > sorry, looks and sounds terrible but you might understand what i'm
: > looking for.
: You're right it's not clear exactly what you mean, but I'll give it
: I believe that you are asking if you can recontruct the filename from
: the filehandle. The answer in general is "no". One *could* scan the
: entire filesystem tree looking for files that match (see stat() and
: File::Find), but you are not guaranteed to find the file, nor is
: the name guaranteed to be the one by which it was opened. And it is
: expensive.
yes, this was exactly my problem. So thanks, you helped me a lot. I
changed the program now.
It works fine now.
Thank you all.
andreas
------------------------------
Date: Fri, 17 Apr 1998 11:25:01 +0200
From: "Torfinn Keringen" <tor@kmd.dk>
Subject: How can i see if a proc/prog is running
Message-Id: <6h77br$mpk$1@news1.tele.dk>
Hy
How can i see if an process is running on an Win95/NT, something like
ps -ef | grep process_to_look_for
This is the case,
I Want to start one process called send, this is simple enough, `send`
The process send starts an other process called core, and then send exits
OK.
What I want to do is to start send, and wait for core to exit, before I go
on with the rest of the script.
How can I do this.
Thanks: Torfinn Keringen --> tor@kmd.dk
------------------------------
Date: 17 Apr 1998 06:41:45 GMT
From: Zenin <zenin@archive.rhps.org>
Subject: Re: How to call an unix rsh in perl
Message-Id: <892795722.31787@thrush.omix.com>
[posted & mailed]
Ying Peng <peng@cae.cig.mot.com> wrote:
: I want to use the following unix command in perl:
: rsh B "/net/A/home/peng/1.tar /home/daok" <--Has to use "
: I only know I can use the "system" function to call unix commands but
: the problem is double quote. the system function requires the double
: quote also such as:
Ahh, but it doesn't require any such thing:
system ("rsh B '/net/A/home/peng/1.tar /home/daok'");
or
system (qq(rsh B "/net/A/home/peng/1.tar /home/daok"));
or
system ('rsh', 'B', '/net/A/home/peng/1.tar /home/daok');
or
my $command = 'rsh';
my @arguments = ('B', '/net/A/home/peng/1.tar /home/daok');
system ($command, @arguments);
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: Fri, 17 Apr 1998 10:29:23 +0200
From: "Michael Helldin" <king_pellinore@hotmial.com>
Subject: Making E-mail with Perl
Message-Id: <353712E3.17B0CA09@hotmial.com>
Hi
I making a script what creates a E-mail what sends every night 23:00.
How do I include a specified file into the E-mail. The file can both a
text-file and a imagefil or a executable. The only thing I know is that
the filename is different evey time. (But it has the same start of
filename.). Ex. GUS13924.txt, GUS12343, GUS45432 etc.
Now it looks like this:
---cut---
#!/usr/bin/perl
$MAILPROG='/usr/sbin/sendmail';
$REPLYADR='to@this.adress';
$MAILFROM='Blaha Corp. <$REPLYADR>';
$MAILTO='send@to.here';
$SUBJECT='Testning of Automail';
$ORGUNIT='Blaha corporation';
open (MAIL, "|$MAILPROG -t") || die "Can't open $MAILPROG!\n";
print MAIL "From: $MAILFROM\n";
print MAIL "Reply-To: $REPLYADR\n";
print MAIL "Organization: $ORGUNIT\n";
print MAIL "Mime-Version: 1.0\n";
print MAIL "To: $MAILTO\n";
print MAIL "Subject: $SUBJECT\n";
print MAIL "Content-Type: multipart/mixed;
boundary=\"------------660A1AE254F2\"\n";
print MAIL "Status: RO\n";
print MAIL "This is a multi-part message in MIME format.\n\n";
print MAIL "--------------660A1AE254F2\n";
print MAIL "Content-Type: text/plain; charset=us-ascii\n";
print MAIL "Content-Transfer-Encoding: 7bit\n\n";
print MAIL "This is a test from $ORGUNIT\n\n";
print MAIL "--------------660A1AE254F2--\n";
close (MAIL);
---cut---
Now I want to add a filedefinition
$FILDEF='GUS*';
The directory where the files are:
$FILDIR='/corp/important/sendfiles/"
And I want to move the files after I have sent them to this directory.
How do I do that?
$OLDDIR='/corp/important/sendfiles/old/"
And I want logg everything to
$LOGFILE='/corp/important/sendfiles/log/"
The text I want to add is also in the letter:
----wan to add into letter---
Following file(s) are attached:
GUS12345.TXT 12324 bytes
GUS22123.TXT 12443 bytes
--- end ----
And I want to print to the logg file:
-------
The file : GUS12345.TXT were sent to corporation at 23:04
The file : GUS22123.TXT were sent to corporation at 23:04
-------
------------------------------
Date: Fri, 17 Apr 1998 12:12:08 +0300
From: Dado Colussi <gdc@xenetic.fi>
Subject: Re: Multi-tasking/threading
Message-Id: <35371CE8.3F54@xenetic.fi>
Zenin wrote:
> The next release (5.005) has threads. If you're into pain, you can
> start playing with the betas available on CPAN.
How about embedding the perl interpreter in a multithreaded
program and running scripts in several threads at the same
time?
--
Dado Colussi Xenetic Oy
email gdc@xenetic.fi puhelin (09) 6689 6480
suora (09) 6689 6485 fax (09) 6689 6489
gsm 040 500 5501 osoite Pursimiehenkatu 29-31 B
00150 HELSINKI
------------------------------
Date: 17 Apr 1998 07:14:31 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Perl Oddity
Message-Id: <6h6vgn$hab$1@client2.news.psi.net>
Mark-Jason Dominus (mjd@op.net) wrote on MDCXC September MCMXCIII in
<URL: news:6h6h6k$ncb$1@monet.op.net>:
++
++ You can read about it in detail at
++ <URL:http://www.plvoer.com/~mjd/perl/py/>
^^
http://www.plover.com/%7Emjd/perl/py/
Abigail
--
perl -wle '$, = " "; sub AUTOLOAD {($AUTOLOAD =~ /::(.*)/) [0];}
print+Just (), another (), Perl (), Hacker ();'
------------------------------
Date: Fri, 17 Apr 1998 06:48:11 GMT
From: tmornini@netcom.com (Tom Mornini)
Subject: Re: rand($.) (was wc-l in Perl)
Message-Id: <tmorniniErJpKB.JqJ@netcom.com>
Ronald J Kimball (rjk@coos.dartmouth.edu) wrote:
: Tom Mornini wrote:
: If n is the number of lines, and m is a specific line number, then the
: probability that line m is the result [call it P(M)] is the probability that
: line m is selected [P(m)] multiplied by the probability that no subsequent
: lines are selected [P(n)].
: P(m) = 1/m
: P(n) = (1 - 1/(m+1)) * (1 - 1/(m+2)) * ... * (1 - 1/(n-1)) * (1 - 1/n)
: = m/(m+1) * (m+1)/(m+2) * ... * (n-2)/(n-1) * (n-1)/n
: = (m * m+1 * ... * n-2 * n-1) / (m+1 * m+2 * ... * n-1 * n)
: = m/n
: P(M) = (1/m) * (m/n)
: = 1/n
: Thus, every line has an equal probability of being the resulting line.
Wow! Perhaps I should have paid more attention in Statistics!
: > If fact, I don't believe this code even guarantees that a line is picked!
: rand(1) is always less than or equal to 1, no?
Ah, yes, I see that now. :-)
-- Tom Mornini
-- InfoMania
------------------------------
Date: Fri, 17 Apr 1998 08:48:03 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Recursive Calls in Perl ?
Message-Id: <35381471.1787259@news.tornado.be>
Andrew F. Lee wrote:
>My (related) question is: Does Perl do tail recursion? (And what the
>heck is tail recursion anyway?)
Tail recursion is the compiler optimization, where the compiler notices
that the last instruction in a sub is a recursive call, and replaces the
call/return sequence with a simple jump.
And wouldn't expect Perl to support it. Recursion is a bit rare in Perl
code to acually be worth the bother, as opposed to programs in Scheme
(sortof minimal Lisp), where every other function end in a
tail-recursive call. But, you never know.
p.s. Is'nt it just a bit remarkable that people, when talking about
computer programs, talk about it as if it was an acting person? I just
did.
Bart.
------------------------------
Date: 17 Apr 1998 06:07:49 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: regular expression question
Message-Id: <6h6rjl$sam$2@marina.cinenet.net>
John Cartwright (jcartwright@wans.net) wrote:
: I'm trying to build a regular expression that will return only the
: signifigant digits to the right of the decimal point. For instance, if my
: value is "1.01200", what I would like to get back is "012". Although I've
: tried a number of alternatives, I was using something like:
:
: $a = "1.01200";
: $a =~ s/^(\d+\.) (\d+)0+$/$2/;
:
: unfortunately, this returns the whole number "1.012". Can someone help me out?
$a =~ s/.*\.(\d+?)0*$/$1/;
HTH!
---------------------------------------------------------------------
| 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: Fri, 17 Apr 1998 00:42:33 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: regular expression question
Message-Id: <3536DDB9.4A7831C7@negia.net>
John Cartwright wrote:
>
> Hello All,
>
> I'm trying to build a regular expression that will return only the
> signifigant digits to the right of the decimal point. For instance, if my
> value is "1.01200", what I would like to get back is "012". Although I've
> tried a number of alternatives, I was using something like:
>
> $a = "1.01200";
> $a =~ s/^(\d+\.) (\d+)0+$/$2/;
i think i'd add 0 to the string to automatically drop the trailing
0's and then 'split' on the decimal, pulling off only the second
element:
$a = (split '\.', $a+=0)[1];
i think this will be pretty fast too, in case this is a highly iterative
process.
hope this helps,
--
dan boorstein
------------------------------
Date: Fri, 17 Apr 1998 09:15:03 GMT
From: doswald@xmission.com (David Oswald)
Subject: Re: regular expression question
Message-Id: <35371a9d.196866398@news.xmission.com>
On Thu, 16 Apr 1998 21:34:55 -0600, jcartwright@wans.net (John
Cartwright) wrote:
>Hello All,
>
>I'm trying to build a regular expression that will return only the
>signifigant digits to the right of the decimal point. For instance, if my
>value is "1.01200", what I would like to get back is "012". Although I've
>tried a number of alternatives, I was using something like:
/\.(\d+?)0*$/
I've made the following assumptions: The scalar being compared with
the regex only contains what would be considered a legal decimal
value. The scalar being compared has a decimal point. The scalar
being compared doesn't contain anything else. My regex doesn't
attempt to verify that the scalar presents a legitimate number.
Here's what happens:
The decimal point is found. (there must be one for this to work)
All digits are non-greedily captured into $1. Trailing zeros will be
given back so that the "0*" section can greedily capture them all the
way to the end of the scalar being compared.
$1 will now contain all digits after the decimal point (not including
the decimal point) except for trailing zeros, which were basically
matched outside of the capturing parenthesis.
The key to making this all work is the $ at the end (so that 0*
doesn't try to match earlier on) and the \d+? which will match any
digit, but that will yield anything back that is asked for later on in
the regex (in this case, 0*$).
Dave
------------------------------
Date: Fri, 17 Apr 1998 09:19:49 GMT
From: doswald@xmission.com (David Oswald)
Subject: Re: regular expression question
Message-Id: <35371dcf.197685131@news.xmission.com>
>$a = "1.01200";
>$a =~ s/^(\d+\.) (\d+)0+$/$2/;
See my previous post for more explanation, but where your
understanding is failing you is in the differences between using
nongreedy and greedy quantifiers. I'd recommend Friedl's book if
you're planning on using regexes for anything more involved than very
simple matching. Also, the regex you're proposing makes an error in
the final 0+. That requires that at least one zero trail, and you
can't be sure that'll be the case (for example, a third .333333333333;
no zeros there). In other words, know your quantifiers, and know the
difference between greedy and lazy quantifiers; then you'll be well on
your way.
Dave
------------------------------
Date: Thu, 16 Apr 1998 20:16:48 -1000
From: Marc de GOUTTES <mdegouttes@mail.pf>
Subject: Searching PERL for SCO 3.2.v4
Message-Id: <3536F3D0.4F32@mail.pf>
I can't find, on SCO's web, PERL for UNIX SCO 3.2.v4 but only for latest
version of SCO (OpenServer V5). Does anyone know where I could find this
?
Thanks for helping.
Marc de Gouttes
------------------------------
Date: Fri, 17 Apr 1998 09:02:12 +0200
From: "Curdin Vital" <curdin.vital@swisscom.com>
Subject: Send Message to Event Viewer
Message-Id: <6h6uph$plg@gd2inews.swissptt.ch>
Hi,
How it is possible with Perl to send a message
to WinNT EventViewer?
Thank you for the help
Curdin
------------------------------
Date: Fri, 17 Apr 1998 07:50:48 +0200
From: Inge Soetens <soetensi@se.bel.alcatel.be>
Subject: Re: unix commands in a perl
Message-Id: <3536EDB8.4B04@se.bel.alcatel.be>
Hello,
I've also tried the "system" statement,
but it gives me the same problem :
the code just stops when it arrives the "system".
$file = " find . -name '*.pr' |" ;
open (FIND, $file );
while ($line = <FIND>) # while notEOF
{
print $line;
system("/usr/bin/chmod -f 0755 $line") ;
}
close FIND ;
Maybe a small detail...
I'm trying to run this perl script under ClearCase.
Possibly THAT gives a problem ?
Any solutions ?
------------------------------
Date: 17 Apr 1998 06:54:26 GMT
From: Zenin <zenin@archive.rhps.org>
Subject: Re: unix commands in a perl
Message-Id: <892796482.720969@thrush.omix.com>
Inge Soetens <soetensi@se.bel.alcatel.be> wrote:
: I've also tried the "system" statement,
: but it gives me the same problem :
: the code just stops when it arrives the "system".
Hmm, odd. Are you sure? Have you run ps to make sure that
chmod isn't hanging? -You won't return from system() until
your called program returns.
: $file = " find . -name '*.pr' |" ;
: open (FIND, $file );
And you don't test the open(), why?
: while ($line = <FIND>) # while notEOF
Actually, this should really be:
while(defined ($line = <FIND>))
: system("/usr/bin/chmod -f 0755 $line");
Any reason you're calling chmod(1) instead of the internal
perl chmod() function? If you want the -f, just don't test
it's return value.
: close FIND;
Any reason you don't test your close()? BTW, when using open()
for pipes (such as the pipe from find(1) you use), testing the
close is actually more important then testing the open. This is
because the open test only checks the fork(), not the exec().
Testing the close will tell you if you couldn't run find(1) for
some reason.
: Maybe a small detail...
: I'm trying to run this perl script under ClearCase.
: Possibly THAT gives a problem ?
Maybe. Does it work from the command line? Have you run it under
the debugger (-d option to perl) to see where it hangs? Depending
on how deep your directorys are and the number of files, find may
take a while to return, and you're loop won't start until it finds
enough data to get pushed through the buffered pipe (a block or so,
depending on how friendly your stdio lib is). -You may want to set
autoflush on your FIND handle to speed this up.
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: 17 Apr 1998 09:07:55 GMT
From: neilb@zetnet.co.uk (Neil Briscoe)
Subject: Re: unix commands in a perl
Message-Id: <memo.19980417100755.28605C@skep.compulink.co.uk.cix.co.uk>
In article <6h52sk$4b5@fridge.shore.net>, grinch@whoville.com (Grinch)
wrote:
> Inge Soetens wrote in message <35360897.506F@se.bel.alcatel.be>...
>
> >The code is executed until it arrives the "exec" statement.
> >There it stops.
>
> That's what exec is _supposed_ to do...
>
> Exec launches a child process that replaces the parent. If you want to
> start
> a child process without killing off the parent, use system().
>
Exec does *not* launch a child process. Exec replaces the currently
running process with the image of what you're execing.
Fork launches a child process. Thats why most people use fork to get the
child, then exec to transform that process into something else.
Regards
Neil
------------------------------
Date: Fri, 17 Apr 1998 06:17:44 GMT
From: "Lion" <dnac-db@rbgkew.org.uk>
Subject: unpacking multiple binary shorts (WORDS)
Message-Id: <ErJo6F.n1M@news.rbgkew.org.uk>
I'm writing a binary disassembler for a particular file type I have to deal
with.
Part of the file contains a long(ish) array (>10,000) of 2-byte WORDS
specifying simple integer values that I need to get into an array. I'm
currently seeking to the beginning of the array, reading 2 bytes at a time
and then unpacking each WORD to an array element:
open (IN, $filename) or die "Cannot open file: $!";
seek (IN, $array_location, 0);
for ($i=0;$i<$array_length;$i++){
$byte_count = read (IN, $buffer,$WORD);
if($byte_count == 2){
$buffer = hex(unpack("H4", $buffer));
push (@slurped_data, $buffer);
}
e{
die "Read failed at WORD $i";
}
}
close (IN);
This seems slow and heavy to me - there a better way to do it, surely!
It would be nice to read in the whole length of the array at once and split it up into unpacked 2 byte chunks in a single operation. Is this possible?
TIA
Tony
*******************************************************************
Dr. Tony Cox
Jodrell Laboratory http: www.rbgkew.org.uk
Royal Botanic Gardens tel: (44)-181-332-5360
Kew, U.K. fax: (44)-181-332-5310
*******************************************************************
------------------------------
Date: 17 Apr 1998 05:57:13 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Wanna laugh? (My First cgi.pm Script)
Message-Id: <6h6qvp$sam$1@marina.cinenet.net>
Mark-Jason Dominus (mjd@op.net) wrote:
: In article <6h66i0$rgk$7@marina.cinenet.net>,
: Craig Berry <cberry@cinenet.net> wrote:
: > while (<HEADER>) {
: > print $_;
: > }
: >
: >That can be written as: print <HEADER>;
:
: I think that's bad advice. That reads every line in the file into
: memory before it prints anything out.
:
: Maybe you meant
:
: print while <HEADER>;
That works too, but is (a little bit) slower. Given that the header file
for an app such as the poster's isn't likely to be larger than a few k at
most, slurping into memory all at once seems a reasonable approach.
YMMV. TMTOWTDI. TANSTAAFL. FNORD. :)
---------------------------------------------------------------------
| 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: 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 2346
**************************************