A little introduction to Filename Globbing

There are many ways to interact over filenames. One of the most flexible is file globbing.

File globbing is a way to aquire filenames from your harddisk without having to run trought a directory tree. From the perlop manual:

If what's within the angle brackets is neither a filehandle nor a simple scalar variable containing a filehandle name, typeglob, or typeglob reference, it is interpreted as a filename pattern to be globbed, and either a list of filenames or the next filename in the list is returned, depending on context. This distinction is determined on syntactic grounds alone. That means "<$x>" is always a readline() from an indirect handle, but "<$hash{key}>" is always a glob(). That's because $x is a simple scalar variable, but $hash{key} is not--it's a hash element.

One level of double-quote interpretation is done first, but you can't say "<$foo>" because that's an indirect filehandle as explained in the previous paragraph. (In older versions of Perl, programmers would insert curly brackets to force interpretation as a filename glob: "<${foo}>". These days, it's considered cleaner to call the internal function directly as "glob($foo)", which is probably the right way to have done it in the first place.) For example:

while (<*.c>) { chmod 0644, $_; }

is roughly equivalent to:

open(FOO, "echo *.c | tr -s ' \t\r\f' '\\012\\012\\012\\012'|" +); while (<FOO>) { chomp; chmod 0644, $_; }

except that the globbing is actually done internally using the standard "File::Glob" extension. Of course, the shortest way to do the above is:

chmod 0644, <*.c>;

And that's it. I think you would like to take a deeper look at the perlop manual, and read more about this operator. Feel free to post a new question at Seekers of Perl Wisdom or ask me directly about this.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Just Another Perl Monk


In reply to Re: Re: Re: Re: Re: Overwrite file protection by monsieur_champs
in thread Overwrite file protection by Willman023

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.