in reply to Newbee to Perl and the error
Since you are new to Perl, I can offer some advice about the code at the top of your script, namely:
First, I don't see how the $FILE variable is set to a value. Having said that, you probably don't need this variable at all because you can capture the command stdout directly to a Perl variable without bothering to save it to an intermediate file. Second, you can use the Perl built-in $^O variable to determine what system you are running on without needing to run the external uname command. Finally, it is good practice to always check the return code any time you run an external command. To illustrate the above points with some code:$SYS_NAME=`uname -s`; if ($SYS_NAME =~ "AIX") { $SYS_TYPE=1; `/usr/bin/df -k | /usr/bin/sort +6 >$FILE`; } # ...
Note further that you can replace:my @df_stdout; if ($^O =~ /aix/i) { $SYSTYPE=1; @df_stdout = `/usr/bin/df -k | /usr/bin/sort +6`; my $rc = $? >> 8; $rc == 0 or die "error: df command failed, rc=$rc"; } # ... for (@df_stdout) { # Put your while loop body here... }
above with:for (@df_stdout) {
to use an explicit variable ($line) rather than relying on $_.for my $line (@df_stdout) {
As for resources for learning Perl, I suggest you start by visiting learn.perl.org. And, as described in detail above by ELISHEVA, you should start all your scripts with use strict and use warnings.
|
|---|