Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why do "\t" not work in a text string inserted into a Listbox

2 views
Skip to first unread message

Phiroze Parakh

unread,
Sep 26, 1998, 3:00:00 AM9/26/98
to
This has to be the coolest snippet of perl code that I have ever writen!
Yeah!!

if $s is the line of text then

$s =~ s/([^\t]*)\t/$1." "x(8-length($1)%8)/ge;

will replace all the tabs with spaces correctly inserted

On Sat, 26 Sep 1998, Graeme N Brown wrote:

> Dear list
>
> Can anyone explain why the following does not produce
> the result I expect ? My code fragment is
>
> #!/usr/bin/perl -w
> use strict ;
> use Tk ;
>
> my $MW = new MainWindow ;
> my $lb1 = $MW->Listbox(
> -selectmode => 'single',
> -width => 25,
> )->pack();
>
> $lb1->insert( 'end', "ABC\tGHI\tKLMNO") ;
> $lb1->insert( 'end', "FGH\tIJK") ;
>
> MainLoop ;
>
>
> I want to align groups of characters with Tab stops in
> each line of a Listbox, but apparently the "\t" are not interpreted as
> Tab characters but come out literally
> as '\t' viz.
>
> ABC\tGHI\tKLMO
> FGH\tIJK
>
> instead of
>
> ABC GHI KLMO
> FGH IJK
>
> Is there a way to achieve this ?
>
> TIA
> Graeme N Brown
> email: graeme...@btinternet.com
> ==========================================================================
> 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 majo...@lists.stanford.edu
>


...../\/\/\.../\....../\./\/\/\... phi...@engin.umich.edu
...../\..../\./\/\..../\./\..../\. phi...@eecs.umich.edu
...../\/\/\/\./\../\../\./\/\/\/\. UNIVERSITY OF MICHIGAN
...../\......./\..../\/\./\....... Electrical Engineering & Computer Science
...../\......./\....../\./\....... Advanced Computer Architecture Lab

-- Phiroze N. Parakh

And the mingling of the water in the earth
is just like the blood in the body of man

==========================================================================
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 majo...@lists.stanford.edu


Bob N.

unread,
Oct 22, 1998, 3:00:00 AM10/22/98
to
The problem is that $lb1->insert is not the same as print. It treats
non-printables (at least some of them) differently. For example, it
chokes on \0, while printing to the console doesn't (at least on Win95).
So the previous posters routine to expand tabs int space may be a
good solution.

If formatted output is your goal, using the Text widget may be better.

HTH

- Bob N.

:

Stephen O. Lidie

unread,
Oct 22, 1998, 3:00:00 AM10/22/98
to
Bob N. <bo...@interaccess.com> wrote:
> The problem is that $lb1->insert is not the same as print. It treats
> non-printables (at least some of them) differently. For example, it
> chokes on \0, while printing to the console doesn't (at least on Win95).
> So the previous posters routine to expand tabs int space may be a
> good solution.

> If formatted output is your goal, using the Text widget may be better.

I missed top-of-thread, but for columnar data you also next a fixed-width
font, not a proportional font.

0 new messages