Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cleaning up the code 1

Status
Not open for further replies.

perlone

Programmer
Joined
May 20, 2001
Messages
438
Location
US
Hi,

I have the following code:

opendir(DIR, "$clanbase");
@clanlist = readdir(DIR);
closedir(DIR);


foreach $clanlist (@clanlist) {
chomp($clanlist);
open(F, "$root/cgi-bin/databases/clans/$clanlist/info.list");
@clannames = <F>;
print &quot;$clannames[0] [<A HREF=\&quot;clans.cgi\&quot;>Explore</A>]<BR>&quot;;
chomp($clannames[0]);
close(F);
}

What it does is take all the values from info.list and displays the first vaue from the info.list. After running the code, it should be looking like this:

Some Name[Explore]
More Name [Explore]


But instead, it looks like this:

[Explore]
[Explore]
Some Name[Explore]
More Name [Explore]


How do i get rid of the the first 2 lines that causing the error? I tried to use the chomp function everywhere but it's not working. Any ideas? Thanks for your time.

-Aaron
 
readdir is probably including the '.' and '..' files in your @clanlist. You
could prevent that like this,

Code:
@clanlist = grep !/^\.\.?$/, readir(DIR);

The 'grep' filters out anything that starts with dots.

(in case I have a typo in there, that is straight out of the ubiquitous,
&quot;Programming Perl&quot; by Wall, Christiansen and Schwartz in the section about
the readdir function.)





keep the rudder amid ship and beware the odd typo
 
Thanks, i was thinking of that. I used the following which tracy told me about:

next if (($clanlist eq '.') || ($clanlist eq '..'));

-Aaron
 
Like they always say about perl: TMTOWTDI (There's More Than One Way To Do It). That's one of the cooler things about perl.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top