Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^7: Find images regardless of filetype extension.

by Chady (Priest)
on Aug 01, 2005 at 20:09 UTC ( #480019=note: print w/replies, xml ) Need Help??

in reply to Re^6: Find images regardless of filetype extension.
in thread Find images regardless of filetype extension.

Compactness affects readability. And besides, you're counting declarations and braces as lines, if I put it on one line it doesn't mean it's a single statement... if you're looking for compactness, here goes:

I'll assume @files and @dirs are already declared then.
map {$d="$dir/$_";$r= -d $d?\@dirs:\@files;push @$r,$d;} grep {!/^\./} + readdir DIR;

Yes, this uses map in void context, but you want compactness, not efficiency :)

He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
Chady |
Are you a Linux user in Lebanon? join the Lebanese GNU/Linux User Group.

Replies are listed 'Best First'.
Re^8: Find images regardless of filetype extension.
by zzspectrez (Hermit) on Aug 02, 2005 at 05:10 UTC

    Ill give you that is compact!

    But I think, that

    • my @files = map { "$dir/$_" } grep { !/^\.{1,2}\z/ && -f "$dir/$_" } @tmp;
    is both compact but very clear and readable. On the otherhand,
    • map {$d="$dir/$_";$r= -d $d?\@dirs:\@files;push @$r,$d;} grep {!/^\./} readdir DIR;
    is compact and clever but not easily readable IMHO.

    On the other hand, I really like your use of the ternary and references. I would not have thought of using it like that. ++ ++ I think that is quite clever. Thanks for the snippet of code.

    Only one complaint, the way you wrote you regex it will skip any dot file. So .my-file would not be picked up.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://480019]
[choroba]: yeah, sounds like one of the strings is not flagged as UTF-8
[choroba]: which usually means its input wasn't handled correctly
[Corion]: choroba: Yeah, I think that would be the good solution
[LanX]: I suspect the first string which comes from the DB ...
[LanX]: ... but this part is already in production for a year now
[Corion]: LanX: The "good" approach here would be to use the appropriate DBI parameters to make the driver decode strings properly. But that will have a ripple-on effect of messing up all the places where manual decoding happens ;)
[LanX]: which means albeit being broken UTF8 it'll be handled correctly
[LanX]: and the problem only occurs since we changed the emails to base64
[LanX]: my main problem will be to cnvince my colleagues that our productive code is broken oO ... so in the end I will just make a workaround :-/
LanX hates UTF8 for causing knots in his brain and stomach

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2017-01-16 14:02 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (150 votes). Check out past polls.