Re: using file globs and regex
- From: Tad J McClellan <tadmc@xxxxxxxxxxxxxx>
- Date: Fri, 07 Aug 2009 16:05:15 -0500
[ Please do not top-post, you have been posting here long enough to know this ]
pgodfrin <pgodfrin@xxxxxxxxx> wrote:
This works fine: my($fn2) = grep ( $_ =~ '6' , glob 'f*');
If "fine" means put the first match into $fn2 and discard all
of the other matches, then it works.
What I'm confused about is the parens around the $fn2 ? Why are those
To provide a list context, as I mentioned in my first followup.
Something tells me that has something to do with making the
scalar $fn2 into a list 'cause that's what grep returns, but i can't
remember what that's called to look it up.
It is called "context". So you read about it in the "Context"
section of perldata.pod.
interpretation of operations and values in Perl sometimes depends
on the requirements of the context around the operation or value.
Assignment is a little bit special in that it uses its left argument
to determine the context for the right argument. Assignment to a
scalar evaluates the right-hand side in scalar context, while
assignment to an array or hash evaluates the righthand side in list
context. Assignment to a list (or slice, which is just a list
anyway) also evaluates the righthand side in list context.
[ snip upside-down quoted text ]
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
- Prev by Date: Re: Process to upload multiple files from a single <input type=file>
- Next by Date: Re: using file globs and regex
- Previous by thread: Re: using file globs and regex
- Next by thread: Re: using file globs and regex