in reply to return stripped characters

For instance:

$salutation =~ s/(\(.*?\))/$stripped .= $1;''/e;

Don't forget to predeclare $stripped.

Replies are listed 'Best First'.
Re^2: return stripped characters
by Roy Johnson (Monsignor) on Apr 26, 2005 at 15:43 UTC
    I would recommend avoiding the eval by assigning as a separate step:
    $salutation =~ s/(\(.*?\))// and $stripped = $1;
    or some such.

    Caution: Contents may have been coded under pressure.
      True. My mind was thinking of global substitutions.

      Or, to use a conditional if construct:

      my $stripped; $stripped = $1 if $salutation =~ s/(\(.*?\))//;

      This is functionally equivalent to the parent post, just a different style of expressing it.

      Update: I was trying to be too concise, thanks to tlm for pointing me to the error of my ways. Code has been updated to predeclare $stripped, since that is much more reliable than declaration and assignment in one step with a conditional.

      radiantmatrix
      require General::Disclaimer;
      s//2fde04abe76c036c9074586c1/; while(m/(.)/g){print substr(' ,JPacehklnorstu',hex($1),1)}

        Nope. (See NOTE at the end of the cited section.)

        the lowliest monk

Re^2: return stripped characters
by Anonymous Monk on Apr 26, 2005 at 15:44 UTC
    Hi sorry but I cannot get this to work
    $stripped=""; $salutation =~ s/(\(.*?\))/$stripped .= $1;''/e; print $stripped;
    $salutation is stripped as usual but $stripped is empty!
      It does work for me... What are you putting in $salutation?

      By the way, when I said "predeclare", I meant with my or our. I assume you're not using strict. You should.