topical media & game development
basic-unix-17.txt / txt
Chapter 17
--------------------------------------
#!/usr/bin/perl -w
# Classic “Hello World” as done with Perl
print “Hello World!\n”;
--------------------------------------
#!/usr/bin/perl -w
# Create a file that will have a directory listing of user’s home dir
print “About to read user’s home directory\n”;
# open the home directory and read it
opendir(HOMEDIR, “.”);
@ls = readdir HOMEDIR;
closedir(HOMEDIR);
print “About to create file dirlist.txt with a directory listing of user’s
home dir\n”;
# open a file and write the directory listing to the file
open(FILE, “>dirlist.txt”);
foreach item .”\n”;
}
close(FILE);
print “All done\n\n”;
}
--------------------------------------
# Global variable name = Paul
# Enter our loop
foreach (@filedata) {
# declare a new variable for just the loop
my name
...
}
--------------------------------------
while ( counter . “\n”;
counter . “\n”;
counter < 10);
--------------------------------------
foreach temp . “\n”;
}
--------------------------------------
if ( name eq ‘Joe’) (
print “Hi Joe\n”;
} elsif (result;
# Next check for any input and then call the proper subroutine
# based on the test
if (@ARGV) {
# If the test condition for data from standard in is true run
# the test subroutine on the input data
ARGV[0].” has “.cmd_arg = cmd_arg =~ m/[0-9]/) {
return (‘numeric’);
} else {
# There was a error in the input; generate an error message
warn “Unknown input”;
}
}
sub error {
# There was no input; generate an error message and quit
die “Usage: check.pl, (<INPUT TO CHECK>)”;
}
--------------------------------------
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.