File::Find - passing argument to &wanted

H

Hobo Salesman

Quoted from File::Find POD:
use File::Find;
find(\&wanted, @directories_to_search);
The wanted function takes no arguments but rather does its work through a collection of variables.

"processFile()" is "The wanted function". Some code from my program:

find( {
wanted => \&processFile,
preprocess => \&processDirectory,
no_chdir => 1,
}, $self->{"rootPath"});

I have what's above in a "site" object, and I want to pass that object
to processFile(), which is called by File::Find. "processFile()" needs
to create a "file" object that has to know a few things from the "site"
object, most importantly which site it's part of. I'm a little stumped
as to the best way to make that data accessable to the file object.
This doesn't work:

wanted => \&processFile($self->{"siteName"}),

Or rather, it does pass the data I need, but in the process it makes
the data File::Find provides ($File::Find::name, etc) innaccesable. Any
suggestions would be appreciated. Thanks,

HS
 
J

John Bokma

Hobo Salesman said:
wanted => \&processFile($self->{"siteName"}),

Or rather, it does pass the data I need, but in the process it makes
the data File::Find provides ($File::Find::name, etc) innaccesable.
Any suggestions would be appreciated. Thanks,

closure?

wanted => sub { processFile( $self->{ siteName } },

(btw: processFile is quite uncommon in Perl (camel case), you probably
will see: process_file more often).
 
H

Hobo Salesman

John said:
closure?

wanted => sub { processFile( $self->{ siteName } },

Thank ya, 'closure' is a new concept to me, after some googling I feel
like a better programmer.
(btw: processFile is quite uncommon in Perl (camel case), you probably
will see: process_file more often).

I tried forcing myself to use that convention but because of my
background with actionscript/lingo I'd find odd variableNames sneaking
in and ruining everything, now I admit defeat and use it all the time.

Besides that I plan on concentrating more on PHP in the future, a
language for which naming conventions are apparently completely unheard
of... I can't imagine what happened in the development of that language
that caused them to choose function names like that.
 
M

Mumia W.

Hobo said:
[...]

find( {
wanted => \&processFile,
preprocess => \&processDirectory,
no_chdir => 1,
}, $self->{"rootPath"});

I have what's above in a "site" object, and I want to pass that object
to processFile(), [...]

Use a localized package variable.

You could also use a closure: perldoc -q closure.
 
U

Uri Guttman

HS> Besides that I plan on concentrating more on PHP in the future, a
HS> language for which naming conventions are apparently completely
HS> unheard of... I can't imagine what happened in the development of
HS> that language that caused them to choose function names like that.

it is called inbreeding. php was first written in perl but the
designers have/had no experience in language development and they all
just poured in their genes into a bucket and watched what
devolved. every recessive and degenerate trait was expressed in the
phenotype. think of the british royals developing a web language. sorry
for the imagery.

perl is so good because it had one designer and his background was
lingustics and computers which make for a solid background for a
computer language designer.

uri
 
H

Hobo Salesman

Uri said:
it is called inbreeding. php was first written in perl but the
designers have/had no experience in language development and they all
perl is so good because it had one designer and his background was
lingustics and computers which make for a solid background for a
computer language designer.

Perl is my favourite language... but I'm actually a web designer/artist
more than a programmer, so I find PHPs ease of use, integration with
HTML, and mountain of available scripts/classes really attractive.
Power and ease of use always seem to be a trade off, so even if perl
can write a more powerful/stable/faster/elegant bulletin board system
it wouldn't be my first choice just because of the extra time involved
in writing it.

However PHP does remind me in many ways of actionscript/lingo... almost
a programming language for non-programmers.

Meh, I like it... everything has shortcomings, even perl.
 
P

Peter Wyzl

Uri Guttman said:
HS> Besides that I plan on concentrating more on PHP in the future, a
HS> language for which naming conventions are apparently completely
HS> unheard of... I can't imagine what happened in the development of
HS> that language that caused them to choose function names like that.

it is called inbreeding. php was first written in perl but the
designers have/had no experience in language development and they all
just poured in their genes into a bucket and watched what
devolved. every recessive and degenerate trait was expressed in the
phenotype. think of the british royals developing a web language. sorry
for the imagery.

I don't often laugh out loud readint this newsgroup, but this one got me.
Well expressed.

P
 
J

John Bokma

PHP:
[QUOTE]
of... I can't imagine what happened in the development of that language[/QUOTE]

We can only wonder :-D. The people who developed PHP in the beginning had
clearly very little experience with developing a language. Somehow I have
the idea they wanted to improve on Perl, but made new, and often bigger,
mistakes.

As to the camel case naming: one of the hardest things in programming is
learning to use the style of other people when switching to a project or
different language.

Try to avoid camel case, since it will make your programs harder to read
for quite some Perl programmers.

Once you are able to fit in with any programming culture, you are a real
traveller eh... programmer.
 
J

John Bokma

Uri Guttman said:
it is called inbreeding. php was first written in perl but the
designers have/had no experience in language development and they all
just poured in their genes into a bucket and watched what
devolved. every recessive and degenerate trait was expressed in the
phenotype. think of the british royals developing a web language. sorry
for the imagery.
LOL

perl is so good because it had one designer and his background was
lingustics and computers which make for a solid background for a
computer language designer.

And yet it has its own oddness here and there.
 
H

Hobo Salesman

John said:
Try to avoid camel case, since it will make your programs harder to read
for quite some Perl programmers.

s/[a-z0-9]([A-Z0-9][a-z0-9]*)/'_'.lc($1)/ge;

That's my best attempt at a regex to convert my code. I don't think
there's anything this pattern would match that wasn't something I've
named or put in comments? I only use alphanumerics in names.
 
J

John Bokma

Hobo Salesman said:
John said:
Try to avoid camel case, since it will make your programs harder to
read for quite some Perl programmers.

s/[a-z0-9]([A-Z0-9][a-z0-9]*)/'_'.lc($1)/ge;

That's my best attempt at a regex to convert my code. I don't think
there's anything this pattern would match that wasn't something I've
named or put in comments? I only use alphanumerics in names.

There are refactoring modules at CPAN, haven't used any, so can't comment
on how useful:

http://search.cpan.org/search?query=refactor&mode=all

The Devel one looks interesting though.
 
J

Juha Laiho

Hobo Salesman said:
Perl is my favourite language... but I'm actually a web designer/artist
more than a programmer, so I find PHPs ease of use, integration with
HTML, and mountain of available scripts/classes really attractive.

If by 'integration with HTML' you mean the ability to write mixed
HTML and PHP in a single file, then see HTML::EmbPerl on perl side.

For the second point, I think you're correct - in perl world there's
not nearly as many PHPNuke clones available as on the PHP side.
"Elementary" modules (doing for whatever "small" thing), however, I think
are more abundant in Perl (f.ex. how often would you like to be able
to generate PostScript (not just text but with graphics primitives) from
a web application).
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
--
 
H

Hobo Salesman

Juha said:
For the second point, I think you're correct - in perl world there's
not nearly as many PHPNuke clones available as on the PHP side.
"Elementary" modules (doing for whatever "small" thing), however, I think
are more abundant in Perl (f.ex. how often would you like to be able
to generate PostScript (not just text but with graphics primitives) from
a web application).

This looks interesting:

http://www.zend.com/php5/articles/php5-perl.php

Best of both worlds?
 
U

Uri Guttman

HS> This looks interesting:

HS> http://www.zend.com/php5/articles/php5-perl.php

HS> Best of both worlds?

i won't even look. IMNSHO there is no best world with php. it's sole win
is easy creation of simple web sites with db backing. that is a very
narrow but popular niche. but all the work you put into them means you
won't learn proper programming skills as php doesn't support even decent
software engineering concepts like namespaces, etc. my point is why tie
yourself something which won't scale, isn't useful outside its narrow
niche, has many major design flaws, inconsistancy rules, etc. you can go
for it but don't expect any encouragement from me or most here. php is
just a toy that kiddies love. my first rule of design is to isolate
things and php breaks that by merging templates and logic. that may be
simpler for kiddies to play with but it is not how i would design such
things. and i trust my skills over the php 'designers' any time.

uri
 
H

Hobo Salesman

Uri said:
just a toy that kiddies love. my first rule of design is to isolate
things and php breaks that by merging templates and logic. that may be
simpler for kiddies to play with but it is not how i would design such
things. and i trust my skills over the php 'designers' any time.

Well I'll have to mull things over for a while... I have a large web
based app to write in the future that I had planned on using PHP but it
could be Perl would be a better choice.
 
T

Ted Zlatanov

you can go for
PHP:
 but don't expect any encouragement from me or
most here.[/QUOTE]

Well that's pretty obvious in this Perl newsgroup.  I see very few
recommendations here (Abigail used to do it) for alternate tools,
e.g. using awk when it's all that's needed.  I wish there were more.
[QUOTE]
php is just a toy that kiddies love.[/QUOTE]

This and other things you said are pretty unfair.  I know Perl, I've
used PHP, and they do different things well.  Disdain for an entire
community (PHP or others) is not productive.  Emacs Lisp doesn't have
namespaces, does that make it a kiddie language?  Assembler doesn't
have <insert feature here>, does that make it primitive?

Ted
 
D

David Squire

Ted Zlatanov wrote:

[snip]
This and other things you said are pretty unfair. I know Perl, I've
used PHP, and they do different things well. Disdain for an entire
community (PHP or others) is not productive. Emacs Lisp doesn't have
namespaces, does that make it a kiddie language? Assembler doesn't
have <insert feature here>, does that make it primitive?

Yes. Almost by definition.

That's not to say that there aren't times when it's the right choice.
But it's primative as F**K.

DS
 
T

Ted Zlatanov

[snip]
This and other things you said are pretty unfair. I know Perl, I've
used PHP, and they do different things well. Disdain for an entire
community (PHP or others) is not productive. Emacs Lisp doesn't have
namespaces, does that make it a kiddie language? Assembler doesn't
have <insert feature here>, does that make it primitive?

Yes. Almost by definition.

That's not to say that there aren't times when it's the right
choice. But it's primative as F**K.

Horses can't go as fast, as far, or as cheaply as cars, does that make
them primitive?

You are looking at words, not my line of reasoning. By Uri's
reasoning Emacs Lisp would be a kiddie language because it has no
namespaces and many other Perl features. I'm saying Assembler is
primitive when you just look at features, but that's not the point,
and concentrating on the features rather than the whole picture of a
language is bound to give a false image. Derisive terms such as
"kiddie" or "primitive" are not technical, and I guess that's what
bothered me in Uri's original tirade, that it took a limited view and
turned it into derision for an entire community.

I hope that explains my thoughts better.

Ted
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top