in reply to Re: How to select specific lines from a file
in thread How to select specific lines from a file

Great, it seems to do the trick... Is it correct that I get all positions in the HoA that you create?
while(<>) %HoA=(); next unless /^ATOM\b/; @split_atom_line=split(/\s+/, $_); $chain=$split_atom_line[4]; $position=$split_atom_line[5]; $Zcoordinate=$split_atom_line[8]; if (not exists $HoA{$chain} or $position < $HoA{$chain}[0]) { $HoA{$chain} = [$position, $Zcoordinate]; } for $key ( keys %HoA ) { print "$key: $HoA{$key}[0]\n"; } }

Replies are listed 'Best First'.
Re^3: How to select specific lines from a file
by Anonymous Monk on Apr 29, 2014 at 17:54 UTC
    I mean, it keeps adding data although the position and the chain have already been inserted... Shouldn't the HoA contain only two lines in this example, i.e. chains A and B and 1 position for each (the smallest)?
      Damn! I had the HoA declaration inside the while loop... Works smoothly now, thanks a lot!