On Tue, 24 Sep 2002, David Samuelsson (PAC) wrote:
> I have an array with a lot of data.
>
> i want to remove certain elements from it:
> so i ran:
> for (@array){
> s/$current_user.*//;
> }
>
> nw when i print it, all $current user are gone as i wanted, but its a big space in
>the array instead.
> like:
>
> user1
> user1
> user2
> user2
>
>
>
> user4
> user4
> user4
> etc..
>
> how do i get the array to be without the spaces, i tried to remove all whitespaces
>with s/\s+/, that didnt seem to work, any ideas?
The loop variable (in this case $_) of a for loop is an alias of the array
varaible being processed (perldoc perlsyn). When you modify it with s///
the array variable is also changed, in this case to a zero length string.
This explains the spaces in your output. Instead of doing a s/// you can
do this
@array = grep {!/^$current_user.*$/} @array;
Anchor your regex, you don't want user1 matching user11 or user12...
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]