Thurs Sep 18 * Questions? * Email was sent out to all of you. * Go over homework? * Use loops! * I have created my solutions ... but you should still try yourself. * do reverse order problem in class, end of chapter 6 ** part 1 : enter up to 20 numbers, print in reverse order ** part 2 : same, but remove duplicates and report count * start chapter 6 ? * part 1 : file input/output In all programming languages, we "open" files, "read" and "write" to them, and then "close" them when we're done. Almost just like reading to and from the command line. The details vary from language to language. print "hello"; is a shortcut for print STDOUT "hello"; NOTE: No comma after STDOUT (a file handle) NOTE: by conventions file handles are all capital letters. my $filename = "filename.txt"; open(INPUT, $filename) or die "Oops - couldn't open $filename $!"; Perl-isms * reading all lines at once, @lines = ; * Special filehandle reads stuff after __END__ or __DATA__ * The "it" (as in "print it") variable in perl: $_ * The filehandle: stuff after __END__ or __DATA__ * part 2 : "regular expressions" - string matching if ($line =~ m/foo/){ # if $line matches /foo/ # ... # do some stuff } * The version above is true if the letters "foo" are anywhere in $line. * string matching expressions are powerful but complicated; few languages pull them into the core syntax the way Perl does. ... I'm not sure we want to do as much with this here as the text does. We'll see. * input/output redirection $ perl yourProgram.pl < input.txt > output.txt