The foo(a => 1, b => 2)
style is the usual way of emulating named arguments. The bar({a => 1, b => 2})
is usually used only for supplementary (and possibly optional) arguments.
For typical usage, I prefer the first form. The {}
are extra typing, extra noise to read, and create a possible error if you leave out either or both braces. Any performance difference is negligible. (If it's not, you have bigger problems.) On the other hand, wrapping the arguments in an anonymous hash constructor can help you find errors at compile-time rather than runtime.
The second form is typically seen mixed with positional arguments. e.g. Benchmark does this:
cmpthese(10000, {
foo => \&foo,
bar => \&bar,
});
While Tk leaves the {}
out:
my $text = $w->Scrolled('Text', -width => 80, -height => 50);
It's usually a stylistic choice.