Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Perl Tk text widget printing problem

by reaper9187 (Scribe)
on Nov 14, 2012 at 14:25 UTC ( [id://1003813]=perlquestion: print w/replies, xml ) Need Help??

reaper9187 has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone,
I'm trying to develop this GUI that uses the perl Tk text widget to print certain values. However when i execute the print command for the text widget, i.e $txt->insert('end', "$worksheet->{Cells}[$row][$col]->{Val}"); the widget does not print the string. It only prints
TCH Drop: TCH Drop: TCH Drop:
I tried to check if the string was empty but it was not. I then output the string to the command window and got this result:
TCH Drop: A M J 0 0 1 B TCH Block: A M J 0 0 1 C TCH Drop: A M J 0 0 1 C TCH Block: B K T 0 0 1 A TCH Drop: B K T 0 0 1 A
I feel this has something to do with the structure of the string that is being passed although the actual string in the excel file looks something like BKT001A, AMJ001C, etc.. I'm new to perl and would really like some help with this problem... !!! Thanks ..!!!!!

Replies are listed 'Best First'.
Re: Perl Tk text widget printing problem
by zentara (Archbishop) on Nov 14, 2012 at 14:41 UTC
    I think your problem may be that Tk::Text's insert dosn't expect to have to dereference hashes. I would first try this:
    # $txt->insert('end', "$worksheet->{Cells}[$row][$col]->{Val}"); my $string = $worksheet->{Cells}[$row][$col]->{Val}; $txt->insert('end', $string);

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Perl Tk text widget printing problem
by thundergnat (Deacon) on Nov 14, 2012 at 15:41 UTC

    I agree with zentara; it looks like you are feeding insert a hash. See the following test code:

    use warnings; use strict; use Tk; my %w; my %hash = ( 'key1' => 'value1', 'key2' => 'value2' ); $w{mw} = MainWindow->new; $w{text} = $w{mw}->Text->pack; $w{text}->insert('end', %hash); $w{text}->insert('end', "\n\n" ); while ( my ($key, $value) = each %hash ){ $w{text}->insert('end', "$key => $value\n"); } MainLoop;
    Update: (after actual code snippet was posted) You are setting yourself up for trouble by accessing private internal data structures directly. Try using the accessor methods instead.

    $txt->insert('end', $worksheet->get_cell($row, $col)->value());
    Update 2:blarg. fixed broken hash iterator in demo code.
      Hi...
      thanks for helping .. works like a charm.. :) :)
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1003813]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-19 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found