CS105 Perl: Introduction

advertisement
CS105 Perl: Introduction
Setting Up a CS Account.
• Get an account from the CS department.
• I highly recommend doing all assignments
on CS Unix machines.
– Environment in which assignments will be
graded.
• CS account comes with webspace.
– Needed for some assignments.
• CS department offers guest account.
Running Perl in Unix
• Three ways to run a perl program:
– Execute program stored in a file:
• variola% perl myfile.pl
– Execute as a single statement:
• variola% perl –e ‘print “Hello World.\n”;’
• Useful in determining if a statement will work.
– Execute as a script/shell program.
Execute as a Shell Program
• First line in the file must tell the OS where Perl is
located:
– #!/usr/bin/perl
• Each statement must end with a semicolon (;).
– In some cases the statement must be on one line.
• Comments begin with # and everything is case
sensitive.
• Must tell OS that the file is executable.
– chmod 700 mymove
– variola% mymove myfile.txt
Some Useful Options
• By default, Perl won’t give any warnings for
syntax or programming errors.
• It will try to “figure out” what you mean.
• This makes catching bugs hard.
• Check but don’t execute.
– variola% perl –c myfile.pl
– Useful for finding syntax errors.
• Check for common mistakes
– Variola% perl –w myfile.pl
– Check for common programming errors and
suspicious code.
Download