perl - Print 10 elements out of array -


this question has answer here:

if have array i've used create 50 random numbers, sort them numerically. lets wanted print out 10 biggest number (elements 40 50) say:

print($array[40]) print($array[41]) print($array[42]) etc etc. there neater way it? hope i'm making myself clear.

cheers

you loop on indexes.

say $array[$_] 40..49; 

offsets end make more sense here.

say $array[$_] -10..-1; 

you use array slice.

say @array[-10..-1]; 

to print them on 1 line, can use join.

say join ', ', @array[-10..-1]; 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -