In this script
#!/usr/bin/perl -w
use strict;
my @ar = (1,2,10,3,5);
@ar = sort {$a <=> $b} @ar;
does @ar now contain (1,2,3,5,10).
Now would I like to get the inverse array i.e. (4,6,7,8,9).
Any suggestions how that can be done?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When working with set operations, hashes work well:
If you will not know the bounds before hand, and would like to determine them from the min/max of
@ar, since its sorted that becomes easy: