using File::Find

U

Uno

On 2011-03-24 03:22, Uno<[email protected]> wrote:

Your script doesn't contain anything which corresponds to "besides the
directory itself". You want that you have to program it. Perl can't read
your mind.

This recent one might, but again I have trouble seeing the basic control:

$ perl find2.pl
../text1 Tue Mar 22 21:31:45 2011
$ cat find2.pl
#!/usr/bin/perl -w
use strict;
use File::Find;
@ARGV = (".") unless @ARGV;
my ($age, $name);
sub youngest {
return if -d;
$age = (stat(_))[9];
$name = $File::Find::name;
}
find(\&youngest, @ARGV);
print "$name " . scalar(localtime($age)) . "\n";
$ ls -t
find2.pl lst2 find1.pl symirror rmtree1 lst ch09.code
text2 text1 uvi rmtree2 rename fdirs
$


I don't see why execution would want to go through youngest more than
once, to begin with.
Don't google, read the documentation that comes with perl

perldoc -f -M

(Prefixing a term with "-" excludes that term from the search in Google.
You didn't want to search for all pages except those which contain an
"M", did you?)

Do you have a context to see some output for this?

while (<>) {
chomp;
next unless -f $_; # ignore specials
#...
}
 
P

Peter J. Holzer

This recent one might, but again I have trouble seeing the basic control:
[...]

Do you have a context to see some output for this?

Sorry, I don't understand what you are talking about. You have to be
clearer.

hp
 
P

Peter J. Holzer

On 03/24/2011 12:18 AM, Uri Guttman wrote:

[a typical Uri-vs-Newbie thread]

Well I look forward to us spending more quality time with each other.


cpan[1]> install News::NNTPClient
[lots of errors]

This doesn't seem to have anything to do with either the original topic
of the thread ("using File::Find" as the subject line still states) or
your quarrel with Uri.

If you start a completely new topic, please start a new thread with a
descriptive subject.

hp
 
A

Alan Curry

Wow, the densely packed misconceptions! First of all, in File::Find, just as
in find(1), the "directory itself" is a legitimate part of the search output.
There's no reason why "/usr/share/man/man1" can't be the answer to "what is
the youngest file found under /usr/share/man/man1?"... Directories are files
too. If you want to exclude them, put "return if -d" at the top of your
filter function.

I can pack them in can't I? I'm very confused still:
$ cat find2.pl
#! usr/bin/perl -w
use strict;
use File::Find;
@ARGV = (".") unless @ARGV;
my ($age, $name);
sub youngest {
return if -d;
$age = (stat(_))[9];
$name = $File::Find::name;
}
find(\&youngest, @ARGV);
print "$name " . scalar(localtime($age)) . "\n";

And now we've found my misconception. I thought you had written the original
script. It was nearly functional, with a couple of mistakes, so you'd be able
to finish it once those mistakes were identified. But I was wrong, you're not
trying to fix an almost-working script that you wrote. You're posting code
from a book that you've broken by trying to modify it without understanding
anything about what it was doing in the first place. That's a dumb game. I
don't want to play.
 
R

Ralph Malph

U> I have a lot of misconceptions, as I'm even newer to unix than I am
U> perl, and I don't mind when you take a tone with me, as you also help
U> as you castigate. That's not true of everyone on usenet.

so if you have misconceptions, shouldn't you learn the culture before
you go barging in? did you read the posted guidelines here?
ha ha ha. You fucking idiot. Nobody reads that shit.
 
M

Mladen Gogala

If you don't want your code to be commented on, then do not post your
code on Usenet.

At least not before running it through perlcritic. Although, there are
things flagged by perlcritic that I disagree with, bareword filehandle
open being one of them.
 
U

Uri Guttman

MG> At least not before running it through perlcritic. Although, there are
MG> things flagged by perlcritic that I disagree with, bareword filehandle
MG> open being one of them.

and why do you like bareword file handles? name one advantage they have
over lexicals. lexical handles are scoped so they close upon scope exit
and they don't pollute your package namespace. as declared my vars you
have to spell them correctly when used vs any bareword string is legal
as a handle anywhere.

i may disagree with perlcritic (and it is highly customizable) but that
is not one of them.

uri
 
R

Randal L. Schwartz

Uri> and why do you like bareword file handles? name one advantage they have
Uri> over lexicals.

Less typing. For a one liner, I'd never use anything *but* a bareword,
and as short as possible, like F or B.

print "Just another Perl hacker,"; # the original
 
P

Peter J. Holzer

Uri> and why do you like bareword file handles? name one advantage they have
Uri> over lexicals.

Less typing. For a one liner, I'd never use anything *but* a bareword,
and as short as possible, like F or B.

For one-liners most style rules don't apply.

hp
 
U

Uri Guttman

Uri> and why do you like bareword file handles? name one advantage they have
Uri> over lexicals.

RLS> Less typing. For a one liner, I'd never use anything *but* a bareword,
RLS> and as short as possible, like F or B.

not many one liners open files! and given one liners don't usually
enable strict, nor worry about closing files, the benefits of lexical
handles become moot. so this is one useful place for them.

uri
 
M

Mladen Gogala

and why do you like bareword file handles?

Because I use Perl since 1993, when it was still version 4, and I have a
bunch of old scripts for which perlcritic now tells me that they're badly
written. Compatibility is the reason. I use lexicals in my newer scripts
but every now and then someone runs one of my old scripts through
perlcritic and starts nagging. Simply, bareword file handles used to be
The Perl Way(TM) and I don't think it's right to now flag them as bad
programming.
 
U

Uri Guttman

MG> Because I use Perl since 1993, when it was still version 4, and I have a
MG> bunch of old scripts for which perlcritic now tells me that they're badly
MG> written. Compatibility is the reason. I use lexicals in my newer scripts
MG> but every now and then someone runs one of my old scripts through
MG> perlcritic and starts nagging. Simply, bareword file handles used to be
MG> The Perl Way(TM) and I don't think it's right to now flag them as bad
MG> programming.

and so what? rewrite them already. they are properly flagged in recent
perl 5 versions. no one cares about perl4 now (and i did tons of perl4
coding too but i didn't keep it alive forever).

uri
 
P

Peter J. Holzer

Because I use Perl since 1993, when it was still version 4, and I have a
bunch of old scripts for which perlcritic now tells me that they're badly
written. Compatibility is the reason.

Compatibility with Perl4? Who's still running Perl4 (Or Perl 5.005 -
lexical file handles were only introduced in 5.6)? And you are only
compatible if you don't use *any* newer feature - just avoiding one
particular feature doesn't make your scripts compatible.
I use lexicals in my newer scripts but every now and then someone runs
one of my old scripts through perlcritic and starts nagging.

There is a simple answer to those people:

"I like the idea. Send patches!"

They want something changed. They have the source. They can change it
themselves.
Simply, bareword file handles used to be The Perl Way(TM) and I don't
think it's right to now flag them as bad programming.

There are now better ways and bareword file handles really are bad
programming. They were bad programming in 1993, there just wasn't an
alternative (except using a different programming language).

hp
 
U

Uno

Compatibility with Perl4? Who's still running Perl4 (Or Perl 5.005 -
lexical file handles were only introduced in 5.6)? And you are only
compatible if you don't use *any* newer feature - just avoiding one
particular feature doesn't make your scripts compatible.


There is a simple answer to those people:

"I like the idea. Send patches!"

They want something changed. They have the source. They can change it
themselves.


There are now better ways and bareword file handles really are bad
programming. They were bad programming in 1993, there just wasn't an
alternative (except using a different programming language).

As near as I can tell, this issue, which is, demonstrably, not even
close to the subject that this OP wrote, is remedied by using "my."

For us new people, we wouldn't even think about doing it otherwise,
since it draws an exception when you use strict.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top