And there are historical examples of this 'flexibility'.
First one that comes to mind is the battle of Marathon.
Although it took place 200 years prior to the Punic Wars and involved the Greeks and Persians, it's a classic example of a general adapting to the situation.
First off, instead of the Hoplites advancing in slow tightly, packed Phalanx formation, Miltiades (I think) ordered his men to spread their formations and charge.
Seeing a Greek Hoplite army running towards them scared the bejesus out of the Persians, who quickly tried to reform a rear guard as the rest of their troops scattered back to their boats.
Miltiades then put his weaker troops in the center and fanned his flanks out in a very risky attempt to match the Persians. As the Persian engaged the center, he brought his flanks in and drove the Persians from the beach (and into a swap).
If you think about it, Marathon really was the first Cannae.