CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Perl

 



andrebarradas
New User

May 7, 2010, 6:33 AM

Post #1 of 2 (529 views)
Perl Can't Post


Code
#!/usr/bin/perl -w 
use strict;

#Verificar argumentos

if (@ARGV != 1) {die("Precisar de entrar um argumento,sendo ele uma directoria")}

#Verificar se o argumento é directoria

if (!-d $ARGV[0]) {die("O argumento não é directoria");}

#abertura da directoria

opendir(DIR,"$ARGV[0]") || die ("Erro ao abrir directoria");
my @dir = readdir(DIR);
chomp (@dir);
close (DIR);

my $fich;
my $emptyfile;

foreach my $i (@dir){

if ($i eq "."){next;}
if ($i eq ".."){next;}

if (-f $i){

$fich++;
if (-z $i){
$emptyfile++;
print "$emptyfile é ficheiro vazio \n";


}
}

}

print " Total Ficheiros: $fich \n Total FichVazios: $emptyfile \n";


The objective of this code is to count the number of files and the number of empty files of the directory that we called as a argument.In the final the terminal will show(for example) this when we write ./totalemptyfiles.pl files/:

Total files:6
Total empty files:2

Where totalemptyfiles.pl is the script(code) and files/ the directory(first and unique argument).
What is wrong in this code?

Best Wishes,

André Barradas


7stud
Enthusiast

May 9, 2010, 9:00 AM

Post #2 of 2 (507 views)
Re: [andrebarradas] Perl [In reply to] Can't Post

Cross post. Already answered elsewhere.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives