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

Can anyone explain this? An unquoted array only prints odd values?
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my $textb = $mw->Text->pack(); my $text = 'This answer is copyright ' . chr(169); my @array = (1..10); $textb->insert('end',@array); $textb->insert('end',"\n@array\n"); $textb->insert('end',$text); MainLoop;
Output:
13579 #??????? 1 2 3 4 5 6 7 8 9 10 This answer is copyright ©

I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re: weird problem inserting an array into a Tk text widget
by zentara (Cardinal) on Oct 16, 2008 at 12:00 UTC
    I'm guessing from the perldoc for Tk::Text, and it's insert method
    If multiple chars-tagList argument pairs are present, they produce the same effect as if a separate insert widget command had been issued for each pair, in order. The last tagList argument may be omitted.
    So possibly an unquoted array is interpreted as a set of char-tag pairs, so the tags (even numbers) don't get printed.

    First time I saw that glitch. :-)


    I'm not really a human, but I play one on earth Remember How Lucky You Are
      Indeed, 1st arg is index where to insert the text, 2nd is text, 3rd is tag, 4th is text 5th is tag - often used for text with non-trivial formatting...

      here is an excerpt from tk docs:

      pathName insert index chars ?tagList chars tagList ...? Inserts all of the chars arguments just before the character at index. + If index refers to the end of the text (the character after the last + newline) then the new text is inserted just before the last newline +instead. If there is a single chars argument and no tagList, then the + new text will receive any tags that are present on both the characte +r before and the character after the insertion point; if a tag is pre +sent on only one of these characters then it will not be applied to t +he new text. If tagList is specified then it consists of a list of ta +g names; the new characters will receive all of the tags in this list + and no others, regardless of the tags present around the insertion p +oint. If multiple chars-tagList argument pairs are present, they prod +uce the same effect as if a separate pathName insert widget command h +ad been issued for each pair, in order. The last tagList argument may + be omitted.