Log in to users.cs.umb.edu
- Log in to a Windows machine
Enter your Unix username as the account name. Then enter your password.- Run the ssh client
Use the values in the table below to connect to users.
ssh configuration parameter value protocol ssh ssh version 2 ssh port 22 host users.cs.umb.edu user name your unix username Authentication method password - Enter your password
A dialog box will appear on the screen into which you must type the password for your Unix account.- Make sure you are in your home directory
cd- Go to your it441 directory
cd it441- Go to your ex directory
cd ex- Create an ex10 directory
mkdir ex10- Go to your ex10 directory
cd ex10- Execute the script command
script- Use your perlsession alias to start the re.pl script.
perlsession(NOTE: If the perlsession alias is not recognized, or if re.pl cannot run, then double-check your Perl configuration, as well as your login shell vs. subshell environments!)Array operations
perl> @months = ("January", "February") ; perl> foreach $m (@months) { print $m ; print "\n"; } perl> push @months, "March"; perl> push @months, "April"; perl> foreach $m (@months) { print $m ; print "\n"; } perl> push @months, "May"; perl> foreach $m (@months) { print $m ; print "\n"; } perl> print (shift @months) ; perl> foreach $m (@months) { print $m ; print "\n"; } perl> print (shift @months) ; perl> foreach $m (@months) { print $m ; print "\n"; } perl> unshift @months, "June"; perl> unshift @months, "July"; perl> foreach $m (@months) { print $m ; print "\n"; } perl> print (pop @months) ; perl> foreach $m (@months) { print $m ; print "\n"; } perl> print (pop @months) ; perl> foreach $m (@months) { print $m ; print "\n"; }(Take note of what push, pop, shift, and unshift are doing...)Other array usage
perl> print "Enter the number of the month you were born: "; chomp ($month =) ; perl> print "Enter year you were born: "; chomp ($year = ) ; perl> @months = qw/January February March April May June July August September October November December/ ; perl> @numDays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) ; perl> $numDaysCorrect = $numDays[$month-1] ; perl> if ($month==2 && $year%4==0) { $numDaysCorrect = 29 ; } perl> print ("$months[$month-1], $year has $numDaysCorrect days \n") ; Array sorting
perl> @words = ("decode", "paradise", "wonder", "absorbable", "charm", "ambulance", "fighting", "artificial", "playtime", "disqualified") ; perl> foreach $word (@words) { print $word ; print "\n"; } perl> @nums = (63, 26, 34, 72, 46, 83, 89, 52, 45, 24) ; perl> foreach $val (@nums) { print $val ; print "\n"; } perl> @sorted_nums_1 = sort @nums ; perl> foreach $val (@sorted_nums_1) { print $val ; print "\n"; } perl> @sorted_nums_2 = sort { $a <=> $b } @nums ; perl> foreach $val (@sorted_nums_2) { print $val ; print "\n"; }End the Perl Session
perl> exitEnd the script session
Use the exit command. You should then have a file called typescript in your current working directory.