CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Sorting Columns

 



DaveC
Novice

Aug 30, 2002, 7:43 AM

Post #1 of 4 (1708 views)
Sorting Columns Can't Post

Is it possible to sort the columns of a text delimited file? See attached file and you will notice that for example all of the Netscape entries don't line up in the same column. What I would like to do is have all of the same software line up with each user.


(This post was edited by DaveC on Aug 30, 2002, 10:07 AM)


davorg
Thaumaturge

Aug 30, 2002, 9:05 AM

Post #2 of 4 (1705 views)
Re: [DaveC] Sorting Columns [In reply to] Can't Post

There was no attachment :)

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


DaveC
Novice

Aug 30, 2002, 9:58 AM

Post #3 of 4 (1704 views)
Re: [davorg] Sorting Columns [In reply to] Can't Post

oops
Attachments: test.txt (6.56 KB)


msds
User

Sep 3, 2002, 11:43 PM

Post #4 of 4 (1685 views)
Re: [davorg] Sorting Columns [In reply to] Can't Post

Smile Hello Dave!

I've been trying(Crazy) to write a script for this problem. Maybe I've gone about it all wrong, and the
code does nothing but juggle text all around,but anyway
here is the code.I have not taken all the text in the
file posted by DaveC(test.txt),but a portion of it: (File
attached)

use strict;
open SORT, 'newtest.txt' or die $!;

while(<SORT>){
chomp;
my @tokens=split;

$len=@tokens;
for($i=0;$i<=$len;$i++){
push @subtokens,$tokens[$i];
}
}

$leng=@subtokens;

#for($k=0;$k<=$leng;$k++){
#print"\n$subtokens[$k]";
#}

$delim="de";

for($l=0;$l<=$leng;$l++){
push @fields,split(/,/,$subtokens[$l]);
push @fields,$delim ;

}

$lens=@fields;
for($j=0;$j<=$lens;$j++){
#print"\n$fields[$j]";

$person=pop @fields;
print "\n$person";
}


close SORT;

The script gives the following as contents of $person :

de
de
de
AdobeAcrobat5.05.0
126MB
850MHz
MicrosoftWindows2000
PPD-65135
VidinhME
de
de
AdobeAcrobat5.05.0
126MB
1.0GHz
MicrosoftWindows2000
PPD-065156
RooplaVD
de
de
AdobeAcrobat5.05.0
126MB
850MHz
MicrosoftWindows2000
PPD-65130
PinterIJ
de
de
AdobeAcrobat5.05.0
126MB
850MHz
MicrosoftWindows2000
PPD-65240
GandhiB
de
de
AdobeAcrobat5.05.0
128MB
300MHz
MicrosoftWindows2000
PPD-054812
Deconism
de
de
AdobeAcrobat5.05.0
126MB
850MHz
MicrosoftWindows2000
PPD-65241
CorrivCA
de
de
AdobeAcrobat5.05.0
126MB
850MHz
MicrosoftWindows2000
PPD-65190
BernierH

Now, how do we go about displaying details of persons, one per line, and related fields of all persons sorted columnwise, like this, from the contents of $person?

BernierH PPD65190 Microsoft Windows2000 .....
CorrivCA PPD-65241 Microsoft Windows2000 .....
Deconism PPD054812 Microsoft Windows2000 .....
GandhiB PPD65240 Microsoft Windows2000 .....
.
.
.
.
Seems complicatedCrazyCrazy.
Would be happy to get this thing done.
Am waiting for ur reply.
Thanx,Smile
msds
Attachments: newtest.txt (0.50 KB)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives