A new Hamiltonian formulation for fluids and plasmas. Part 1. The perfect fluid