Re: Finding the number of occurences in an array
- From: "Dr.Ruud" <rvtol+news@xxxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 12:15:33 +0200
Bill H schreef:
Perl has so many quick ways of doing things, I wonder if there is an
easy way to find out how many entries in an array match a string?
if I use the following to get a directory list of the sub directory
"things" into @gfnames, is there an easy way of find out how many of
the entries in @gfnames contain the string ".txt" without going
through and comparing each one?
(variant of Sinan's reply)
use strict;
use warnings;
opendir(BASE, "things");
opendir my $base_dir, 'things'
or die "Cannot open 'things' directory: $!";
@gfnames = readdir(BASE);
my @gfnames = readdir $base_dir;
my $txt_count = grep( /\.txt/, @gfnames );
closedir(BASE);
closedir $base_dir;
--
Affijn, Ruud
"Gewoon is een tijger."
.
- Follow-Ups:
- Re: Finding the number of occurences in an array
- From: Mintcake
- Re: Finding the number of occurences in an array
- References:
- Finding the number of occurences in an array
- From: Bill H
- Finding the number of occurences in an array
- Prev by Date: Re: Reloading perl file dynamically
- Next by Date: Re: Converting codepages to UTF8
- Previous by thread: Re: Finding the number of occurences in an array
- Next by thread: Re: Finding the number of occurences in an array
- Index(es):
Relevant Pages
|