Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

interate files in glob 1

Status
Not open for further replies.

msingle

MIS
Jul 15, 2002
22
0
0
US
How would I count the number of file in:
e.g. my @files = sort glob ('3E*.log');
??
 
the index of the last element in any array can be found like
@array = ('1','2','3','4');
$index_of_last_element = [red]$#[/red]array;


Code:
#!/usr/local/bin/perl
my @files = sort glob ('*.gif');
print "How Many?
[red]$#[/red]
Code:
files\n";
print "FILES: \n@files\n";
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Using the $# syntax gives you the last index, which is actually n-1 where n is the number of files since the array begins at zero. To get the file count, use
Code:
my $count = scalar @files
.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top