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.


In reply to Re^3: Getting error while executing the script by ww
in thread Getting error while executing the script by arunkarthick

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.