I create an array of files in the directory (@dirs_and_files).
After that I try to write a file "/home/joao/PERLFOLDERTESTE/fff
with the contents of the directory.
The problem is that I get this error:
"error opening file /home/joao/FOLDERTESTE/fff: Ficheiro ou directoria inexistente at direx1 line 17.".
But I'm sure the file exists and I verified the full path with the 'pwd' command.
Can anyone give me some help?
THis is my code:
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl
- use File::Util;
- my($f) = File::Util->new();
- my(@dirs_and_files) = $f->list_dir('/home/joao/PERLFOLDER','--files-only');
- $file = '/home/joao/FOLDERTESTE/fff';
- foreach $d (@dirs_and_files) {
- open ('$file') or die "error opening file $file: $!";
- print $file $d;
- close ($file) or die;
- }
João