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.
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
What Makes Software Apps High Quality - http://shlom.in/sw-quality
I hope that you agree with me that 99.9218485921% of the users wouldn't bother
themselves with recompilation (or any other manual step for that matter) to
make their games run 1.27127529900685765% faster ;-) -- Nadav Har'El
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/