For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > January 2005 > what does find return for a tk::canvas in scalar context









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author what does find return for a tk::canvas in scalar context
Christophe Mertz

2005-01-15, 8:56 pm

Hello,

Happy new year to all list members.

I just tested the value returned by a $canvas->find(...command...) in
scalar context.

In perl/tk 800, the returned value is the first item found
In perl/tk 804, the returned value is an array.

Is this considered as a bug, a bug correction or whatever else?
BTW, the Tk::Canvas man page is the same for both perl/tk version and
the man page is not very clear on the expected results in case of scalar
context


a simple test case:

use Tk;
use Tk::Canvas;

my $canvas = MainWindow->new()->Canvas()->pack;
$canvas->createRectangle(10,10,100,80, -tag => ['foo']);
my $canvasItem = $canvas->find('withtag','foo');

print "TkVersion=$Tk::VERSION canvas item is $canvasItem\n";


-- Christophe Mertz

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu

zentara

2005-01-16, 8:56 am

On Sat, 15 Jan 2005 21:51:02 +0000 (UTC), Christophe Mertz
<mertz@intuilab.com> wrote:

>Hello,
>
>Happy new year to all list members.
>
>I just tested the value returned by a $canvas->find(...command...) in
>scalar context.
>
>In perl/tk 800, the returned value is the first item found
>In perl/tk 804, the returned value is an array.
>
>Is this considered as a bug, a bug correction or whatever else?
>BTW, the Tk::Canvas man page is the same for both perl/tk version and
>the man page is not very clear on the expected results in case of scalar
>context
>
>
>a simple test case:
>
>use Tk;
>use Tk::Canvas;
>
>my $canvas = MainWindow->new()->Canvas()->pack;
>$canvas->createRectangle(10,10,100,80, -tag => ['foo']);
>my $canvasItem = $canvas->find('withtag','foo');
>
>print "TkVersion=$Tk::VERSION canvas item is $canvasItem\n";
>
>
>-- Christophe Mertz


I ran into a similar probem awhile ago. This is what slaven wrote:

########################################
##################
Interesting. This seems to be another scalar vs. array vs. arrayref
change between Tk800 and Tk804. Try the following code in Tk800 and
Tk804. The first one shows the stringified array reference, while the
second one shows the array.

perl -MTk -e '$txt = tkinit->Text->pack; $txt->insert("end", [1,2,3]);
+MainLoop'

So to be portable: always write

my($result) = $w->method

instead of

my $result = $w->method

(e.g. for Tk::Listbox::curselection)

and do not use the arrayref forms where it is possible (e.g. in
Tk::Canvas::createLine).



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Jack D.

2005-01-16, 8:57 pm


It has changed - but wasn't documented. A patch was issued a few months ago
to describe this change in the POD.

http://groups.google.ca/groups?selm...i.CC.Lehigh.EDU

Jack

> -----Original Message-----
> From: owner-ptk@lists.Stanford.EDU
> [mailto:owner-ptk@lists.Stanford.EDU] On Behalf Of Christophe Mertz
> Sent: January 15, 2005 1:03 PM
> To: ptk
> Subject: what does find return for a tk::canvas in scalar context
>
> Hello,
>
> Happy new year to all list members.
>
> I just tested the value returned by a
> $canvas->find(...command...) in scalar context.
>
> In perl/tk 800, the returned value is the first item found In
> perl/tk 804, the returned value is an array.
>
> Is this considered as a bug, a bug correction or whatever else?
> BTW, the Tk::Canvas man page is the same for both perl/tk
> version and the man page is not very clear on the expected
> results in case of scalar context
>
>
> a simple test case:
>
> use Tk;
> use Tk::Canvas;
>
> my $canvas = MainWindow->new()->Canvas()->pack;
> $canvas->createRectangle(10,10,100,80, -tag => ['foo']); my
> $canvasItem = $canvas->find('withtag','foo');
>
> print "TkVersion=$Tk::VERSION canvas item is $canvasItem\n";
>
>
> -- Christophe Mertz
>
> -++**==--++**==--++**==--++**==--++**==--++**==--++**==
> This message was posted through the Stanford campus mailing
> list server. If you wish to unsubscribe from this mailing
> list, send the message body of "unsubscribe ptk" to
> majordomo@lists.stanford.edu
>

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu

Christophe Mertz

2005-01-17, 3:58 pm

Thanks for your reply!

it will be helpfull.

Le Sun 16/01/2005 à 20:16, Jack D. a écrit :[color=darkred]
> It has changed - but wasn't documented. A patch was issued a few months ago
> to describe this change in the POD.
>
> http://groups.google.ca/groups?selm...i.CC.Lehigh.EDU
>
> Jack
>
-- Christophe Mertz

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com