in reply to Re: Re: Re: Attempt to free unreferenced scalar...
in thread Attempt to free unreferenced scalar...

The first one ($fol_wzg_cel =~ s/<B6>/%B6/g;) works great, but the second ($fol_wzg_cel =~ /<(B6|B1|F3|A6|AC|D3)>/%$1/g;) does not because <B6>, <B1> and so on are single polish national letters, not just 4 characters...

But thanks again for simplifying my code :)

Q: Is there a possibbility to write someting like this: s/(a|b|c|d)/(1|2|3|4)/ ? It should substitute 1 for a, 2 for b, etc...

-- Daniellek

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Attempt to free unreferenced scalar...
by Fastolfe (Vicar) on Dec 11, 2000 at 19:46 UTC
    If you're dealing with single characters, you can use tr:
    tr/abcd/1234/;
    Otherwise a more complex way of doing that:
    my %tr = ( a => 1, b => 2, c => 3, d => 4 ); my $tr_keys = join('\E|\Q', keys %tr); s/(\Q$tr_keys\E)/$tr{$1}/g;
    The latter method has the benefit of being able to work with arbitrarily long strings instead of just single characters.