List Info

Thread: Regex




Regex
country flaguser name
United States
2007-06-04 02:06:51

I read in a file with 5 csc.

#!/usr/bin/perl
$expect=qr/([^,]+),([^,]+),([^,]),([^,]+),(^,]+)/;
foreach (<>){
$string=~/$expect/ and $rule=&quot;$1++,uc($2),uc($3),$4,uc($5),$1.$2&quot;;
print "$rulen";
}

But I get uninitialized values for $1,2,...

Here is the input file:

1,Vikash,BE,24,MP
2,Anshuman,Be,29,MH
3,Rajesh,mca,29,MH

What is wrong here ??

Thnx.

I know Karate, Kung fu and 47 other dangerous words.


---------------------------------
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre.

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: Regex
country flaguser name
United States
2007-06-04 07:27:23

Your regex was corrected, but I had suggested a modification. The output can
be compared.

$expect = qr{([0-9]+),([^,]+),([^,]+),([^,]+),([^,]+)};

foreach (<DATA&gt;){

chomp($_);

$_ =~ $expect;
$rule = "$1&#43;+,uc($2),uc($3),$4,uc($5),$1.$2";
print "kapil_output = $rulen&quot;;

$num = $1;
$rule = ++$num . ', ' . uc($2) . ', ' . uc($3) . ", $4, " . uc($5) . ",
$1$2";
print "other_output = $rulenn&quot;;
}

__DATA__
1,Vikash,BE,24,MP
2,Anshuman,Be,29,MH
3,Rajesh,mca,29,MH

HTH.

On 6/4/07, kapil v < aaaaax2003%40yahoo.com">aaaaax2003yahoo.com> wrote:
&gt;
> I read in a file with 5 csc.
>;
> #!/usr/bin/perl
>; $expect=qr/([^,]+),([^,]+),([^,]),([^,]+),(^,]+)/;
> foreach (<>){
> $string=~/$expect/ and $rule=&quot;$1++,uc($2),uc($3),$4,uc($5),$1.$2&quot;;
&gt; print "$rulen";
> }
>
> But I get uninitialized values for $1,2,...
>
>; Here is the input file:
&gt;
> 1,Vikash,BE,24,MP
> 2,Anshuman,Be,29,MH
> 3,Rajesh,mca,29,MH
>
>; What is wrong here ??
>
> Thnx.
&gt;
> I know Karate, Kung fu and 47 other dangerous words.
&gt;
>
> ---------------------------------
> To help you stay safe and secure online, we've developed the all new
> Yahoo! Security Centre.
>
> [Non-text portions of this message have been removed]
>
>;
>

--
Thiago Nascimento
perl -e '$_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while
s/(..)(.)//;print substr$_,1,1;'
&quot;...just because I don't know the meaning of my art, does not mean it has no
meaning..." S.D.

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: Regex
country flaguser name
United States
2007-06-04 10:15:38

If you're using CSV, why not use Text::CSV_XS:

use Data:umper;
use Text::CSV_XS;

open( my $fh, 'r', '/path/to/file')
or die "unable to read from /path/to/file: $!n";

my $csv = Text::CSV_XS->new();

while ( my $line = <$fh>; ) {
my $arrray_ref $csv->parse( $line );
print Dumper( $array_ref );
}
close $fh;

On Mon, Jun 04, 2007 at 08:06:51AM +0100, kapil v wrote:
&gt; I read in a file with 5 csc.
>;
> #!/usr/bin/perl
>; $expect=qr/([^,]+),([^,]+),([^,]),([^,]+),(^,]+)/;
> foreach (<>){
> $string=~/$expect/ and $rule=&quot;$1++,uc($2),uc($3),$4,uc($5),$1.$2&quot;;
&gt; print "$rulen";
> }
>
> But I get uninitialized values for $1,2,...
>
> Here is the input file:
&gt;
> 1,Vikash,BE,24,MP
> 2,Anshuman,Be,29,MH
> 3,Rajesh,mca,29,MH
>
> What is wrong here ??
>
> Thnx.
&gt;
> I know Karate, Kung fu and 47 other dangerous words.
&gt;
> ---------------------------------
> To help you stay safe and secure online, we've developed the all new
> Yahoo! Security Centre.
>
> [Non-text portions of this message have been removed]
>
>

--
Brad Lhotsky

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )