List Info

Thread: glob, paging merlyn




glob, paging merlyn
country flaguser name
United States
1969-12-31 18:00:00

Hey all,

I wrote a script that counts how much code I've written in numbers of
lines - just an excercise in recursion and perl - anyway I was wondering
the following about glob:
1. Is there a recursive version of glob? So if I went glob(";*.pl") it
would traverse subdirectories as well? (This is where I used my
recursion originally)
2. Does glob cough in certain situations? When I did a glob on a folder
with subdirectories that had spaces in the name, it seemed to return the
first part of a subfolder name without the space.
3. Is glob an older way of doing things? I see equivalents of IO::File
and so on and wonder if I can still use the examples from my old copy of
Learning Perl. I'd love to get a new one but because I'm always short
on book money I'd like as much mileage out of my old edition as I can get.

Thanks much,

David

ps. Here's the sub, it's messy and any pointers are appreciated.

sub getCount{
my $dirPath = $_[0] . "/";
my $filename;
my $filelines;
while(defined($filename = glob(";$dirPath*.pl")))
{
next unless($filename =~ /.pl/); #this shouldn't be necessary,
should it?

open CODE, $filename or die "$filename cause $!";
my len = <CODE&gt;;
$filelines = len;
$lineCount += len;
print "n$filename -- $filelinesn";
#write;
}
my $d;
opendir(CODEDIR, $dirPath) || die "sorry bad path: $dirPath.n$!";
foreach $d (readdir(CODEDIR))
{
unless($d =~ /.?(.)/){
getCount(&quot;$dirPath" . "$d&quot;);
}
}

}

__._,_.___
.

__,_._,___
Re: glob, paging merlyn
country flaguser name
United States
1969-12-31 18:00:00

>>&gt;>> "da5id" == da5id < da5id%40t3rse.com">da5idt3rse.com> writes:

da5id>; 1. Is there a recursive version of glob? So if I went glob(";*.pl") it
da5id&gt; would traverse subdirectories as well? (This is where I used my
da5id&gt; recursion originally)

File::Find does that. Also see my File::Finder in the CPAN for
(what I think is) a nicer interface.

da5id> 2. Does glob cough in certain situations? When I did a glob on a folder
da5id&gt; with subdirectories that had spaces in the name, it seemed to return the
da5id&gt; first part of a subfolder name without the space.

The glob input has to be quoted, but the responses will be ready-to-use.

So to glob the folder named "Foo Bar" for files that end in ".pm&quot;, use glob
'Foo Bar/*.pm'. Note the single quotes, because you want a backslash
followed by a space in the argument.

da5id&gt; 3. Is glob an older way of doing things? I see equivalents of IO::File
da5id&gt; and so on and wonder if I can still use the examples from my old copy of
da5id&gt; Learning Perl. I'd love to get a new one but because I'm always short
da5id&gt; on book money I'd like as much mileage out of my old edition as I can get.

Glob is modern. I use it every day.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<; merlyn%40stonehenge.com">merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )