in reply to substr problem

I think substr is doing exactly what you're asking it to.

You've set the offset to -1. That means, "Start at the last character on the string." From the last character of the string to the last character + $length characters is still only going to return the last character.

What had you hoped to get instead?


_______________
D a m n D i r t y A p e
Home Node | Email

Replies are listed 'Best First'.
Re: Re: substr problem
by Anonymous Monk on Jul 13, 2002 at 18:19 UTC
    I was hoping to get a certain number($length) of characters from the end of the string.
    But using -$lenght returns "" regardless of $length.
      so what you need is:
      my $offset = -5; # or however many characters from the end # that you want my $new_string = substr $filename, $offset;

      UPDATE: You might also want to read this

      TStanley
      --------
      Never underestimate the power of very stupid people in large groups -- Anonymous