in reply to Re: Opening Unknown Filenames
in thread Opening Unknown Filenames

I just tried to do it your way, but had no success. Instead i tried writing it like below, but now i am stuck with the fact that i get the error 'No such file or directory' and the code doesn't run with taint!
#! /usr/bin/perl my $directory = '/var/log/cr_user/'; opendir DIR, $directory or die $!.$/; my @files = readdir(DIR); closedir DIR or warn $!.$/; for my $file (@files) { open FILE, $file or die $!.$/; my ( $username, $domain, $email, $service ) = split /,/, <FILE>; print "$username"; close FILE or warn $!.$/; unlink $file; }

Replies are listed 'Best First'.
Re: Re: Re: Opening Unknown Filenames
by chromatic (Archbishop) on Jul 05, 2003 at 17:01 UTC

    The filenames returned from readdir are relative. You can either chdir to the directory or add the file path:

    chdir '/var/log/cr_user/'; # or use File::Spec; my $dir = '/var/log/cr_user/'; my @files = map { File::Spec->catfile( $dir, $_ ) } grep { $_ !~ /^\.{1,2}/ } readdir DIR;