1 / 5

Basic Input/Output

Basic Input/Output. Review: Perl Basics. Perl Variables Scalar  holds number, character, string e.g. $var1 = “Mary”; $var2= 1; Array  holds a list of scalars e.g. @array1 = (“Mary”,”Tom”); Standard Input <STDIN>  reads 1 line from standard input e.g., $line= <STDIN>;

baakir
Télécharger la présentation

Basic Input/Output

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic Input/Output Web Programming

  2. Review: Perl Basics • Perl Variables • Scalar  holds number, character, string • e.g. $var1 = “Mary”; $var2= 1; • Array  holds a list of scalars • e.g. @array1 = (“Mary”,”Tom”); • Standard Input • <STDIN> reads 1 line from standard input • e.g., $line= <STDIN>; • Standard Output • print writes to standard output • e.g., print “My name is $name\n”; Web Programming

  3. File Input/Output • Reading from a file • open (INF,”$file1”);# open $file1 for reading • $line = <INF>;# read in one line • Writing to a file • open (OUTF, “>$file2”);# open $file2 for writing • open (OUTF, “>>$file2”);# open $file2 for appending • print OUTF “This is line1\n”;# print to $file2 • Closing a file after reading/writing • close (FILE); • Terminating program for bad file I/O • open (FILE,$file) || die “can’t read $file”; Example script Web Programming

  4. Determining File Status • Syntax • if ( -test $file ) { statements } • File test operators • -d : Is $file a directory? • -e : Does $file exist? • -f : Is $file is an ordinary file? • -l : Is $file a symbolic link? • -s : Is $file a non-empty file? • -z : Is $file an empty file? • -r/-w/-x : Is $file readable/writable/executable? Example script Web Programming

  5. Working with Directories • Open a directory • opendir (IND, $directory); • Read the contents. • @files = readdir (IND); • Close the directory • closedir (IND);  Example script Web Programming

More Related