Ask a Question related to PERL Miscellaneous, Design and Development.
-
Janek Schleicher #1
Re: unlink full path to files
Tony wrote at Thu, 03 Jul 2003 15:40:43 +0000:
I doubt it.> I would like to use the full pathname with the unlink
> function but it doesn't seem to work that way?
> Is it possible or must you always be in the directory
> that the files are deleted from?
>
> This is perl, v5.6.1 built for i386-linux
>
> use strict;
> use warnings;
>
> These first two work,
>
> chdir '/floppy' or die "Can't cd to /floppy: $!\n";
> system("rm /floppy/@delete_files") == 0 or warn
> "Problem when system rm @delete_files: $!"; # works
That will only work if @delete_files contains only 1 element.
If @delete_files = ("a", "b") for example
"rm /floppy/@delete_files" is interpolated to
"rm /floppy/a b"
what is perhaps something different of what you wanted to achieve.
That try to do something lik> chdir '/floppy' or die "Can't cd to /floppy: $!\n";
> unlink @delete_files or warn
rm a b
(with @delete_files like above)
You might better try something like> "Problem when unlinking @delete_files: $!"; # works
unlink map "/floppy/$_", @delete_files or die "...";
Greetings,
Janek
Janek Schleicher Guest
-
Insert full path on browse file?
Don't suppose you could post that code here? :) -
full path name
I am a Windows programmer, so I got a very simple question regarding the full path name in Mac. I use MoreFiles library to convert a FSSpec to... -
Full path to the perl intrepter
I'm in a very old project and my scripts are calling other scripts. I have 3 or 4 different perl version in the server. I need to call the... -
Full path to the perl interpreter
the script are being called like /usr/local/bin/perl5.8.0/bin/perl -w /proj/xpto.pl I need the "/usr/local/bin/perl5.8.0/bin/perl" The usual... -
grabbing full path and file name
Is there a method of setting up a button on a form and browsing available drives to get the full path and file name. The function would be... -
Tad McClellan #2
Re: unlink full path to files
Tony <tony1911@hotmail.com> wrote:
>> I would like to use the full pathname with the unlink
> function
That will be fine.
> Is it possible
Yes.
> These don't work.
>
> chdir '/floppy' or die "Can't cd to /floppy: $!\n";
> unlink "/floppy/@delete_files" or warn
Try looking at what you are giving to unlink():
print "/floppy/@delete_files";
And you might see something like:
/floppy/file1 file2 file3
That is a single scalar, unlink wants a _list_.
that should one file named '/floppy/file1 file2 file3',
ie a filename with spaces in it.
> "Problem when unlinking @delete_files: $!"; # error
> No such file or directory at..
What you _want_ unlink to see is the list of absolute paths:
unlink '/floppy/file1', /floppy/file2', ...
You could get that with (untested):
unlink map { "/floppy/$_" } @delete_files;
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest
-
Gunnar Hjalmarsson #3
Re: unlink full path to files
Tony wrote:
Yes it does. You do not need to chdir to the directory where the files> I would like to use the full pathname with the unlink
> function but it doesn't seem to work that way?
to be deleted are.
---------^^^^^^^^^^^^^^^^^^^^^^^> These don't work.
>
> chdir '/floppy' or die "Can't cd to /floppy: $!\n";
> unlink "/floppy/@delete_files" or warn
If the array @delete_files would include the elements 'file1.txt' and
'file2.txt', that expression tries to do:
unlink '/floppy/file1.txt file2.txt'
which obviously cannot work.
You can try to just do this (chmod not necessary):
for (@delete_files) {
unlink "/floppy/$_" or warn $!;
}
--
Gunnar Hjalmarsson
Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
Gunnar Hjalmarsson Guest



Reply With Quote

