Re: How to remove [], {}, and other characters, rendering numeric values in a CSV file ?



Hi dear Yitzle:

Thank you very much for your great help :-)

Your perl code works great !

The problem was indeed from my side, since I was over-confident in the
(mis)use of blank space (a beginner sin)

But now your code works, thank to your helpful replies and I now i got
my a... neck covered

And Yitzle, I now own you one :-)

Thank you very much for all

Regards

Erasmo


On 26/06/2008, yitzle <yitzle@xxxxxxxxxxxxxxxxxxxxx> wrote:
On Thu, Jun 26, 2008 at 5:22 PM, <perez.erasmo@xxxxxxxxx> wrote:
Hi Yitzle:

Thank you very much for your suggestion:

Here is my perl file: clusters.pl

#! /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";
}

my input file (clusters.in) is:

cluster[1] = { 1 2 3 4 8 10 12 13 14 18 20 22 }
cluster[2] = { 5 6 7 11 17 }
cluster[3] = { 9 15 16 19 21 23 27 30 31 33 34 }
cluster[4] = { 24 25 26 28 29 32 }

When I input to the shell

bash-3.00$ ./clusters.pl clusters.in > clusters.out

I do get the following error message:

Quantifier follows nothing in regex; marked by <-- HERE in m/+ <--
HERE / at ./clusters.pl line 6.

and got nothing written at the output file

Where am I making the mistake ?

Am I wrongly invocating the perl code ?

Thank you for any help

Regards

Erasmo

If you look carefully, the code I pasted and the code you pasted are
not the same.
On line 6, /+/ ought to be / +/ (a missing space) and on line 5, "=
~/" ought to be "=~ /"

.



Relevant Pages