Tracking which elements from an array have been matched.



Hello



I have an array of records. I need to search this array for a
particular record (or records) based on a record id.



This is simple enough (e.g. using the grep function)



@found = grep {/$rec_id/} @array;



However, I also need to keep a track of which records in the array have
been 'found' (so I can later identify any records that haven't).



This would be pretty simple with a loop, something like:



for ($i=0; $i < @data; $i++)

{

if ($array[$i] =~ /$rec_id/)

{

push (@found, $array[$i]) ;

$found_recs{$i} = "TRUE";

}

}



But this seems quite inefficient, and I'm sure there must be a better
way of doing this. This is part of a larger script that is becoming
quite large so I'm trying to be more efficient (and to improve my
coding).



Can anyone offer any suggestions.



Cheers

Andy Taylor


Capgemini is a trading name used by the Capgemini Group of companies which includes Capgemini UK plc, a company registered in England and Wales (number 943935) whose registered office is at No. 1 Forge End, Woking, Surrey, GU21 6DB.
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.


Relevant Pages

  • Re: ishandle(h) vs. try(get(h))
    ... > that is, an array of zeros. ... try abused to hide bad/lazy coding. ... % filter out zeros ...
    (comp.soft-sys.matlab)
  • RE: VLOOKUP Function using Data Ranges.
    ... an external reference to an array in another spreadsheet (assume the ... spreadsheet is in the same directory on the same computer). ... > What is very time consuming is this "coding" part. ... > according to column 2 in my ranged data table. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Difficulty with slice of referenced array
    ... >> get an array to pass to my subroutine am I condemned to coding the ... or is there a correct way of coding the slice? ... what happens when I have "use diagnostics" on: ... Argument "" isn't numeric in aelem at ./bar2.pl line 10. ...
    (comp.lang.perl.misc)
  • Re: Difficulty with slice of referenced array
    ... or is there a correct way of coding the slice? ... but with a ref to @array, ... can't be a slice, there can only ever be one scalar in the ). ... in scalar context has the peculiarity that ...
    (comp.lang.perl.misc)
  • Re: array name
    ... > OK, in fact, I summed up my coding pb in order not to have a too long ... > As this function is called from different files, the array name ... > I'd like to use the first prototype and being able to get the name of ... [Obi Wan tone off] ...
    (comp.lang.php)