[9651] in Perl-Users-Digest
Perl-Users Digest, Issue: 3244 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 24 12:07:51 1998
Date: Fri, 24 Jul 98 09:00:27 -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, 24 Jul 1998 Volume: 8 Number: 3244
Today's topics:
Re: "While" Loops.. Possible Perl Bug ? dave@mag-sol.com
Re: "While" Loops.. Possible Perl Bug ? (Larry Rosler)
Re: "While" Loops.. Possible Perl Bug ? pabraham@my-dejanews.com
Re: "While" Loops.. Possible Perl Bug ? <jdporter@min.net>
Re: "While" Loops.. Possible Perl Bug ? (Tad McClellan)
Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Pos <merlyn@stonehenge.com>
Re: [Perl for WIn32] -e Command line script? (Bob Trieger)
Re: Code showing apparent "Perl While Bug" <jdporter@min.net>
Condensed followup and continued puzzlement Re: -e glob <John.Adams@BentonvilleAR.ncr.com>
Crazy Math Leon Schmetz
Date Question... <rkim@temple.edu>
Re: Date Question... (Larry Rosler)
Re: Date Question... (Josh Kortbein)
Re: extracting price from string (again) dwiesel@my-dejanews.com
Re: extracting price from string <maraism@sterlingdi.com>
Re: Help! To capture errors... (Josh Kortbein)
Re: htpasswd (Larry Rosler)
Re: newbie Q: self-calling script? <merlyn@stonehenge.com>
Re: newbie Q: self-calling script? (Bart Lateur)
Re: OT? Fly GIF's <rurban@sbox.tu-graz.ac.at>
Re: parsing question <jdporter@min.net>
Re: parsing question <jdporter@min.net>
Re: parsing question <minich@globalnet.co.uk>
perl 5.004_04 - cygwin32: make problems <rurban@sbox.tu-graz.ac.at>
Re: perl as pseudocode <jdporter@min.net>
Re: Perl Beautifier Home Page (Larry Rosler)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 24 Jul 1998 13:53:21 GMT
From: dave@mag-sol.com
Subject: Re: "While" Loops.. Possible Perl Bug ?
Message-Id: <6pa3kh$nuo$1@nnrp1.dejanews.com>
Mark,
It's not a bug in 'while', it's a misunderstanding of how 'each' works. You
should reread the documentation for 'each', in particular the bits about what
resets 'each' to the start of a hash. I think you'll find exiting from a sub
doesn't do it.
hth,
Dave...
In article <35B868CF.41C6@webleicester.co.uk>,
Mark Simonetti <marks@webleicester.co.uk> wrote:
> I think I may have discovered a bug in perl involving the use of while
> loops and associative arrays.
>
> Basically, if I have a subroutine containing a while loop as such:
>
> sub thing {
> my $fred = @_;
> my ($cmd, $prm);
>
> while(($cmd, $prm) = each(%$fred)) {
> return(1) if($cmd eq 'pants');
> }
> }
>
> Ok, its just some code I made up on the spot, but it helps to illustrate
> the problem.. which is,
>
> I call that sub routine, passing a hash pointer.
> The "While" loop starts.
> $cmd is found to equal 'pants'..
> The subroutine returns 1.
>
> Okay, bug time:
>
> The subroutine is called again.. and instead of the while loop starting
> from where it left off, it seems to carry on from where it left off !!
>
> Anyone else found this ? I seem to be able to get round the problem
> using "foreach" blah blah.. Which I beleive is less efficient.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Fri, 24 Jul 1998 07:21:16 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: "While" Loops.. Possible Perl Bug ?
Message-Id: <MPG.1022383a7de9e57e989780@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc; copy mailed.]
In article <35B868CF.41C6@webleicester.co.uk> on Fri, 24 Jul 1998
11:58:23 +0100, Mark Simonetti <marks@webleicester.co.uk> says...
> I think I may have discovered a bug in perl involving the use of while
> loops and associative arrays.
Er, hashes. Highly unlikely, in any case.
> Basically, if I have a subroutine containing a while loop as such:
>
> sub thing {
> my $fred = @_;
> my ($cmd, $prm);
>
> while(($cmd, $prm) = each(%$fred)) {
> return(1) if($cmd eq 'pants');
> }
> }
>
> Ok, its just some code I made up on the spot, but it helps to illustrate
> the problem.. which is,
Better to post code that has a chance of working. In this case, you are
using the number of arguments in the function call as a hash reference.
Most unlikely to be correct.
> I call that sub routine, passing a hash pointer.
> The "While" loop starts.
> $cmd is found to equal 'pants'..
> The subroutine returns 1.
>
> Okay, bug time:
>
> The subroutine is called again.. and instead of the while loop starting
> from where it left off, it seems to carry on from where it left off !!
How certain are you that there is not a use of 'keys' or 'values' on the
hash you are presumably using 'each' on, between your calls to 'each'?
As documented clearly in `perlfunc -f each`, these functions share an
iterator, which will be reset the way you report.
> Anyone else found this ? I seem to be able to get round the problem
> using "foreach" blah blah.. Which I beleive is less efficient.
Only in the use of space, as the entire list is generated at once.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 24 Jul 1998 14:27:04 GMT
From: pabraham@my-dejanews.com
Subject: Re: "While" Loops.. Possible Perl Bug ?
Message-Id: <6pa5jq$qoj$1@nnrp1.dejanews.com>
In article <35B868CF.41C6@webleicester.co.uk>,
Mark Simonetti <marks@webleicester.co.uk> wrote:
> I think I may have discovered a bug in perl involving the use of while
> loops and associative arrays.
Hmmmm.
> Basically, if I have a subroutine containing a while loop as such:
>
> sub thing {
> my $fred = @_;
> my ($cmd, $prm);
>
> while(($cmd, $prm) = each(%$fred)) {
> return(1) if($cmd eq 'pants');
> }
> }
>
> Ok, its just some code I made up on the spot, but it helps to illustrate
> the problem.. which is,
>
> I call that sub routine, passing a hash pointer.
> The "While" loop starts.
> $cmd is found to equal 'pants'..
> The subroutine returns 1.
>
> Okay, bug time:
>
> The subroutine is called again.. and instead of the while loop starting
> from where it left off, it seems to carry on from where it left off !!
I'm not sure I follow you here.
> Anyone else found this ? I seem to be able to get round the problem
> using "foreach" blah blah.. Which I beleive is less efficient.
According to the Perl manual, calling "each" will return the next
key/value pair of the hash.
So the first time you call your subroutine you loop iterate down the
hash until you find your pants, so to speak. The second time you
call your subroutine, you have already gone past your pants, so the
loop continues until "each" returns 0, which signifies the end of
the list.
So, not a bug IMO.
A shorter version could be:
return 1 if exists $$fred{ pants };
which doesn't require an iterator.
Hope this helps.
Paul Abraham.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Fri, 24 Jul 1998 15:07:53 GMT
From: John Porter <jdporter@min.net>
Subject: Re: "While" Loops.. Possible Perl Bug ?
Message-Id: <35B8A4D6.BA4@min.net>
Mark Simonetti wrote:
>
> sub thing {
> my $fred = @_;
> my ($cmd, $prm);
>
> while(($cmd, $prm) = each(%$fred)) {
> return(1) if($cmd eq 'pants');
> }
> }
>
> Ok, its just some code I made up on the spot,
As evident from the the horrendous bug, which causes the code to
not do anything at all like what you says it does -- namely:
> my $fred = @_;
This must, of course, be
my( $fred ) = @_;
or
my $fred = $_[0];
or
my $fred = shift;
> The subroutine is called again.. and instead of the while loop starting
> from where it left off, it seems to carry on from where it left off !!
Well, aside from the fact that those sound like the same thing to me,
you are seeing each() exhibit its documented behavior.
If you want it to start over from the beginning, you can reset it by
doing as TFM says, and calling keys %$fred in a scalar context.
--
John Porter
------------------------------
Date: Fri, 24 Jul 1998 08:00:17 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: "While" Loops.. Possible Perl Bug ?
Message-Id: <1h0ap6.shl.ln@localhost>
Mark Simonetti (marks@webleicester.co.uk) wrote:
: I think I may have discovered a bug in perl involving the use of while
: loops and associative arrays.
: Basically, if I have a subroutine containing a while loop as such:
: sub thing {
: my $fred = @_;
: my ($cmd, $prm);
: while(($cmd, $prm) = each(%$fred)) {
: return(1) if($cmd eq 'pants');
: }
: }
: Ok, its just some code I made up on the spot, but it helps to illustrate
^^^^^^^^^^^^^^^^^^^
: the problem.. which is,
Did you execute it to verify that it displays the behavior you
are trying to fix?
And then cut and paste it into your article?
If you are going to invoke the "B" word, things must be exactly
right in order to chase it down.
Might be in your code (always the most likely), or it might
be in perl.
We have to go on the code you give us.
GIGO may rear its ugly head in the debugging process as well
as in the program's data.
Hi GIGO ;-)
If you do a
print "$fred\n"
before the while, you'll see that you also want to change a line to:
my($fred) = @_;
^ ^
^ ^
: Okay, bug time:
I see a bug in the code given.
And I already had to construct some
code to even try it out. It only takes a minute or two to make
a complete program that calls your sub. You could have done that.
Used up my "per article" time budget for this post already.
Gotta go to the next one.
Repost with complete code that really does show your problem...
----------------------------
#!/usr/bin/perl -w
%hash = ( one => One,
two => Two,
three => Three
);
if ( thing(\%hash) == 1 )
{print "returned 1\n"}
else
{print "returned not-1\n"}
##################
sub thing {
my($fred)= @_;
my ($cmd, $prm);
while(($cmd, $prm) = each(%$fred)) {
return(1) if($cmd eq 'pants');
}
}
----------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Jul 1998 15:05:33 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Posted Twice Weekly ***
Message-Id: <8cemvbnvbd.fsf@gadget.cscaper.com>
>>>>> "Terry" == Terry Cora <TerryLCora@worldnet.att.net> writes:
Terry> But I was supprised that the mini-FAQ only contained 1 book
Terry> reccomendation with a link to their commercial website -
Terry> O'Reilly press. There are many other books that may be of
Terry> interest to those who visit this newsgroup and not all are by
Terry> O'Reilly. I checked a little further and found out that Nathan
Terry> Torkington, Perl mini-FAQ maintainer is an author who's book,
Terry> "The Perl Cookbook" is being published by O'Reilly, available
Terry> August, '98 $39.95.
The FAQ maintainer is not the person who posted the Spamazon article.
Please do not confuse them.
I, too, have an "Amazon kickback" webpage, but I don't go posting it.
When someone tells me in private mail that they are thinking about
getting some of my books, I let them know they can get it through
amazon in a way that costs them nothing extra, but gives me a little
extra, if they choose to want to do that.
But I don't go spamming every time I see a book mentioned here.
There's something smelly about that.
print "Just another Perl book author,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Fri, 24 Jul 1998 15:22:46 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: [Perl for WIn32] -e Command line script?
Message-Id: <6pa911$t7t$1@strato.ultra.net>
[ posted and mailed ]
Jan Krynicky <JKRY3025@comenius.ms.mff.cuni.cz> wrote:
-> comand.com and cmd.exe understand only doublequotes!
-> Furthermore, you may not escape the dblquote anyhow.
-> Things like
-> c:\> perl -e "...\"...\"..."
-> will not work.
->
-> You wil need to write your code as:
->
-> c:\> perl -e "print qq{Hello world\n}"
Bull!
perl -e "print \"hello world\""
works fine on win32 toys.
Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-400-1972
Ext: 1949 and let the jerk that answers know
that his toll free number was sent as spam. "
------------------------------
Date: Fri, 24 Jul 1998 15:11:22 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Code showing apparent "Perl While Bug"
Message-Id: <35B8A5A6.37D5@min.net>
F.Quednau wrote:
>
> I suppose that there
> is some while internal counter that only becomes reset when the whole
> construct to go through with while has been passed.
> Some other internals seem to be working there.
Sure there is. It's documented under 'each'.
--
John Porter
------------------------------
Date: Fri, 24 Jul 1998 09:49:37 -0500
From: John Adams <John.Adams@BentonvilleAR.ncr.com>
Subject: Condensed followup and continued puzzlement Re: -e glob $filename returns true and false in identical cases
Message-Id: <35B89F01.3586@BentonvilleAR.ncr.com>
I'm still stumped. Here's a snippet of the code where the odd stuff was
happening:
if (-e glob "isp0001.inventory.????????????") { print "0001okay!\n"; }
if (-e glob "isp0002.inventory.????????????") { print "0002okay!\n"; }
foreach $key (sort keys %numzone) {
print "$key\t$numzone{$key}\n";
$storefile = "isp" . "$key" . ".inventory.????????????";
if (-e glob $storefile) {
print glob $storefile ;
print "\n";
print "Yassir! $key\n";
} else {
print "Nossir! $key\n";
}
}
There are files called isp0001.inventory.199807061643 and
isp0002.inventory.199807141011. I get a printout of:
0001okay!
0002okay!
But then get:
0001 648M00
isp0001.inventory.199807061643
Yassir! 0001
0002 123D56
Nossir! 0002
0003 322K30
Nossir! 0003
immediately thereafter. Now the strange part. When I did this:
touch isp0001.inventory.199899999999
I got this output:
0001okay!
0002okay!
0001 648M00
isp0001.inventory.199807061643isp0001.inventory.199999999999
Yassir! 0001
0002 123D56
isp0002.inventory.199807141011
Yassir! 0002
0003 322K30
Nossir! 0003
Now, that's weird! And when I did this:
touch isp0001.inventory.199899999998
I got this!:
0001okay!
0002okay!
0001 648M00
isp0001.inventory.199807061643isp0001.inventory.199999999998isp0001.inventory.199899999999
Yassir! 0001
0002 123D56
isp0002.inventory.199807141011
Yassir! 0002
0003 322K30
<----Note the blank line in the
output!
Yassir! 0003
Now, why would the number of files found to exist in the conditional be
equal to the number of consecutive times through the outer loop that the
conditional would be found true? I've tried N(files matching isp0001*)=4
and gotten consistent (that is to say, equally weird) results.
I'm really bamfoozled on this! I've tried replacing:
if (-e glob $filename) {
with
$filenames = glob $filename;
if (-e glob $filename) {
but the behavior is the same. I'm really out of ideas and ready to work
around it, but I just! don't! understand! this! WEIRD! BEHAVIOR!
> John A
> ...speaking only for himself, not his employer...
> ...but speaking preetty loudly anyhoo, I'd say...
------------------------------
Date: Fri, 24 Jul 1998 11:37:59 +0200
From: Leon Schmetz
Subject: Crazy Math
Message-Id: <35b8537d.2320890@news.origin-it.com>
# I am trying to find out wether one or more bits are set in a given
# value. Below is my testscript. Can you explain why Perl does
# not find values equal????
print sprintf "\nvalue1 is % 11d \(%08x\)", (-1609432919),
(-1609432919);
print sprintf "\nvalue2 is % 11d \(%08x\)", (-2147483648),
(-2147483648);
print sprintf "\n\nResult by OR is %08x\n\n",((-1609432919) |
(-2147483648));
print "Result should equal value1\n";
if (((-1609432919) | (-2147483648)) == (-1609432919))
{
print "\n Matched value";
}
else
{
print "\n If statement does not find this equal";
}
print sprintf "\n\nResult by AND is %08x\n\n",((-1609432919) &
(-2147483648));
print "Result should equal value2\n";
if (((-1609432919) & (-2147483648)) == (-2147483648))
{
print "\n Matched value";
}
else
{
print "\n If statement does not find this equal also";
}
------------------------------
Date: Fri, 24 Jul 1998 10:58:59 -0400
From: Richard Kim <rkim@temple.edu>
Subject: Date Question...
Message-Id: <Pine.OSF.3.91.980724105246.16340A-100000@thunder.ocis.temple.edu>
Hello all,
My problem may be easy for some, but I am having difficulty finding the
answer. I am interested in getting yesterday's date using the localtime
function. Any other method would be nice, but I am not interested in
writing a long drawn out program just to extract yesterday's date.
When I use :
print scalar localtime,
"\n";
I get this response:
Fri Jul 24 10:52:24 1998
I am interested in getting something like this:
Thu Jul 23 10:52:24 1998
Thanks for your help.
Rich
[5;1m rkim@temple.edu [0m
------------------------------
Date: Fri, 24 Jul 1998 08:25:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Date Question...
Message-Id: <MPG.102247421191ea47989784@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <Pine.OSF.3.91.980724105246.16340A-
100000@thunder.ocis.temple.edu> on Fri, 24 Jul 1998 10:58:59 -0400,
Richard Kim <rkim@temple.edu> says...
> Hello all,
> My problem may be easy for some, but I am having difficulty finding the
> answer. I am interested in getting yesterday's date using the localtime
> function. Any other method would be nice, but I am not interested in
> writing a long drawn out program just to extract yesterday's date.
...
print scalar localtime(time - 24 * 60 * 60); # aka 86400 :-)
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Jul 1998 15:42:58 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: Date Question...
Message-Id: <6paa22$ffb$2@news.iastate.edu>
Richard Kim (rkim@temple.edu) wrote:
: Hello all,
: My problem may be easy for some, but I am having difficulty finding the
: answer. I am interested in getting yesterday's date using the localtime
: function. Any other method would be nice, but I am not interested in
: writing a long drawn out program just to extract yesterday's date.
: When I use :
: print scalar localtime,
: "\n";
: I get this response:
: Fri Jul 24 10:52:24 1998
: I am interested in getting something like this:
: Thu Jul 23 10:52:24 1998
/home/kortbein% perldoc -f localtime
=item localtime EXPR
Converts a time as returned by the time function to a 9-element array
with the time analyzed for the local time zone. Typically used as
follows:
# 0 1 2 3 4 5 6 7 8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
All array elements are numeric, and come straight out of a struct tm.
In particular this means that $mon has the range 0..11 and $wday has
the range 0..6 with sunday as day 0. Also, $year is the number of
years since 1900, that is, $year is 123 in year 2023.
If EXPR is omitted, uses the current time (C<localtime(time)>).
In a scalar context, returns the ctime(3) value:
$now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
This scalar value is B<not> locale dependent, see L<perllocale>,
but instead a Perl builtin.
Also see the Time::Local module, and the strftime(3) and mktime(3)
function available via the POSIX module.
... so the idea is to grab the array and then subtract one from the day.
Josh
--
__________________________________________
She had heard all about excluded middles;
they were bad shit, to be avoided.
- Thomas Pynchon
------------------------------
Date: Fri, 24 Jul 1998 13:59:55 GMT
From: dwiesel@my-dejanews.com
Subject: Re: extracting price from string (again)
Message-Id: <6pa40r$ogd$1@nnrp1.dejanews.com>
Actually... there is more to tell :)
The line is actually a part of a whole webpage...
--snip--
<INPUT TYPE="hidden" NAME="add_|1562763687|Fraize, P. etc.|'PC Magazine'
Programming Java Applets|Paperback||829.00|V" VALUE="1">
--snip--
// Daniel
In article <35b85ec8.0@nnrp1.news.uk.psi.net>,
"Simon Fairey" <simonf@conduit.co.uk> wrote:
> Heheheh *sigh*
>
> Ok I make one suggestion and one assumption :-)
>
> Assumption: This is the complete line containing essentially 6 fields.
>
> Suggestion: Split the line and extract the required field as follows:
>
> $price = (split /\|+/, $string )[4];
>
> Are we getting there...or is there more to tell ;-)
>
> Have Fun
>
> Simon
> dwiesel@my-dejanews.com wrote in message
> <6p9jpe$25b$1@nnrp1.dejanews.com>...
> >Hi again,
> >
> >Thank you for all you answers. I've tried a lot of things that you
> suggested
> >but... it still does not work. The problem is that when I asked you the
> first
> >time I didn't think it was necessary to tell you the whole $string. But now
> I
> >realise that it is.
> >
> >The string could either look like this
> >
> >$string = "add_|9163604728|author_name|book_tile||400.00|V";
> >
> >or like this
> >
> >$string = "add_|9163604728|author_name|book_tile|||400.00|V";
> >
> >I want $1 to be '400.00' or '400' (it doesn't matter)
> >
> >This is what I've tried
> >
> >$string =~ /\|{2,3}(.+?)\|V/;
> >$string =~ /\|\|+(\d{3,4}).00\|V/; # Always ends with '.00'
> >
> >but it doesn't work.
> >
> >// Daniel
> >
> >> I have a small problem. I have a string could look either like this
> >>
> >> $string = 'product||500.00||';
> >>
> >> or like this
> >>
> >> $string = 'product|||500.00||';
> >>
> >> I want to extract the price from $string. I have done it like this...
> >
> >-----== Posted via Deja News, The Leader in Internet Discussion ==-----
> >http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
>
>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Fri, 24 Jul 1998 10:11:27 -0400
From: Michael Maraist <maraism@sterlingdi.com>
Subject: Re: extracting price from string
Message-Id: <35B8960F.D892239E@sterlingdi.com>
> > I have a small problem. I have a string could look either like this
> >
> > $string = 'product||500.00||';
> >
> > or like this
> >
> > $string = 'product|||500.00||';
> >
> > I want to extract the price from $string. I have done it like this...
> >
> > $string =~ /\|\|(.*?)\|\|/;
> >
> > but then $1 eq '|500.00'.
> >
> > Can you help me?
>
> $string =~ /\|*([\d\.]*?)\|*/;
> ^^^^^^ looks only for dezimals and dot.
> see man perlre.
Contains a possible trap.. Due to all fields being optional, this will
never fail.
If you _only_ ever want numbers between |'s, then the following should
work, as well as be more efficient:
$string =~ /\|+ ( [\d\.] + ) \| /x;
This method will invoke little back-tracking on a success, as would *?.
If the format you specified is required for the number to be valid, then
the following should work.
$string =~ / product \|\|\|? ( [\d\.] + ) \|\| /x;
\|{2,3} could have worked, but it's slower.
------------------------------
Date: 24 Jul 1998 15:31:35 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: Help! To capture errors...
Message-Id: <6pa9cn$ffb$1@news.iastate.edu>
Robert Sadler (bsadler@worldbank.org) wrote:
: $Stat = open(MAIL, "|$MailCmd -- \"-s$Subject\" \"\@$ToList\"");
Might be helpful to try
$Stat = open(MAIL, "|$MailCmd -- \"-s$Subject\" \"\@$ToList\"") or
die "open pipe to mail failed: $!\n";
Josh
--
__________________________________________
She had heard all about excluded middles;
they were bad shit, to be avoided.
- Thomas Pynchon
------------------------------
Date: Fri, 24 Jul 1998 07:08:23 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: htpasswd
Message-Id: <MPG.10223535eecca7a398977f@nntp.hpl.hp.com>
In article <35b82e13.23219300@news2.cais.com> on Fri, 24 Jul 1998
06:57:29 GMT, root.noharvest.\@not_even\here.com (-)
<root.noharvest.\@not_even\here.com (-)> says...
...
> $salt = $passwd_pw;
> $salt =~ /\w\w/;
> $crypt_password = crypt($password, $salt);
Fascinating. This code is equivalent (except for speed) to
$crypt_password = crypt($password, $passwd_pw);
It works because that is all you need in the first place. The crypt
function uses the first two characters only of its second argument, as
has been discussed here aplenty.
`perldoc -f crypt` on my 5.004_03 perl shows
$salt = substr($pwd, 0, 2);
which is what you were trying to do, but this is (quoting Randal
Schwartz, I believe) a waste of CPU cycles. I hope this documentation
overkill has been fixed in 5.005.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 24 Jul 1998 15:01:03 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: newbie Q: self-calling script?
Message-Id: <8ciuknnviv.fsf@gadget.cscaper.com>
>>>>> "Joe" == Joe Halbrook <joe@halbrook.com> writes:
Joe> Can anyone point mein the right direction?
Joe> I have a mulit-purpose script that I'd like to perform a do
Joe> 'same-script' or use the 'eval' function to pass a different ACTION
Joe> parm to itself and follow a different execution path. Is this possible?
As we support people say to ourselves from time to time:
"Do you suppose you could be a little more vague please?
I'm actually thinking I understand you."
In jest, of course. But seriously, your question is SO vague, I can
only guess that it might be possible. But then again, it might not.
Depends.
You'll get a better answer if you ask a more specific question.
print "Just another Perl hacker,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Fri, 24 Jul 1998 15:46:02 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: newbie Q: self-calling script?
Message-Id: <35b8ab9c.29195658@news.tornado.be>
Joe Halbrook wrote:
>I have a mulit-purpose script that I'd like to perform a do
>'same-script' or use the 'eval' function to pass a different ACTION
>parm to itself and follow a different execution path. Is this possible?
I guess you could just put the bulk of the script code in a sub. You can
call that sub once, with the main parameters, as the main body of the
script. You can call it again, recursively, from within that sub. I
guess this would allow you to do whatever variation you'd want.
HTH,
Bart.
------------------------------
Date: Fri, 24 Jul 1998 15:36:52 GMT
From: Reini Urban <rurban@sbox.tu-graz.ac.at>
Subject: Re: OT? Fly GIF's
Message-Id: <35b8a997.22252427@judy>
Jesse Rosenberger <jesse@savalas.com> wrote:
>I am in the process of writing a Perl script that will use 'Fly' to take text from a
>form (I already know how to do that part), and place it on an image at a
>certain spot, at a certain size, and in a certain color.
<blabla>
>How can I do it? If you don't know...can you please refer me to another newsgroup,
>or someone that would know?
fly/examples/cgi-perl-example.pl should be enough
works perfectly on unix and win32 for me.
fly always needs dummy files.
---
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg."
-- Bjarne Stroustrup on C++
------------------------------
Date: Fri, 24 Jul 1998 14:18:59 GMT
From: John Porter <jdporter@min.net>
Subject: Re: parsing question
Message-Id: <35B8995F.39F3@min.net>
Uri Guttman wrote:
>
> >> open INF, "< $filename" or die "open $filename: $!";
>
> < is unnecessary as files open for reading by default. and it is safer
> to call open as a function so precedence problems don't crop up
>
> open( INF, $filename) || die "open $filename: $!";
I completely disagree.
The current thinking among the gurus (not including myself among them,
although I agree with them) is that the low-precedence 'or' is to be
used for flow control, the high(er)-precedence '||' is to be used for
logical conjunction. This is a case of the former, and therefore
the parens are unnecessary. You can still use them if you prefer.
In any case, open is a built-in function; it does not magically lose
its function nature by leaving off the parens.
WRT the "< $filename", it provides better readability, especially in
cases where you have something like:
open INF, "< $inf" or ...
open OUT, "> $out" or ...
I'm surpised that you, of all people, would argue against this
convention.
> >> chomp;
>
> why do yo chomp when you just match later on. a waste of cpu time.
Why, you ask? Because you don't just match later on. Every line of
the input (except for blank lines) gets stored in a variable for
later processing. I think it's reasonable to expect that the
newlines will not be wanted at that time, so get rid of them now.
> >> if ( /^[MTWFS]/ ) {
> >> $firstline = $_;
>
> since you are using a var, bind it directly to the regex.
>
> if ( $firstline =~ /^[MTWFS]/ ) {
That completely changes the semantics -- to be incorrect!
You only want to assign $_ to $firstline IFF the match succeeds.
> elsif ( $firstline =~ /=/ ) {
...wrong again, for the same reason.
> i like to use range expressions to parse files like this.
>...
Cool!
--
John Porter
------------------------------
Date: Fri, 24 Jul 1998 14:26:22 GMT
From: John Porter <jdporter@min.net>
Subject: Re: parsing question
Message-Id: <35B89B07.213D@min.net>
Martin wrote:
>
> >2. unless you have some specific need to store the entire
> > input file in memory at once, it's better to while()
> > over it instead of foreach(). You'll notice the
> > difference as the files get larger.
>
> The question asked about reading the entire record into a
> string. So I read it all into the array.
Each entire *record*, not the entire *file*!
> >5. superfluous quoting:
> >> $firstline = "$indata";
>
> I always do that in case indata contains a semicolon.
It's still superfluous. Where did you get this strange notion?
Just do a few tests for yourself, if you don't believe me.
> They asked to have it read into an array though.
So put it in an array. I elided over the part where each
complete record gets processed, whether put into an array
or whatever. "Left as an excercise..." you know.
> >6. But you don't cleanly handle the case where the last line
> > of input is the last "name = value" line of the last
> > record.
>
> Is it?
I didn't say it *is*, I said you didn't handle that case.
If the supplier of the input data can assure us that that case
never occurs, then your code is safe (that aspect of it,
anyway).
> Oops, they should repeat the else routine once at the
> end of the foreach loop.
Yes, if by "at the end" you mean "after the end".
And even then, only if the appropriate test indicates that
there is an unprocessed record.
> >7. One should just use $/ for this kind of thing.
>
> Obviously ?!?!?!? LOL!
Hmm. Sorry. "It's obvious, if you already know about it."
--
John Porter
------------------------------
Date: Fri, 24 Jul 1998 15:46:03 +0100
From: "Martin" <minich@globalnet.co.uk>
Subject: Re: parsing question
Message-Id: <6pa6oc$j6$1@heliodor.xara.net>
>> The question asked about reading the entire record into a
>> string. So I read it all into the array.
>
>Each entire *record*, not the entire *file*!
Oops, my mistake <g>. Sorry!
>It's still superfluous. Where did you get this strange notion?
>Just do a few tests for yourself, if you don't believe me.
It's not just semicolons but if the data were all numerals then
if ($data eq $para) would turn out false wouldn't it because
I'd need to use if($data == $para).
>> >6. But you don't cleanly handle the case where the last line
>> > of input is the last "name = value" line of the last
>> > record.
>>
>> Is it?
>
>Yes, if by "at the end" you mean "after the end".
>And even then, only if the appropriate test indicates that
>there is an unprocessed record.
Then you could store the previous unique identifier (I can't remember
if there was one anyway now <g>) and compare at the end. If
it isn't the same at the end then you could process the result. But,
if I had not used inverted commas then then eq may need to be
== and the last data record would not have been processed - see
a previous gripe :-)
>> >7. One should just use $/ for this kind of thing.
>>
>> Obviously ?!?!?!? LOL!
>
>Hmm. Sorry. "It's obvious, if you already know about it."
LOL! Like most things.
Martin
------------------------------
Date: Fri, 24 Jul 1998 15:31:12 GMT
From: Reini Urban <rurban@sbox.tu-graz.ac.at>
Subject: perl 5.004_04 - cygwin32: make problems
Message-Id: <35b8a68e.21475099@judy>
make with cygnus b19 fails with perl 5.004_04
I followed "README.cygwin32" and it compiles until
Anone got it beyond?
the MSVC make ran perfectly.
The reason why I want to use cygwin is the perl compiler a3 which
doesn't compile with msvc.
Cygnus Cygwin32 B19
bash-2.01$ make
<blabla...>
ar rcu libperl.a perl.o malloc.o gv.o toke.o perly.o op.o regcomp.o
dump.o util.
o mg.o hv.o av.o run.o pp_hot.o sv.o pp.o scope.o pp_ctl.o pp_sys.o
doop.o doio.
o regexec.o taint.o deb.o universal.o globals.o perlio.o
gcc2 -o miniperl miniperlmain.o libperl.a -lcygwin -lm -lc -lkernel32
libperl.a(pp_sys.o)(.text+0x6e8d):pp_sys.c: undefined reference to
`getnetbyname'
libperl.a(pp_sys.o)(.text+0x6f0f):pp_sys.c: undefined reference to
`getnetbyaddr'
..
and so on.
looks like a failure on the net lib.
any hints?
config.sh:
libs='-lcygwin -lm -lc -lkernel32'
libswanted='sfio net socket inet nsl nm ndbm gdbm dbm db malloc dl dld
ld sun m c cposix posix ndir dir crypt ucb bsd BSD PW x'
---
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg."
-- Bjarne Stroustrup on C++
------------------------------
Date: Fri, 24 Jul 1998 14:45:25 GMT
From: John Porter <jdporter@min.net>
Subject: Re: perl as pseudocode
Message-Id: <35B89F91.416A@min.net>
Adam Atkinson wrote:
>
Suggestion #1: use English;
Suggestion #2: use ' ' in that split, instead of / /;
it's probably better anyway (handles any amount of any
kind of whitespace), and it avoids the use of a regex,
which might be problematic for your audience.
So
split(/ /, $_)
becomes
split( ' ', $ARG );
> for ($i=0;$i<$symbols;$i++) {
> $j=$up[$i];
> $k=$i;
> while ($j!=undef) {
> if ($k==$left[$j]) {
> $string[$i]="0".$string[$i];
> } else {
> $string[$i]="1".$string[$i];
> }
> $k=$j;
> $j=$up[$k];
> }
> }
Human-readability was a high priority for you, and this is what
you produced? Geez. Might this be better?:
for ( $i = 0; $i < $symbols; $i++ ) {
$j = $up[ $i ];
$k = $i;
while ( $j != undef ) {
if ( $k == $left[ $j ] ) {
$string[ $i ] = "0" . $string[ $i ];
}
else {
$string[ $i ] = "1" . $string[ $i ];
}
$k = $j;
$j = $up[ $k ];
}
}
Also, why not use the built-in "defined" operator?
while ( defined $j ) {
I also wonder if the range operator might not be more readable too:
for $i ( 0 .. $symbols-1 ) {
And so on, and so on.
--
John Porter
------------------------------
Date: Fri, 24 Jul 1998 07:47:34 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl Beautifier Home Page
Message-Id: <MPG.10223e5d9eca7333989782@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <6pa3s9$320$1@xmission.xmission.com> on 24 Jul 1998 07:57:29 -
0600, Snowhare <snowhare@xmission.xmission.com> says...
...
> The subtle failure is that it
> doesn't account for 'leap seconds' - this means that (at least in theory
> and only if your OS is smart enough to include documented leap seconds) it
> will 'slip' everytime it crosses a leap second boundary. Depending on the
> location of the recurrance, this can ripple up through the date until it
> does something like generate '199712312359' when it should have generated
> '199801010000'.
...
> As you can see, the slippage is nearly 1/2 minute from 1972 to 1997. Leap
> seconds aren't a problem in the original code because it doesn't depend on
> the absolute interval. :)
As was fully discussed recently (see DejaNews), this is totally
irrelevant to Epoch time. Despite the frivolous documentation in
ctime(3C), there are no minutes with 61 (or 62!) seconds in this time
scale. Every day is 86400 seconds, and every midnight is divisible by
86400. This is a Good Thing.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3244
**************************************