Introducing UNIX and Linux |
PerlOverview |
The DATA filehandleThe Worked exampleWrite a Perl script to read into an array
# Set variable i to count the lines of data read in
$i=0;
# Repeatedly read lines of data
while (<DATA>) {
# Remove the trailing newline character
chomp($_);
# Set the array value indexed by i to the line
$weekday[$i]=$_;
# Print the line on standard output
printf "$weekday[$i]\n";
# Increment i
$i++;
}
# The Perl program ends and the data follows
__END__
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
|
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck