Solved

Splitting the file with its values in perl

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rename outfile before writing 2 78
unable to remove invisible characters with perl 2 99
Exchange 2010 Transport Rule Regex 28 159
Perl Write to Specific line in a file 15 125
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

710 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