Solved

Splitting the file with its values in perl

Posted on 2004-08-26
1
213 Views
Last Modified: 2010-03-05
Hi Kandura,

Regarding the splitting of the file in perl, the previous o/p was correct but now I need the o/p in diff way.

1,9908,8754
2,9908,8755
3,9908,8756
4,9908,8757
5,9908,8758
6,9908,8759
7,9908,8760
8,9909,8750
9,9909,8751
10,9909,8752
11,9909,8753
12,9909,8754
13,9909,8755
14,9909,8758
15,9909,8759
16,9909,8760
17,9910,8754
18,9910,8755
19,9910,8756
20,9910,8757


Previously the o/p was
1,10
11,20

But I need the values also in the o/p...like for 1,10 i need values of 2 to 9, excluding 1 & 10. (tab delimitor used between values & code)

1,10,[tab][values of 2 to 9 (only five paires)]
[tab][remaining values]

e.g.

1,10,[tab]9908,8755,9908,8756,9908,8757,9908,8758,9908,8759,
[tab]9908,8760,9909,8750,9909,8751
11,20,[tab]9909,8754,9909,8755,9909,8758,9909,8759,9909,8760,
[tab]9910,8754,9910,8755,9910,8756

Thanks,
csp
0
Comment
Question by:radha_sudha
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 11909815
sub output{
    $one=shift;
    $ten=pop;
    my @p=map{/,(\d+),(\d+)/}@_;
    $p[10] =~s//\n\t/ if defined $p[10];
    print $one=~/(\d+)/,",",$ten=~/(\d+)/,",\t",(join",",@p),"\n";
}
my @a;
while( <> ){
    if( (push @a,$_) == 10 ){
        output @a;
        @a=();
    }
}
output @a if @a;
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question