Re: problem with stat?

2006-09-22 Thread Mathew Snyder
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mathew Snyder wrote: > I'm trying to figure out how to use stat. I have the following code: > > #!/usr/bin/perl -w > > use strict; > > my @filenames; > my $processDir = "/usr/bin"; > > opendir DH, $processDir or die "cannot open $processDir: $!";

Re: problem with stat?

2006-09-22 Thread John W. Krahn
Mathew Snyder wrote: > I'm trying to figure out how to use stat. I have the following code: You should really figure out how to use readdir perldoc -f readdir > #!/usr/bin/perl -w > > use strict; > > my @filenames; > my $processDir = "/usr/bin"; > > opendir DH, $processDir or die "cannot op

Re: problem with stat?

2006-09-22 Thread Mathew Snyder
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Updated my code to look like this: #!/usr/bin/perl -w use strict; my %filenames; my $file_count = 0; my $processDir = "/usr/bin"; opendir DH, $processDir or die "cannot open $processDir: $!"; foreach my $file (sort(readdir DH)){ next if ($f

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
Mathew Snyder schreef: > #!/usr/bin/perl -w > > use strict; I would change that to: #!/usr/bin/perl -w use warnings ; use strict ; > my @filenames; > my $processDir = "/usr/bin"; > > opendir DH, $processDir or die "cannot open $processDir: $!"; > foreach my $file (sort(readdir DH)){ >

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
"Dr.Ruud" schreef: > Mathew Snyder: >> #!/usr/bin/perl -w >> >> use strict; > > I would change that to: > > #!/usr/bin/perl -w > use warnings ; > use strict ; Oops, the whole point of that was to remove the "-w". See `perldoc perllexwarn`. -- Affijn, Ruud (now you'll remember even better)

Re: problem with stat?

2006-09-22 Thread Mumia W.
On 09/22/2006 02:58 AM, Mathew Snyder wrote: [...] my $mod_time = (stat($file))[9]; [...] If $file is not in the current directory, this won't work. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: problem with stat?

2006-09-22 Thread Mathew Snyder
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 John W. Krahn wrote: >> #!/usr/bin/perl -w >> >> use strict; >> >> my @filenames; >> my $processDir = "/usr/bin"; >> >> opendir DH, $processDir or die "cannot open $processDir: $!"; >> foreach my $file (sort(readdir DH)){ >> push @filenames, $f

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
Mathew Snyder schreef: > foreach my $file (sort(readdir DH)){ > next if ($file =~ /^.%|^..$/); > my $mod_time = (stat($file))[9]; > $filenames{$file} = $mod_time; > } No need to sort before you put things in a hash: hashes don't keep order. Try this: my %file_modtime

Re: problem with stat?

2006-09-22 Thread Mathew Snyder
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dr.Ruud wrote: > Mathew Snyder schreef: > >> foreach my $file (sort(readdir DH)){ >> next if ($file =~ /^.%|^..$/); >> my $mod_time = (stat($file))[9]; >> $filenames{$file} = $mod_time; >> } > > No need to sort before you put

Re: problem with stat?

2006-09-22 Thread John W. Krahn
Mathew Snyder wrote: > John W. Krahn wrote: my @filenames; my $processDir = "/usr/bin"; opendir DH, $processDir or die "cannot open $processDir: $!"; foreach my $file (sort(readdir DH)){ push @filenames, $file; } >>>Why not just: >>> >>>my @filenames = sort

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
Mathew Snyder schreef: > John W. Krahn: >> Mathew: >>> #!/usr/bin/perl -w >>> >>> use strict; >>> >>> my @filenames; >>> my $processDir = "/usr/bin"; >>> >>> opendir DH, $processDir or die "cannot open $processDir: $!"; >>> foreach my $file (sort(readdir DH)){ >>> push @filenames, $file; >

Re: problem with stat?

2006-09-22 Thread Mathew Snyder
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 John W. Krahn wrote: > Mathew Snyder wrote: >> John W. Krahn wrote: > my @filenames; > my $processDir = "/usr/bin"; > > opendir DH, $processDir or die "cannot open $processDir: $!"; > foreach my $file (sort(readdir DH)){ >

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
"Dr.Ruud" schreef: > Mathew Snyder: >> foreach my $file (sort(readdir DH)){ >> push @filenames, $file; >> } > > You sort too early. Ignore that. Just use John's alternative: my @filenames = sort readdir DH; or make that my @filenames = sort grep -f, readdir DH; Globs are sorted no

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
Mathew Snyder schreef: > I [...] > removed the initialization to 0 for 'my > $file_count' since it doesn't need to be set to an initial value > anyway. There was nothing wrong with that initialization, but it is OK too to leave it out. But: you don't really need that $file_count, do you? The leng

Re: problem with stat?

2006-09-22 Thread Mathew Snyder
Dr.Ruud wrote: > "Dr.Ruud" schreef: >> Mathew Snyder: > >>> foreach my $file (sort(readdir DH)){ >>> push @filenames, $file; >>> } >> You sort too early. > > Ignore that. Just use John's alternative: > > my @filenames = sort readdir DH; > > or make that > > my @filenames = sort gre

Re: problem with stat?

2006-09-22 Thread Mathew Snyder
Dr.Ruud wrote: > "Dr.Ruud" schreef: >> Mathew Snyder: > >>> foreach my $file (sort(readdir DH)){ >>> push @filenames, $file; >>> } >> You sort too early. > > Ignore that. Just use John's alternative: > > my @filenames = sort readdir DH; > > or make that > > my @filenames = sort gre

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
Mathew Snyder schreef: > Dr.Ruud: >> my @filenames = sort grep -f, readdir DH; > > I tried this line using $dh. Nothing was getting placed in the array. > Would that be because everything in /usr/bin is an executable file? Aaargh no, I am making the same mistake as you did: not prepending the

Re: problem with stat?

2006-09-22 Thread Mathew Snyder
Dr.Ruud wrote: > Mathew Snyder schreef: >> Dr.Ruud: > >>> my @filenames = sort grep -f, readdir DH; >> I tried this line using $dh. Nothing was getting placed in the array. >> Would that be because everything in /usr/bin is an executable file? > > Aaargh no, I am making the same mistake as you

Re: problem with stat?

2006-09-22 Thread John W. Krahn
Dr.Ruud wrote: > "Dr.Ruud" schreef: >>Mathew Snyder: > >>>foreach my $file (sort(readdir DH)){ >>>push @filenames, $file; >>>} >>You sort too early. > > Ignore that. Just use John's alternative: > > my @filenames = sort readdir DH; > > or make that > > my @filenames = sort grep -f,

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
Mathew Snyder schreef: > Did a bit o' Googling and found how to use the 'not' operator and now > have this line that eliminates the . and .. while still populating the > array in as few lines as possible: > > @filenames = sort grep { !/^\.$|^\.\.$/ } readdir $dh; Yes, but that still doesn't filte

RE: problem with stat?

2006-09-22 Thread Thomas Bätzler
Mathew Snyder <[EMAIL PROTECTED]> wrote: > Did a bit o' Googling and found how to use the 'not' operator > and now have this line that eliminates the . and .. while > still populating the array in as few lines as possible: > > @filenames = sort grep { !/^\.$|^\.\.$/ } readdir $dh; You can optim

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
Mathew Snyder schreef: > Dr.Ruud: >>my @filenames = grep -f "$dir/$_", sort readdir DH; > > Interesting. The above line returns 1648 items while the following > > @filenames = sort grep { !/^\.$|^\.\.$/ } readdir $dh; > > returns 1650. That would mean that there are 2 other "no-plain-files"

Re: problem with stat?

2006-09-22 Thread John W. Krahn
Dr.Ruud wrote: > > The '.' and '..' are directories, not plain files. Some file systems do not have the directories '.' and '..' so they *could* just be plain files. > You can write > > !/^\.$|^\.\.$/ > > as > > !/^\.\.?$/ > > so also as > > !/^[.][.]?$/ Until Perl 5.8.10 comes alon

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
"John W. Krahn" schreef: > Dr.Ruud: >> The '.' and '..' are directories, not plain files. > > Some file systems do not have the directories '.' and '..' so they > *could* just be plain files. Right, and that is one of the reasons why I keep bringing -f() up. I am also testing with a file called

Re: problem with stat?

2006-09-22 Thread Dr.Ruud
Thomas Bätzler schreef: > [ !/^\.$|^\.\.$/ and !/^\.\.?$/ ] > I'm assuming that this regex would be faster, too, since it > does not contain an alternation. That is hard to say without actual benchmarking: the regex-optimizer gets better with every new version of perl. Check also the re=debug

Re: problem with stat?

2006-09-22 Thread Mathew
Dr.Ruud wrote: > Thomas Bätzler schreef: > >> [ !/^\.$|^\.\.$/ and !/^\.\.?$/ ] >> I'm assuming that this regex would be faster, too, since it >> does not contain an alternation. > > That is hard to say without actual benchmarking: the regex-optimizer > gets better with every new version of per

Re: problem with stat?

2006-09-22 Thread Mathew
John W. Krahn wrote: > Dr.Ruud wrote: >> The '.' and '..' are directories, not plain files. > > Some file systems do not have the directories '.' and '..' so they *could* > just be plain files. > > >> You can write >> >> !/^\.$|^\.\.$/ >> >> as >> >> !/^\.\.?$/ >> >> so also as >> >> !/^[.

Re: problem with stat?

2006-09-22 Thread John W. Krahn
Mathew wrote: > John W. Krahn wrote: >>Dr.Ruud wrote: >> >>>You can write >>> >>> !/^\.$|^\.\.$/ >>> >>>as >>> >>> !/^\.\.?$/ >>> >>>so also as >>> >>> !/^[.][.]?$/ >>Until Perl 5.8.10 comes along literals are more efficient than character >>classes so the first one would be better. > > I had t

Re: problem with stat?

2006-09-23 Thread Dr.Ruud
Mathew schreef: > I had tried this > > /^[.]$|^[..]$/ but had been getting errors about Posix. I'm not at > the same system or even same OS now so I can't reproduce though. [..] is equal to [.], like [cbbbaaa] is equal to [a-c]. See `perldoc perlre`. -- Affijn, Ruud "Gewoon is ee

Re: problem with stat?

2006-09-23 Thread Dr.Ruud
Mathew schreef: > Dr.Ruud wrote: >> Thomas Bätzler schreef: >> >>> [ !/^\.$|^\.\.$/ and !/^\.\.?$/ ] >>> I'm assuming that this regex would be faster, too, since it >>> does not contain an alternation. >> >> That is hard to say without actual benchmarking: the regex-optimizer >> gets better with

Re: problem with stat?

2006-09-23 Thread Dr.Ruud
"Dr.Ruud" schreef: > Thomas Bätzler: >> [ !/^\.$|^\.\.$/ and !/^\.\.?$/ ] >> I'm assuming that this regex would be faster, too, since it >> does not contain an alternation. > > That is hard to say without actual benchmarking: the regex-optimizer > gets better with every new version of perl. See

Re: Problem with STAT under Windows

2008-03-31 Thread Gunnar Hjalmarsson
anders wrote: I tryed some testkod below, i like Perl to give med TIME for every file, But all variable just get blank, (i got filename). You need to either alter the current directory using chdir(), or pass the full path to stat(). You may want to try this code: use strict; use war