我有这个 perl 脚本运行良好,输出显示在控制台中。但是,我的想法是重定向到一个文件....到目前为止,我能够完成一半的任务。除了在“sub writepage”中调用的两个子例程之外,我可以打印所有内容
有任何想法吗?
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw/strftime/;
#use warnings;
my $TOTALIOS = 'totalios';
my $READP = 'readpe';
my $CACHEP = 'cachehit';
my $CKBSEC = 'currentkb';
my $MKBSEC = 'maximumkb';
my $CIOSEC = 'currentio';
my $MIOSEC = 'maxio';
my $DATESTORE = 'dates.sec';
my $DATECMD = strftime "%m/%d/%y", localtime;
my $TIOS = 'Tios';
my $READp = 'readp';
my $CACHEp = 'cachep';
my $CKBsec = 'ckbsec';
my $MKBsec = 'mkbsec';
my $CIOsec = 'ciosec';
my $MIOsec = 'miosec';
my ($STORENUM, $STORENAME, $IMGPREFIX, $MONTH, $DAY, $YEAR) = &mysubinput;
#my $STORENUM;
#my $STORENAME;
#my $IMGPREFIX;
#my $MONTH;
#my $DAY;
#my $YEAR;
my $outfile = 'datastore.txt';
sub mysubinput
{
print "Enter the number for the datastore: \n";
my $STORENUM = <STDIN>;
chomp($STORENUM);
print "Enter the name for the datastore e.g: DataStore or ServerStore: \n";
my $STORENAME = <STDIN>;
chomp($STORENAME);
print "Enter the data store image prefix e.g. datastore or serverstore: \n";
my $IMGPREFIX = <STDIN>;
chomp($IMGPREFIX);
print "Enter the month MM: \n";
my $MONTH = <STDIN>;
chomp($MONTH);
print "Enter the day DD: \n";
my $DAY = <STDIN>;
chomp($DAY);
print "Enter the Year YYYY: \n";
my $YEAR = <STDIN>;
chomp($YEAR);
return ($STORENUM, $STORENAME, $IMGPREFIX, $MONTH, $DAY, $YEAR);
# print "$STORENUM $STORENAME $IMGPREFIX $MONTH $DAY $YEAR\n";
# print "Not a very interesting routine\n";
# print "This does the same thing every time\n";
# print "$TOTALIOS\n";
# print "Enter the number for the datastore: \n";
# $line = <STDIN>;
# chomp($line);
# print "$line\n";
# print "$DATECMD\n";
}
sub writedate
{
print "! $DATECMD\n";
}
sub writesections
{
print "| [[File:$STORENAME-$STORENUM-$TIOS-$MONTH-$DAY-$YEAR.png| 100px]]\n";
print "| [[File:$STORENAME-$STORENUM-$READp-$MONTH-$DAY-$YEAR.png| 100px]]\n";
print "| [[File:$STORENAME-$STORENUM-$CACHEp-$MONTH-$DAY-$YEAR.png| 100px]]\n";
print "| [[File:$STORENAME-$STORENUM-$CKBsec-$MONTH-$DAY-$YEAR.png| 100px]]\n";
print "| [[File:$STORENAME-$STORENUM-$MKBsec-$MONTH-$DAY-$YEAR.png| 100px]]\n";
print "| [[File:$STORENAME-$STORENUM-$CIOsec-$MONTH-$DAY-$YEAR.png| 100px]]\n";
print "| [[File:$STORENAME-$STORENUM-$MIOsec-$MONTH-$DAY-$YEAR.png| 100px]]\n";
}
sub writepage
{
open (FILE, ">> $outfile") || die "problem opening $outfile\n";
print FILE "Go back to [[MD3000i-Perf]] \n";
print FILE "{| border=1 cellspacing=5 cellpadding=2 style=text-align: center \n";
print FILE "|-\n";
print FILE "! [[DataStore-1]]\n";
print FILE "! [[DataStore-2]]\n";
print FILE "! [[DataStore-3]]\n";
print FILE "! [[DataStore-4]]\n";
print FILE "! [[DataStore-5]]\n";
print FILE "! [[DataStore-6]]\n";
print FILE "! [[DataStore-7]]\n";
print FILE "! [[DataStore-8]]\n";
print FILE "! [[DataStore-9]]\n";
print FILE "|-\n";
print FILE "| [[File:disk.png |60px]]\n";
print FILE "| [[File:disk.png |60px]]\n";
print FILE "| [[File:disk.png |60px]]\n";
print FILE "| [[File:disk.png |60px]]\n";
print FILE "| [[File:disk.png |60px]]\n";
print FILE "| [[File:disk.png |60px]]\n";
print FILE "| [[File:disk.png |60px]]\n";
print FILE "| [[File:disk.png |60px]]\n";
print FILE "| [[File:disk.png |60px]]\n";
print FILE "|}\n";
print FILE "{| border=1 cellspacing=5 cellpadding=2 style=text-align: center\n";
print FILE "|-\n";
print FILE writedate();
print FILE "|-\n";
print FILE writesections();
print FILE "|-}\n";
close(FILE);
}
#open (FILE, "> $myfile") || die "Couldn't open $myfile: $!\n";
#print FILE writepage();
#close (FILE);
writepage();