RE: directory listing to array

2001-06-08 Thread Richard Hulse
Thanks folks, this is ANOTHER module I'm going to start using. I have to say that this is a lot more fun than counting clock cycles, which was the last bench-marking I did a long, long time ago... regards, Richard At 19:53 7/06/2001 -0700, Peter Cornelius wrote: >Looking at the other postin

Re: directory listing to array

2001-06-07 Thread Richard Hulse
Since someone raised the general question of differences, which is faster? Randal's suggestion: my @result = <*.jpg>; or variations on: @files = grep /jpg/i, readdir DIR; regards, Richard

Re: directory listing to array

2001-06-07 Thread iansmith
On 7 Jun 2001, Randal L. Schwartz wrote: > Was this on 5.6 or 5.6.1, where the glob is internalized, or on 5.5 or > earlier, where glob called an external process? This is on a RedHat Linux 7.1 os with 5.6.0. -- Ian

RE: directory listing to array

2001-06-07 Thread Peter Cornelius
> I got > > Benchmark: timing 5 iterations of Randals, variations... >Randals: 79 wallclock secs (28.94 usr + 49.99 sys = 78.93 > CPU) @ 633.46/s > (n=5) > variations: 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU) @ > 166.67/s (n=5) > (warning: too few it

Re: directory listing to array

2001-06-07 Thread Randal L. Schwartz
> "iansmith" == iansmith <[EMAIL PROTECTED]> writes: iansmith> On Fri, 8 Jun 2001, Richard Hulse wrote: >> Since someone raised the general question of differences, which is faster? >> my @result = <*.jpg>; >> or variations on: >> @files = grep /jpg/i, readdir DIR; iansmith> use Benchmark;

RE: directory listing to array

2001-06-07 Thread Peter Cornelius
> which is faster? > > Randal's suggestion: > > my @result = <*.jpg>; > > or variations on: > > @files = grep /jpg/i, readdir DIR; > Try this... use Benchmark; opendir (DH, ".") or die; timethese(5, { 'Randals' => q{my @result = <*.jpg>}, 'variations' => q{my @result =

Re: directory listing to array

2001-06-07 Thread iansmith
On Fri, 8 Jun 2001, Richard Hulse wrote: > Since someone raised the general question of differences, which is faster? > my @result = <*.jpg>; > or variations on: > @files = grep /jpg/i, readdir DIR; use Benchmark; timethese(1, { 'Glob' => sub { my @result = <*.jpg>; }, 'Read' => sub { opendir

RE: directory listing to array

2001-06-07 Thread Peter Cornelius
Looking at the other posting to this I realize I should have included the open and close in the test block. That makes the results... Benchmark: timing 1 iterations of Randals, variations... Randals: 16 wallclock secs ( 6.00 usr + 10.05 sys = 16.05 CPU) @ 622.98/s (n=1) variations: 3 w

RE: directory listing to array

2001-06-07 Thread iansmith
On Thu, 7 Jun 2001, Peter Cornelius wrote: > use Benchmark; > opendir (DH, ".") or die; > timethese(5, { > 'Randals' => q{my @result = <*.jpg>}, > 'variations' => q{my @result = grep /\.jpg$/i, readdir DH} > }); > closedir(DH) This only reads the directory in once for the 'variati

Re: directory listing to array

2001-06-07 Thread Peter Scott
At 01:45 PM 6/7/01 -0500, Shawn wrote: >Can someone let me know what effectively is the difference between >@files = grep {/jpe?g$/i} readdir DIR; >and >@files = grep /jpe?g$/i, readdir DIR; >? > >Or is there any? There isn't. Some people like to use only the block form even in those cases wher

Re: directory listing to array

2001-06-07 Thread Jeff 'japhy' Pinyan
On Jun 7, Shawn said: >Japhy pointed out this particular syntax to me. Before this, I was using >@files = grep {/jpe?g$/i} readdir DIR; > >Can someone let me know what effectively is the difference between >@files = grep {/jpe?g$/i} readdir DIR; >and >@files = grep /jpe?g$/i, readdir DIR; If you

Re: directory listing to array

2001-06-07 Thread Shawn
Japhy pointed out this particular syntax to me. Before this, I was using @files = grep {/jpe?g$/i} readdir DIR; Can someone let me know what effectively is the difference between @files = grep {/jpe?g$/i} readdir DIR; and @files = grep /jpe?g$/i, readdir DIR; ? Or is there any? On 06/07, Pete E

Re: directory listing to array

2001-06-07 Thread Pete Emerson
...and just to include both .jpg and .jpeg like John's program: opendir DIR, "./" or die "can't open $directory: $!\n"; @files = grep /jpe?g$/i, readdir DIR; Nice code, Shawn. I must admit that my original way of doing this was even worse than John's (by not using opendir and closedir). Zoiks. G

Re: directory listing to array

2001-06-07 Thread Shawn
Holy JESUS! Why not: opendir DIR, $directory or die "can't open $directory: $!\n"; @files = grep /jpg$/i, readdir DIR; On 06/07, John Storms rearranged the electrons to read: > my($path) = "/home/jstorms/public_html/images/"; > my(@files) = get_jpg_from_dir($path); > > sub get_jpg_from_dir { >

Re: directory listing to array

2001-06-07 Thread Evan McNabb
Thanks for the info, I got everything up and running. I've never had so many responses in such a short amount of time, and with so many ways of getting the job done... :-) -Evan Evan McNabb [EMAIL PROTECTED] http://www.mcnabbs.org/evan

Re: directory listing to array

2001-06-07 Thread Michael Fowler
On Thu, Jun 07, 2001 at 11:16:36AM -0500, Evan McNabb wrote: > > I've been working on a little script for a while but I can't seem to get > this part working. What I want to do is list all of the *.jpg files in a > directory (ls *.jpg) and then have an array with each filename as elements > of th

RE: directory listing to array

2001-06-07 Thread John Storms
my($path) = "/home/jstorms/public_html/images/"; my(@files) = get_jpg_from_dir($path); sub get_jpg_from_dir { my($path) = $_[0]; opendir(DIR,"$path"); my($filename,@jpeg); $filename = readdir(DIR); while($filename ne "") { if( substr($filen

RE: directory listing to array

2001-06-07 Thread Andrew Nelson
# begin cheap non portable hack $list = `/bin/ls -1 *.jpg`; @array = split(/\n/, $list); # end cheap non portable hack # try this a little cleaner opendir(DIR, "."); @dir_entries = readdir(DIR); closedir(DIR); foreach (@dir_entries) { next if(!/\.jpg/); push(@arr, $_); } #end attempt

Re: directory listing to array

2001-06-07 Thread Jean-Matthieu Guerin
@list = `ls *.jpg`; print @list; Evan McNabb wrote: > > I've been working on a little script for a while but I can't seem to get > this part working. What I want to do is list all of the *.jpg files in a > directory (ls *.jpg) and then have an array with each filename as elements > of that arr

Re: directory listing to array

2001-06-07 Thread Paul
--- Evan McNabb <[EMAIL PROTECTED]> wrote: > I've been working on a little script for a while but I can't seem to > get this part working. What I want to do is list all of the *.jpg > files in a directory (ls *.jpg) and then have an array with each > filename as elements of that array. Its probab

Re: directory listing to array

2001-06-07 Thread Randal L. Schwartz
> "Evan" == Evan McNabb <[EMAIL PROTECTED]> writes: Evan> I've been working on a little script for a while but I can't seem to get Evan> this part working. What I want to do is list all of the *.jpg files in a Evan> directory (ls *.jpg) and then have an array with each filename as elements Ev