Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Argh

by athomason (Curate)
on Oct 22, 2000 at 10:32 UTC ( #37825=note: print w/ replies, xml ) Need Help??

in reply to Argh

I'm assuming that by "biggest name", you mean longest name. In that case, your problem is with $file gt $greatest. This does a string comparison of those two scalars, which is not what you want. Instead, you want to compare the length of the scalars. Do that with length($file) > length($greatest).

More generally, I'd go with something like this:

#!perl -w use strict; use CGI ":standard"; my $longest = ""; my $dir = '/data'; opendir DIR, $dir or die "Couldn't readdir $dir"; while(my $file = readdir DIR) { print "'$longest'\n"; $longest = $file if length($file) > length($longest); } closedir DIR; print header, start_html("Longest filename"), "Longest filename in '$dir' is '$longest', which has ", length($longest), ' characters.', end_html;

Comment on Re: Argh
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://37825]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2015-11-27 00:01 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (710 votes), past polls