xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks!
I'm attempting find all "pl" files in machine,and store to database.below is my code:
1. @search_results will be much large if files is too many.I want to deal with files "streamly",other than push all to array. any suggestion?
2. $count is ugly,have any built-in variable?
Thanks in advance!!!!
I'm attempting find all "pl" files in machine,and store to database.below is my code:
questions:#!/usr/bin/perl #use Getopt::Long; use strict; use File::Find; use DBI qw(:sql_types); my @search_result; # find files find (\&wanted,"."); #save to database. foreach (@search_result) { my @file_stat = stat; save_data(@file_stat,$_); } sub wanted { if(/\.pl$/i) { push @search_result,$File::Find::name; } } sub save_data { my $sql = q(insert into file_stat values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)) +; my $dbh = DBI->connect('dbi:ODBC:test','test','test123',{AutoCommi +t => 1,RaiseError => 1}) or die "error!!\n"; my $sth = $dbh->prepare($sql); my $count = 1; foreach (@_) { if($count==14) { $sth->bind_param(14,$_); } else { $sth->bind_param($count,$_,SQL_INTEGER); } $count ++; } $sth->execute; }
1. @search_results will be much large if files is too many.I want to deal with files "streamly",other than push all to array. any suggestion?
2. $count is ugly,have any built-in variable?
Thanks in advance!!!!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regarding File::Find
by chromatic (Archbishop) on Nov 17, 2006 at 07:00 UTC | |
by xiaoyafeng (Deacon) on Nov 17, 2006 at 07:21 UTC | |
by Hofmator (Curate) on Nov 17, 2006 at 09:46 UTC | |
Re: regarding File::Find
by quester (Vicar) on Nov 17, 2006 at 07:13 UTC | |
Re: regarding File::Find
by inman (Curate) on Nov 17, 2006 at 12:59 UTC |
Back to
Seekers of Perl Wisdom