Use the qx operator, also known as backticks. For example my $out = `/usr/bin/amixer get Master`; will call that command and store its output in $out. Even better, use system and capture from IPC::System::Simple, that's got better error handling.

The manipulations you're currently doing with grep and awk can be done in Perl. If I understand correctly you want to get the first value that looks like a percentage. You could do this via e.g. my ($vol) = $out=~/\b(\d+)%/;

In your current code, $VolCur contains a value like "26%", when you add one to that you get a value of 27 (and a warning, which is why my code above doesn't grab the percentage sign into $vol), which you would need to add a percent sign to get amixer to accept it as a percentage value.

Lastly, I don't think your line system($VolCur); is doing anything useful, since it's just trying to call commands named after percentages... that's another reason why in general, you should always check for errors from system calls, see for example system on how to do that.


In reply to Re: Store system call in a variable by Anonymous Monk
in thread Store system call in a variable by amboxer21

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.