wow. never realized all such things at glance! this is DynamitePerl (maybe it is worth a new section..
;=) ).
Anyway, with the excuse of explaining your code to the OP, i'll try to describe it further with the hope to retain it in memory..
my @files = <*.txt>;
This is almost easy, but not completely. The clue is in a big section of
perlop concerning
IO Operators:
while speaking about diamond operator <>
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.
So,if no all glitter is gold, not all diamonds contain filehandle..
The keyword in the above sentece result to be
glob and in his own
manpage is stated:
This is the internal function implementing the <*.c> operator, but you can use it directly. If EXPR is omitted, $_ is used.
This lead to the second code:
#To process every line of those files one at a time, use:
{
local @ARGV = <*.txt>;
while( <> ) {
# $_ contains the lines of the files one at a time; for each f
+ile in turn
# To display file(line no): line for every .txt file in the cu
+rrent directory use:
chomp; print $ARGV, '(', $., '):', $_;
}
}
Docs state:
The null filehandle <> is special: it can be used to emulate the behavior of sed and awk, and any other Unix filter program that takes a list of filenames, doing the same to each line of input from all of them.
..
Here's how it works: the first time <> is evaluated, the @ARGV array is checked,..
..read also the missing part..
You can modify @ARGV before the first <> as long as the array ends up containing the list of filenames you really want.
So the first diamond is used on a (localized!) @ARGV to fill it whit a list of files created via glob and then the second diamond is that special one.
HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.