| |||||||||||
| |||||||||||
display content in file to listbox Posted by wei (wei), 10 May 2007 Hii 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.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |