[29704] in Perl-Users-Digest
Perl-Users Digest, Issue: 948 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 18 11:09:42 2007
Date: Thu, 18 Oct 2007 08:09: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, 18 Oct 2007 Volume: 11 Number: 948
Today's topics:
and perl integration <stefano.sabatini@caos.org>
how to capture exit value via pipe <ku996r@gmail.com>
Re: Is perl a good candidate for Data Mining <tadmc@seesig.invalid>
Re: Is perl a good candidate for Data Mining <stoupa@practisoft.cz>
Re: jabba the tuh <bik.mido@tiscalinet.it>
Re: line 16 <bik.mido@tiscalinet.it>
Need this $dir variable be replaced by the new one adde <hara.acharya@gmail.com>
Re: Need this $dir variable be replaced by the new one <josef.moellers@fujitsu-siemens.com>
Re: perl time function <josef.moellers@fujitsu-siemens.com>
Re: please help optimize sub <ulmai@gmx.de>
Re: please help optimize sub QoS@domain.invalid
Re: please help optimize sub QoS@domain.invalid
polymorphic regex -- encoding issue <dale.gerdemann@googlemail.com>
Re: polymorphic regex -- encoding issue <ben@morrow.me.uk>
Re: printing a subject line <bik.mido@tiscalinet.it>
Re: printing a subject line <bik.mido@tiscalinet.it>
Re: variable bewilderingly becomes undefined <dominique.dumont@hp.com>
Re: variable bewilderingly becomes undefined <taylor@metasyntax.net>
Re: variable bewilderingly becomes undefined <taylor@metasyntax.net>
Re: variable bewilderingly becomes undefined <taylor@metasyntax.net>
Re: variable bewilderingly becomes undefined <taylor@metasyntax.net>
Re: variable bewilderingly becomes undefined <taylor@metasyntax.net>
Re: variable bewilderingly becomes undefined <taylor@metasyntax.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 18 Oct 2007 15:29:06 +0200 (CEST)
From: Stefano Sabatini <stefano.sabatini@caos.org>
Subject: and perl integration
Message-Id: <slrnfhensv.i2b.stefano.sabatini@geppetto.reilabs.com>
Hi perlers,
there is a way to integrate nicely Perl code with Pod?
I love the Pod::Usage module very much, and I would like to do
something like this:
my $program_name=foo;
my $foo= 1;
...
=head1 NAME
$program_name - Foo and bazz all the bars of the world.
=head1 SYNOPSIS
$program_name <options> <input-file>
=head1 OPTIONS
=item B<--foo|-F>
Foo value to use when fooing (default is $foo).
=back
Is this possible (I think it isn't)? Can you suggest some way to
achieve the same effect (maybe with some other module)?
Many thanks in advance.
Regards.
--
Stefano Sabatini
Linux user number 337176 (see http://counter.li.org)
------------------------------
Date: Thu, 18 Oct 2007 07:50:58 -0700
From: ku916 <ku996r@gmail.com>
Subject: how to capture exit value via pipe
Message-Id: <1192719058.167293.104510@i13g2000prf.googlegroups.com>
I wrote a perl script that would read stdout and parse for particular
set of keywords, if found it will exit with error status.
sample cmd:
> sqlplus user/wrong_password @somesql.sql | perl_filter.pl
perl_filter.pl is my script
since we passed in <wrong_password> into sqlplus, perl_filter.pl will
parse the stdout (from sqlplus) and find the keyword (i.e. error) and
exit with non-zero value
but the problem I'm having now is that when the parent command itself
errors out how can perl_filter.pl catch the exit value ($?) viva pipe
like:
> sqlpus user/wrong_password @somesql.sql | perl_filter.pl
since there is no program called sqlpus, it will return non-zero exit
value, but perl_filter.pl would not detect any stdout keyword and it
will just exit and return success (zero) value.
any suggestions would be great help
Thanks
------------------------------
Date: Thu, 18 Oct 2007 10:51:36 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Is perl a good candidate for Data Mining
Message-Id: <slrnfhdglh.h6l.tadmc@tadmc30.sbcglobal.net>
Bo Yang <struggleyb@gmail.com> wrote:
> I am wondering is perl a good candidate for Data Mining?
Yes.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 18 Oct 2007 14:12:10 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Is perl a good candidate for Data Mining
Message-Id: <ff7j2d$204h$1@ns.felk.cvut.cz>
Bo Yang wrote:
> Hi,
> I am wondering is perl a good candidate for Data Mining? I intend to
> use Perl to analyze tons of data and fetch some useful informatino
> from them. Does perl designed for this?
> Thanks in advance!
>
Yes, Perl is a good candidate to this type of job. You can use any other
language which know RegExp but perl script is all time source code and you
must not to compile it before running. This is a big advantage in debug time
;-)
Possible other candidates are C (C++), Python, PHP, but PHP is not a good
idea for long run time.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Thu, 18 Oct 2007 11:51:10 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: jabba the tuh
Message-Id: <d1beh3hv20ckialcml9cn6a9ucfo6qdnm5@4ax.com>
On Wed, 17 Oct 2007 18:22:39 -0700, "Wade Ward" <zaxfuuq@invalid.net>
wrote:
>> Yeah, kidiots use it in that acceptation.
> [form.]
No, I did mean *acceptation*:
: 2. The meaning in which a word or expression is understood,
: or generally received; as, term is to be used according to
: its usual acceptation.
:
: My words, in common acceptation, Could never give
: this provocation. --Gay.
Or
: 2: the meaning of a word [syn: {word meaning}, {word sense}]
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 18 Oct 2007 11:54:04 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: line 16
Message-Id: <i7beh3hgvvpc54pksto6mcfbvtaq3sbij9@4ax.com>
On Wed, 17 Oct 2007 22:06:12 -0700, "Wade Ward" <zaxfuuq@invalid.net>
wrote:
>>> Testing for return values is a bit more than my current perl game.
>>
>> You should always test return values.
>> If you feel you are not competent enough to do that, then you should
>> hire someone else to do the programing for you.
>2 interpersonal normative statements, which are philosophically
>unintelligible.
>
>How do I test for return values?
Too many ways. A common one is the
or do_something; # idiom
But of course you can use an if-else construct instead.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 18 Oct 2007 12:09:50 -0000
From: king <hara.acharya@gmail.com>
Subject: Need this $dir variable be replaced by the new one added in windows.
Message-Id: <1192709390.610325.309670@t8g2000prg.googlegroups.com>
#!c:\Perl\bin\perl.exe
use Strict;
use File::Copy;
#use File::find;
$dir = "2.00.A07";
print "enter the name of the file to be copied:";
$file=<>;
chomp $file;
$filetobecopied = "//Builds/Prerelease/$dir/$file";
$newfile = "C:/PERL";
copy ($filetobecopied,$newfile) or print "file not found\n";
#find(\&wanted, @directories);
This $dir i.e 2.00.A07 is changing on daily basis.Means new
directories is getting added So how can this be detected that a new
dir has been added and the $dir will replaced by the new one.
------------------------------
Date: Thu, 18 Oct 2007 15:33:55 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Need this $dir variable be replaced by the new one added in windows.
Message-Id: <ff7nc7$n3a$1@nntp.fujitsu-siemens.com>
king wrote:
> #!c:\Perl\bin\perl.exe
> use Strict;
> use File::Copy;
> #use File::find;
> $dir =3D "2.00.A07";
> print "enter the name of the file to be copied:";
> $file=3D<>;
> chomp $file;
> $filetobecopied =3D "//Builds/Prerelease/$dir/$file";
>=20
> $newfile =3D "C:/PERL";
> copy ($filetobecopied,$newfile) or print "file not found\n";
>=20
> #find(\&wanted, @directories);
>=20
> This $dir i.e 2.00.A07 is changing on daily basis.Means new
> directories is getting added So how can this be detected that a new
> dir has been added and the $dir will replaced by the new one.
Use a globbing operator to get all names that match the directory name=20
pattern and then apply whatever algorithm is necessary to find the=20
latest one.
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Thu, 18 Oct 2007 10:48:46 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: perl time function
Message-Id: <ff76ll$r2b$1@nntp.fujitsu-siemens.com>
lerameur wrote:
> On Oct 17, 10:33 am, Josef Moellers <josef.moell...@fujitsu-
> siemens.com> wrote:
>=20
>>lerameur wrote:
>>
>>>Hello,
>>
>>>I know there are lot of function in perl.
>>>Can somebody tell me which function does the following:
>>>I have the : year, month, day, hours I want to increment the hours
>>>everytime the script is run. once the hours reaches 23 to 24 (actually=
>>>0), it will increment the days. My concerns are with leap years and
>>>months
>>
>>See Date::Calc (Add_Delta_YMDHMS).
[...]
> I used the same localtime I used, but I added hours+1 so that it
> output to another time variable and use that time to do my
> calculation.
This was my first solution as well (use POSIX::mktime to convert from=20
DMYhms to seconds, then add the delta, and then use localtime to convert =
back to DMYhms), but as others have pointed out, this doesn't take into=20
account leap seconds. If this is for a production system, you better=20
take care of this, or you may be called out of bed early one newyear's da=
y.
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Thu, 18 Oct 2007 10:00:16 +0200
From: Jan Pluntke <ulmai@gmx.de>
Subject: Re: please help optimize sub
Message-Id: <u8x6097jj.fsf@ID-18539.user.dfncis.de>
QoS@domain.invalid writes:
> Are there ways to have this execute faster using hashes or map functions?
> Any ideas on optimizing the following subroutine would be greatly appreciated.
Somehow, this has the reek of homework ...
> ========================================================================
> sub optimizeMePlease
> {
> my $input = $_[0];
> my $return;
> my @array = (
> 1.6931595338935, 5.07947860168049, 8.46579766946749,
> 11.8521167372545, 15.2384358050415, 18.6247548728285,
> 22.0110739406155, 25.3973930084025, 28.7837120761895,
> 32.1700311439765, 35.5563502117635, 38.9426692795505,
> 42.3289883473375, 45.7153074151245, 49.1016264829115,
> 52.4879455506985, 55.8742646184855, 59.2605836862725,
> 62.6469027540595, 66.0332218218465, 69.4195408896335,
> 72.8058599574205, 76.1921790252075, 79.5784980929945,
> 82.9648171607815, 86.3511362285685, 89.7374552963554,
> 93.1237743641424, 96.5100934319294, 100,
> );
>
> if ($input <= $array[0]) {
> $return = 29;
> }
> else {
> my $from = 1;
> foreach my $to (10, 20, 29) {
> if ($input <= $array[$to]) {
> foreach my $index ($from..$to) {
> if ($input <= $array[$index]) {
> $return = $index;
> last;
> }
> }
> last;
> }
> $from += 10;
> }
> }
> unless ($return) {
> warn "Invalid input value: [$input]\nUsing default!$!";
> $return = 29;
> }
> return ($return);
> }
This is not 100% exact, and you will need to check the special cases
( < $array[0], > $array[29]), but from the data I would assume that
int (($input - 1,6931595338935) / 3,38631906778700)
is what you are actually looking for ...
Regards,
Jan
------------------------------
Date: Thu, 18 Oct 2007 10:20:58 GMT
From: QoS@domain.invalid
Subject: Re: please help optimize sub
Message-Id: <esGRi.2783$pl2.399@trndny09>
Jan Pluntke <ulmai@gmx.de> wrote in message-id: <u8x6097jj.fsf@ID-18539.user.dfncis.de>
>
> QoS@domain.invalid writes:
>
> > Are there ways to have this execute faster using hashes or map functions?
> > Any ideas on optimizing the following subroutine would be greatly appreciated.
>
> Somehow, this has the reek of homework ...
Not homework, just trying to update a old script; the entire program can be
found on CPAN here:
http://www.cpan.org/authors/id/Q/QO/QOS/Accessories/LPCal_v1_1.plx
The sub is called 'assign image'.
>
> > =======================================================================> sub optimizeMePlease
> > {
> > my $input = $_[0];
> > my $return;
> > my @array = (
> > 1.6931595338935, 5.07947860168049, 8.46579766946749,
> > 11.8521167372545, 15.2384358050415, 18.6247548728285,
> > 22.0110739406155, 25.3973930084025, 28.7837120761895,
> > 32.1700311439765, 35.5563502117635, 38.9426692795505,
> > 42.3289883473375, 45.7153074151245, 49.1016264829115,
> > 52.4879455506985, 55.8742646184855, 59.2605836862725,
> > 62.6469027540595, 66.0332218218465, 69.4195408896335,
> > 72.8058599574205, 76.1921790252075, 79.5784980929945,
> > 82.9648171607815, 86.3511362285685, 89.7374552963554,
> > 93.1237743641424, 96.5100934319294, 100,
> > );
> >
> > if ($input <= $array[0]) {
> > $return = 29;
> > }
> > else {
> > my $from = 1;
> > foreach my $to (10, 20, 29) {
> > if ($input <= $array[$to]) {
> > foreach my $index ($from..$to) {
> > if ($input <= $array[$index]) {
> > $return = $index;
> > last;
> > }
> > }
> > last;
> > }
> > $from += 10;
> > }
> > }
> > unless ($return) {
> > warn "Invalid input value: [$input]\nUsing default!$!";
> > $return = 29;
> > }
> > return ($return);
> > }
>
> This is not 100% exact, and you will need to check the special cases
> ( < $array[0], > $array[29]), but from the data I would assume that
>
> int (($input - 1,6931595338935) / 3,38631906778700)
Hmm interesting, I will test this.
>
> is what you are actually looking for ...
>
> Regards,
> Jan
Thank you very much for your attention.
------------------------------
Date: Thu, 18 Oct 2007 10:23:02 GMT
From: QoS@domain.invalid
Subject: Re: please help optimize sub
Message-Id: <auGRi.2135$HU1.1536@trndny07>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message-id: <Xns99CCDA9215648asu1cornelledu@127.0.0.1>
>
> QoS@domain.invalid wrote in news:T9yRi.15082$fm1.8984@trnddc01:
>
> > sub optimizeMePlease
> > {
> > my $input = $_[0];
> > my $return;
> > my @array = (
> > 1.6931595338935, 5.07947860168049, 8.46579766946749,
> > 11.8521167372545, 15.2384358050415, 18.6247548728285,
> > 22.0110739406155, 25.3973930084025, 28.7837120761895,
> > 32.1700311439765, 35.5563502117635, 38.9426692795505,
> > 42.3289883473375, 45.7153074151245, 49.1016264829115,
> > 52.4879455506985, 55.8742646184855, 59.2605836862725,
> > 62.6469027540595, 66.0332218218465, 69.4195408896335,
> > 72.8058599574205, 76.1921790252075, 79.5784980929945,
> > 82.9648171607815, 86.3511362285685, 89.7374552963554,
> > 93.1237743641424, 96.5100934319294, 100,
> > );
>
> ...
>
> I first moved the definition of @array outside of the subroutine. That
> resulted in a speed-up of about 55% on my system.
>
> Sinan
>
> --
> A. Sinan Unur <1usa@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
> clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
Ah yes of course, the loading of the array must be alot of work, a tradoff
then.. memory for speed. Thank you for your attention.
------------------------------
Date: Thu, 18 Oct 2007 08:28:13 -0000
From: Dale <dale.gerdemann@googlemail.com>
Subject: polymorphic regex -- encoding issue
Message-Id: <1192696093.642008.237440@q5g2000prf.googlegroups.com>
Consider the following:
my $html_string =3D get "http://stock.narod.ru/fibo.htm";
my $russian_page =3D decode("cp1251", $html_string);
while ($russian_page =3D~ m/(=D0=A4=D0=B8=D0=B1=D0=BE=D0=BD=D0=B0=D1=87=D1=
=87=D0=B8)\s+\b(\w+)/g) {
print "$1 $2\n";
}
I get a CP1251-encoded page from a Russian site and search for words
that might follow the word =D0=A4=D0=B8=D0=B1=D0=BE=D0=BD=D0=B0=D1=87=D1=87=
=D0=B8 (Fibonacci). But isn't this bit
of code inefficient? I start right off by decoding the whole page,
where I really only need to have decoded those portions of the page
that match. So wouldn't it be better to encode the regex in CP1251 to
do the matching, and then convert any matched strings to the encoding
I want before printing out. Something like the following:
$russian_page =3D get "http://stock.narod.ru/fibo.htm";
my $search_word =3D encode("cp1251", "=D0=A4=D0=B8=D0=B1=D0=BE=D0=BD=D0=B0=
=D1=87=D1=87=D0=B8");
while ($russian_page =3D~ m/($search_word)\s+(\w+)/g) {
print decode("cp1251", "$1 $2\n");
}
This doesn't obviously fail, but it doesn't give the expected result
either. Presumably, the problem is that I've only encoded part of my
regex in CP1251. So the question is: Is there a way to change the
encoding of a regular expression?
A couple details:
Perl version:
5=2E8.8
Pragmas and modules used:
LWP::Simple
utf8;
Encode;
binmode(STDOUT, ":utf8");
------------------------------
Date: Thu, 18 Oct 2007 13:36:27 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: polymorphic regex -- encoding issue
Message-Id: <bj0ku4-881.ln1@osiris.mauzo.dyndns.org>
Quoth Dale <dale.gerdemann@googlemail.com>:
> Consider the following:
>
> my $html_string = get "http://stock.narod.ru/fibo.htm";
> my $russian_page = decode("cp1251", $html_string);
> while ($russian_page =~ m/(Фибоначчи)\s+\b(\w+)/g) {
> print "$1 $2\n";
> }
>
> I get a CP1251-encoded page from a Russian site and search for words
> that might follow the word Фибоначчи (Fibonacci). But isn't this bit
> of code inefficient? I start right off by decoding the whole page,
> where I really only need to have decoded those portions of the page
> that match. So wouldn't it be better to encode the regex in CP1251 to
> do the matching, and then convert any matched strings to the encoding
> I want before printing out. Something like the following:
>
> $russian_page = get "http://stock.narod.ru/fibo.htm";
> my $search_word = encode("cp1251", "Фибоначчи");
> while ($russian_page =~ m/($search_word)\s+(\w+)/g) {
> print decode("cp1251", "$1 $2\n");
> }
>
> This doesn't obviously fail, but it doesn't give the expected result
> either. Presumably, the problem is that I've only encoded part of my
> regex in CP1251. So the question is: Is there a way to change the
> encoding of a regular expression?
Nope, there isn't. All you can do is decode all the separate parts into
bytes, and then ask for a regex that matches by bytes.
At the very least you want a 'use bytes' around that regex and match.
You also need to be aware that perl will be doing a byte-by-byte match,
so if it's possible for part of a character to match (which depends on
the encoding: it is possible with UTF16, but not with UTF8, for
instance. I'm afraid I don't know about cp1251.) you will get false
positives. You also need to be sure that LWP is returning you the page
as bytes, and not trying to be clever and decoding it to UTF8 already. I
presume you already know that.
Unless you have an awful lot of these matches to do (and you know this
is what's slowing you down), it's not worth the bother.
Ben
------------------------------
Date: Thu, 18 Oct 2007 12:08:59 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: printing a subject line
Message-Id: <1nbeh3l0t3b73u3k9or9jv9dvk9h2l75f2@4ax.com>
On Wed, 17 Oct 2007 17:25:11 -0700, "Wade Ward" <zaxfuuq@invalid.net>
wrote:
>> Due to severe lack of time, I didn't read the whole code, but that
>> looks suspiscious: what is $_ at that point?!? Why should it contain
>> an arrayref? Suspect: didn't you by any chance think you're in a
>> C<for> loop or other construct creating an alias to $_, when in fact
>> you're not?
>On the one hand, a background in C is good for learning perl, OTOH, not so
>much.
Huh?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?
>I kept on whittling down the output until I got what I wanted. The debugger
I wouldn't regard that as a very good way of proceeding, where a
better one would be to have some idea of what one is doing, but if you
like that...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 18 Oct 2007 12:19:04 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: printing a subject line
Message-Id: <7kceh35npon4kgm38t5hd4h7dsuch8qko7@4ax.com>
On Wed, 17 Oct 2007 17:40:40 -0700, "Wade Ward" <zaxfuuq@invalid.net>
wrote:
>> Due to severe lack of time, I didn't read the whole code, but that
>> looks suspiscious: what is $_ at that point?!? Why should it contain
>> an arrayref? Suspect: didn't you by any chance think you're in a
>> C<for> loop or other construct creating an alias to $_, when in fact
>> you're not?
>Oh, and since you mention C and presumably know more Italian than I, can you
>help me translate this:
Huh?!? (Again) Where in hell did I ever mention C at all?!?
Re the translation: no, it's way too OT here. Write to me by email and
I may be so gentle as to translate that for you.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 18 Oct 2007 14:13:09 +0200
From: Dominique Dumont <dominique.dumont@hp.com>
Subject: Re: variable bewilderingly becomes undefined
Message-Id: <kgi8x608vu2.fsf@komarr.gre.hp.com>
Taylor Venable <taylor@metasyntax.net> writes:
> Hello all,
>
> I have some text in a file, that I'm scanning over and pulling out of
> columns for use in some graphs. One piece of the code, however, is
> bothering me because a variable seems to suddenly become undefined for no
> reason. Here's the code:
>
> my $i = 0;
> 385: while ($i < $timeMax + .01) {
> print "DOOD - timeMax undef!\n" if (not defined $timeMax);
> print "$i:$timeMax";
> unshift @xs, $i;
> unshift @ys, scalar (grep { $_ > $i && $_ < $i + 0.01 } @times);
> 390: $i += .01;
> }
>
> This is for a histogram graph, so I'm finding the number of entries in the
> data set that fall in the current range, starting at zero and going up
> until the maximum. I know it's not perfect, but for now I'd settle for any
> results period, because at the moment the output is:
>
> 0.35:0.380084
> 0.36:0.380084
> 0.37:0.380084
> 0.38:0.380084
> 0.39:0.380084
Given the value printed above, the program will exit the while loop at
the next test.
> Use of uninitialized value in addition (+) at ./stress.pl line 385,
> <$opt{...}> line 20.
> DOOD - timeMax undef!
Here the loop is re-run.
> Use of uninitialized value in concatenation (.) or string at ./stress.pl
> line 387, <$opt{...}> line 20.
> 0:Use of uninitialized value in addition (+) at ./stress.pl line 390,
> <$opt{...}> line 20.
>
> So it seems that $timeMax is suddenly undef'd while inside the loop.
I don't think so. Your program wandered somewhere else. You should
print $timeMax before entering the loop.
HTH
--
Dominique Dumont
"Delivering successful solutions requires giving people what they
need, not what they want." Kurt Bittner
------------------------------
Date: Thu, 18 Oct 2007 09:14:45 -0400
From: Taylor Venable <taylor@metasyntax.net>
Subject: Re: variable bewilderingly becomes undefined
Message-Id: <ff7m3s$6vu$1@registered.motzarella.org>
Dominique Dumont wrote:
> I don't think so. Your program wandered somewhere else. You should
> print $timeMax before entering the loop.
Hm, nope it's correct before the loop. And no other code is executed, it's
definitely still inside the loop when it goes awry.
------------------------------
Date: Thu, 18 Oct 2007 09:16:19 -0400
From: Taylor Venable <taylor@metasyntax.net>
Subject: Re: variable bewilderingly becomes undefined
Message-Id: <ff7m6p$6vu$2@registered.motzarella.org>
Brian McCauley wrote:
> What reason do you have to suspect it was ever defined?
Because (1) the conditional on it being not defined fails except for the
last time through the loop, and (2) a value gets printed,
namely "0.380084". I'm afraid I don't understand you. Is there something
else amiss here?
------------------------------
Date: Thu, 18 Oct 2007 09:18:33 -0400
From: Taylor Venable <taylor@metasyntax.net>
Subject: Re: variable bewilderingly becomes undefined
Message-Id: <ff7mb2$6vu$3@registered.motzarella.org>
Brian McCauley wrote:
> What do references have to do with the price of fish?
Yeah, you're right. What I was originally considering I think is not
possible.
> $timeMax is undef. This will happen if @timing is empty (or indeed if
> one element of @timing is undef and all the rest are negative, or...).
None of these are the case.
------------------------------
Date: Thu, 18 Oct 2007 09:19:18 -0400
From: Taylor Venable <taylor@metasyntax.net>
Subject: Re: variable bewilderingly becomes undefined
Message-Id: <ff7mcc$6vu$4@registered.motzarella.org>
Mumia W. wrote:
> What do you mean by parallelized?
Using multiple interpreter threads. But while this code is executed, there
is only one thread.
------------------------------
Date: Thu, 18 Oct 2007 09:20:28 -0400
From: Taylor Venable <taylor@metasyntax.net>
Subject: Re: variable bewilderingly becomes undefined
Message-Id: <ff7mei$6vu$5@registered.motzarella.org>
it_says_BALLS_on_your forehead wrote:
> what happens if you print Dumper( \@timing ) before and after each
> time your max sub is called?
When you dump out @timing you get exactly what I expect, the timing values
(formatted as floating point numbers) with carriage returns at the end.
Getting rid of the carriage returns did not change the outcome.
------------------------------
Date: Thu, 18 Oct 2007 09:27:43 -0400
From: Taylor Venable <taylor@metasyntax.net>
Subject: Re: variable bewilderingly becomes undefined
Message-Id: <ff7ms6$cc5$1@registered.motzarella.org>
Taylor Venable wrote:
> So it seems that $timeMax is suddenly undef'd while inside the loop. How
> can this be? The numbers I'm pulling from the file are at the end of the
> line and haven't been chomp()'d, but I wouldn't think that should matter.
Well, whatever was going on is gone now. I switched to using a for-loop
instead, corrected the logical error that the index variable $i was
incrementing .01 too high, and it's gone. Not sure why that would cause
this problem, and I can no longer reproduce. Extremely odd; oh well. I'm
going to switch to using R on the raw data anyway, we need more statistical
analysis than I care to write in Perl. Thanks for all the suggestions.
------------------------------
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 V11 Issue 948
**************************************