469,328 Members | 1,316 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

How to remove the first two element from an array and more!

Hi...

I have two questions:

1)
I know I can use...
# shift() - which removes the first element of an array.

if I do this operation twice... I get my desired result.

But was wondering any effective way to do it... rather than the above method?

2)
How to sort a array that contains empty values, alphanuric values (strings) that have numbers, chars and few special chars ('.' and '@')?

Ex: @arry = ("12@arter"," ", "sort.kel","@demo.1","demo1 demo2");

Thankz in advance for looking
Nov 16 '07 #1
8 8837
KevinADC
4,059 Expert 2GB
Don't know if this is any better/worse than using shift twice:

Expand|Select|Wrap|Line Numbers
  1. @array = (1..10);
  2. @array = @array[2..#$array];
  3. print @array;
Nov 16 '07 #2
KevinADC
4,059 Expert 2GB
How to sort a array that contains empty values, alphanuric values (strings) that have numbers, chars and few special chars ('.' and '@')?
Sort or filter? If sort, sort how? If filter, filter how?

You can alwyas use a generic sort:

Expand|Select|Wrap|Line Numbers
  1. @array = sort @array;
  2. print @array;
But that is generally useless for mixed data.
Nov 16 '07 #3
Don't know if this is any better/worse than using shift twice:

Expand|Select|Wrap|Line Numbers
  1. @array = (1..10);
  2. @array = @array[2..#$array];
  3. print @array;
Thankz Kevin. Ya I understood what you were trying to do here.

But I read in the below site that it can be done in this way...
http://dev.perl.org/perl6/rfc/56.html

@shifted = shift @numbers, 3; # Take away the first 3 values...

But I don't know for some reason it is not working
Nov 16 '07 #4
Sort or filter? If sort, sort how? If filter, filter how?

You can alwyas use a generic sort:

Expand|Select|Wrap|Line Numbers
  1. @array = sort @array;
  2. print @array;
But that is generally useless for mixed data.
This sort is the one I usually use n also I use
' @newsortoutput = sort { $a <=> $b } @input;'

But because it is having some special chars, empty values.. it is giving some wired output. Am expecting first value to be empty, follwed by special chars, followed by alphanumeric values...
Nov 16 '07 #5
KevinADC
4,059 Expert 2GB
This sort is the one I usually use n also I use
' @newsortoutput = sort { $a <=> $b } @input;'

But because it is having some special chars, empty values.. it is giving some wired output. Am expecting first value to be empty, follwed by special chars, followed by alphanumeric values...
I need to see some of the data you are sorting and how you want it sorted.
Nov 17 '07 #6
KevinADC
4,059 Expert 2GB
Thankz Kevin. Ya I understood what you were trying to do here.

But I read in the below site that it can be done in this way...
http://dev.perl.org/perl6/rfc/56.html

@shifted = shift @numbers, 3; # Take away the first 3 values...

But I don't know for some reason it is not working

That is for perl 6. Are you using perl 6?
Nov 17 '07 #7
miller
1,089 Expert 1GB
I know I can use...
# shift() - which removes the first element of an array.

if I do this operation twice... I get my desired result.

But was wondering any effective way to do it... rather than the above method?
Check out splice.

- Miller
Nov 17 '07 #8
I agree with Kevin. Instead of using shift twice which might in one way increase a function call , its always a good option to use the assignment operator.
Nov 17 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

12 posts views Thread by Sam Collett | last post: by
11 posts views Thread by koperenkogel | last post: by
11 posts views Thread by Stefan Finzel | last post: by
4 posts views Thread by eksamor | last post: by
14 posts views Thread by oLgAa25 | last post: by
11 posts views Thread by Richard Maher | last post: by
3 posts views Thread by Barkingmadscot | last post: by
6 posts views Thread by tedpottel | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.