Well, if I remember right, I think the system's volume info is restricted to administrator access, but I'm not sure. That section of your snippet worked on my computer; however, I'm running as Administrator so I'm not sure.

Next, a few suggestions. In your wanted subroutine, you use an if statement like this:

if (/^VCVARS32.BAT\z/s) { ... }

I'm pretty sure this is not what you want. /s makes . match any character INCLUDING newlines, and there most certainly won't be a newline where the . is. Try rewriting it as so:

if (/^VCVARS32\.BAT$/) { ... }

Next, your drive checking if statement seems a bit shiesty. Instead of checking Volume name ($x[0]), you might want to check Volume Serial Number (in your case, will be $x[2]) instead for more reliable results.

Since you are declaring the wanted subroutine inside the foreach loop, perl will scope the sub to that loop; that means it will be recreated at each pass. That will make it slow, so move it out. Finally, I assume the exit is there only for testing purposes...


In reply to Re: Two questions (two birds with one stone) by jryan
in thread Two questions (two birds with one stone) by Anonymous Monk

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.