in reply to Re: String Length
in thread String Length

I think your suggestion may work. I guess the best way to approach this problem would be to get the length and if the length = 3 then use chomp and then substring the numeric charcter out of the string and pass it to a variable. Then the same would hold true for other similar situations?? TIA- ep

Replies are listed 'Best First'.
Re: Re: Re: String Length
by ton (Friar) on Apr 04, 2001 at 23:35 UTC
    actually, you should use chop twice. chomp only eats end of line characters (default are "\r\n"). chop eats whatever is there. Although I really think you should use a regexp instead, in case the last couple characters aren't "ST".
      What if I'm looking for "ST" or "TH" or "RD"? How would a regular expression help in this instance? ep
        This is crossing the line between our helping out and our doing your homework for you. Read perlre.

        (Aimed that the Anonymous Monk, not ep.)

        $string =~ s/(.*).{2}$/$1/;
        will take ANY two characters off of the end of the string.

        my $name = 'Ben Kittrell'; $name=~s/^(.+)\s(.).+$/\L$1$2/g; my $nick = 'tha' . $name . 'sta';