title: Trying to print one element of an array somehow prints all elements
body: <p>I am writing a script to take a list of integers from file <code>aryData</code>, sort them, print the sorted array, the highest value, and the lowest value.</p>
  
  <h3>aryData</h3>
  
  <pre><code>89 62 11 75 8 33 95 4
  </code></pre>
  
  <p>But when printing the highest or lowest value, all elements of the array are printed.</p>
  
  <p>This is my Perl code</p>
  
  <pre><code>#!/bin/perl
  
  use strict;
  use warnings;
  
  print "Enter filename to be sorted: ";
  my $filename = &lt;STDIN&gt;;
  chomp( $filename );
  
  open( INFILE, "&lt;$filename" );
  my @nums = &lt;INFILE&gt;;
  close INFILE;
  
  my @sorted = sort { $a cmp $b } @nums;
  
  open my $outfile, '&gt;', "HighLow.txt";
  
  print $outfile "Sorted numbers: @sorted";
  print $outfile "Smallest number: $sorted[0] \n";
  print $outfile "Largest number: $sorted[-1] \n";
  </code></pre>
  
  <h3>output <code>HighLow.txt</code></h3>
  
  <pre><code>Sorted numbers: 89 62 11 75 8 33 95 4
  Smallest number: 89 62 11 75 8 33 95 4
  Largest number: 89 62 11 75 8 33 95 4
  </code></pre>