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



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

  • Re: Your opinion on large file processing
    ... the script below count word occurences in input file. ... hash structure to store unique words and its frequencies. ... use strict; ...
    (perl.beginners)
  • Your opinion on large file processing
    ... the script below count word occurences in input file. ... It uses simple hash structure to store unique words and its frequencies. ... use strict; ...
    (perl.beginners)
  • Re: GAWK fatal error if input file is a directory
    ... uncatchable error if it cannot open an input file. ... Who here has not done something like: gawk -f program * ... Soryy my first reaction is that if you care, put a shell wrapper ...
    (comp.lang.awk)
  • Re: UNIX Shell Program
    ... One file is an input file created by me and it will be as follows: ... And if a match founds ..then i have to place those names in some other ... I am thinking to write thisprogram in C shell .Is this shell Ok? ... Shell Scripting Recipes: | My code in this post, if any, ...
    (comp.unix.programmer)
  • Re: How to remove [], {}, and other characters, rendering numeric values in a CSV file ?
    ... use warnings; ... use strict; ... Am I wrongly invocating the perl code? ... the word "cluster" from the input file, ...
    (perl.beginners)