> -----Original Message-----
> From: Patrik Hasibuan [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, June 28, 2007 12:55
> To: Milis CPAN-Perl-Beginners
> Subject: Need idea for doing automatic iteration, please.
> 
> Dear my friends...
> 
> I want my code does an action if it find a directory or file, 
> namely: storing the url/path of a file or a directory onto 
> mysql database.
        Working too hard, just use File::Find and you can control how
deep you want to go, but if  you just want all files, then take a look
at the doc and with thexamples provided, should be very simple to do.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449           FAX
http://fedex.com/us 

> 
> I am meaning, my code should look up every file/directory 
> name resides under the "$rootdir" iteratively for doing 
> storing onto mysql on each find.
> 
> The algorithm For doing find from beginning to the end of the 
> 1 level under $rootdir is still simple, it's only a "while{..}{...}". 
> But the problem comes when the directory has a/some 
> directory/-es whereas my code should also find them and 
> stores them onto the mysql. 
> If every directory has a limited level (for instance maximum 
> only 3 level subdirectories below to the bottom) then all I 
> have to do is simply creating nested "while(...)[..] " for 3 
> level. But in this case of course each directory may 
> unpredictably has hundreds or thousands subdirectories/files 
> in hundreds or thousands levels below to the bottom.
> 
> Please suggest me some ideas where I can implement into my 
> codes in order to enable my code to find all subdirectories 
> and files where placed under $rootdir.
> A very simple code-sample is very......very.......welcomed.
> 
> Here is my current code under below. This code still only can 
> find 1 level, only exactly 1 level under $rootdir.
> ---------------------
> package iterdir;
> use kueri;
> 
> sub baru{
>   my $kelas = shift if @_;
>   print "Nama superkelas: $kelas \n";
>   return( bless{} );
> }
> 
> sub bukadir{
>   my $kelas = shift;
>   $rootdir="/home/patrikh/sementara/tes";
>   opendir("dirku", "$rootdir");
>   $statusp=chdir($rootdir);
>   if ($statusp){
>     print "berhasil membuka direktori-->$rootdir\n";
>     while ($entridir=readdir("dirku")){
>       print "entridir: $entridir\n";
>       $sqlku=kueri->baru;
>       $sqlku->konek;
>       if (($entridir ne '.') and ($entridir ne '..')){
>       my $strsql = "insert into tblarsip (location) values 
> ('".$entridir."')";
>       print "strsql: $strsql\n";
>       $sth=$kueri::dbh->prepare($strsql);
>       $sth->execute;
>       $sth->finish;
>       }
>     }
>   } else{
>     print "gagal membuka direktori yang diinginkan: $rootdir\n";
>     exit 1;
>   }
> }
> 
> 1;
> 
> -- 
> Patrik Hasibuan <[EMAIL PROTECTED]>
> Junior Programmer
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
> 
> 
> 

**********************************************************************
This message contains information that is confidential and proprietary to FedEx 
Freight or its affiliates.  It is intended only for the recipient named and for 
the express  purpose(s) described therein.  Any other use is prohibited.
**********************************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to