Ahem. Your code (formatted)
my $call = `mminfo -r 'volume,state,written,%used,space,pool,location, +ssinsert' -q 'ssinsert <= three week ago`; foreach ($call) { if ( $call =~ /Daily\S+\s/) { print "Daily true $_ .\n"; } else { print "not found\n "; } }

raises a question. What is your backtick mminfo command giving back? a bunch of lines? If so, they are a single long string which you assign to $call. Then you iterate over that string, which gets aliased as $_ inside the loop, do a match and output just all the stuff your backtick command returned. The foreach loop is executed once.

Want to iterate over the lines your mminfo yields? Break that string up with split. Then your code would look like

my @calls = split /\r?\n/, `mminfo -r 'volume,state,written,%used,spac +e,pool,location,ssinsert' -q 'ssinsert <= three week ago`; foreach $call (@calls) { if ( $call =~ /Daily\S+\s/) { print "Daily true $call .\n"; } else { print "not found\n "; } }

<update> You can also say @calls = `cmd`, the output of cmd will be split with $/ (see perlvar).</update>

Another way to do that is using a pipe open:

my $cmd = 'mminfo -r 'volume,state,written,%used,space,pool,location,s +sinsert' -q 'ssinsert <= three week ago'; open CMD, "$cmd |" or die "Can't run '$cmd': $!\n"; while (<CMD>) { if (/Daily\S+\s/) { print "Daily true $_"; } else { print "not found\n "; } }

Use captures if you don't want the whole line but part of it, e.g.

if (/Daily(\S+)\s/) { print "Daily true $1\n"; }

See perlre, perlretut.

And append updates to your post, don't change the original content without a proper note, since you render the replies already given to you useless. Read the PerlMonks FAQ, section Posting on PerlMonks, there How do I change/delete my post?.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Match into scalar by shmem
in thread Match into scalar by gavintokyo

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.