Here's something that AFAICT meets your requirements, but since it's Friday evening I might be missing a test case for which it fails*. But as I mention here, it's really still just an approximation.
sub mysay (;+@) { return say $_ unless @_; if ( ref $_[0] eq 'ARRAY' ) { unshift @_, @{shift()} } elsif ( ref $_[0] eq 'HASH' ) { unshift @_, %{shift()} } say join "\n", @_; }
* Update: Of course, just two minutes after posting I thought of one: say \@x would normally print ARRAY(0x...), this function dereferences it. Like I said, an approximation! I think you might be better off just biting the bullet and writing say join "\n", ...; ...
Test cases...
#!/usr/bin/env perl use warnings; use strict; use feature 'say'; $_ = "Foo"; my @x = ("x", "y"); my @y = (); my $z = "Bar"; my %h = ( abc => 123 ); { local $, = "\n"; say; say "------"; say $z; say "------"; say "Hello"; say "------"; say "cool", "world"; say "------"; say @x; say "------"; say "foo", @x; say "------"; say @y; say "------"; say %h, "xyz"; say "######"; } sub mysay (;+@) { return say $_ unless @_; if ( ref $_[0] eq 'ARRAY' ) { unshift @_, @{shift()} } elsif ( ref $_[0] eq 'HASH' ) { unshift @_, %{shift()} } say join "\n", @_; } mysay; say "------"; mysay $z; say "------"; mysay "Hello"; say "------"; mysay "cool", "world"; say "------"; mysay @x; say "------"; mysay "foo", @x; say "------"; mysay @y; say "------"; mysay %h, "xyz"; say "######";
In reply to Re: Spotting an empty array as argument
by haukex
in thread Spotting an empty array as argument
by Chuma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |