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
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
display content in file to listbox

Posted by wei (wei), 10 May 2007
Hi

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 ?

thanks

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();
$main->resizable(0,0);

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],
              -xscrollcommand=>['set',$xaxis]);
my $show = $main->Button(-text=>"show",-command=>\&show);
$show -> grid(-row=>4, -column=>1, -sticky=>'w');

MainLoop;

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

sub end
{
     exit(0);
}



This page is a thread posted to the opentalk forum at www.opentalk.org.uk 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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho