Thanks for that Rob, Jenda I hadn't realized you could do that with the hash value,
Easy when someone shows you. Brian :-) -----Original Message----- From: Rob Dixon [mailto:[EMAIL PROTECTED]] Sent: 29 January 2003 16:10 To: [EMAIL PROTECTED] Subject: Re: References Brian Ling wrote: > Hi list, > > The following code fragment works but has a horrible feel about it, > can anyone suggest ways to improve it. > > The data structure is generated by an XML parser. > > for ( keys %{$parsed_data->{value}->{NetworkServices}->{value}} ) { > if ( > $parsed_data->{value}->{NetworkServices}->{value}->{$_}->{value}->{Inter > face}->{value}->{DeviceName}->{value} eq "modem" and > > $parsed_data->{value}->{NetworkServices}->{value}->{$_}->{value}->{PPP}- >> {value}->{UserDefinedName}->{value} eq $serviceName) { > print "found correct modem\n"; > > $parsed_data->{value}->{NetworkServices}->{value}->{$_}->{value}->{PPP}- >> {value}->{AuthName}->{value} = $username; > } > } Hi Brian. As Jenda said, use temporary variables. Also you can go through all of the _values_ in the hash instead of all the keys, which is all you need here since you're only using the key to index the hash. Thirdly any }->{ or ]->[ pair can be abbreviated to }{ or ][. So how about this: for ( values %{$parsed_data->{value}{NetworkServices}{value}} ) { my $iface = $_->{Interface}{value}; next unless $iface->{DeviceName}{value} eq "modem"; my $ppp = $_->{PPP}{value}; next unless $ppp->{UserDefinedName}{value} eq $serviceName; print "found correct modem\n"; $ppp->{AuthName}{value} = $username; } HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] BBCi at http://www.bbc.co.uk/ This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system, do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]