Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2015-07-31 15:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls