in reply to String Length

Oh poo, I'm gonna do a MeowChow here...

No regex needed as long as you're sure all will need last two chars removing. Here's an example.

# one way; my $day = '1ST'; my $num = substr ($day, 0, -2) print $num; # another, more fun way, if doing to $_; chop; chop; print; # so to print out a list for (@days) { print substr($_, 0, -2)."\n"; }

cLive ;-)

Replies are listed 'Best First'.
Re: Re: String Length
by buckaduck (Chaplain) on Apr 05, 2001 at 01:08 UTC
    As long as you're doing that, why not grab both the number and the suffix? It's not critical for this example, but as long as we're being picky...
    my $day = '1ST'; my $suffix = substr($day, -2, 2, ''); print $day; # "1" print $suffix; # "ST"
    buckaduck
      Why declare a variable just because we can? if it's not needed, there's no point...

      Also, $day is still "1ST", not "1" as you have not amended it.

      cLive ;-)