Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Splitting the file with its values in perl

Posted on 2004-08-26
1
Medium Priority
?
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Six Sigma Control Plans

660 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