[28504] in Perl-Users-Digest
Perl-Users Digest, Issue: 9868 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 19 18:06:00 2006
Date: Thu, 19 Oct 2006 15:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 19 Oct 2006 Volume: 10 Number: 9868
Today's topics:
Re: CGI on NT help! <sadmachines0@yahoo.com>
Re: Efficient Searching <hlarons@yahoo.com>
Re: Efficient Searching <wahab@chemie.uni-halle.de>
Finding lowest numeric value in an array with undef val usenet@DavidFilmer.com
Re: Finding lowest numeric value in an array with undef <mritty@gmail.com>
Re: Finding lowest numeric value in an array with undef <DJStunks@gmail.com>
Re: Finding lowest numeric value in an array with undef <bwilkins@gmail.com>
Re: Finding lowest numeric value in an array with undef <mritty@gmail.com>
Re: Finding lowest numeric value in an array with undef <wahab@chemie.uni-halle.de>
Re: Finding lowest numeric value in an array with undef <glex_no-spam@qwest-spam-no.invalid>
Re: Finding lowest numeric value in an array with undef <DJStunks@gmail.com>
Re: Finding lowest numeric value in an array with undef <sherm@Sherm-Pendleys-Computer.local>
Re: Finding lowest numeric value in an array with undef <mritty@gmail.com>
Re: Finding lowest numeric value in an array with undef xhoster@gmail.com
Re: Finding lowest numeric value in an array with undef <glex_no-spam@qwest-spam-no.invalid>
Re: Finding lowest numeric value in an array with undef <bwilkins@gmail.com>
Re: Finding lowest numeric value in an array with undef <bwilkins@gmail.com>
Re: how to do programming in perl in windows <bwilkins@gmail.com>
Re: how to do programming in perl in windows <jialinli1981@gmail.com>
Re: how to do programming in perl in windows <mritty@gmail.com>
Re: Matching umlauts anno4000@radom.zrz.tu-berlin.de
Re: modify posting guidelines to allow MIME charset=utf <hjp-usenet2@hjp.at>
Problem with hashes <mikedawg@gmail.com>
Re: Problem with hashes <uri@stemsystems.com>
Re: Problem with hashes <glex_no-spam@qwest-spam-no.invalid>
Re: Problem with hashes <glex_no-spam@qwest-spam-no.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Oct 2006 14:31:40 -0700
From: "Scott Trinh" <sadmachines0@yahoo.com>
Subject: Re: CGI on NT help!
Message-Id: <1161293500.219472.22320@f16g2000cwb.googlegroups.com>
Thanks for the responses. Turns out, I'll now be serving the script
locally from my Mac, so I have a new set of problems. =]
However, seeing as it's *nix, I'm much more comfortable, and think I
have a decent chance at making it work. Thanks again!
Scott
On Oct 19, 1:02 pm, "Paul Lalli" <mri...@gmail.com> wrote:
> Scott Trinh wrote:
> > I'm running an NT4 server with IIS4 (I know, I know... Get linux. Well,
> > it's unfortunately not my call... yet), and I'm have a hard time
> > getting all of the *nix CGI code around to work on this machine.
> > Obviously there are huge differences between the two, but after two
> > days of Googling around trying to find the answers, I figured I'd post
> > here.
>
> > I'm basically trying to get a file from the input type="file". I've
> > downloaded 5 or so different piece of code, and tried them all every
> > which way, and still can't wrap my head around getting everything
> > straight for NT. If anyone has any insight into this, I'd love the
> > help.You have given no information of any kind that could be useful to
> debugging your problem.
>
> At the absolute *least*, we need to see:
> A) A short-but-complete script that demonstrates the error
> B) A description of the results
> C) Any warnings or errors that are printed, both to the server log and
> to the browser.
>
> This is, of course, assuming your CGI script is written in Perl. If
> it's not, you're very much in the wrong group.
>
> Paul Lalli
------------------------------
Date: Thu, 19 Oct 2006 18:42:05 -0000
From: HaroldWho <hlarons@yahoo.com>
Subject: Re: Efficient Searching
Message-Id: <slrnejfhnt.23u.hlarons@Beagle.mylocal.net>
On Wed, 18 Oct 2006 18:40:11 -0000, HaroldWho wrote in comp.lang.perl.misc:
> I have an 2.7 Mb, 75,000 line comma-separated ASCII file with each line
> of the form: integer_1,integer_2,string_1,string_2
>
> Given a target integer, I need to search for the record for which
> target >= integer_1 && target <= integer_2.
To answer some of the many questions posed by all the replies:
1. Ranges do not overlap.
2. The point of the search is to get the strings. I thought that would be
clear, but evidently it wasn't.
3. I have used a linear search, going line-by-line through the array to find
the line where target >= integer_1 && target <= integer_2.
BTW, reading the file into memory is very fast. I tried just reading
line-by-line, but the results aren't noticeably different.
There seems to be two ideas here for me to followup on:
a) A binary search (full disclosure: I'm not a CS person, so I'll need to learn
more about this).
b) The suggestion by Mirco Wahab. Particular thanks to you for trying to read
my mind.
Work continues; many thanks to all.
HW
--
Powered by Slackware 10.2 Linux -- Kernel 2.6.13
News Reader slrn 0.9.8.1
------------------------------
Date: Thu, 19 Oct 2006 22:33:59 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Efficient Searching
Message-Id: <eh8nou$3vi$1@mlucom4.urz.uni-halle.de>
Thus spoke HaroldWho (on 2006-10-19 20:42):
> On Wed, 18 Oct 2006 18:40:11 -0000, HaroldWho wrote in comp.lang.perl.misc:
> There seems to be two ideas here for me to followup on:
>
> a) A binary search (full disclosure: I'm not a CS person, so I'll need to learn
> more about this).
>
> b) The suggestion by Mirco Wahab. Particular thanks to you for trying to read
> my mind.
>
> Work continues; many thanks to all.
I did a RWC (real word check) on all this and createt a 2,5MB
csv 2/100K lines and made $targets that lead to a 25% hit rate.
The following came out (times rounded):
=> the regex approach
# determine @targets up front
...
open(my $inh, '<', 'stuff.csv') or die "for a reason $!";
my $content; { local $/; $content = <$inh> };
close $inh;
for my $n ( @targets ) {
@ar = ();
$target = $n; # @ar and $target must be defined outside the loop
my $rg = qr/ ([^,\n]+) [,\n]+ ([^,\n]+)[,\n]+ # the numbers $1 $2
([^,\n]+) [,\n]+ ([^,\n]+)[,\n]+ # the strings $3 $4
(?{ push @ar, "$3,$4" if( $target>=$1 && $target<=$2 ) }) /mx;
1 while $content =~ /$rg/g # fortran style, ==> 9 sec
# @{[ $content =~ /$rg/g ]}; # void expansion, ==> 15 sec
# @@ =()= $content =~ /$rg/g; # 'goatse' style ==> 16 sec
print "-> hits for $target found: ", scalar @ar, "\n";
}
=> the array approach
# determine @targets up front
...
open(my $inh, '<', 'stuff.csv') or die "for a reason $!";
my @content = map [split /,/, $_], <$inh>;
close $inh;
for my $t (@targets) {
my @ar = map "$$_[2],$$_[3]", grep $t>=$$_[0] && $t<=$$_[1], @content;
print "-> hits for $t found: ", scalar @ar, "\n"; # array remap ==> 2 sec
}
This means in the end - the array approach, where one may prepare
all values for simple comparisons, is much much faster (2 seconds)
than the regex approach (9 seconds) if applied properly.
Regards
Mirco
------------------------------
Date: 19 Oct 2006 11:42:15 -0700
From: usenet@DavidFilmer.com
Subject: Finding lowest numeric value in an array with undef values
Message-Id: <1161283335.439136.276520@m73g2000cwd.googlegroups.com>
Suppose I have an array:
my @array = (1, 2, undef, 3);
I want to find the smallest numeric value (ignoring undef values). My
first inclination is to use the min() method of List::Util, but the
undef value causes problems (the method throws a warning and then
returns the undef).
I could do this:
use List::Util qw{ min };
print min ( grep /\d+/, @array );
which returns the expected value (1), but strikes me as kludgy (and
still throws a warning).
Any better suggestions?
Thanks!
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 19 Oct 2006 11:57:45 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <1161284265.624038.294090@i42g2000cwa.googlegroups.com>
usenet@DavidFilmer.com wrote:
> Suppose I have an array:
>
> my @array = (1, 2, undef, 3);
>
> I want to find the smallest numeric value (ignoring undef values). My
> first inclination is to use the min() method of List::Util, but the
> undef value causes problems (the method throws a warning and then
> returns the undef).
>
> I could do this:
>
> use List::Util qw{ min };
> print min ( grep /\d+/, @array );
>
> which returns the expected value (1), but strikes me as kludgy (and
> still throws a warning).
>
> Any better suggestions?
Just as clunky, but no warning....
use List::Util qw/min/;
print min ( grep { defined } @array );
Paul Lalli
------------------------------
Date: 19 Oct 2006 11:59:02 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <1161284342.401993.298600@k70g2000cwa.googlegroups.com>
usenet@DavidFilmer.com wrote:
> Suppose I have an array:
>
> my @array = (1, 2, undef, 3);
>
> I want to find the smallest numeric value (ignoring undef values). My
> first inclination is to use the min() method of List::Util, but the
> undef value causes problems (the method throws a warning and then
> returns the undef).
>
> I could do this:
>
> use List::Util qw{ min };
> print min ( grep /\d+/, @array );
>
> which returns the expected value (1), but strikes me as kludgy (and
> still throws a warning).
>
> Any better suggestions?
right off the top, I can get rid of that warning for you :P
print min grep defined, @array;
I wouldn't be framing that line and mouting it above my desk though.
-jp
------------------------------
Date: 19 Oct 2006 12:00:20 -0700
From: "Brian Wilkins" <bwilkins@gmail.com>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <1161284420.737277.306400@i42g2000cwa.googlegroups.com>
usenet@DavidFilmer.com wrote:
> Suppose I have an array:
>
> my @array = (1, 2, undef, 3);
>
> I want to find the smallest numeric value (ignoring undef values). My
> first inclination is to use the min() method of List::Util, but the
> undef value causes problems (the method throws a warning and then
> returns the undef).
>
> I could do this:
>
> use List::Util qw{ min };
> print min ( grep /\d+/, @array );
>
> which returns the expected value (1), but strikes me as kludgy (and
> still throws a warning).
>
> Any better suggestions?
>
You could do it the old fashioned way (not tested):
$current = 0;
for my $t (@array) {
if(defined($t)) {
if ($current > $t) {
$current = $t;
}
}
}
print "Lowest value in array is $current\n";
> Thanks!
>
> --
> The best way to get a good answer is to ask a good question.
> David Filmer (http://DavidFilmer.com)
------------------------------
Date: 19 Oct 2006 12:07:48 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <1161284868.403657.19790@e3g2000cwe.googlegroups.com>
Brian Wilkins wrote:
> usenet@DavidFilmer.com wrote:
> > Suppose I have an array:
> >
> > my @array = (1, 2, undef, 3);
> >
> > I want to find the smallest numeric value (ignoring undef values). My
> > first inclination is to use the min() method of List::Util, but the
> > undef value causes problems (the method throws a warning and then
> > returns the undef).
> >
> > I could do this:
> >
> > use List::Util qw{ min };
> > print min ( grep /\d+/, @array );
> >
> > which returns the expected value (1), but strikes me as kludgy (and
> > still throws a warning).
> >
> > Any better suggestions?
> >
>
> You could do it the old fashioned way (not tested):
>
> $current = 0;
>
> for my $t (@array) {
> if(defined($t)) {
>
> if ($current > $t) {
> $current = $t;
> }
> }
> }
>
> print "Lowest value in array is $current\n";
This has the same bug that so many of my students make. :-)
You're assuming all the values in the array are positive.
Paul Lalli
> > The best way to get a good answer is to ask a good question.
> > David Filmer (http://DavidFilmer.com)
------------------------------
Date: Thu, 19 Oct 2006 21:09:38 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <eh8iqo$2bc$1@mlucom4.urz.uni-halle.de>
Thus spoke usenet@DavidFilmer.com (on 2006-10-19 20:42):
> my @array = (1, 2, undef, 3);
>
> I want to find the smallest numeric value (ignoring undef values). My
> first inclination is to use the min() method of List::Util, but the
> undef value causes problems (the method throws a warning and then
> returns the undef).
> Any better suggestions?
The "best things" have already been pointed
out above, but in case you want it without
modules, you could have used:
print( (sort { $a <=> $b } grep defined, @array)[0] );
Regards
M.
------------------------------
Date: Thu, 19 Oct 2006 14:23:13 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <4537d055$0$10298$815e3792@news.qwest.net>
Paul Lalli wrote:
> Brian Wilkins wrote:
>> usenet@DavidFilmer.com wrote:
>>> Suppose I have an array:
>>>
>>> my @array = (1, 2, undef, 3);
>>>
>>> I want to find the smallest numeric value (ignoring undef values). My
>>> first inclination is to use the min() method of List::Util, but the
>>> undef value causes problems (the method throws a warning and then
>>> returns the undef).
>>>
>>> I could do this:
>>>
>>> use List::Util qw{ min };
>>> print min ( grep /\d+/, @array );
>>>
>>> which returns the expected value (1), but strikes me as kludgy (and
>>> still throws a warning).
>>>
>>> Any better suggestions?
>>>
>> You could do it the old fashioned way (not tested):
>>
>> $current = 0;
It should be set to a value from @array.
my $current = $array[0];
>>
>> for my $t (@array) {
>> if(defined($t)) {
>>
>> if ($current > $t) {
>> $current = $t;
>> }
>> }
>> }
>>
>> print "Lowest value in array is $current\n";
>
> This has the same bug that so many of my students make. :-)
>
> You're assuming all the values in the array are positive.
Really. Where's the bug?
my @array = qw( 4 -300 5 -400 );
my $current = $array[0];
for my $t (@array) {
if(defined($t)) {
if ($current > $t) {
$current = $t;
}
}
}
print "Lowest value in array is $current\n";
Lowest value in array is -400
------------------------------
Date: 19 Oct 2006 12:26:15 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <1161285975.395557.84580@k70g2000cwa.googlegroups.com>
J. Gleixner wrote:
> Paul Lalli wrote:
> > Brian Wilkins wrote:
> >> usenet@DavidFilmer.com wrote:
> >>> Suppose I have an array:
> >>>
> >>> my @array = (1, 2, undef, 3);
> >>>
> >>> I want to find the smallest numeric value (ignoring undef values). My
> >>> first inclination is to use the min() method of List::Util, but the
> >>> undef value causes problems (the method throws a warning and then
> >>> returns the undef).
> >>>
> >>> I could do this:
> >>>
> >>> use List::Util qw{ min };
> >>> print min ( grep /\d+/, @array );
> >>>
> >>> which returns the expected value (1), but strikes me as kludgy (and
> >>> still throws a warning).
> >>>
> >>> Any better suggestions?
> >>>
> >> You could do it the old fashioned way (not tested):
> >>
> >> $current = 0;
> It should be set to a value from @array.
>
> my $current = $array[0];
>
> >>
> >> for my $t (@array) {
> >> if(defined($t)) {
> >>
> >> if ($current > $t) {
> >> $current = $t;
> >> }
> >> }
> >> }
> >>
> >> print "Lowest value in array is $current\n";
> >
> > This has the same bug that so many of my students make. :-)
> >
> > You're assuming all the values in the array are positive.
>
> Really. Where's the bug?
you fixed it.
> my @array = qw( 4 -300 5 -400 );
> my $current = $array[0];
> for my $t (@array) {
> if(defined($t)) {
> if ($current > $t) {
> $current = $t;
> }
> }
> }
> print "Lowest value in array is $current\n";
>
> Lowest value in array is -400
-jp
------------------------------
Date: Thu, 19 Oct 2006 15:40:18 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <m2ac3snlgd.fsf@Sherm-Pendleys-Computer.local>
"J. Gleixner" <glex_no-spam@qwest-spam-no.invalid> writes:
> Paul Lalli wrote:
>> Brian Wilkins wrote:
>>> You could do it the old fashioned way (not tested):
>>>
>>> $current = 0;
> It should be set to a value from @array.
>
> my $current = $array[0];
...
> Really. Where's the bug?
The bug was the initial assignment of 0. You fixed it already. :-)
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 19 Oct 2006 12:45:55 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <1161287155.580556.177340@h48g2000cwc.googlegroups.com>
J. Gleixner wrote:
> Paul Lalli wrote:
> > Brian Wilkins wrote:
> >> usenet@DavidFilmer.com wrote:
> >>> Suppose I have an array:
> >>>
> >>> my @array = (1, 2, undef, 3);
> >>>
> >>> I want to find the smallest numeric value (ignoring undef values). My
> >>> first inclination is to use the min() method of List::Util, but the
> >>> undef value causes problems (the method throws a warning and then
> >>> returns the undef).
> >>>
> >>> I could do this:
> >>>
> >>> use List::Util qw{ min };
> >>> print min ( grep /\d+/, @array );
> >>>
> >>> which returns the expected value (1), but strikes me as kludgy (and
> >>> still throws a warning).
> >>>
> >>> Any better suggestions?
> >>>
> >> You could do it the old fashioned way (not tested):
> >>
> >> $current = 0;
> It should be set to a value from @array.
>
> my $current = $array[0];
>
> >>
> >> for my $t (@array) {
> >> if(defined($t)) {
> >>
> >> if ($current > $t) {
> >> $current = $t;
> >> }
> >> }
> >> }
> >>
> >> print "Lowest value in array is $current\n";
> >
> > This has the same bug that so many of my students make. :-)
> >
> > You're assuming all the values in the array are positive.
>
> Really. Where's the bug?
You corrected it, of course. He set the initial value of $current to a
value not in the array.
However, I admit I did misread the code. My mistake. The code doesn't
fail if one of the values is negative. Rather, it fails if NONE of the
values is negative.
perl -e'
@array = (5, 10, 20);
$current = 0;
for my $t (@array) {
if(defined($t)) {
if ($current > $t) {
$current = $t;
}
}
}
print "Lowest value in array is $current\n";
'
Lowest value in array is 0
Paul Lalli
------------------------------
Date: 19 Oct 2006 20:01:07 GMT
From: xhoster@gmail.com
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <20061019160225.931$3t@newsreader.com>
"Paul Lalli" <mritty@gmail.com> wrote:
> Brian Wilkins wrote:
> >
> > You could do it the old fashioned way (not tested):
> >
> > $current = 0;
> >
> > for my $t (@array) {
> > if(defined($t)) {
> >
> > if ($current > $t) {
> > $current = $t;
> > }
> > }
> > }
> >
> > print "Lowest value in array is $current\n";
>
> This has the same bug that so many of my students make. :-)
Maybe, but it isn't the one you think it is!
>
> You're assuming all the values in the array are positive.
Actually he's assuming at least one value is nonpositive. Which
is still buggy, but certainly a less common bug.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 19 Oct 2006 15:26:53 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <4537df41$0$3570$815e3792@news.qwest.net>
Paul Lalli wrote:
> J. Gleixner wrote:
>>> This has the same bug that so many of my students make. :-)
>>>
>>> You're assuming all the values in the array are positive.
>> Really. Where's the bug?
>
> You corrected it, of course. He set the initial value of $current to a
> value not in the array.
Yes. I understand. I know I pointed out the issue with initialization
and was suggesting that assuming the values are positive, wasn't the bug.
> However, I admit I did misread the code. My mistake. The code doesn't
> fail if one of the values is negative. Rather, it fails if NONE of the
> values is negative.
That states the actual issue very well. Setting it to [0] isn't all
that great either, since it could be undef, but that's a simple fix.
------------------------------
Date: 19 Oct 2006 14:44:39 -0700
From: "Brian Wilkins" <bwilkins@gmail.com>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <1161294279.644828.170820@b28g2000cwb.googlegroups.com>
Paul Lalli wrote:
> Brian Wilkins wrote:
> > usenet@DavidFilmer.com wrote:
> > > Suppose I have an array:
> > >
> > > my @array = (1, 2, undef, 3);
> > >
> > > I want to find the smallest numeric value (ignoring undef values). My
> > > first inclination is to use the min() method of List::Util, but the
> > > undef value causes problems (the method throws a warning and then
> > > returns the undef).
> > >
> > > I could do this:
> > >
> > > use List::Util qw{ min };
> > > print min ( grep /\d+/, @array );
> > >
> > > which returns the expected value (1), but strikes me as kludgy (and
> > > still throws a warning).
> > >
> > > Any better suggestions?
> > >
> >
> > You could do it the old fashioned way (not tested):
> >
> > $current = 0;
> >
> > for my $t (@array) {
> > if(defined($t)) {
> >
> > if ($current > $t) {
> > $current = $t;
> > }
> > }
> > }
> >
> > print "Lowest value in array is $current\n";
>
> This has the same bug that so many of my students make. :-)
>
> You're assuming all the values in the array are positive.
>
> Paul Lalli
> > > The best way to get a good answer is to ask a good question.
> > > David Filmer (http://DavidFilmer.com)
I'm glad I caveated it :) I just wrote it up in like 5 seconds. Thanks
for the clarification. I should of assigned it to array[0] :)
------------------------------
Date: 19 Oct 2006 14:44:39 -0700
From: "Brian Wilkins" <bwilkins@gmail.com>
Subject: Re: Finding lowest numeric value in an array with undef values
Message-Id: <1161294279.819825.301890@h48g2000cwc.googlegroups.com>
Paul Lalli wrote:
> Brian Wilkins wrote:
> > usenet@DavidFilmer.com wrote:
> > > Suppose I have an array:
> > >
> > > my @array = (1, 2, undef, 3);
> > >
> > > I want to find the smallest numeric value (ignoring undef values). My
> > > first inclination is to use the min() method of List::Util, but the
> > > undef value causes problems (the method throws a warning and then
> > > returns the undef).
> > >
> > > I could do this:
> > >
> > > use List::Util qw{ min };
> > > print min ( grep /\d+/, @array );
> > >
> > > which returns the expected value (1), but strikes me as kludgy (and
> > > still throws a warning).
> > >
> > > Any better suggestions?
> > >
> >
> > You could do it the old fashioned way (not tested):
> >
> > $current = 0;
> >
> > for my $t (@array) {
> > if(defined($t)) {
> >
> > if ($current > $t) {
> > $current = $t;
> > }
> > }
> > }
> >
> > print "Lowest value in array is $current\n";
>
> This has the same bug that so many of my students make. :-)
>
> You're assuming all the values in the array are positive.
>
> Paul Lalli
> > > The best way to get a good answer is to ask a good question.
> > > David Filmer (http://DavidFilmer.com)
I'm glad I caveated it :) I just wrote it up in like 5 seconds. Thanks
for the clarification. I should of assigned it to array[0] :)
------------------------------
Date: 19 Oct 2006 11:35:19 -0700
From: "Brian Wilkins" <bwilkins@gmail.com>
Subject: Re: how to do programming in perl in windows
Message-Id: <1161282919.770066.265090@i3g2000cwc.googlegroups.com>
Jack wrote:
> Hello all
> I am a new perl programmer and i have been doing many programs
> in perl o UNIX machine but im unable to run a program on my windows
> using active perl and i have installed the active perl. Well im not
> sure if i have followed the correct procedure to install active perl or
> not. I would like to know how to install and then how to start perl
> programming in windows
> thanx
To run your Perl scripts on Windows, install ActiveState, and change
your she-bang to :
#!C:/Perl/bin
then type [filename].pl at the command-line. If everything is setup
correctly, it should work.
------------------------------
Date: Thu, 19 Oct 2006 14:22:13 -0500
From: Jialin Li <jialinli1981@gmail.com>
Subject: Re: how to do programming in perl in windows
Message-Id: <eh8jab$b0i$1@joe.rice.edu>
I would suggest cygwin
Jack wrote:
> Hello all
> I am a new perl programmer and i have been doing many programs
> in perl o UNIX machine but im unable to run a program on my windows
> using active perl and i have installed the active perl. Well im not
> sure if i have followed the correct procedure to install active perl or
> not. I would like to know how to install and then how to start perl
> programming in windows
> thanx
>
------------------------------
Date: 19 Oct 2006 12:48:45 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: how to do programming in perl in windows
Message-Id: <1161287325.527561.171930@i42g2000cwa.googlegroups.com>
Brian Wilkins wrote:
> Jack wrote:
> > not. I would like to know how to install and then how to start perl
> > programming in windows
>
> To run your Perl scripts on Windows, install ActiveState, and change
> your she-bang to :
>
> #!C:/Perl/bin
>
> then type [filename].pl at the command-line. If everything is setup
> correctly, it should work.
That's a massive red herring. Windows Perl couldn't care less what the
path to Perl is on the shebang. The only thing Windows Perl cares
about on the shebang line is any switches present.
The filename.pl associations are set the same way as any other file
associations in Windows, and has nothing to do with the shebang.
Paul Lalli
------------------------------
Date: 19 Oct 2006 19:25:34 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Matching umlauts
Message-Id: <4pq1peFk35chU1@news.dfncis.de>
Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de wrote:
> > Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote in
> comp.lang.perl.misc:
> >
> >>fritz-bayer@web.de wrote:
> >>
> >>>Hi,
> >>>
> >>>I have to match words, which contains umlauts like äöü and also
> >>>french and other ones.
> >>>
> >>>Is there a way to use regular expressions in such a way that those get
> >>>treated like their normal corresponding letters?
> >>>
> >>>In other words, that "München" = "Munchen" when I do a pattern match
> >>>with =~ ?
> >>
> >>Why should they be the same if they aren't?
> >
> >
> > With that argument you'd also have to argue that m//i is useless. After
> > all "Tad" and "tad" aren't the same either. In the right context it may
> > make perfect sense to have /München/ match "Munchen".
>
> No. IMHO ü and u are different characters with different pronunciation.
> See my example below (Agreed, in "Wenn hinter Fliegen Fliegen fliegen,
> fliegen Fliegen Fliegen hinterher" there _is_ a definite difference
> between "Fliegen" and "fliegen").
> Outside of Germany, "ü" may very well be "u", e.g. in Dutch (Ruud,
> please correct me if I'm wrong) "ü" would mean "a _u_ even if it would
> otherwise be coerced to the previous letter" ("reunie" might be
> pronounced differently from "reünie").
That's all good and well, but we're talking about matching. The
mis-spellings you complain about are a fact of life. After all,
what's a guy to do when there is no u-umlaut on the keyboard?
So when you want to include the most common mis-spellings in the
match, you'll have to match "ö" against "o", like it or not.
> > I know of no feature that would automatically map an accented character
> > to its un-accented version. You'll have to come up with your own
> > equivalence tables, probably in form of tr/// statements.
>
> That would be the closest thing Fritz would get.
>
> >>Why should Münster in Northrhine-Westfalia be the same as Munster in
> >>Lower Saxony?
They are both possible answers to a query about "Munster, Germany".
> Josef, getting angry when his second name is spelt "Mollers" ;-)
Prepare to get angry some more then :)
Anno
------------------------------
Date: Thu, 19 Oct 2006 21:48:17 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: modify posting guidelines to allow MIME charset=utf8
Message-Id: <slrnejflk1.lvf.hjp-usenet2@yoyo.hjp.at>
On 2006-10-18 19:50, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Ted" == Ted Zlatanov <tzz@lifelogs.com> writes:
>Ted> Usenet is not a prison. comp.lang.perl.misc is not even moderated.
>Ted> Can you explain your analogy a little bit?
>
> The analogy is that *this* is not *yours* and not *mine*. *This* belongs
> to the people who run Usenet. Unless you're also in charge of a spool
> somewhere, you are *not* an admin and have *no* say about the format
> of the messages or even the charter.
I am an admin but I don't have any more say about the format of message
or the charter than anybody else.
From my point of view as an admin details of the message content are
absolutely immaterial. Except for a very few headers (Newsgroups, Date,
Message-Id, Path, Control, ...) a message is just a blob of octets
which the server will receive, pass on to its neighbours and send to its
clients until it is expired.
I do care about the total traffic - a group with too many or too large
messages may get deleted locally because it eats valuable resources
which could be used by other groups.
As a reader and poster in this group I do care about the readability of
articles. That's where MIME comes in - and for me it's roughly
comparable to line lengths, proper English grammar, proper quoting,
using "strict" and and not flaming - write your articles in such a
fashion that they are acceptable to the readers.
> Even if you *are* in charge of a spool, you don't get interchange
> rights unless you play along well with the *collective* *anarchy*
> known as "Usenet".
I'm pretty sure that any news-admin who blocked MIME and/or 8bit content
would be considered as *not* playing along well on this side of the
Atlantic.
> So, that's how it applies. You can vote all you want, but it's ultimately up
> to the people running the show, and that's NOT US in THIS GROUP. It's the
> people in news.admin. As far as I remember last time I looked, MIME is *not*
> acceptable, here or anywhere on Usenet except in groups that match
> "*.binaries.*".
You probably looked last sometime around 1990. But MIME wasn't even
invented then.
To add a bit of historical perspective, even Henry Spencer's
"son-of-1036", which was last updated in 1994, strongly recommends the
use of MIME.
It forbids the use of 8bit and binary encodings except in "cooperating
subnets", but even at that time the whole usenet (except for a few
EBCDIC hosts) could be considered a cooperating subnet in that aspect:
B-News was dead and C-News and INN didn't have any problems with 8bit
characters; 8bit characters were common in non-English hierarchies
before MIME had reasonably wide-spread support.
Son-of-1036 never became an RFC. But among news admins it was long
considered to be the de-facto standard and preferred over 1036. By now
son-of-1036 also seems to be considered obsolete by many: Usenet has
evolved, but no formal successor to RFC 1036 was ever published, so by
now "what other netizens accept" is more important than what the RFC
says.
> Just another Usenet old-timer (since 1980 when it first began),
I can't compete with that. I only started using usenet in 1988.
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: 19 Oct 2006 13:08:47 -0700
From: "Mike" <mikedawg@gmail.com>
Subject: Problem with hashes
Message-Id: <1161288527.269982.326330@i3g2000cwc.googlegroups.com>
I'm having a little bit of problems finishing up a previous co-workers
perl project. I'm a little confused as to why its not working. What
the script is doing is add values in a text file together (daily
values) and add up the totals and throw it in a monthly total. I think
there is something going on with the hashes, or entering the data into
the hashes.
(sorry for bad formatting in the newsgroup, I also changed some of the
variables names and values)
#!/bin/perl
@servers = ("server1", "server2");
%values1 = ();
foreach $server (@servers){
print "$server\n";
opendir DATADIR, "$server";
@files = readdir DATADIR;
closedir DATADIR;
foreach $file (@files){
chomp;
next if ($file eq "." || $file eq "..");
open(IN," < $server/$file") or next;
while(<IN>){
chomp;
next if (length $_ == 0);
next if ($_ =~ /--------|Report Title/);
if ($_ =~ /This is Header 1|This is Header
2|This is Header 3/) {
$prefix = $_;
}
if ($_ =~ /Sub Report 1-1\D+:|Sub Report
2-1\D+:|number\D+:|Sub
Report 3-1\D+:)\s+(\d+)/) {
$suffix = $1;
$key = $prefix . $suffix;
$value = $2;
if (exists $values1{$key}) {
$values1{$key} += $value;
}else{
$values1{$key} = $value;
}
}
}
}
}
open (FILEOUT, ">data.txt");
while ( ($key,$value) = each %values1 ) {
print "$key => $value\n";
}
foreach $key (keys (%values))
{
print FILEOUT $key, ",", $values1{$key}, "\n";
}
__END__
Variable names are at begining of each line. Sample Report follows.
---------------------------------------------------------------------------
Report Title
---------------------------------------------------------------------------
Start date: 20060202
End date: 20060203
This is header 1:
Sub Report 1-1: 2504
Sub Report 1-2: 16320
Sub Report 1-3: 83
Sub Report 1-4: 63
This is header 2:
Sub Report 2-1: 785
Sub Report 2-2: 363
Sub Report 2-3: 725
Sub Report 2-4: 9835
This is header 3:
Sub Report 3-1: 9653
Sub Report 3-2: 135
Sub Report 3-3: 132
Sub Report 3-4: 135
------------------------------
Date: Thu, 19 Oct 2006 16:44:25 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Problem with hashes
Message-Id: <x7y7rc828m.fsf@mail.sysarch.com>
>>>>> "M" == Mike <mikedawg@gmail.com> writes:
M> I'm having a little bit of problems finishing up a previous co-workers
M> perl project. I'm a little confused as to why its not working. What
M> the script is doing is add values in a text file together (daily
M> values) and add up the totals and throw it in a monthly total. I think
M> there is something going on with the hashes, or entering the data into
M> the hashes.
M> (sorry for bad formatting in the newsgroup, I also changed some of the
M> variables names and values)
some general code comments. i haven't gotten into the bug but cleaning
up the code will help.
M> #!/bin/perl
use strict ;
use warnings ;
M> @servers = ("server1", "server2");
M> %values1 = ();
no need to initialize a hash to ().
M> foreach $server (@servers){
foreach my $server (@servers){
that is for strict. let perl help you
M> print "$server\n";
M> opendir DATADIR, "$server";
no need to quote that. read the FAQ for why. also use a lexical handle
or even better, use File::Slurp::read_dir as it does 4 of your lines in
1 call.
M> @files = readdir DATADIR;
M> closedir DATADIR;
M> foreach $file (@files){
M> chomp;
that is very wrong. file names from a dir are unlikely to have a
trailing \n and if they did, chomping will break the code.
M> next if ($file eq "." || $file eq "..");
handled by the read_dir call
M> open(IN," < $server/$file") or next;
why not say why the file didn't open correctly?
M> while(<IN>){
while(my $line = <IN>){
don't use $_ so much. better to use named vars as that helps with
understanding the code.
M> chomp;
chomp here is better.
M> next if (length $_ == 0);
next unless length $line
M> next if ($_ =~ /--------|Report Title/);
no need to use $_ =~ as $_ is what m// works on by default. if you
switch to a named var, then you need =~.
M> if ($_ =~ /This is Header 1|This is Header
M> 2|This is Header 3/) {
gack! all that redundant text. factor it out:
if ($_ =~ /This is Header [123]/) {
M> $prefix = $_;
M> }
M> if ($_ =~ /Sub Report 1-1\D+:|Sub Report
M> 2-1\D+:|number\D+:|Sub
M> Report 3-1\D+:)\s+(\d+)/) {
i am sure that can be cleaned up. others will tackle it for sure. :)
M> $suffix = $1;
M> $key = $prefix . $suffix;
M> $value = $2;
M> if (exists $values1{$key}) {
M> $values1{$key} += $value;
M> }else{
M> $values1{$key} = $value;
M> }
that if/else is majorly wasted code. perl autovivifies values in many
situations. all you need is this line and it does the same thing:
$values1{$key} += $value;
M> }
M> }
M> }
M> }
M> open (FILEOUT, ">data.txt");
always check the results of open.
M> while ( ($key,$value) = each %values1 ) {
M> print "$key => $value\n";
M> }
M> foreach $key (keys (%values))
M> {
M> print FILEOUT $key, ",", $values1{$key}, "\n";
M> }
why the two different loops when they loop over the same data? just put
both print lines in the first loop.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 19 Oct 2006 15:56:28 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Problem with hashes
Message-Id: <4537e630$0$602$815e3792@news.qwest.net>
if ($_ =~ /Sub Report 1-1\D+:|Sub Report
2-1\D+:|number\D+:|SubMike wrote:
> I'm having a little bit of problems finishing up a previous co-workers
> perl project. I'm a little confused as to why its not working. What
> the script is doing is add values in a text file together (daily
> values) and add up the totals and throw it in a monthly total. I think
> there is something going on with the hashes, or entering the data into
> the hashes.
>
> (sorry for bad formatting in the newsgroup, I also changed some of the
> variables names and values)
Don't apologize for something you can correct. Use perltidy, or take the
time to format it for the hundreds (??) of people that are trying to
help you. Also, post code that actually compiles.
> if ($_ =~ /This is Header 1|This is Header
2|This is Header 3/) {
There isn't a line like "This is Header 1".. Note: Header doesn't match
header.
A bit shorter as:
if( /This is header [123]/ ) {
> if ($_ =~ /Sub Report 1-1\D+:|Sub Report
> 2-1\D+:|number\D+:|Sub
> Report 3-1\D+:)\s+(\d+)/) {
^
You're missing a '(' to go with that one.
It can be shorted a lot, however, look up what \D+ matches, or doesn't
match, and the use of a '+' and determine if it will match your data.
OK.. I'll answer that.. it doesn't match.
perldoc perlretut
A few "print" statements through your code will help YOU debug it yourself.
You could also use the perl debugger.
perldoc perldebtut
------------------------------
Date: Thu, 19 Oct 2006 16:09:05 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Problem with hashes
Message-Id: <4537e926$0$606$815e3792@news.qwest.net>
J. Gleixner wrote:
> Mike wrote:
>> if ($_ =~ /Sub Report 1-1\D+:|Sub Report
>> 2-1\D+:|number\D+:|Sub
Also, why is "number\D+:" in there? "number" doesn't exist in your data.
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 9868
***************************************