Download presentation
Presentation is loading. Please wait.
1
Basic Input/Output Web Programming
2
Review: Perl Basics Perl Variables Standard Input Standard Output
Scalar holds number, character, string e.g. $var1 = “Mary”; $var2= 1; Array holds a list of scalars = (“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 Writing to 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.