in reply to Variable Removal From End of String

Your post is not really clear. Do you mean Array or String?

substr( $str, -20 )= ''; #string, removes chars splice( @array, -20 )= (); #array, removes scalars

Jeroen
"We are not alone"(FZ)
Update: Avoided double numbers by using the lvalue property of these functions.

Replies are listed 'Best First'.
Re: Re: Variable Removal From End of String
by cdherold (Monk) on May 01, 2001 at 11:49 UTC
    Apologies for the lack of clarity in the post (still new to this game)...

    I have an array ,@images, that I made into a scalar by the following method (my mistake on terming this a string if it is not) ...

    $links = join(",", @img), "\n";

    When I print $links out I get a list (a,b,c...etc). The size of this list is variable, but I wish to get rid of the last 20 components in every case.

    I tried to use the splice () option you suggested before joining @img into a scalar. I had compilation problems, however. More than likely I am doing it incorrectly ...

    Could you let me know?

    splice( @img, -20 )= @img; $links = join(",", @img), "\n";
    thanks for your patience,

    cdherold

(tye)Re: Variable Removal From End of String
by tye (Sage) on May 01, 2001 at 19:22 UTC
    splice( @array, -20 )= ();   #array, removes scalarsCan't modify splice in scalar assignment

    I don't think you tested that code. splice can't be assigned to. You instead want: splice @array, -20;

            - tye (but my friends call me "Tye")
      Arghle.... ahum. Yes. Got carried away by substr, clearly. Thx for pointing that one out.
Re: Re: Variable Removal From End of String
by cdherold (Monk) on May 01, 2001 at 12:00 UTC
    Never mind about the last post ... got it with splice(@img,-20);

    thanks very much for your and everyone else's help.

    cdherold