in reply to Re^2: subdirectory question
in thread subdirectory question

Clever code!

I would have used chomp instead of "/(.*)/", and split on ";" for Windoze.

Anyway, to respond to your question - I had not optimized my proposed solution to the extent you have, so I did not see the "contradiction". My proposal suggested storing the file names in an array, and "grep"ping it for each file.

I would agree that your solution is faster. To optimize memory it even more, you could set "$names{$1}=undef", and use "exists $names{$_}" when querying.

    ..."I don't know what the facts are but somebody's certainly going to sit down with him and find out what he knows that they may not know, and make sure he knows what they know that he may not know, and that's a good thing. I think it's a very constructive exchange," --Donald Rumsfeld

Replies are listed 'Best First'.
Re^4: subdirectory question
by ambrus (Abbot) on Jan 04, 2005 at 10:32 UTC

    Originally I thought of a hash because both posts (reading in a text file and subdirectory question) ask for a hash. If this was indeed some kind of homework, then whoever thought it out knew he can use a hash.

    You are right: chomp is actually better, because if you have newlines in filenames, you can give the program a nul-delimited list of filenames, start the script with perl -0, and it would magically work.

    I don't think that $names{$_} = (); would be better on memory usage than $names{$_} = 1;, as the former has to allocate an undef, which is not any smaller than an integer. Don't trust me in this however, as I'm not good in perlguts.