The problem is the \ before the . in your regex.


On Mon, 30 Apr 2001 12:06:55 +0100, Gary Stainburn said:

> Hi all,
>  
>  can anyone tell me why the following code does not come out with 
>  '-123.45'.  It actually comes out with '123.45-'.
>  
>  I think that it is because it's treating it as a number at some point, 
>  but I can't see when/why.
>  
>  #!/usr/bin/perl -w
>   
>  my $vat='123.45CR';
>   
>  $vat=~s/(\.*)CR/-$1/i;


The regex means:
Find zero or more literal dots before the CR in the string.
Save these dots in $1.
Replace the dots and CR with a hyphen and the contents of $1 (the dots)

In your String there are no dots in front of CR. 
"\.*" will match because zero dots is perfectly OK.
So $1 will contain nothing and the hyphen will effectivly 
replace "CR".

I think what you want is:

$vat=~s/(.*)CR/-$1/i;

Now the dot matches any character.


>   
>  print "VAT='".$vat."'\n"; 
>  -- 
>  Gary Stainburn
>   
>  This email does not contain private or confidential material as it
>  may be snooped on by interested government parties for unknown
>  and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 
>      
>  

Hope this help,

cr

Reply via email to