Attempting to execute (with Perl 5.014) your script , as you presented it, results in:
syntax error ... near "} else"
syntax error ... near "}"
Execution of 976005.pl aborted due to compilation errors.
The first complaint relates to the use of } else inside the while ($DF > 50){. The second grows out of the first.
An if clause can use an else clause; while can't. You need to close the curly-brace of your while ($DF > 50){ before the } else (and that makes the brace at your line 38 redundant). You also need a verb such as print -- or say if you're using a recent Perl -- at your line 36. Consistently using indentation for if, when, while, unless (and so forth) would help make the missing } more obvious.
Avoiding blank lines between each line of code might also be helpful (which is not to suggest removing all blank lines. They're useful visual cues (to some of us, anyway) to program flow... that one stanza or function is ending and another beginning.
Including strict provides information about additional errors. But making those easily readable requires that you first use my with your variables, $OS, $FILESYSTEM and $DF so that the complaints that each $var "requires explicit package name at ..." don't swamp the most relevant (in thiscode) problem.
When you've done so, you'll learn that SunOS is a bareword. If you put it in quotes and use the numeric comparison operator, ==, your script will still fail. Try eq instead.
Finally, a general observation: while it's entirely possible and sometimes even useful to string a bunch of native OS commands together inside a Perl script, using `, system or </c>exec</c>, doing so can be the hard way to do things. You'd do well to explore Perl's own capabilities, and those found in modules in CPAN, such as "Filesys::Df"
Update: See also df equivolent in Perl.
Update 2: Several of the points here have been addressed by responders who were quicker to post than I but the fifth para (using strict directly after the italicized para) has now been updated re "readable" to explain the usage of "readable" which initially might have suggested that it's hard to read error message. That's not the point; the point was and is that finding the key error in a long string of error messages can require very careful attention. |