#!/usr/bin/perl -w # arrayplay.pl # 2002-03-20 22:10 CST # 2001-04-30 use strict; # using ternary op: my $donechar = $^O =~ /MSWin32/ ? 'CTRL+Z' : 'CTRL+D'; print "\n Enter words, follow each with .\n"; print " $donechar after final .\n\n"; # same thing, but with default val+if: # my $donechar = 'CTRL+D'; # $donechar = 'CTRL+Z' if ($^O eq 'MSWin32'); # print "\n Enter words, follow each with .\n"; # print " $donechar after final word+.\n\n"; chomp(my @words = ); print "\n ", $#words+1, " words entered.\n"; my $random = rand(@words); my $first = shift(@words); my $last = pop(@words); unshift(@words, $first); push(@words, $last); print " first entry: $first\n", " last entry: $last\n", " random entry: $words[$random]\n", "\n"; print " as entered:\n"; PrintList(@words); print " reverse order:\n"; my @reversed = reverse(@words); PrintList(@reversed); print " sorted alphabetically:\n"; my @sorted = sort(@words); PrintList(@sorted); print " reverse alphabetic:\n"; my @revalpha = reverse(@sorted); PrintList(@revalpha); if ($^O eq 'MSWin32') { print " Hit to exit."; ; exit; } sub PrintList { print " $_\n" for(@_); print "\n"; }