SPUG: RE: Simple program - gone wrong
Brian Maddux
brianmaddux at yahoo.com
Mon Jul 8 12:56:15 CDT 2002
Try this:
#!/usr/bin/perl
open(RDIR,"./admin/data/rdir.txt");
opendir(DIR, "../");
@files = readdir(DIR);
$num = 1;
foreach $name (@files) {
if(-d $name){
}elsif($name eq "." || $name eq ".."){
}else{
print RDIR "$num | $name\n";
$num++;
}
}
close(RDIR);
close(DIR);
exit;
---------
You don't need the for loop, just a counter; print was
in the wrong form; and you forgot to open RDIR for
write.
Coding and colds do not mix well ;-) especially if you
know multiple languages and start mixing them up!
Hope this helps and you feel better....
Brian
--- Sweethomes <sweetsue at sweethomes.com> wrote:
> Not sure if this went through - resending:
>
> Scratching my head over this one. All I want is
> to read the upper
> directory, list out the files names and then print
> the results with
> numbering to a file. Here is what I have:
>
> #!/usr/bin/perl
> open(RDIR,"./admin/data/rdir.txt");
> opendir(DIR, "../");
> @files = readdir(DIR);
> for($num = 0; $num <= 100; $num += 1)
> foreach $name (@files) {
> if(-d $name){}elsif($name eq "." || $name eq
> ".."){}else{
> print(RDIR, "$num | $name\n");}}
> close(RDIR);
> close(DIR);
> exit;
>
> I've got the worst headcold in my personal
> history and I'm thinking that
> my brain just is not functioning. If anyone can
> clear this up for me, I'd
> appreciate it!
> Happy 4th of July to all!
>
> www.web-dev-design.com
> ------------------------------------
> Susanne Bullo, Developer Web Dev Design
> 16646 SE 10th Street Bellevue, WA
> 98008
> Telephone: 425.562.6040 Facsimile:
> 425.671.0571
>
=====
Brian Maddux Whidbey Island, WA
brianmaddux at yahoo.com
**
__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list