rianne809 has asked for the wisdom of the Perl Monks concerning the following question:
package Load; #use strict; use warnings; use vars qw ($VERSION @ARRAY_LIST @SEARCH_STRING); our $VERSION=0.10; our @ARRAY_LIST=(); our @SEARCH_STRING=(); sub new { my ($class) = @_; my $self = { _listNames => undef, _search => undef }; bless $self,$class; return $self; } sub listNames { my ($self,$listNames) = @_; $self->{_listNames}= $listNames if defined ($listNames); open(LIST,"$listNames") || die "Error::Cannot load names!!!\n"; #my $buff="./data/buffed.dat"; #open(BUFF,">$buff") || die "Error::Cannot load buffer file!!!\n"; while(<LIST>) { chomp($_); push (@ARRAY_LIST,$_); } } sub search { my ($self,$search) = @_; $self->{_search}=$search if defined ($search); our @SEARCH_STRING=grep(/$search/,@ARRAY_LIST); } sub display { my ($self) = @_; print "\n\nSearching directory ...\n\n"; sleep 2; print "Search Results:\n"; print "=======================================\n\n"; foreach $files (@SEARCH_STRING){ print "$files\n"; } } 1;
And here is my perl script:
#! /usr/perl/bin/perl use lib qw(./modules); use warnings; use Load; $list="./data/list.txt"; $dir=Load->new(); $dir=Load->listNames($list); $counter=0; print "=============================================\n"; print "== D I R E C T O R Y ==\n"; print "=============================================\n\n"; sleep 1; ### Search Loop until($counter==1){ print "Please enter name to be searched:\n\n"; chomp($string=<STDIN>); sleep 2; $dir=Load->search($string); $dir=Load->display(); sleep 2; print "Would you like to search another?[y/n]\n\n"; chomp($ans=<STDIN>); if ($ans=~/^[yY]/){ print "\n"; next; } elsif ($ans=~/^[Nn]/){ print "\nClosing directory ...\n\n"; sleep 2; $counter++; } else { $counter++; } }
Edit: g0n - moved text out of code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how can i load the files and search for match?
by Zaxo (Archbishop) on Oct 12, 2005 at 12:50 UTC | |
|
Re: how can i load the files and search for match?
by davidrw (Prior) on Oct 12, 2005 at 13:11 UTC | |
by rianne809 (Novice) on Oct 13, 2005 at 18:03 UTC |