Solved

Splitting the file with its values in perl

Posted on 2004-08-26
1
186 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now