http://qs321.pair.com?node_id=101801

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have been learning perl for the last two months and now I have presented myself with a problem. I decided to write a Perl script that will basically search my linux box for all files with the suid or sgid buit set starting from the root directory (/). I already know that there will involve some sort of recursion I just can't figure out a good approach to this:
chdir("/")||die "Error:$!\n"; opendir(ROOT_DIR,"/")|| die "Error:$!\n"; foreach $dir_cont (sort readdir(ROOT_DIR)){ next if $dir_cont =~s/^\.\.?$/; if (-f $dir_cont){ log_sbit($dir_cont) if (-u $dir_cont || -g $dir_cont); } elsif (-d $dir_cont && opendir(SUB_DIR,"$dir_cont"){ do_stuff....... }
This is where I get stuck .... I guess I need some kind of recursion or a way to search all directories and their respective sub-directories. Also I need a way for my script to remember where each file (if it has the suid or sgid bit) is located so the log file has:
/usr/local/bin/some_file suid /var/log/.hidden/file sgid /home/greco/bin/be_greco sgid
I know that there are various modules out there (File::Find) that I can utilize, but since I am still in my learning stages, I would like to go on this journey of reinventing the wheel so to speak, so I can better understand perl and learn some things along the way :) All help will be much appreciated.