Hi dear Yitzle and Perl list:

I have discovered that the number between square brackets [] won't be
only a one-digit number, but now it can contain an un-foreseen number
of digits, because the number inside the square brackets will grow
from 1 to several millions

As I have just stated, with a one-digit number, the script run
flawlessly, but now that the [number] grow of to millions, I have
problems again

How should I change the code in order to be able to remove the
previous mentioned characters ("cluster", {}, [], =, etc), but now
taking into account that [number] will grow, from 1 to millions ?

Thank you very much for your time and help

Kind regards

Erasmo


On 26/06/2008, yitzle <[EMAIL PROTECTED]> wrote:
> On Thu, Jun 26, 2008 at 3:28 PM, Erasmo Perez <[EMAIL PROTECTED]>
> wrote:
>> Hi dear list:
>>
>> Thank you very much for you great help in solving my past issue,
>> regarding the removing of the trailing commas and points.
>>
>> Thank you very much indeed :-)
>>
>> Now, my last (I hope) issue.
>>
>> I got another text file in the following format:
>>
>> cluster[1] = { 2 3 4 8 10 14 }
>> cluster[2] = { 25 26 29 32 }
>> cluster[3] = { 1 5 6 7 11 12 13 17 18 22 }
>> cluster[4] = { 9 19 21 23 24 27 28 30 31 33 34 }
>>
>> and I need to tranform it in a new CSV file that starts each line with
>> the "cluster" value (the square-brackets enclosed value), followed by
>> its {}-bracket enclosed list values (in the same order), as is shown
>> below:
>>
>> 1,2,3,4,8,10,14
>> 2,25,26,29,32
>> 3,1,5,6,7,11,12,13,17,18,22
>> 4,9,19,21,23,24,27,28,30,31,33,34
>>
>> How could I accomplish it using Perl ?
>>
>> How could I remove the square-brackets, the {}'s , the "=" sign and
>> the word "cluster" from the input file, rendering the same number
>> sequence, but now just separated by commas ?
>>
>> Thank you very much for your great help, it is _saving_ my neck in the job
>> :-)
>>
>> Regards
>>
>> Erasmo
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> while ( my $line =  <> ) {
>     $line =~ /cluster\[(\d)+\] = {([\d ]+)}/ or die;
>     my @vals = split( / +/, "$1 $2" );
>     print join(",", @vals) . "\n";
> }
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to