array is not the best data structure for this kind of search operation, but 
if you insist on using an array, try:

my $userinput = "abcd";
my @allfilesystems = (["xxx",1234,5678],["abcd",9999,1111]);
my @buffer = ();

foreach my $i (0 .. $#allfilesystems){
        my $flag = 0;
        foreach my $j ( 0 .. $#{$allfilesystems[$i]}){
                push(@buffer,$allfilesystems[$i][$j]);
                $flag = 1 if($allfilesystems[$i][$j] =~ /$userinput/io);
        }
        print join("\n",@buffer) if($flag);
        @buffer = ();
}

the above prints:

abcd
9999
1111

which should be what you want right? :-)

as i said before, this is not the best appoach. if you always want to search 
for a certain field(in your case, i think you are searching the Plex_Name 
field), you should index that field such as using a hash instead of an 
array.

david

Yanet I wrote:

> Actually, the problem with the previous one (very stupid, by the way) was
> that I wasn't providing the user input.  Anyway, the output right now is
> the following:
> 
> #./getinfo.pl data02
> Filesystem Information:
> data02-01
> 
> 
> How can I print the whole row? So my output will look as I described on my
> previous email:
> #./getinfo.pl data02
> Filesystem Information:
> Disk_Type:            sd
> Disk_Name:            oradg_C9-09
> Plex_Name:            roll02-01
> Disk_VolName:         oradg_C9
> Device_Number:        HDS99600_19
> 
> 
> 
> -----Original Message-----
> From: Leon, Yanet I,,DMDCWEST
> Sent: Tuesday, August 27, 2002 10:42 AM
> To:   [EMAIL PROTECTED]
> Subject:      LISTS OF LISTS - Help please!!
> 
> I have an array which contains the entries below - the
> output was generated with the following loop:
> for $r ( 0 .. $#allfilesystems ) {
> for $c ( 0 .. $#{
> $allfilesystems[$r] } ) {
> print "elt $r $c is
> $allfilesystems[$r][$c]\n";
> }
> print"\n";
> }
> OUTPUT:
> elt 0 0 is sd
> elt 0 1 is appsdg_CA-01
> elt 0 2 is dmdcapps_archive-01
> elt 0 3 is appsdg_CA
> elt 0 4 is HDS99600_18
> 
> elt 1 0 is sd
> elt 1 1 is appsdg_CB-01
> elt 1 2 is dmdcapps_archive-01
> elt 1 3 is appsdg_CB
> elt 1 4 is HDS99600_17
> 
> elt 29 0 is sd
> elt 29 1 is oradg_C9-09
> elt 29 2 is roll02-01
> elt 29 3 is oradg_C9
> elt 29 4 is HDS99600_19
> 
> elt 30 0 is sd
> elt 30 1 is oradg_C9-10
> elt 30 2 is arch01-01
> elt 30 3 is oradg_C9
> elt 30 4 is HDS99600_19
> 
> 
> 
> What I need to do is to compare the user input with each of
> the entries in my array.  For instance, if the user enters roll02 - the
> whole row containing roll02 must be printed.
> 
> yanet@myhost#getinfo.pl roll02
> Filesystem Information:
> Disk_Type:            sd
> Disk_Name:            oradg_C9-09
> Plex_Name:            roll02-01
> Disk_VolName:         oradg_C9
> Device_Number:        HDS99600_19
> 
> The above is the ideal output.  However, I have had trouble
> comparing my user output with each of the elements of my array.  The
> following was attempted but, it doesn't work:
> for $r ( 0 .. $#allfilesystems ) {
> for $c ( 0 .. $#{ $allfilesystems[$r] } ) {
> print "$allfilesystems[$r][$c]\n" if
> $allfilesystems[$r][$c] =~ /$userinput/i;
> }
> print"\n";
> }
> 
> OUTPUT:
> Use of uninitialized value at ./vxprint2.pl line 29.
> sd
> Use of uninitialized value at ./vxprint2.pl line 29.
> oradg_C9-10
> Use of uninitialized value at ./vxprint2.pl line 29.
> arch01-01
> Use of uninitialized value at ./vxprint2.pl line 29.
> oradg_C9
> Use of uninitialized value at ./vxprint2.pl line 29.
> HDS99600_19
> 
> I know that the above is supposed to print only the entry,
> WHICH CONTAINS THE USER INPUT but I want all the entries in the
> corresponding row.  How may accomplish this??  My attempt is not even
> doing
> the minimum.  Any suggestions???
> 
> Thank you!!!
> 
> Yanet


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to