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.

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 <patrikh@xxxxxxxxxxxxxxxxxxxxx>
Junior Programmer
.



Relevant Pages

  • Re: Unicode from Web to MySQL
    ... It's for storing too. ... and just pass it to MySQL as you created it. ... It probably contained illegal characters from SQL point of view. ...
    (comp.lang.python)
  • Re: java float problem
    ... Since some of the fuzz factor may be starting and ending in MySQL, ... 5 is the precision and 2 is the scale. ... Since these are financial calculations, you might consider storing this ...
    (comp.lang.java.programmer)
  • Re: SQL question about performance...
    ... I don't think anyone minds, and those who have knowledge will try to help, but you would really probably be better off asking on a MySQL list. ... You are storing, I think, 4 bytes of data, and considering storing it as a hex-encoded 8-character string. ... The MySQL docs have lots of good optimization advice. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)
  • Re: detecting the existance of a table [was: undefined behaviour for sub-transactions?]
    ... my $method = shift; ... database name, but I guess I was wrong; ... for the Pg, MySQL, and SQLite2 drivers to either make use of that attribute, ...
    (perl.dbi.users)
  • [PATCH] postgres support for DBIx::TextIndex
    ... This should not break mysql. ... my $self = shift; ... +sub db_delete_mask { ... max_word_length int NOT NULL default 0, ...
    (perl.dbi.users)