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 ex12 directory
mkdir ex12- Go to your ex12 directory
cd ex12- Execute the script command
script- Copy over .txt files
cp /home/ckelly/course_files/it441_files/*.txt ./- Copy over .pl files
cp /home/ckelly/course_files/it441_files/*.pl ./(NOTE: The file grab_ip.pl will not copy over because of permissions. This is ok. Running the ls command should confirm that other files copied over.)- 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!)The split function
perl> print ("Enter the word you wish to search for: "); perl> chomp($term = <STDIN>); perl> open ( INFILE , '<' , './gettysburg.txt' ) or die $!; perl> foreach (<INFILE>) { foreach $word (split) { if ($word eq $search) { print ("I found the word $search in the file \n"); last; } } } perl> close (INFILE);(What is the code foreach $word (split) doing here? Consider the context of the outer foreach loop.)Previous code -- see how it would look inside a script file!
perl> open ( PERLCODE , '<' , './readAndPrint1.pl' ) or die $!; perl> while (<PERLCODE>) { chomp $_ ; print "$_\n" ; } perl> close (PERLCODE);More split function
perl> open ( INFILE , '<' , './gettysburg.txt' ) or die $!; perl> $string = <INFILE>; perl> close (INFILE); perl> print $string; perl> @array = split (/,/ , $string); perl> foreach $part (@array) { print "$part\n" ; } perl> @words = split (/ /, $string); perl> foreach $word (@words) { print "$word\n" ; } perl> @lines = split (/\./, $string); perl> foreach $line (@lines) { print "$line\n" ; }(For the last one, do some of the lines look funny?)The join function
perl> @array = (1..9) ; perl> print @array; perl> $string = join (" ", @array); perl> print $string; perl> $string = join (",", @array); perl> print $string; perl> $string = join (", ", @array); perl> print $string; perl> @array = ("Billy", "Joel", "David", "Bowie") ; perl> print (join (", ", @array)); perl> print (join ("\n#####\n", @array));(The join function can be very useful, particularly with arrays!)First regex
perl> open ( INFILE , '<' , './alice.txt' ) or die $!; perl> foreach (<INFILE>) { if (/and/) { print "$_\n" ; } } perl> close (INFILE);(What is the code if (/and/) doing here? Consider the context of the default loop variable, which is known as $_)Previous code -- see how it would look inside a script file!
perl> open ( PERLCODE , '<' , './readAndPrint.pl' ) or die $!; perl> while (<PERLCODE>) { chomp $_ ; print "$_\n" ; } perl> close (PERLCODE);Regexes - Anchors (start and end of line)
perl> open ( INFILE , '<' , './alice.txt' ) or die $!; perl> @lines = <INFILE> ; perl> close (INFILE); perl> use Time::HiRes; perl> foreach $line (@lines) { if ($line =~ /^Alice/) { print "$line\n" ; Time::HiRes::sleep (0.1); } } perl> $DELAY = 0.5; perl> foreach $line (@lines) { if ($line =~ /^Alice did/) { print "$line\n" ; Time::HiRes::sleep ($DELAY); } } perl> $DELAY = 0.1; perl> foreach $line (@lines) { if ($line =~ /she$/) { print "$line\n" ; Time::HiRes::sleep ($DELAY); } } perl> $DELAY = 0.5; perl> foreach $line (@lines) { if ($line =~ /so she$/) { print "$line\n" ; Time::HiRes::sleep ($DELAY); } }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.