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 ex04 directory
mkdir ex04- Go to your ex04 directory
cd ex04- 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!)Practice with numeric comparisons
perl> print 3 == 3 ; perl> print 349 == 5 ; perl> print 0+ (349 == 5) ; perl> print 349 > 5 ; perl> $float1 = 9.9997 ; perl> $float2 = 9.9995 ; perl> print $float1 == $float2 ; perl> print 0+ ($float1 == $float2) ; perl> print abs($float1 - $float2) < 0.001 ;(What do you think the 0+ part does?)
(What do you think the expression abs($float1 - $float2) < 0.001 is doing for us here?)Practice with string comparisons
perl> print 'hello' eq 'hello' ; perl> print 'hello' eq 'Hello' ; perl> print 0+ ('hello' eq 'Hello') ; perl> print 'hello' ne 'Hello' ; perl> print 'hello' gt 'Hello' ; perl> print 0+ ('hello' lt 'Hello') ; perl> print 'hello' ge 'Hello' ;Practice with boolean operators
perl> print 3 == 3 && 'hello' eq 'hello' ; perl> print 3 == 3 && 'hello' eq 'Hello' ; perl> print 0+ (3 == 3 && 'hello' eq 'Hello') ; perl> print 3 == 3 || 'hello' eq 'Hello' ; perl> print 0+ ('hello' eq 'Hello' || 3 == 4) ; perl> print ! ('hello' eq 'Hello' || 3 == 4) ; perl> print 0+ (! 'hello' gt 'Hello') ;Practice with true/false values in Perl
perl> if (1) { print "true" ; } else { print "false" ; } perl> if (100) { print "true" ; } else { print "false" ; } perl> if (-100) { print "true" ; } else { print "false" ; } perl> if (-1) { print "true" ; } else { print "false" ; } perl> if (0) { print "true" ; } else { print "false" ; } perl> if (0.0) { print "true" ; } else { print "false" ; } perl> if ("0") { print "true" ; } else { print "false" ; } perl> if ("00") { print "true" ; } else { print "false" ; } perl> if ('Red Sox') { print "true" ; } else { print "false" ; } perl> if ('') { print "true" ; } else { print "false" ; } perl> if (' ') { print "true" ; } else { print "false" ; } perl> if ('true') { print "true" ; } else { print "false" ; } perl> if ('false') { print "true" ; } else { print "false" ; } perl> if (undef) { print "true" ; } else { print "false" ; }Practice with user input
perl> print "Enter a whole number: " ; $user_val = <> ; perl> print "You entered: " . $user_val ; perl> print "Multiplied by 2: " . $user_val * 2 ; perl> print "Indeed, $user_val was the number that you entered!" ; perl> chomp($user_val) ; perl> print "Indeed, $user_val was the number that you entered!" ; perl> print "Enter a floating-point (decimal) number: " ; $user_dec1 = <> ; perl> print "Enter a floating-point (decimal) number: " ; $user_dec2 = <> ; perl> if (abs($user_dec1 - $user_dec2) < 0.0001) { print "They are (practically) equal." ; } else { print "They are sufficiently different." ; } perl> print "Enter a string: " ; $user_string = <> ; perl> chomp($user_string) ; perl> print "Your string repeated 5 times: " . $user_string x 5 ;(Why are we using the chomp function here?)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.