in reply to Chomping Frenzy question

my $s = "xyabcy*+!*+!*+!*+!*+!*+!"; $s =~ y/*+!//d;


From perlop :
if you want to use variables either in the SEARCHLIST or REPLACEMENTLIST , you must use an eval()

hth,
PooLpi

'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

Replies are listed 'Best First'.
Re^2: Chomping Frenzy question
by rovf (Priest) on Jul 10, 2008 at 14:18 UTC
    $s =~ y/*+!//d;

    This would replace all the characters in $s, not only those in the end, and it would replace them in any sequence - so this is not useable in my situation.

    -- 
    Ronald Fischer <ynnor@mm.st>
      $s =~ y/*+!//d;
      This would replace all the characters in $s, not only those in the end, and it would replace them in any sequence - so this is not useable in my situation.

      No, it wouldn't (remove any character).
      It removes any occurence of the characters '*', '+' and '!' (it's a use of the transliterate operator tr/// (same as y///). It doesn't care about the position of the characters.

      $ perl -e 'my $s = "xyabcy*+!*+!*+!*+!*+!*+!"; $s =~ y/*+!//d; print +$s, $/;' xyabcy $ perl -e 'my $s = "*+!xyabcy*+!*+!*+!*+!*+!*+!"; $s =~ y/*+!//d; pri +nt $s, $/;' xyabcy $

      I don't think, that tr/// or y/// can help you with your chomp problem.

      update: minor changes in text (... remove any char...)

        It removes any occurence of the characters '*', '+' and '!'

        Yes, that's what I meant. Sorry for being unclear. In any case, this is not a solution for my original problem.

        -- 
        Ronald Fischer <ynnor@mm.st>