Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems

Phone System reconfiguration 11.1.2018 to 26.1.2018 - we are on email but incoming landline not available. Temp number 0797 4 925928
display content in file to listbox

Posted by wei (wei), 10 May 2007

i had execute a linux command to list all the file in /root and store the output in a file. When i open the file and print the content to a listbox which i had created, the content are not arrange properly.
as in
-rw------- 1 root root 123 Nov 1 12.00 a.txt
-rwxrwxrwx 1 root root 124 Dec 4 17.34 b.txt
i wish to show it in this format to make it nicer
-rw-------                 1 root root 123 Nov 1  12.00 a.txt
-rwxrwxrwx   1root root 124 Dec 3  17.34 b.txt

is there any method to print it in the second format ?


Posted by admin (Graham Ellis), 10 May 2007
Apart from one saying 4th December and the other saying 3rd, what's teh difference?   They look the same to me?   And, by the way, how's this a Perl question and how does it relate to a listbox??

Posted by wei (wei), 11 May 2007
This is my code...sorry coz i just started learning perl...i wanted to show the detail as displayed in the file but when it was shown in the listbox, each string in the line was separated by a specific amount of space...

#!/usr/bin/perl -w

use Tk;

my $main = new MainWindow();

my $list = $main->Listbox(-width=>60, -height=>10);
$list -> grid(-row=>2, -column=>1);
my $yaxis = $main->Scrollbar(-orient=>'v', -command=>[yview=>$list]);
$yaxis -> grid(-row=>2, -column=>2, -stick=>'ns');
my $xaxis = $main->Scrollbar(-orient=>'h', -command=>[xview=>$list]);
$xaxis -> grid(-row=>3, -column=>1, -stick=>'ew');
$list -> configure(-yscrollcommand=>['set',$yaxis],
my $show = $main->Button(-text=>"show",-command=>\&show);
$show -> grid(-row=>4, -column=>1, -sticky=>'w');


sub show
     $list -> delete('0.1','end');
     my $display = `ls -l /root > to.log`;
     open FILE, "to.log";
           my $line = $_;
           $list -> insert('end',$line);
     close FILE;

sub end

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho