Hi good day to all. I have created a module which will load a list of addresses and help users to search for the name they wanted to search. I just cant load the list so the search returns nothing. here is my module, please help, thanks a many.

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


In reply to how can i load the files and search for match? by rianne809

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.