Home > Archive > PerlTk > October 2005 > Find problems with Linux
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 |
Find problems with Linux
|
|
| laurad 2005-10-18, 9:56 pm |
| Hi,
To begin with I am not going to include much code as my code is
extensive and it would be difficult to include enough parts to
demonstrate my problem. So I will have to make do with words.
Basically, I have been writing this code and testing it on Solaris with
a very old version of perl (5.005_03) and Tk version 8.0. There is
nothing I can do about these versions as I am on network. Funnily
enough though, I don't have any problems with my program using these
versions, probably because it was written specifically for it.
However we have a computer that runs Linux and has perl v5.8.5 and Tk
8.4. Now I am having problems. 90% of my program is fine. But then I
have created a canvas and I when I place the mouse over certain objects
I wish to find the closest widget to it and bring another dialog box up
about that widget.
So I use createoval and I place a tag on all the ovals called 'oval':
$oval[$i]=createOval($x1,$y1,$x2,$y2);
$canvas->addtag('oval','withtag',$oval[$i]);
I want to know the file attached to this oval as that is the
informationI wish to display inthe second dialogbox:
$datfile{$oval[$i]}=$fitsfile[$i];
I then use:
$canvas->bind("oval","<Button-1>",sub{
my $w=shift;
my $event=$w->XEvent;
my $tmp=$canvas->find(withtag=>'current');
print "tmp:$tmp\n";
print "$datfile{$tmp}"\n;
go do other stuff......
}
)
So when I run this is solaris the output I receive is:
tmp:390
and then the correct file for the appropriate oval.
However when I run this in Linux I get:
tmp:ARRAY(0x9e8b6fc)
and the hash does not recognise this as a key and hence cannot find the
appropriate file name.
Whey am I getting the correct key in Solaris and I get this strange
ARRAY in Linux? Do I have to do something different in LInux or is it
to do with the version of Perl that I am using.
I also tested this on X86 Solaris machine which has perl v5.6.1 and Tk
8.0 and it runs the same as the other Solaris machine.
It is very important that I get this running on the Linux machine so
any help would be greatly appreciated.
Sorry for the lack of code (and yes I am using warnings and strict). If
its really needed I can attempt to post some more but it would require
hacking my program into bits that make sense.
Thanks in advance,
Laura
| |
| thundergnat 2005-10-19, 6:57 pm |
| laurad wrote:
> I have been writing this code and testing it on Solaris with
> a very old version of perl (5.005_03) and Tk version 8.0. There is
> nothing I can do about these versions as I am on network. Funnily
> enough though, I don't have any problems with my program using these
> versions, probably because it was written specifically for it.
> However we have a computer that runs Linux and has perl v5.8.5 and Tk
> 8.4. Now I am having problems.
[snip]
> $canvas->bind("oval","<Button-1>",sub{
> my $w=shift;
> my $event=$w->XEvent;
> my $tmp=$canvas->find(withtag=>'current');
> print "tmp:$tmp\n";
> print "$datfile{$tmp}"\n;
> go do other stuff......
> }
> )
>
> So when I run this is solaris the output I receive is:
> tmp:390
> and then the correct file for the appropriate oval.
>
> However when I run this in Linux I get:
> tmp:ARRAY(0x9e8b6fc)
The problem is not with Linux, rather it is a difference
in how the different versions of Perl/Tk return values.
canvas->find returns a list. To make it cross compatible,
use an array variable and just work with the first value.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $top = MainWindow->new;
my $canvas = $top->Canvas->pack(-expand => 1, -fill => 'both');
my @oval;
for (0..9){
$oval[$_] = $canvas->createOval(
25 + $_ * 35, 25, 50 + $_ * 35, 50,
-fill => 'red'
);
$canvas->addtag('oval', 'withtag', $oval[$_]);
}
$canvas->bind('oval', '<Enter>' => sub{
my @tmp = $canvas->find(withtag => 'current');
print "tmp:$tmp[0]\n";
}
);
MainLoop;
__END__
|
|
|
|
|