this is not working
here is an example of my file and I just want to replace with one
regexp
in file1 ddd ddd dddd by the value stored in my hash table
in file2 all d
in file3 not the first d; but all the others which is preceed by
WORD;
in all files
not replacing block like that d;d;dd
not replacing the 2 in WORD/WORD2;
file1
WORD/WORD2; d;d;dd; d;d;dd; d;d;d;
d;d;d; ddd ddd ddd ddd dddd
WORD/WORDWORD1/WORD1; d;d;dd; d;d;dd; d;d;d; d;d;d; ddd ddd
ddd ddd ddddd
file2
WORD; d; dd; dd; dd; d; d; d; dd; dd; d; ddd; ddd; ddd;
ddd; ddd; dddd;
file3
WORD/WORD1; d; d; ddd; dddd;
Thanks Rob if you can help
On 1 juil, 19:46, [EMAIL PROTECTED] (Rob Dixon) wrote:
> 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/