Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Splitting the file with its values in perl

Posted on 2004-08-26
1
Medium Priority
?
233 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 85

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
Six Sigma Control Plans

886 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