$^O is MSWin32 under Windows (at least recent ones)... unfortunately, as Abigail points out above, using $^O turns out not to be a completely reliable way to determine whether the globbing behavior is safe. To take one simple example, some shells on MSWin32 (Cygwin bash) expand wildcards and others (MS-DOS) don't.

The thing is that I would like to be able to do something that Does What I Mean -- or more precisely, Does What A Potentially Naive User Means. I suspect that somebody who uses DOS/Win and is familiar with commands like copy *.txt \over_here would expect to be able to write munge *.txt and have it do what he'd expect, not report File not found: *.txt.

I suppose one kludgish approach would be to perform the globbing if ($filename =~ /[?*]/ && !-e $filename), for example. Since this particular munging process is non-destructive, there's probably no danger in trying to glob if and only if the filename passed in does not exist. (Yes, I realize that testing for /[?*]/ is a very DOS-centric approach because Unix shells may support more sophisticated wildcarding... this is just a "for example".)

Interesting that this turns out to be a harder problem to solve that it seemed at first. As Abigail says, the real answer is probably to use a globbing vs. a non-globbing shell. I was just hoping there would be a way to make the behavior essentially consistent across platforms and shells without requiring that much thought on the part of a user. (I guess that's what GUIs are for ;-)


In reply to Re: Re: portable globbing behavior for command-line tool by seattlejohn
in thread portable globbing behavior for command-line tool by seattlejohn

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.