nico io wrote:
>
> I have wrote this :
> s/(?<![0-9A-Za-z;])(\d+)(?!(\;\d+|\d+|\;\s+\d+\;\d+))/$hashTable{$1}/g
>  
> it works but when a number is not as a key of the hash table it replace
> the numer by nothing.
>  
> I would like to let the number if it doesn't belong to my hash table,
> how can I do ?

Please keep your posts confined to the perl.beginners group so that others can
both help and be helped by your questions.

Please bottom-post your responses to the perl.beginners group so that extended
threads remain comprehensible. Thank you.

You should always put

  use strict;
  use warnings;

at the start of your program, which would have given you a warning when missing
keys were substituted.

Your regex isn't clearly thought-out. For instance
/(\d+)(?!(\;\d+|\d+|\;\s+\d+\;\d+)/ says that the string can't be followed by a
semicolon and digits, or just digits, or a semicolon and whitespace and digits.
Because (/d+) is greedy and will consume all the digits available there is no
need to specify anything other than /(\d+)(?!;)/.

You can stop missing keys being substituted by making your replacement string an
expression. This should do what you want:

  $str =~ s/(?<![A-Z;])(\d+)(?!;)/ exists $hash{$1} ? $hash{$1} : $1 /gei;

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to