These are the exercises and references for the third class of the course Dokumenthanteringen
#!/usr/local/bin/perl printf "Hello world!\n"; perl -e 'printf "Hello world!\n";'
@list1 = split(//,$lineOfText); # split $lineOfText in characters and # put result in @list1 @list2 = split(/\s/); # split $_ in words and # put result in @list2 split(/^/,$lineOfText); # split $lineOfText in lines and # put result in @_
if ($test<0) { printf "test is negative\n"; } elsif ($test == 0) { printf "test is zero\n"; } else { printf "test is positive\n"; } for (1..10) { printf $_; } for ($i=1; $i<=10; $i++) { printf $i; } for (@list) { printf $_; } foreach (keys %list) { printf $_; # print key printf $list{$_}; # print value } while ($number < 10) { $number = $number+1; }
while (/tets/) { # search for tets in $_ s/tets/test/; # replace tets in $_ by test $errorsFound = $errorsFound+1; # increase counter }
while (<STDIN>) { # read a line from standard input printf STDOUT $_; # print the line on standard output $linesRead = $linesRead+1; # increase line counter } if ($linesRead == 0) { printf STDERR "empty file!\n"; # print a warning message die; # stop the program } printf "%5.2f %-20s %d\n",33.97,"William Boney",17;
#!/usr/local/bin/perl $i = 0; # initialize argument counter to one $arg = shift(@ARGV); # put first argument in $arg while ($arg) { # repeat until $arg is empty $i++; # new argument: increase counter printf "Argument %d is %s\n",$i,$arg; $arg = shift(@ARGV); # put next argument in $arg }
#!/usr/local/bin/perl sub max { # start of definition of subroutine max $currentMax = @_[0]; # initialize current maximum for (@_) { # repeat for all arguments if ($_ > $currentMax) { # if the current argument is larger # than the current maximum then $currentMax = $_; # current maximum = current argument } } $currentMax; # return current maximum }
#!/usr/local/bin/perl -w use Tk; # include Tk toolkit use strict; # include strict my $mainWindow = new MainWindow; # make a window mainWindow $mainWindow->title('Test window'); # define the title of the window $mainWindow->Label(-text=>' Dokumenthantering VT97 ')->pack; # define a text in the window MainLoop; # start the main loop
The results of the exercises marked with * have to be handed in.
Now examine the MIF file. Find the codes for the lower case variants of the three Swedish vowels. Make a rough estimation of how many percent of the file is format markup (style definition?) and how many percent text and content type markup by finding out after how many percent the actual text starts (use the more command).
Examine the binary Frame file by loading it in emacs. You will see that the document contains a lot of zeroes and some recognizable text which sometimes is markup code. In UNIX there is a general program for extracting printable strings from a binary file: strings. Apply the program to the binary file. It will show all sequences of four or more printable characters. Do you think that is usable as a Frame to plain text converter?