in reply to Re: How do I use regex to strip out specific characters in a string?
in thread How do I use regex to strip out specific characters in a string?

Doing it this way causes the creation of 7 temporary variables.

You also should use a tr when you are only trying to affect a single character:

tr/://d; # instead of s/://g;
runrig below gave you a very elegant solution using substr and tr

Replies are listed 'Best First'.
Re: Re: Re: How do I use regex to strip out specific characters in a string?
by dragonchild (Archbishop) on Aug 23, 2001 at 00:54 UTC
    I agree with the tr/// instead of the s///.

    But, the creation of temp variables shouldn't be an issue. But, if you're that concerned with the creation of temporary variables, just undef the variables after you're done. You could even combine the variables as such:

    { my @temp_variables; push @temp_variables, split ' ', $stamp; push @temp_variables, split '/', $temp_variable[1]; $temp_variables[2] =~ tr/://d; $stamp = join '_', @temp_variables[3,4,2]; undef @temp_variables; }

    ------
    /me wants to be the brightest bulb in the chandelier!

    Vote paco for President!

      Temporary variables can clutter things up, and cause confusion. You solution seems to start leaning more towards the confusing side as well. I know that I personally would want to see a good regular expression rather than a bunch of array slice uses.

      Perhaps it is just personal preference.

        I suspect it is personal preference. However, any time someone is using a regex to parse out a line of text, I start itching to rewrite. That's just getting too fancy-schmancy for maintainable code ... in my opinion. (I don't want to start a crusade here!)

        ------
        /me wants to be the brightest bulb in the chandelier!

        Vote paco for President!