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

Glad you got your problem fixed, though among other things I noticed that you could probably write this a little clearer:
while ($fol_wzg_cel =~ /<B6>/) {$fol_wzg_cel =~ s/<B6>/%B6/;} # as: $fol_wzg_cel =~ s/<B6>/%B6/g;
In addition, you could probably shrink all 6 of those lines into one regexp:
$fol_wzg_cel =~ /<(B6|B1|F3|A6|AC|D3)>/%$1/g;

Replies are listed 'Best First'.
Re: Re: Re: Re: Attempt to free unreferenced scalar...
by Daniellek (Sexton) on Dec 11, 2000 at 16:32 UTC
    Oh, yes, some day i needed it real FAST and made this in such "ugly" way and the forgot about it, I'll use your suggestion rigth now :)

    Thanks!

    -- Daniellek
Re: Re: Re: Re: Attempt to free unreferenced scalar...
by Daniellek (Sexton) on Dec 11, 2000 at 18:45 UTC
    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
      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.