Gary Stainburn wrote:

Hi folks,

I've got a hash such as:

%masters=('VSL01'=>{'type'=>'S','name'=>'Vehicle Ledger accounts'},
         'ALD01'=>{'type'=>'S','name'=>'ALD Automotive Ltd'},
         'ALP01'=>{'type'=>'S','name'=>'Alphabet GB Ltd'},
         'ANC01'=>{'type'=>'S','name'=>'ANC Rental Group'},
         'APP01'=>{'type'=>'S','name'=>'Appleyard Group'},
         'ARR01'=>{'type'=>'B','name'=>'Arrive Group'},
         'ARV01'=>{'type'=>'S','name'=>'ARVAL PHH Ltd'},
         'ATS01'=>{'type'=>'B','name'=>'ATS Group'});

and at the moment I use a join like:

$SQL.=join("', '",keys %masters);

How can I change this so that it only includes those master keys where the type = 'S'.

I know that I could do it with a foreach/if etc, but seem to think that this should be a perfect use for map - having never used it and want to play - but I can't seem to get started.


grep is what you need, perldoc -f grep $SQL = join ("', '", grep {$masters{$_}->{'type'} eq 'S'} keys %masters);


The closest I got was:


$SQL.=join("', '",map {($masters{$_}{'type'} eq 'S') ? $_ : undef } sort keys %masters);

but that just returned the same number, but undef for the 'B' entries, causing null strings to be included and warnings to be printed.
Anyone got any ideas?






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



Reply via email to