Can anyone help me resolving below mentioned problem

#!/usr/bin/perl
@data=N;
$sum=0;
print"enter the required No. of numbers to be inputed : f";
$N=<STDIN>;
print"enter the number";
for($i=0;$i<$N;$i+=1)
{$data[$i]=<STDIN>;
# chomp $data[$i];
$sum=$sum + $data[$i];}

# for($j=0;$j=$data[$i];$j+=1)
print"the entered numbers are",@data,"\n";
print"sum of the number:",$sum,"\n";
print"Average value the numbers:",$sum/$N,"\n";

@sorting=sort(@data);
$lengt=@data;
for ($j=0;$j < $lengt;$j++)
{# print $sorting[$j],"\n";
}

$X= (@sorting[($j-1)/2]+ @sorting[$j/2])/2;
print"the median is :$X";


Q:the median is the middle value if the numbers have been sorted in
ascending order (for even numbers of values it is your choice to pick
the first or second of the middle numbers

is this school work? If you are entering integers sort() will not work properly. That is a lexical sort in ASCII order, not numeric order. To properly sort numbers use: <=>

@sorted = sort {$a <=> $b} @unsorted;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.