-   Programming (
-   -   Perl to order a list (

Trotel 06-13-2012 12:53 PM

Perl to order a list

I want to order a list, my list is similar to this:

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)

fileA1    fileA2
fileC1    fileC2

I'm beginner so I only tried this:

@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?


Sergei Steshenko 06-13-2012 05:27 PM

You do not need 'ls'.



use strict;
use warnings;

after the '#!/usr/bin/perl' or whatever else you have as the very first line of your script.

Read <-

Hopefully the above will get you started.

theNbomr 06-13-2012 07:35 PM

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.

All times are GMT -5. The time now is 04:05 AM.