SPUG: Problem deleting files
Daniel Chetlin
daniel at chetlin.com
Fri Dec 1 11:44:38 CST 2000
On Fri, Dec 01, 2000 at 08:34:00AM -0800, Scott Blachowicz wrote:
> Yes, unlink takes a LIST of files and the <$oldfiles> should return a
> list of filenames matching the glob pattern contained in the $oldfiles
> var.
Because `<>' is overloaded in Perl, `<$oldfiles>' won't do what you'd
expect here.
[snip]
> It must not to variable expansion inside the globbing brackets, so you
> have to the expansion yourself by using "eval".
Well, no, not exactly. See perlop:
If angle brackets contain is a simple scalar variable (e.g.,
<$foo>), then that variable contains the name of the filehandle to
input from, or its typeglob, or a reference to the same. For
example:
$fh = \*STDIN;
$line = <$fh>;
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.)
I haven't used the `<>' form of globbing in years. Come to think of it,
I haven't used globbing in Perl at all in years. Generally readdir
and/or File::Find are much more robust, predictable, easy to use, and
Perlish.
-dlc
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list