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

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;

Log In?

What's my password?
Create A New User
Domain Nodelet?
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 examining the Monastery: (1)
As of 2021-10-19 02:16 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (76 votes). Check out past polls.