James Kelty wrote: > > Hello. Hello,
> I am using the File::Find module from Cpan to travers some filesystems to, > well, find a file. > Here is my small snippet of code. Basically what is happening is that the > sub is returning a 0 instead of the file name. What am I doing wrong? > > #!/usr/bin/perl -w > use strict; > use File::Find; > use vars qw/*name *dir *prune/; > *name = *File::Find::name; > *dir = *File::Find::dir; > *prune = *File::Find::prune; > > print "You havn't defined an \$CONF file. Please do so: "; > $Conf = <STDIN>; > chomp($Conf); > while($Conf eq "") { > print "You havn't defined an \$CONF file. Please do so: "; > chomp($Conf = <STDIN>); > } Why have two copies of the print and input statements? my $Conf; do { print "You havn't defined an \$CONF file. Please do so: "; chomp( $Conf = <STDIN> ); } until ( length $Conf ); > if(not -f $Conf) { > print "Sorry, that file does not exist, at all!\n\n\n"; > print "I am now going to traverse the file system and look for: > \"base.conf\"\n"; > > my $newConf = File::Find::find({wanted => \&wanted}, '/'); File::Find::find() does not return any useful value, you have to store the file found in a variable. > print "I found this file $newConf. Would you like to use it? [y]\n"; > chomp(my $answer = <STDIN>); > if($answer =~ /y|Y/) { > $Conf = $newConf; > } > else{ > print "Okiee, dokiee!\n"; > } > > sub wanted { > /^base\\.conf\z/s && This regex looks for 'base\' at the start of the string, then any character '.' and then 'conf' at the end of the string. You probably want /^base\.conf\z/ > return("$name"); perldoc -q quoting Found in /usr/lib/perl5/5.6.0/pod/perlfaq4.pod What's wrong with always quoting "$vars"? > } #!/usr/bin/perl -w use strict; use File::Find; my $Conf; do { print "You havn't defined an \$CONF file. Please do so: "; chomp( $Conf = <STDIN> ); } until ( length $Conf ); if ( -f $Conf ) { print "Okiee, dokiee!\n"; } else { print "Sorry, that file does not exist, at all!\n\n\n"; print qq(I am now going to traverse the file system and look for: "base.conf"\n); my @newConf; find( { no_chdir => 1, wanted => sub { m|/base\.conf$| and push @newConf, $_ } }, '/' ); for ( @newConf ) { print "I found this file $_. Would you like to use it? [y]\n"; chomp( my $answer = <STDIN> ); $answer ||= 'y'; if ( $answer =~ /^y/i ) { $Conf = $newConf; last; } else { print "Okiee, dokiee!\n"; } } } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]