unlink command: <$files> argument fails

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

$mydir = "/usr/myname" ;
$files = "$mydir/*.cc" ;

a)  unlink  <$files> ;   ===> fails
b)  unlink <$mydir/*.cc>   ==> works.

Why? What is the difference?


Re: unlink command: <$files> argument fails

On Fri, 31 Oct 2008 01:41:44 -0700, dn.perl@gmail.com wrote:
Quoted text here. Click to load it

You should always put

    use warnings;

as one of the first lines of your program.

Peter Scott
http://www.perlmedic.com /
http://www.perldebugged.com /

Re: unlink command: <$files> argument fails

On Fri, 31 Oct 2008 01:41:44 -0700 (PDT), "dn.perl@gmail.com"

Quoted text here. Click to load it
~$ perldoc -f unlink
       unlink LIST
       unlink  Deletes a list of files.  Returns the number of files
successfully deleted.

                   $cnt = unlink 'a', 'b', 'c';
                   unlink @goners;
                   unlink <*.bak>;

               Note: "unlink" will not attempt to delete directories unless you
are superuser
               and the -U flag is supplied to Perl.  Even if these conditions
are met, be
               warned that unlinking a directory can inflict damage on your
               Finally, using "unlink" on directories is not supported on many
operating sys-
               tems.  Use "rmdir" instead.

               If LIST is omitted, uses $_.

Why is it you ask somebody else to RTFM for you?


Re: unlink command: <$files> argument fails

Quoted text here. Click to load it

Quoted text here. Click to load it

Because finding the right FM to R is hard. What you quoted is of no
help. The right documentation to read is the 'I/O Operators' section
of 'perldoc perlop':

       If what the 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>" is always a glob(). That's
       because $x is a simple scalar variable, but $hash is not--it's a
       hash element.  Even "<$x >" (note the extra space) is treated as
       "glob("$x ")", not "readline($x)".


Site Timeline