Hello monks,

This seemingly simple problem frustrated me enough to sign up as a new user just to ask your opinions! I am no stranger to perl, but am a beginner incorporating TK into my scripts...

My problem is that I have a TK listbox which I am using to display search results of a database. The catch is that each result contains a "short title" and a "description", each of varying lengths. I want each line in the listbox to display the short title followed by the description. I can easily do this with various forms of concatenation, however the differing character lengths make for a "jagged" and ugly listing.

The obvious answer would be to use a tab (\t) in between, but the listbox doesn't seem to recognize escape sequences and instead displays their regex (xism?) equivalent?? I have looked everywhere for some listbox-specific tab, but as it doesn't use TK::text as a base I don't think it supports insertTab()? I don't see this problem when using ROText.

EXAMPLE:

my $text1 = "cherry\tred fruit"; my $text2 = "carrot\torange vegetable"; $lb->insert('end', $text1, $text2);
displays (literally):
cherry\x{9}red fruit carrot\x{9}orange vegetable
What is the "\x{9}"?? How do I use escape sequences / regex with listbox?? Thanks!!

Thanks for the input folks. sprintf was a good idea, but no luck; it still printed the \x{9} equivalent. I had briefly read about HList, but didn't want to go through the trouble of changing the widget. I think I'll try that now.

Until then, I have temporarily kludged it for our users haha:

my $string1 = "cherry"; my $string2 = "a red fruit"; my $spaces = 30 - length($string1); my $text = sprintf("%-${spaces}s\%s\%s",$string1,$string2);

In reply to TK listbox escape text by jbuck

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.