in reply to how can i load the files and search for match?

First thing i see is this:
package Load; #use strict;
Which probably means there was some warning and it "went away" with strict commented out... First, remove that, and we get:
Global symbol "$files" requires explicit package name at Load.pm line +44. Global symbol "$files" requires explicit package name at Load.pm line +45.
To fix that, make it read foreach my $files (@SEARCH_STRING){ in the display() method.

Next error is this, which is the root cause of your problem:
Can't use string ("Load") as a HASH ref while "strict refs" in use at +Load.pm line 22.
Line 22 is in listNames() and is:
$self->{_listNames}= $listNames if defined ($listNames);
The calling code is:
$dir=Load->new(); $dir=Load->listNames($list);
That needs to be something along the lines of:
my $load = Load->new(); my $dir = $load->listNames($list);
Since listNames() accesses values of the object (blessed hashref), you can only invoke it on an object, and not directly on the class name. You should similarily modifiy the ->search() and ->display calls as well.

Also, be _sure_ to add use strict; in your program file as well...

Replies are listed 'Best First'.
Re^2: how can i load the files and search for match?
by rianne809 (Novice) on Oct 13, 2005 at 18:03 UTC
    Hi I already changed the script to this :

    #! /usr/perl/bin/perl use lib qw(./modules); use warnings; use strict; use Load; my $list="./data/list.txt"; my $dir=Load->new(); $dir->listNames($list); my $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(my $string=<STDIN>); sleep 2; $dir->search($string); $dir->display(); sleep 2; print "Would you like to search another?[y/n]\n\n"; chomp(my $ans=<STDIN>); if ($ans=~/^[yY]/){ print "\n"; next; } elsif ($ans=~/^[Nn]/){ print "\nClosing directory ...\n\n"; sleep 2; $counter++; } else { $counter++; } }

    but still no returned search result. Please help, thanks.

    Edit: g0n - moved node text out of code tags