[18865] in Perl-Users-Digest
Perl-Users Digest, Issue: 1033 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 1 00:06:03 2001
Date: Thu, 31 May 2001 21:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <991368315-v10-i1033@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 31 May 2001 Volume: 10 Number: 1033
Today's topics:
ANNOUNCE: YAPC Lightning Talks submission deadline exte <mjd@plover.com>
Re: Appending to a Text file <wyzelli@yahoo.com>
Re: Fcntl usage? (Martien Verbruggen)
Re: Frustrated people (not) answering questions <godzilla@stomp.stomp.tokyo>
Re: Frustrated people (not) answering questions <mitia.nospam@northwestern.edu.invalid>
How to walk dir structures (Fred Zimmerman)
Re: How to walk dir structures (Tad McClellan)
Re: IPC:Shareable vs mod_perl ipcs not dying <djberg96@hotmail.com>
Re: Net::SMTP -- why must I specify recipient twice? (Eric Bohlman)
Re: parsing perl again (Damian Conway)
Perl Hotmail (Create232)
Re: Perl Hotmail (Damian James)
Re: Perl Hotmail <buggs@geekmail.de>
Posting Etiquette <"relaxedrob@optushome.com.au">
Re: Posting Etiquette (Tad McClellan)
Re: Posting Etiquette <"relaxedrob@optushome.com.au">
Re: Posting Etiquette <uri@sysarch.com>
Re: Posting Etiquette <"relaxedrob@optushome.com.au">
Problem with matching with variable regular expression <res@usaveak.com>
Re: Problem with matching with variable regular express (Tad McClellan)
Re: Problem with matching with variable regular express (Damian James)
Re: Problem with matching with variable regular express <joe+usenet@sunstarsys.com>
Re: Problems with incrementing decimal numbers, bug wit (Eric Bohlman)
Re: Problems with incrementing decimal numbers, bug wit (E.Chang)
Re: Problems with incrementing decimal numbers, bug wit (Tad McClellan)
Re: Reading binary data (method and style)? <mitia.nospam@northwestern.edu.invalid>
test <jliebgot@eni.net>
Re: test <godzilla@stomp.stomp.tokyo>
Re: tie() losing values <jboes@qtm.net>
Re: Upgrade from Activeperl 620 to 626 on a Microsoft b <bowman@montana.com>
Using Perl to keep track on internet usage? <spis@worldnet.att.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 31 May 2001 23:44:40 -0400
From: Mark-Jason Dominus <mjd@plover.com>
Subject: ANNOUNCE: YAPC Lightning Talks submission deadline extended
Message-Id: <20010601034441.13260.qmail@plover.com>
There were only 19 submissions, and we have time for 16 talks. So I'm
extending the submission deadline by 24 hours to allow some
last-minute proposals. A lightning talk is only five minutes long, so
it shouldn't take long to come up with a proposal.
Proposals should include an explanation of the talk (no more than four
sentences, please) and a title. Please send them to
mjd-yapc-lightning+@plover.com
The deadline is 2 June 2001 at 04:00 UTC.
For complete information, please visit:
http://perl.plover.com/lightning-talks.html (English)
http://perl.plover.com/lightning-talks.fr.html (Francais)
I am especially interested in receiving proposals from first-time speakers.
------------------------------
Date: Fri, 1 Jun 2001 10:57:20 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Appending to a Text file
Message-Id: <t9CR6.10$7g4.5214@vic.nntp.telstra.net>
"Henry Hartley" <hartleh1@westat.com> wrote in message
news:3B169B1B.C44C1589@westat.com...
> "<< SilverSting >>" wrote:
> >
> > Can anyone tell me how to append text to a file.
> >
> > My open file code:
> > open(CLIENTINFO,">client.txt");
>
> first, you want to be sure the file was opened:
>
> open(CLIENTINFO,">client.txt") || die "Could not open client.txt: $!\n\n"
;
That will create a file, or overwrite one if it exists, NOT append to it.
BTW Why two \n at the end?
You need to open the file in append mode, which is >>
Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;
------------------------------
Date: Fri, 01 Jun 2001 01:55:53 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Fcntl usage?
Message-Id: <slrn9hdth9.epd.mgjv@verbruggen.comdyn.com.au>
On Thu, 31 May 2001 12:24:47 +0100,
Mark Grimshaw <m.grimshaw@salford.ac.uk> wrote:
>
>
> Bart Lateur wrote:
>>
>> And print out their values. They all should produce numbers. My guess is
>> that at least one is a string, while it should be a zero. That's how it
>> can still work.
>
> print "\nRDONLY ", O_RDONLY, "\n";
> print "\nCREAT ", O_CREAT, "\n";
> print "\nWRONLY ", O_WRONLY, "\n";
> print "\nRDRW ", O_RDWR, "\n";
> print "\nRDWR-CREAT ", O_RDWR|O_CREAT, "\n\n";
>
> produces:
>
> RDONLY 0
>
> CREAT 256
>
> WRONLY 1
>
> RDRW 2
>
> RDWR-CREAT 258
That looks approximately right.
> I could have (and have in the past) used just the numbers but would like
> to use the constants for portability. I've read somewhere that O_RDONLY
> cannot be guaranteed to be 0 on all systems.
None of the constants are guaranteed to have specific values, IIRC. On
my system:
$ perl -MFcntl -Mstrict -w
print "RDONLY ", O_RDONLY, "\n";
print "CREAT ", O_CREAT, "\n";
print "WRONLY ", O_WRONLY, "\n";
print "RDRW ", O_RDWR, "\n";
print "RDWR-CREAT ", O_RDWR|O_CREAT, "\n";
__END__
RDONLY 0
CREAT 64
WRONLY 1
RDRW 2
RDWR-CREAT 66
As you can see, neither -w or strict have any problems with this. I'm
still wondering what your original problem is, if it isn't that the
constants aren't defined...
Could you submit some code that, for you, gives warnings, and/or
errors?
Martien
--
Martien Verbruggen |
Interactive Media Division | I took an IQ test and the results
Commercial Dynamics Pty. Ltd. | were negative.
NSW, Australia |
------------------------------
Date: Thu, 31 May 2001 18:21:38 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Frustrated people (not) answering questions
Message-Id: <3B16EE22.D24C0DEB@stomp.stomp.tokyo>
brian d foy wrote:
> Truly not important wrote:
> > brian d foy wrote:
> > > Michael D. Risser wrote:
(snipped)
> > But don't stupid (ie degrading posts) also get archived. Your point applies
> > to useless posts period. Which includes degrading posts, yes?
> degrading posts are just that. they don't pretend to be an authority
> or give an answer. whether or not they are archived makes no intrinsic
> difference to the life of bad answers. they do however, as a side
> effect, make some people consider whether or not they should post.
> that is a good thing.
> but nobody is going to confuse degrading posts with the right way
> to solve their problem. they are easily ignored. bad answers are
> not easily ignored because the new Perl user cannot distinguish
> between good and bad advice. they can easily tell when they are
> being degraded, apparently.
You are saying, paraphrased,
"Degrading posts are of no value. However, if you don't
like what a person posts, respond with degrading remarks
in an attempt to force this person to stop posting."
Goodness, such a perfect reflection of the average
mentality and social approach of participants here.
Your approach to socialization is quite novel. You are
quite the lady charmer, I am sure.
Godzilla! Queen of Snake Charmers.
------------------------------
Date: Thu, 31 May 2001 20:42:08 -0500
From: Dmitry Epstein <mitia.nospam@northwestern.edu.invalid>
Subject: Re: Frustrated people (not) answering questions
Message-Id: <3B16F2F0.44CB4BAC@northwestern.edu.invalid>
brian d foy wrote:
> unanswered posts often become answered when a less-than-proficient
> poster guesses at an answer. this answer is archived on various
> usenet search engines for everyone to see later. bad answers live
> forever and cause more confusion and the cycle continues.
Your point is more relevant to answers than to questions. I am not a
Perl expert, but I am more proficient in some other fields. My personal
policy on other forums is that I may not reply to a trivial or "stupid"
question (leaving it to lower ranking members), but if I see an
erroneous answer, I will post a correction.
------------------------------
Date: Fri, 01 Jun 2001 02:21:16 GMT
From: fredz@silversoftware.com (Fred Zimmerman)
Subject: How to walk dir structures
Message-Id: <3b16b543.187516133@news.ne.mediaone.net>
How can I use Perl to walk directories recursively
and query files for date/timestamp for copying to
a target directories.
Sample code appreciated.
silversw@hotmail.com
------------------------------
Date: Thu, 31 May 2001 21:46:36 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to walk dir structures
Message-Id: <slrn9hdsvs.7io.tadmc@tadmc26.august.net>
Fred Zimmerman <fredz@silversoftware.com> wrote:
>How can I use Perl to walk directories recursively
use File::Find;
To see how to use the module:
perldoc File::Find;
>and query files for date/timestamp for
perldoc -f -M
perldoc -f stat
>copying to
>a target directories.
>
>Sample code appreciated.
Your spec does not allow coding. What does the timestamp have to
do with copying?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 01 Jun 2001 03:16:40 GMT
From: "Daniel Berger" <djberg96@hotmail.com>
Subject: Re: IPC:Shareable vs mod_perl ipcs not dying
Message-Id: <sODR6.39270$V6.2039614@typhoon.mn.mediaone.net>
"Konstantinos Agouros" <elwood@news.agouros.de> wrote in message
news:elwood.991164106@news.agouros.de...
> Hi,
>
> I created a small server that shares an array via IPC::Shareable. There
are
> two CGI-Scripts called with the mod_perl-Handler from apache that use this
> array. One of these erases elements from the shared array with something
> like
> @SHARED_ARRAY = grep ($_ != $element_to_destroy), @SHARED_ARRAY. This is
> enclosed by a shlock/shunlock.
> The whole stuff is working (meaning after the cgi the element is missing),
> but I see a growing number of shared memory segments and semaphores (I
take
> it the tie allocates on of each).
> At the end of the script I do an untie but I am not really sure that is
enough.
> Anybody has an opinion since ipcrm'ing gets a little annoying.
>
> Konstantin
> --
> Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
> Otkerstr. 28, 81547 Muenchen, Germany. Tel +49 89 69370185
> --------------------------------------------------------------------------
--
> "Captain, this ship will not sustain the forming of the cosmos." B'Elana
Torres
Sorry if this is a re-post. Doesn't look like my first post showed up.
Anyway, at the end of your program (probably within an END block), do
IPC::Shareable->clean_up().
For already existing memory segments and semaphores, ipcrm doesn't seem to
like wildcards. I wrote a little perl script that gets rid of all them if
you're interested.
Dan
------------------------------
Date: 1 Jun 2001 01:45:03 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Net::SMTP -- why must I specify recipient twice?
Message-Id: <9f6s2v$e7i$1@bob.news.rcn.net>
pt <mnemotronic@yahoo.com> wrote:
> The example for Net::SMTP show the recipient being specified twice:
> $smtp->mail($ENV{USER});
> $smtp->to('postmaster');
> $smtp->data();
> $smtp->datasend("To: postmaster\n");
> [snip]
> I'm guessing the 'to' method does the SMTP "RCPT TO:", while the
> 'datasend' does the SMTP "To" header. Are both necessary? Does this
> have something to do with "forward path" and "relaying" per RFC 821
> (which I obviously haven't memorized).
No, it has to do with the fact that an e-mail message, just like a postal
letter, includes the recipient's address both on the envelope (which is
all that SMTP really concerns itself with) and on the letter inside.
------------------------------
Date: 1 Jun 2001 02:55:32 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: parsing perl again
Message-Id: <9f7074$q38$1@towncrier.cc.monash.edu.au>
jdimov@cis.clarion.edu (Jordan Dimov) writes:
>How do I use it to extract a list of arguments passed to a function? The
>assumption is that the code is nice and clean (passed through Deparse,-p for
>example). How do I get from here:
'Twere me doing it, I'd write an extract_subcall() subroutine along the
lines of the other extract_whatevers in Text::Balanced. That sub would
first match an identifier, then a left paren, then use a call to
extract_multiple() to extract strings, variables, other sub calls
(i.e. recursively using extract_subcall()!), expressions, and commas. Then
match a closing paren, throw away the commas, and Bob's your
non-gender-specific-parental-sibling!
And once you've done it, send it to me and I'll add it to Text::Balanced ;-)
Damian
------------------------------
Date: 01 Jun 2001 03:47:20 GMT
From: create232@aol.com (Create232)
Subject: Perl Hotmail
Message-Id: <20010531234720.21770.00002224@ng-fs1.aol.com>
I was looking around for a CGI script that would run a hotmail script.
Everyone of them are REALLY expensive. I found one that wasn't priced too
much, but was wondering if anyone here had used it? Does it really work? It
works on their site, but I would like to know if anyone else here uses it?
The site was www.worldwidecreations.com and the script was called the
messenger.
Any help would be appreciated :)
------------------------------
Date: 1 Jun 2001 03:57:18 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Perl Hotmail
Message-Id: <slrn9he4l1.lli.damian@puma.qimr.edu.au>
Create232 chose 01 Jun 2001 03:47:20 GMT to say this:
>I was looking around for a CGI script that would run a hotmail script.
>
I am guessing here, but you are referring to a CGI program that acts as a
web-based email client, yeah?
>Everyone of them are REALLY expensive.
I guess you are :-).
You might be interested to have a look at:
http://neomail.sourceforge.net/
HTH
Cheers,
Damian
--
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...
------------------------------
Date: Fri, 1 Jun 2001 05:59:03 +0200
From: buggs <buggs@geekmail.de>
Subject: Re: Perl Hotmail
Message-Id: <9f73q8$nij$00$1@news.t-online.com>
Create232 wrote:
> Any help would be appreciated :)
wrong group ;-)
Buggs
------------------------------
Date: Fri, 01 Jun 2001 03:05:47 GMT
From: "Rob" <"relaxedrob@optushome.com.au">
Subject: Posting Etiquette
Message-Id: <fEDR6.5464$25.19786@news1.eburwd1.vic.optushome.com.au>
Tad,
> Unless the reply is posted to some other newsgroup, the reply belongs
> following the (trimmed) original text. This is a much more well-accepted
> quoting style here, and precludes those who insist on doing otherwise
> from becoming killfile entries, as you have.
Please do not threaten me. I try and help others when I can and hope to get the
same in return.
If my style is not acceptable to you, do not reply to my posts.
> The point is not which is "better". The point is, if you post
> Jeopardy style here, your articles will be widely ignored by
> the very people likely to be able to answer your Perl questions.
The point is to make a post that is easy to understand.
To date I have used a style that is different to the one you are used to. To
date I have not had trouble making my point understandable using the style I am
used to.
>
> When in Rome do as the Romans do.
>
Yes, good point: but there is always more than one way to achieve a goal and you
will always make more friends by *being nice* about it.
Rob
------------------------------
Date: Thu, 31 May 2001 22:23:22 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Posting Etiquette
Message-Id: <slrn9hdv4q.7n1.tadmc@tadmc26.august.net>
Rob <> wrote:
>Tad,
>
>> Unless the reply is posted to some other newsgroup, the reply belongs
>> following the (trimmed) original text. This is a much more well-accepted
>> quoting style here, and precludes those who insist on doing otherwise
>> from becoming killfile entries, as you have.
>
>Please do not threaten me.
I did not threaten you.
What is threatening in the above?
Do you know what "killfile" means?
>If my style is not acceptable to you, do not reply to my posts.
I (and I expect, many others) will not be seeing any of your posts.
That is what "killfile" means.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 01 Jun 2001 03:32:02 GMT
From: "Rob" <"relaxedrob@optushome.com.au">
Subject: Re: Posting Etiquette
Message-Id: <S0ER6.5468$25.19644@news1.eburwd1.vic.optushome.com.au>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9hdv4q.7n1.tadmc@tadmc26.august.net...
> Rob <> wrote:
> >Tad,
> >
> >> Unless the reply is posted to some other newsgroup, the reply belongs
> >> following the (trimmed) original text. This is a much more well-accepted
> >> quoting style here, and precludes those who insist on doing otherwise
> >> from becoming killfile entries, as you have.
> >
> >Please do not threaten me.
>
>
> I did not threaten you.
>
> What is threatening in the above?
>
> Do you know what "killfile" means?
>
>
> >If my style is not acceptable to you, do not reply to my posts.
>
>
> I (and I expect, many others) will not be seeing any of your posts.
>
> That is what "killfile" means.
>
That is what 'threat' means.
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Fri, 01 Jun 2001 03:41:45 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Posting Etiquette
Message-Id: <x7n17szx1n.fsf@home.sysarch.com>
>>>>> "R" == Rob <"relaxedrob@optushome.com.au"> writes:
>> I (and I expect, many others) will not be seeing any of your posts.
>>
>> That is what "killfile" means.
>>
R> That is what 'threat' means.
poor you. you have no clue. killfiling will not directly affect you so
there is no threat. it just means you will not get help from most of the
people here. killfiling is an individual thing but obvious entries are
created all the time and you just made one for many
regulars. congratulations.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Fri, 01 Jun 2001 03:46:37 GMT
From: "Rob" <"relaxedrob@optushome.com.au">
Subject: Re: Posting Etiquette
Message-Id: <xeER6.5469$25.19603@news1.eburwd1.vic.optushome.com.au>
"Uri Guttman" <uri@sysarch.com> wrote in message
news:x7n17szx1n.fsf@home.sysarch.com...
> >>>>> "R" == Rob <"relaxedrob@optushome.com.au"> writes:
>
> >> I (and I expect, many others) will not be seeing any of your posts.
> >>
> >> That is what "killfile" means.
> >>
>
> R> That is what 'threat' means.
>
> poor you. you have no clue. killfiling will not directly affect you so
> there is no threat. it just means you will not get help from most of the
> people here.
And that is the threat.
Thank you for being such a friendly person.
> killfiling is an individual thing but obvious entries are
> created all the time and you just made one for many
> regulars. congratulations.
>
> uri
>
> --
> Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
> SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
> Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
> Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Thu, 31 May 2001 18:31:27 -0800
From: U-Save Auto Rental <res@usaveak.com>
Subject: Problem with matching with variable regular expression
Message-Id: <3B16FE7F.F3C09177@usaveak.com>
@pattern = #SOME SOURCE#;
lOOPING{
if ($string =~ /$pattern[$i]/) {
print "match found \n";
}
}END OF LOOPING
Of course, $i is changing, which makes it to be a different pattern
after every loop:
The porblem that I have is that some array elements are equal to ''
(empty string).
No matter what I have in $string, it always matches to the $pattern[$i]
when $pattern[$i] equals to an empty string which is not good.
Does anybody have a solution?
Thank You.
------------------------------
Date: Thu, 31 May 2001 22:00:15 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Problem with matching with variable regular expression
Message-Id: <slrn9hdtpf.7l5.tadmc@tadmc26.august.net>
U-Save Auto Rental <res@usaveak.com> wrote:
>@pattern = #SOME SOURCE#;
>
>lOOPING{
> if ($string =~ /$pattern[$i]/) {
> print "match found \n";
> }
>}END OF LOOPING
>
>The porblem that I have is that some array elements are equal to ''
>(empty string).
>
>No matter what I have in $string, it always matches to the $pattern[$i]
>when $pattern[$i] equals to an empty string which is not good.
It _is_ good. That is exactly what it is supposed to do.
*Every* string contains the empty string, so the pattern _should_
match every string. It would be broken if it did not match.
>Does anybody have a solution?
Remove the empty strings from the array before matching:
@pattern = grep length, @pattern;
Even better, see the Perl FAQ, part 6:
"How do I efficiently match many regular expressions at once?"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 1 Jun 2001 03:13:35 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Problem with matching with variable regular expression
Message-Id: <slrn9he232.lli.damian@puma.qimr.edu.au>
U-Save Auto Rental chose Thu, 31 May 2001 18:31:27 -0800 to say this:
>...
>No matter what I have in $string, it always matches to the $pattern[$i]
>when $pattern[$i] equals to an empty string which is not good.
>
>Does anybody have a solution?
>
Yes -- don't use those empty strings:
my @patterns_to_loop_over = grep { length $_ }, @pattern;
See:
perldoc -f grep
perldoc -f length
HTH
Cheers,
Damian
--
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...
------------------------------
Date: 31 May 2001 23:30:28 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Problem with matching with variable regular expression
Message-Id: <m366egubaj.fsf@mumonkan.sunstarsys.com>
U-Save Auto Rental <res@usaveak.com> writes:
> @pattern = #SOME SOURCE#;
>
> lOOPING{
> if ($string =~ /$pattern[$i]/) {
> print "match found \n";
> }
> }END OF LOOPING
>
[...]
> No matter what I have in $string, it always matches to the $pattern[$i]
> when $pattern[$i] equals to an empty string which is not good.
Not necessarily- empty patterns are often magic and always
require extra care:
% perl -wlne '/foo/; $pat = ""; print "match:$_" if /$pat/'
bar
match:bar
foo
match:foo
bar
bar
foobar
match:foobar
This queer behavior is fully documented in a single sentence in
perlop- here it is in case you missed it while grepping your
pod files for "null pattern".
If the PATTERN evaluates to the empty string, the
last successfully matched regular expression is
used instead.
So why not just add a test for a "PATTERN that evaluates to
the empty string" before inadvertently hexing yourself?
if ( length( $pattern[$i] ) and $string =~ /$pattern[$i]/ ) {
...
Perhaps you can deal with the loop by using something like this:
for my $pattern ( grep { length and $string =~ $_ } @pattern ) {
print "'$string' matches /$pattern/";
#...
}
HTH
--
Joe Schaefer "Familiarity breeds contempt -- and children."
--Mark Twain
------------------------------
Date: 1 Jun 2001 01:53:41 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Problems with incrementing decimal numbers, bug with PERL??
Message-Id: <9f6sj5$e7i$2@bob.news.rcn.net>
Lan Xing <lan_xing@hotmail.com> wrote:
> Could someone point out to me why this code prints out "1"???
> When count is incremented to 1, doesn't the expression in while loop
> becomes false and exits??
> $count = 0;
> Perl code
> ---------
> while ($count < 1)
> {
> print ("$count\n");
> $count+=0.1;
> }
> Result
> ------
> 0
> 0.1
> 0.2
> 0.3
> 0.4
> 0.5
> 0.6
> 0.7
> 0.8
> 0.9
> 1
Because floating-point arithmetic isn't exact. You'll have the same
problem in any language that uses binary floating-point arithmetic. 0.1
is a number that can't be exactly represented in a finite-length binary
value, just as 1/3 can't be exactly represented in a finite-length decimal
value. 0.1 is actually represented as something smaller than 1/10, so
adding it to zero ten times gives you something slightly smaller than 1.
The first lesson every programmer learns about floating point numbers is
that you never compare two calculated floating-point values for exact
equality.
> Additional Problems
> -------------------
> Also I have noticed that if I use a bigger number in the expression in
> the while loop say, $count < 50, I will get strange result after the
> loop
> runs for some time. The result will have a lot of decimal places.
Same problem. Use printf or sprintf to round your numbers.
If you're doing financial calculations, the usual advice is to do all your
arithmetic in cents (or whatever the smallest unit of currency you can
deal with is) and convert to dollars (or similar units) only on output.
------------------------------
Date: Fri, 01 Jun 2001 02:10:39 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Problems with incrementing decimal numbers, bug with PERL??
Message-Id: <Xns90B2E2080A060echangnetstormnet@207.106.93.86>
lan_xing@hotmail.com (Lan Xing) wrote in
<2a6ee727.0105311636.7b00f2c3@posting.google.com>:
I am just starting out with PERL,
although I have experience in programming with C.
Could someone point out to me why this code prints out "1"???
When count is incremented to 1, doesn't the expression in while loop
becomes false and exits??
$count = 0;
Perl code
---------
while ($count < 1)
{
print ("$count\n");
$count+=0.1;
}
Result
------
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
>
> Could someone out there please tell me what is going on with PERL??>
Nothing is going wrong with Perl. (BTW, read 'What's the difference
between "perl" and "Perl"?' in the FAQ.) This situation occurs in all
computer languages, though where it shows up may vary. Essentially,
although 0.1, 1/10, has a terminating representation in decimal, it
cannot be represented exactly in binary - similar to trying to expand
1/3 in decimal.
printf("%.17f", 0.1);
prints
0.10000000000000001
Because of this intrinsic error (in the technical sense, not the
"mistake" sense), the sum is not exactly one. It happens to be smaller,
not larger, so the 1 gets printed out. When you interate more times,
the differences accumulate and show up in fewer decimal places of
output. Here's a closer look at the values you were printing (on one
specific platform - others will vary.).
$count = 0;
while ($count < 1) {
printf("%.17f", $count);
print(" $count\n");
$count+=0.1;
}
0.00000000000000000 0
0.10000000000000001 0.1
0.20000000000000001 0.2
0.30000000000000004 0.3
0.40000000000000002 0.4
0.50000000000000000 0.5
0.59999999999999998 0.6
0.69999999999999996 0.7
0.79999999999999993 0.8
0.89999999999999991 0.9
0.99999999999999989 1
[remainder snipped]
--
EBC
------------------------------
Date: Thu, 31 May 2001 21:43:38 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Problems with incrementing decimal numbers, bug with PERL??
Message-Id: <slrn9hdsqa.7io.tadmc@tadmc26.august.net>
Lan Xing <lan_xing@hotmail.com> wrote:
>
>Could someone point out to me why this code prints out "1"???
I think this code can point it out:
---------------------
#!/usr/bin/perl -w
use strict;
my $count = 0;
while ($count < 1)
{
print "$count: ";
printf("%30.20f\n", $count);
$count+=0.1;
}
---------------------
>When count is incremented to 1, doesn't the expression in while loop
>becomes false and exits??
Because it isn't 1, it is 0.99999999999999988898 (on my machine).
>Could someone out there please tell me what is going on with PERL??
Perl FAQ, part 4:
"Why am I getting long decimals (eg, 19.9499999999999)
instead of the numbers I should be getting (eg, 19.95)?"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 31 May 2001 20:03:31 -0500
From: Dmitry Epstein <mitia.nospam@northwestern.edu.invalid>
Subject: Re: Reading binary data (method and style)?
Message-Id: <3B16E9E3.2673D58E@northwestern.edu.invalid>
nobull@mail.com wrote:
> > Incidentally, is there a way to write a string on multiple lines in
> > Perl?
>
> I take it you mean without the newlines actually being part of the
> string. Yes, string contatenation. Are you perhaps forgetting that
> constant sub-expressions are evaluated at compile time?
Perhaps :) Thanks for your help.
--
Dmitry Epstein
Northwestern University, Evanston, IL. USA
mitia(at)northwestern(dot)edu
------------------------------
Date: Thu, 31 May 2001 18:47:20 -0700
From: Jim Liebgott <jliebgot@eni.net>
Subject: test
Message-Id: <3B16F428.B7BCB9B6@eni.net>
etest
------------------------------
Date: Thu, 31 May 2001 19:30:25 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: test
Message-Id: <3B16FE41.5F47793C@stomp.stomp.tokyo>
Jim Liebgott wrote:
> etest
Hot here in Southern California.
What is your weather like up there in 'Frisco?
* laughs *
Godzilla!
------------------------------
Date: Thu, 31 May 2001 21:30:04 -0400
From: Jeff Boes <jboes@qtm.net>
Subject: Re: tie() losing values
Message-Id: <ktrdhtcpjdr98hdqlm1lhnpagm4p3c5pcg@4ax.com>
At some point in time, jboes@nexcerpt.com wrote:
>sub FETCH {
> my $record = shift;
> my $table = ref($record);
> my $field = shift;
> my $value;
> unless (exists $record->{$field}) {
> carp "no such field $field in $table";
> return undef;
> } else { return $value }
>}
Duh ... er, ah ...
Perhaps if I initialized $value before I returned it? Sheesh ... (my forehead
has a hand-shaped imprint on it).
--
~~~~~~~~~~~~~~~~|It is by caffeine alone I set my mind in motion,
Jeffery Boes |It is by the beans of Java that thoughts acquire speed,
jboes@qtm.net |The hands acquire shaking, the shaking becomes a warning,
UIN 3394914 |It is by caffeine alone I set my mind in motion.
------------------------------
Date: Thu, 31 May 2001 21:43:15 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: Upgrade from Activeperl 620 to 626 on a Microsoft box
Message-Id: <P8ER6.546$G91.1842@newsfeed.slurp.net>
"John Imrie" <07950232225@one2one.net> wrote in message
news:3B164875.29156156@one2one.net...
>
> Download the new version.
> Uninstall the current version
blow away the Perl directory, for good luck. msi isn't the sharpest knife in
the Microsoft drawer.
> Install the new version
------------------------------
Date: Fri, 01 Jun 2001 03:36:22 GMT
From: "Ed" <spis@worldnet.att.net>
Subject: Using Perl to keep track on internet usage?
Message-Id: <W4ER6.55816$t12.4463151@bgtnsc05-news.ops.worldnet.att.net>
Hello group,
Have been using Perl for a short while and have be asked to something I
really am not sure where to start. My boss want to keep track of what files
are being viewed on each PC (approx 8 PC (Win98)) on each account. Is there
an easy way to make a program run when the puter is turned on, perferable
without anyone knowing it is running. I thought about automatically copying
the temp and history files but this does not seem to be a great idea.
Any ideas would be appreciated.
Ed
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1033
***************************************