in reply to Re: last character in string ?
in thread last character in string ?

you suggested :

$date = substr($date,0,(length($date)-1)); # remove last char

It's worth noting that perl uses negative numbers to "count backwards" when dealing with string (and array, and probably many other surprising things) indexes, removing the need to do things like length($date)-1)). Code looks nicer and scans better for the effort.
See Piercer's code below.

Update : Wouldn't it be nice if push, pop and (un)shift worked on characters in a string? Yes, there's chop. that's true enough, but still.

Replies are listed 'Best First'.
Re: Perl that moves.
by demerphq (Chancellor) on Oct 01, 2001 at 19:44 UTC
    In regard to your update, you should check out Tie::CharArray

    :-)

    Yves
    --
    You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)

Re: Perl that moves.
by Amoe (Friar) on Oct 01, 2001 at 19:26 UTC
    @l=split(//,$date);pop(@l);foreach(@l){$r.=$_}print$r;

    What fun :)

    --
    my @words = grep({ref} @clever);
    sub version { print "I cuss your capitalist pig tendencies bad!\n" }
      Hi Amoe

      Just thought that someone should mention that your code could be written as so:

      @l=split//,$date;pop @l;print join"",@l;
      The two points I want to make are first, if you are trying to make your code as small as possible then often the parentheses can be left out (as well as trailing semicolons in a scope). Second that the foreach(@l){$r.=$_} is better written as $r=join"",@l;.

      Anyway,

      :-)

      Yves
      --
      You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)