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 ex06 directory
mkdir ex06- Go to your ex06 directory
cd ex06- 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 reading from a file
(If you do not have a .bashrc file in your home directory, then just substitute some other text file in your home directory. Or, really, any absolute path to a text file will do.)perl> open ( INA , '<' , '/home/your_username/.bashrc' ) or die $!; Replace your_username with your actual username on users.cs.umb.edu perl> while (<INA>) { print "$_" ; } perl> close INA;(What happens if you use ~ instead of typing out the absolute path to your home?)
(What happens if you just use the filename -- such as .bashrc -- on its own, without the absolute path?)Practice with writing to a file
perl> open ( OUT1 , '>' , './test_out.txt' ) or die $!; perl> print OUT1 "foo\n"; perl> print OUT1 "bar\n"; perl> print OUT1 "blech\n"; perl> close (OUT1);Now, let's look at the file's contents...
perl> open ( IN1 , '<' , './test_out.txt' ) or die $!; perl> print <IN1>; perl> close (IN1);(How is using the code print <IN1>; different from printing the file's contents using a while loop? Is it any different, in terms of the resulting output?)Writing to a pre-existing file
perl> open ( OUT2 , '>' , './test_out.txt' ) or die $!; perl> print OUT2 "first\n"; perl> print OUT2 "second\n"; perl> print OUT2 "third\n"; perl> print OUT2 "fourth\n"; perl> close (OUT2);Look at the file's contents...
perl> open ( IN2 , '<' , './test_out.txt' ) or die $!; perl> while (<IN2>) { chomp $_ ; print "$_\n" ; } perl> close IN2;(What happened?)
(Is any part of our while loop redundant? What part and why or why not?)Appending to a pre-existing file
perl> open ( OUT3 , '>>' , './test_out.txt' ) or die $!; perl> print OUT3 "5th\n"; perl> print OUT3 "6th\n"; perl> print OUT3 "7th\n"; perl> print OUT3 "8th\n"; perl> close (OUT3);Look at the file's contents...
perl> open ( IN3 , '<' , './test_out.txt' ) or die $!; perl> while (<IN3>) { chomp $_ ; print "$_\n" ; } perl> close IN3;(What happened?)
(Is any part of our while loop redundant? What part and why or why not?)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.