LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-13-2012, 12:53 PM   #1
Trotel
LQ Newbie
 
Registered: Mar 2012
Posts: 16

Rep: Reputation: Disabled
Perl to order a list


Hi,

I want to order a list, my list is similar to this:
Code:
lrwxrwxrwx. 1 root root 62 Jun  4 21:54 fileA1 -> /.../ProgramA/fileA1
lrwxrwxrwx. 1 root root 46 Jun  5 09:06 fileA2 -> /.../ProgramA/fileA2
lrwxrwxrwx. 1 root root 63 Jun  4 21:54 fileB1 -> /.../ProgramB/bin/fileB1
lrwxrwxrwx. 1 root root 73 Jun 10 13:10 fileC1 -> /.../ProgramC/run/fileC1
lrwxrwxrwx. 1 root root 68 Jun 10 13:10 fileC2 -> /.../ProgramC/run/fileC2
lrwxrwxrwx. 1 root root 66 Jun 10 13:10 fileC3 -> /.../ProgramC/run/fileC3
I want to make a script that show me a reult like this (the name of the program: ProgramA, ProgramB .. alway they are on the 5 row)
Code:
ProgramA
fileA1     fileA2
ProgramB
fileB1
ProgramC
fileC1     fileC2
fileC3
I'm beginner so I only tried this:
Code:
@PROGRAMS = `ls -l /usr/local/bioinfo`;
print @PROGRAMS,"\n";
Well the list is bigger, and always I add more programs, how can I write a script that always show me all programs and its files?

Thanks

Last edited by Trotel; 06-13-2012 at 02:14 PM.
 
Old 06-13-2012, 05:27 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
You do not need 'ls'.

Put

Code:
use strict;
use warnings;
after the '#!/usr/bin/perl' or whatever else you have as the very first line of your script.

Read

http://perldoc.perl.org/functions/opendir.html
http://perldoc.perl.org/functions/readdir.html
http://perldoc.perl.org/functions/closedir.html
http://perldoc.perl.org/functions/-X.html <- http://perldoc.perl.org/search.html?q=file+tests
http://perldoc.perl.org/functions/sort.html
.

Hopefully the above will get you started.
 
Old 06-13-2012, 07:35 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
It's good that you showed a sample of the input data and what you want to get out of it. For our benefit, and even more for your own, it is helpful to include a verbal description of how the output is related to the the input. If it were me, I would say that you want a table where names matching 'Program*' are the keys, and names matching 'File*' are the values. You should especially explain how some 'File' records are spread across more that one line, while others are grouped on one line. Forcing yourself to describe the relationship between the input and output usually leads more directly to the method that solves the problem. With just a start and end as description of the problem, one can usually find many transformations that fit the example, but most will not work in the general case.

--- rod.
 
  


Reply

Tags
list, perl


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sort a list in decending order drone01 Linux - Newbie 9 09-29-2011 07:10 AM
ls -t and ls -lt list entries in the same order? stf92 Linux - Newbie 3 09-12-2011 03:17 AM
List 4 names from users list and output them to fbusers in numbered ascending order? fezzie Programming 4 02-10-2010 02:05 PM
How to list the 'chkconfig --list' in alphabetical order? thomas2004ch Linux - Newbie 3 01-08-2010 03:09 AM
Gen Hd List +pkg Order sajjadc Red Hat 0 10-10-2005 03:08 PM


All times are GMT -5. The time now is 12:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration