Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Extracting Directories and Sub Directories and Counting

Reply
Thread Tools

Extracting Directories and Sub Directories and Counting

 
 
Ron Smith
Guest
Posts: n/a
 
      11-02-2004
#!/usr/bin/perl

use strict;

print "\n";
my %HoA;
for ( `dir /b/s` ) {
push @{ $HoA{$1} }, $2 if /(.+)\\(\w+)\.\d+\.\w+$/;
}

for my $dir ( sort keys %HoA ) {
print join ( "\n", $dir ), "\n\n";
my @basenames = @{ $HoA{$dir} };
my %count;
for my $frames ( @basenames ) {
$count{$frames} += 1;
}

for ( sort keys %count ) {
printf "%30s\t%04d\n", $_, $count{$_};
}
print "\n";
}

gives me:

file_base_name file_count

in two columns. How would I add additional columns like:

file_base_name file_count File_extension file_size

Which construct would I use? Would it be a 'HoH', or simply expand on
a 'HoA', or is it another construct like 'AoA' or AoH?

Any help would be appreciated.

TIA
Ron
 
Reply With Quote
 
 
 
 
Michele Dondi
Guest
Posts: n/a
 
      11-02-2004
On 1 Nov 2004 20:48:39 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) (Ron Smith)
wrote:

>#!/usr/bin/perl

[snip code]

Please don't take my words as a personal attack, but this made my
heart really hurt. I didn't even try to understand your code. What do
you really want to do? Maybe someone may suggest more effective ways
to do it.

Also, the 'dir /b/s' bit suggests you may be interested in File::Find,
anyway.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      11-02-2004
Ron Smith <(E-Mail Removed)> wrote:


> print join ( "\n", $dir ), "\n\n";


That statement is equivalent to this one:

print "$dir\n\n";

i.e. the join() doesn't do anything.

What were you hoping that join() would do for you there?


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-02-2004
Ron Smith wrote:

<code snipped>

> gives me:
>
> file_base_name file_count
>
> in two columns. How would I add additional columns like:
>
> file_base_name file_count File_extension file_size
>
> Which construct would I use? Would it be a 'HoH', or simply expand on
> a 'HoA', or is it another construct like 'AoA' or AoH?


I was very disappointed to see this post here, Ron. First of all, since
you posted basically the same question to (E-Mail Removed) (where I
have answered it, btw), what you did is called multi-posting and is
considered rude. See why here:

http://www.uwasa.fi/~ts/http/crospost.html

Furthermore, your question was preceded by a long thread at
(E-Mail Removed):

http://www.mail-archive.com/beginner.../msg63290.html

Do you really believe that you explained your problem properly to those
who have not read the previous posts?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      11-02-2004


Michele Dondi wrote:

> On 1 Nov 2004 20:48:39 -0800, (E-Mail Removed) (Ron Smith)
> wrote:
>
>
>>#!/usr/bin/perl

>
> [snip code]
>
> Please don't take my words as a personal attack, but this made my
> heart really hurt. I didn't even try to understand your code. What do
> you really want to do? Maybe someone may suggest more effective ways
> to do it.
>
> Also, the 'dir /b/s' bit suggests you may be interested in File::Find,
> anyway.


I have found that File::Find can be slow on Win32 (because, IIRC, stat()
is rediculously slow[1]). For most things this is not enough to stop me
using File::Find but occasionally for really big trees I've resorted to
parsing the output of 'dir /b /s'.

[1] I'm not sure this is still the case as I'm talking about something I
encountered many years ago.

 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      11-02-2004
On Tue, 02 Nov 2004 18:08:26 +0000, Brian McCauley <(E-Mail Removed)>
wrote:

>I have found that File::Find can be slow on Win32 (because, IIRC, stat()
>is rediculously slow[1]). For most things this is not enough to stop me
>using File::Find but occasionally for really big trees I've resorted to


Well, in my personal experience it is fast enough that I don't notice
it to be slow. But then I carry on most of my file management
activities under Linux, even on Win* FS's.

For the record I've tried this both under Windows98 (sorry, i.e.
happy: no XP yet!) and Linux (kernel 2.6.9):


#!/usr/bin/perl -l

use strict;
use warnings;
use Time::HiRes 'time';

my ($n,$t)=(250_000,time);
stat $ARGV[0] while $n--;
print time - $t;

__END__


As a rough indication I get these figures (no claim of real accuracy):

(*) Windows98

32s both with files in CWD and with absolute paths,

(*) Linux

vfat[1] -> 0.34s with files in CWD (relative path),
0.43s with files "involving two dirs"[2],

ReiserFS & tmpfs -> 0.26s with files in CWD (relative path),
0.38s with files "involving two dirs".

>parsing the output of 'dir /b /s'.


OTOH *on my system* (and I do not doubt that it is a quirk of it)
starting a shell by whichever means (no matter if via C<qx/.../>,
'-|'-open()s or whatever) involves some "mysterious" and annoying
floppy disk activity. This is not by any means limited to perl and
happens also, e.g. with my text editor in shell interaction mode[3].


[1] To be precise, exactly the same file(s) also tested under Windows.
[2] I mean: whose full path is of the kind of /mnt/winc/test.txt.
[3] Irritatingly enough, this behaviour is intermittent.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Death To Sub-Sub-Sub-Directories! Lawrence D'Oliveiro Java 92 05-20-2011 06:50 AM
Recognising Sub-Items and sub-sub items using xslt Ben XML 2 09-19-2007 09:35 AM
counting up instead of counting down edwardfredriks Javascript 6 09-07-2005 03:30 PM
extracting HTML fragments and counting words Ksenia Marasanova Python 0 02-18-2005 08:28 PM
How to map Project directories to Production sub-directories Joel Finkel ASP .Net 0 09-12-2003 06:47 PM



Advertisments