[27342] in Perl-Users-Digest
Perl-Users Digest, Issue: 9051 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 14 14:05:41 2006
Date: Tue, 14 Mar 2006 11:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 14 Mar 2006 Volume: 10 Number: 9051
Today's topics:
Re: A Problem With GD <markem@airmail.net>
Re: debugging perl program with Tk mainloop <ngoc@yahoo.com>
Re: error when accessing hash of arrays xhoster@gmail.com
Re: error when accessing hash of arrays <no_spam@gmx.de>
Re: error when accessing hash of arrays <no_spam@gmx.de>
Re: error when accessing hash of arrays <1usa@llenroc.ude.invalid>
Re: error when accessing hash of arrays <tadmc@augustmail.com>
MAIL code error hope@hope.com
Re: MAIL code error <1usa@llenroc.ude.invalid>
Re: manipulating JPEG images <1usa@llenroc.ude.invalid>
Re: stack traces for warnings? <bugbear@trim_papermule.co.uk_trim>
Re: stack traces for warnings? <1usa@llenroc.ude.invalid>
Re: stack traces for warnings? <bugbear@trim_papermule.co.uk_trim>
Re: stack traces for warnings? xhoster@gmail.com
Re: stack traces for warnings? <1usa@llenroc.ude.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 14 Mar 2006 12:50:48 -0600
From: Mark Manning <markem@airmail.net>
Subject: Re: A Problem With GD
Message-Id: <121e4203g00m77f@corp.supernews.com>
Abigail wrote:
<code snipped for space>
I have to say that that is an absolutely wonderful program you wrote. I added
in a new line which reads "$v = ++$v % 2" and the results are:
$v = 1 - $v : 0.26 0.28 0.28 0.27 0.28 0.28
$v = ++$v % 2 : 0.33 0.33 0.31 0.33 0.31 0.32
$v = $v ? 0 : 1 : 0.33 0.33 0.33 0.34 0.33 0.33
$v = $set [$v] : 0.36 0.34 0.36 0.36 0.34 0.35
$v = !$v : 0.36 0.38 0.36 0.34 0.38 0.36
($v += 1) %= 2 : 0.36 0.39 0.39 0.39 0.39 0.38
$v = ($v + 1) % 2 : 0.39 0.39 0.38 0.39 0.39 0.39
$v = $$set [$v] : 0.39 0.39 0.38 0.41 0.39 0.39
$v = (1, 0) [$v] : 0.44 0.39 0.41 0.41 0.42 0.41
$v = [1, 0] -> [$v]: 2.23 2.19 2.30 2.23 2.25 2.24
I have found though that the times do vary quite dramatically depending upon
what else is running. The line I put in has, in some cases, dropped as far as
to be almost last and the "$v = ($v + 1) % 2" has (in one case) gone to second
place. Overall though, things tend to fall out as above. Interesting that the
"[1, 0]" is so slow. I am assuming that it is due to the setting up of the
array and then the destruction of that array.
------------------------------
Date: Tue, 14 Mar 2006 19:15:08 +0100
From: ngoc <ngoc@yahoo.com>
Subject: Re: debugging perl program with Tk mainloop
Message-Id: <K7edndS8WdH6ZIvZRVnzvA@telenor.com>
>
> 1. Learn what a callback is.
> 2. Learn what scope is.
> 3. Set a breakpoint inside a callback that has $variable_name in its scope.
>
A callback as in Master Perl/Tk is a subroutine to be called
Scope is inside or in the reach
But the problem here is
use Tk;
.................
$mw->Button (
-text => 'Add',
-command => \&add,
)->pack (-side => 'bottom', -anchor => 'sw', -pady => 3);
.........................
MainLoop;
sub add {
my $variable = &other_function;
}
So add() subroutine is a callback of -command. $variable is in the scope
of add().
To set breakpoint <DB1>b "line before end }" as you suggest (inside a
callback). And run <DB2>c
But It does not go over to <DB3> to type in "p $variable". It just goes
over when I click the exit button of the GUI.
------------------------------
Date: 14 Mar 2006 15:04:12 GMT
From: xhoster@gmail.com
Subject: Re: error when accessing hash of arrays
Message-Id: <20060314101029.758$Ml@newsreader.com>
Harald <no_spam@gmx.de> wrote:
> HI!
>
> I am a perl newbie and have a problem which can be reduced to the
> following:
>
> I have a hash-reference of a hash, which values are references to
> arrays. Now I want to know the length of the first value. I try it with:
Generally, hashes have no "first" value. Do you want the length of (the
array referenced by) an arbitrary entry?
>
> use strict;
>
> my $hash = {"A"=>[1,2,3,4], "B"=>[5,6,7,8]};
> my $length = $#{values(%{$hash})[0]};
> print $length;
Thank you for using strict, and for posting complete, runnable (well,
runnable other than the very syntax error which you were asking about)
code.
[0] is used to index into either an array or a list. But to index into
a list, the list must be paranthesized. In this case, your intended list
is not parenthesized. Move the '(' from just after to just before the
"values".
my $length = $#{(values %{$hash})[0]};
Now the list returned by values is a paranthesized and hence indexable
list, and it will work. (But it isn't the length, it is the index of the
last element, i.e. the length minus one.)
>
> But if I run it, perl says:
> ##############
> Global symbol "$length" requires explicit package name at t.pl line 5.
> Execution of t.pl aborted due to compilation errors.
> ##############
In my perl, I get the below syntax error first, then the above "requires
explicit package" on the next line. Are you sure that isn't the case for
you as well, and perhaps you are missing the first error statment?
Anyway, perl doesn't just stop at the first syntax error it sees. It tries
to go on to critique the rest of your code as well. But to do so, it has
to somehow recover from the syntax error. That recovery is rarely perfect,
and here one result of it is that it fails to record the "my"ing of
$length.
Generally, any errors or warnings reported after the occurence of a syntax
error are dubious.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 14 Mar 2006 16:54:58 +0100
From: Harald <no_spam@gmx.de>
Subject: Re: error when accessing hash of arrays
Message-Id: <dv6p0h$ggb$00$1@news.t-online.com>
Hello,
thanks for your reply.
In my problem all the arrays that are hashed are of the same length so I
am just interested in one arrays size. No matter which. So I will stick
with the solution of the other posters.
Thanks a lot for your reply and your comments. Perl becomes more and
more clearer.
but this does not work with my perl:
>
> my $length = @[ $hash->{A} ];
>
It works only with
my $length = @{ $hash->{A} };
Regards,
Harald
------------------------------
Date: Tue, 14 Mar 2006 17:02:36 +0100
From: Harald <no_spam@gmx.de>
Subject: Re: error when accessing hash of arrays
Message-Id: <dv6peq$p3r$02$1@news.t-online.com>
Hello.
Thanks a lot.
As far as I imagine I had tried it with different ways of ('s and )'s
but it did not work :-(
And no, the error message was produces just as I have printed it in my
first mail.
Regards,
Harald
------------------------------
Date: Tue, 14 Mar 2006 16:06:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: error when accessing hash of arrays
Message-Id: <Xns978671204D7E5asu1cornelledu@127.0.0.1>
Harald <no_spam@gmx.de> wrote in news:dv6p0h$ggb$00$1@news.t-online.com:
> but this does not work with my perl:
>
>>
>> my $length = @[ $hash->{A} ];
>>
>
> It works only with
> my $length = @{ $hash->{A} };
Of course, I was typing too fast for my own good. Thanks for catching
that.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 14 Mar 2006 11:44:09 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: error when accessing hash of arrays
Message-Id: <slrne1e079.e4s.tadmc@magna.augustmail.com>
Harald <no_spam@gmx.de> wrote:
> the error message was produces just as I have printed it in my
> first mail.
This is not email.
This is a Usenet newsgroup.
The difference matters.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 14 Mar 2006 17:23:27 GMT
From: hope@hope.com
Subject: MAIL code error
Message-Id: <flud121066op0o18unb6hps2gbccb12p3v@4ax.com>
Hi All
I have a test.cgi
When I run it with the strict mode I get this error
=========================
Bareword found where operator expected at test.cgi line 560, near "&o_0 MAIL"
(Missing operator before MAIL?)
syntax error at test.cgi line 560, near "&o_0 MAIL"
Execution of test.cgi aborted due to compilation errors.
============================
I cannot find the ref to near "&o_0 MAIL" at all
this is what is in line 560
line 560
open MAIL, "|$config{'mailprog'}";
print MAIL "To: $to\nFrom: $from\nSubject: $subject\n$message\n";
close MAIL;
I have done a search on the net but this is the only thing I can find
## open (MAIL,"|$config{'mailprog'}");
Missing ( ) BUT when I put that in and run it with Strict I get
=====================================
Bareword "MAIL" not allowed while "strict subs" in use at test.cgi line 560.
Execution of test.cgi aborted due to compilation errors.
=================================
SO what have I got wrong please
Thank you
------------------------------
Date: Tue, 14 Mar 2006 17:50:06 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: MAIL code error
Message-Id: <Xns978682ADFFBADasu1cornelledu@127.0.0.1>
hope@hope.com wrote in news:flud121066op0o18unb6hps2gbccb12p3v@4ax.com:
> =========================
> Bareword found where operator expected at test.cgi line 560, near
> "&o_0 MAIL"
> (Missing operator before MAIL?)
> syntax error at test.cgi line 560, near "&o_0 MAIL"
> Execution of test.cgi aborted due to compilation errors.
> ============================
>
> I cannot find the ref to near "&o_0 MAIL" at all
Not surprising.
> this is what is in line 560
>
> line 560
>
> open MAIL, "|$config{'mailprog'}";
What is in $config{mailprog}?
> print MAIL "To: $to\nFrom: $from\nSubject: $subject\n$message\n";
> close MAIL;
...
> SO what have I got wrong please
You have not posted a short, complete, self-contained program that
others can run easily.
Please consult the posting guidelines for information on not only how
you can help yourself, but also help others help you.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 14 Mar 2006 17:47:09 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: manipulating JPEG images
Message-Id: <Xns9786822E4DA2Aasu1cornelledu@127.0.0.1>
"Murray R. Van Luyn" <vanluynm@NOSPAM.iinet.net.au> wrote in
news:4416a1cf$0$23302$5a62ac22@per-qv1-newsreader-01.iinet.net.au:
> Date: Tue, 14 Mar 2006 19:07:43 -0800
Please fix the date on your computer.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 14 Mar 2006 14:23:37 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: stack traces for warnings?
Message-Id: <4416d1e9$0$3641$ed2e19e4@ptn-nntp-reader04.plus.net>
A. Sinan Unur wrote:
>>>perldoc Carp
>>
>>I'm already using this in my code; the warnings are comming
>>from perl's internals, and I wish to know where (I am...)
>>
>>I don't see how Carp applies to me question. If it does
>>I'm willing to have it explained.
>
>
> * You wrote both modules.
And the script :-)
>
> * The warnings are not capricious statements from the guts of Perl. They
> are emitted because you are passing or using uninitialized values in
> some routine in the module you created.
Yep. But I didn't mean to. It's a bug. I create those
every so often. I'm now looking to fix the bug,
and was hoping to use a stack trace to short cut
the search for the location of the bug so I can fix it.
> * So, check the arguments, and use cluck to report the condition before
> it is detected by Perl.
> * or, use the debugger. However, if your routine requires values to be
> passed to function correctly, you should check the arguments anyway.
I'll check out the debugger - I haven't seen many people referring to using
it, so I assumed it was poor. But I'll check.
BugBear
------------------------------
Date: Tue, 14 Mar 2006 14:37:01 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: stack traces for warnings?
Message-Id: <Xns978661F156832asu1cornelledu@127.0.0.1>
bugbear <bugbear@trim_papermule.co.uk_trim> wrote in
news:4416d1e9$0$3641$ed2e19e4@ptn-nntp-reader04.plus.net:
> A. Sinan Unur wrote:
>>>>perldoc Carp
>>>
>>>I'm already using this in my code; the warnings are comming
>>>from perl's internals, and I wish to know where (I am...)
>>>
>>>I don't see how Carp applies to me question. If it does
>>>I'm willing to have it explained.
>>
>>
>> * You wrote both modules.
>
> And the script :-)
>
>>
>> * The warnings are not capricious statements from the guts of Perl.
>> They are emitted because you are passing or using uninitialized
>> values in some routine in the module you created.
>
> Yep. But I didn't mean to. It's a bug. I create those
> every so often. I'm now looking to fix the bug,
> and was hoping to use a stack trace to short cut
> the search for the location of the bug so I can fix it.
>
>> * So, check the arguments, and use cluck to report the condition
>> before it is detected by Perl.
See also http://www.perl.com/pub/a/2002/05/07/mod_perl.html
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Tue, 14 Mar 2006 14:45:24 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: stack traces for warnings?
Message-Id: <4416d704$0$70282$ed2619ec@ptn-nntp-reader03.plus.net>
bugbear wrote:
>> * or, use the debugger. However, if your routine requires values to be
>> passed to function correctly, you should check the arguments anyway.
>
>
> I'll check out the debugger - I haven't seen many people referring to using
> it, so I assumed it was poor. But I'll check.
OK. I have a workable solution (thank god I'm not debugging
CGI).
I have added
use warnings FATAL => 'all';
to each of my modules/scripts. This promotes warnings
into errors.
Now running under the debugger
(perl -d scriptname <scriptargs>)
and simply hitting "c" to continue
runs my program until I hit the first
warning, which bombs the program out
into the debugger where I get a stack trace.
Problem solved and technique noted.
BugBear
------------------------------
Date: 14 Mar 2006 15:23:30 GMT
From: xhoster@gmail.com
Subject: Re: stack traces for warnings?
Message-Id: <20060314102948.181$Xb@newsreader.com>
bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> A. Sinan Unur wrote:
> >>>perldoc Carp
> >>
> >>I'm already using this in my code; the warnings are comming
> >>from perl's internals, and I wish to know where (I am...)
> >>
> >>I don't see how Carp applies to me question. If it does
> >>I'm willing to have it explained.
> >
> >
> > * You wrote both modules.
>
> And the script :-)
>
> >
> > * The warnings are not capricious statements from the guts of Perl.
> > They are emitted because you are passing or using uninitialized values
> > in some routine in the module you created.
>
> Yep. But I didn't mean to. It's a bug. I create those
> every so often. I'm now looking to fix the bug,
> and was hoping to use a stack trace to short cut
> the search for the location of the bug so I can fix it.
Since you are one of those people who creates bugs every now and
then, you should make the modules which you write and use tolerant
of people who create bugs every now and then.
The warning you are currently getting tells you where in the bottom
level module the error is coming from. So go insert a line just above that
one in your that bottom level module, and make it check for undefinedness
and then do whatever it should do to help people using this bottom level
module know what they did wrong. In other words, if you don't like Perl's
warning message, pre-empt it with your own.
>
> > * So, check the arguments, and use cluck to report the condition before
> > it is detected by Perl.
>
> > * or, use the debugger. However, if your routine requires values to be
> > passed to function correctly, you should check the arguments anyway.
>
> I'll check out the debugger - I haven't seen many people referring to
> using it, so I assumed it was poor. But I'll check.
In my opinion, it is poor, or at least it is usually more trouble than it
is worth to me. I prefer Sinan's first recommendation over the second one.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 14 Mar 2006 16:10:03 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: stack traces for warnings?
Message-Id: <Xns978671B6FF4A4asu1cornelledu@127.0.0.1>
xhoster@gmail.com wrote in news:20060314102948.181$Xb@newsreader.com:
> bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
>> A. Sinan Unur wrote:
...
>> > * So, check the arguments, and use cluck to report the condition
>> > before it is detected by Perl.
>>
>> > * or, use the debugger. However, if your routine requires values to
>> > be passed to function correctly, you should check the arguments
>> > anyway.
>>
>> I'll check out the debugger - I haven't seen many people referring to
>> using it, so I assumed it was poor. But I'll check.
>
> In my opinion, it is poor, or at least it is usually more trouble than
> it is worth to me. I prefer Sinan's first recommendation over the
> second one.
Me too ;-)
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
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 9051
***************************************