Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Iterating over arrays reference - filtering data based on condition? 1

Status
Not open for further replies.

dmazzini

Programmer
Jan 20, 2004
480
US
I different arrays references got from different sheets (xls files).

Array reference looks like this:

Code:
RncId | WBTSId | X | Y | Z
1    100 100  100 100 
2    200     200  200 200
3    300     400  600
..........................
..........................
ans so on




Code:
RncId | WBTSId |WCelID | X | Y | Z
1 100	100     100 100 
2 200     200     200 200
3 300     400     600 300
..........................
..........................
an so on

Script reads it very well and produce the desired output. Now I want to filter "array reference data" based on user input.

I have a hash $SINGLESITE{$RNCID}{$WBTSId}) that is built based on user input (Tk window).

$SINGLESITE{$UserRncId}{$UserWbtsId}=1;

In few words just I want to go the next row of the array reference if the hash is not defined.
instead of go down to the rest of the " <CODE>. "

Code:
Sub xx {

for  $objectClass (keys(%DATA)) {
 
  <SOMECODE>

foreach my $ref_array (@$array) {
columns=(0 .. $LastCol-1);                            
   for $col(@columns){
       $value = $PARAMETER_VALUE{$col}{$objectClass}{@$ref_array[$col]};
       $header = $PARAMETER_HEADER{$col}{$objectClass};
       $RNCID= $value if ($header eq "RncId" && @$ref_array[$col] ne "" ); 
       $WBTSId= $value if ($header eq "WBTSId" && @$ref_array[$col] ne "" );
       $RNCID= trim($RNCID);
       $WBTSId = trim($WBTSId);
                       
       if ($action eq 'SINGLE') {                      	                  
           if (!defined ($SINGLESITE{$RNCID}{$WBTSId})) {                       
               print "Go to next row of the reference and not execute the <CODE> below\n";
           }
       }
                       
                      <CODE> 
                      <CODE>
                      <CODE>
                      <CODE>
                      <CODE>
                      <CODE>
                      <CODE>
                      <CODE>
                      <CODE>
                      <CODE>     
                      
  } 
  }
  
 }
  
}

I was trying using last, next etc, but it works just when RNCID and WBTSid are in the first row....
BTW, Condition with the hash works fine.

cheers

dmazzini
GSM System and Telecomm Consultant

 
use the "next" control.

Code:
for (array) {
   if (condtion) {
      next;
   }
}

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Hi Kev

next function did the job, I had issues with some conditions for some other sheets.....that's why it did not work before. Thanks

Code:
if ($action eq 'SINGLE') {    
    unless ($SINGLESITE{$RNCID}{$WBTSId}) {next};                		          
 }

dmazzini
GSM System and Telecomm Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top