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. | [reply] [d/l] |
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
| [reply] [d/l] [select] |
| [reply] [d/l] [select] |
Arghle.... ahum. Yes. Got carried away by substr, clearly. Thx for pointing that one out.
| [reply] |
| [reply] |
Assuming that each variable is a string containing no commas, you could do this:
@string = split(',',$string);
$newstring = join(',',@string[0..$#string-20]);
I'm assuming that $string contains all the variables concatenate together as in:
$string = "$a,$b,$c,....." | [reply] [d/l] [select] |
($a, $b, $c...) is a list and not a string, if that's the case, then you can pop them out of the array that you will put them in, if not, then your string would be like,
$string = "$a$b$c";
then you would have to check the length of the last 20 to substr your string to the desired length..
try to be more precise in your questions...
Update: jeroenes has already answered that...
He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
Chady | http://chady.net/ | [reply] [d/l] [select] |
$sentence="Error Problem in read_vhdl No designs were read DBR 011";
$sentence =~ s/[\w\s]{20}$//;
should be what you need.
Diarmuid | [reply] [d/l] |