Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 studying the Monastery: (10)
As of 2014-12-22 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (119 votes), past polls