On Wed, Apr 20, 2011 at 4:14 PM, Shlomi Fish <[email protected]> wrote:
> On Wednesday 20 Apr 2011 12:50:45 Agnello George wrote:
>> Hi
>>
>> I have script where i need to go in to a directory and put all files
>> in to a array
>>
>> if ( chdir ("$dirtemp") ) {
>> find (sub { push @all , $File::Find::name}, ".");
>>
>> my %selectfiles = qw( /classes/mail.class.php
>> classes/dealer.class.php
>> classes/memcache.class.php
>> classes/phpmailer
>> classes/phpmailer/.htaccess
>> classes/phpmailer/class.phpmailer.php
>> classes/phpmailer/class.smtp.php
>> classes/phpmailer/ChangeLog.txt
>> classes/phpmailer/language
>> );
>>
>> foreach (@all){
>> if ( defined $selectfiles{$_} ){
>> push (@filesfinal , $_);
>> }
>> }
>>
>> this obviously will not work cause of the ./ in the File::Find
>> function , how can i work around this .
>>
>
> You can remove the ./:
>
> [CODE]
> foreach my $filename (@all)
> {
> my $fn_wo_prefix = $filename;
> $fn_wo_prefix =~ s{\A\./}{};
>
> if (exists($selectfiles{$fn_wo_prefix}))
> {
> push @final_files, $filename;
> }
> }
> [/CODE]
>
> A few more comments:
>
> 1. You should use exists instead of defined.
>
> 2. You initialise the hash incorrectly. You need:
>
> my %selected_files = (map { $_ => 1 } @FILES);
>
> 3. See http://perldoc.perl.org/functions/grep.html
>
> 4. "$dirtemp" should be $temp_dir without the quotes.
>
> 5. Use some underscores in your identifiers.
>
in what you mentioned what does \A stand for ??
$fn_wo_prefix =~ s{\A\./}{};
--
Regards
Agnello D'souza
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/