perl.beginners
[Top] [All Lists]

Re: How to remove [], {}, and other characters, rendering numeric values

Subject: Re: How to remove [], {}, and other characters, rendering numeric values in a CSV file ?
From: yitzle@xxxxxxxxxxxxxxxxxxxxx (Yitzle)
Date: Thu, 26 Jun 2008 17:32:22 -0400
Newsgroups: perl.beginners

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 "=~ /"

<Prev in Thread] Current Thread [Next in Thread>