in reply to What is correct way to reference?
Hi, see what the Monks said about using the right tools to work with your XML.
But in general, one way to do what you want when you don't know whether you have a simple scalar value or a reference to an array, without a loop or multiple print statements, is to use the default list separator, stored in the special global var $", and just interpolate the list, after you extract it based on your ref check:
Output:perl -Mstrict -wE ' my $foo = "bar"; my $baz = [ "qux", "quux" ]; # we have both kinds local $" = "\n"; # change list separator to a newline say ( ref $_ eq "ARRAY" ? "@$_" : $_ ) for ( $foo, $baz ); '
bar qux quux
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: What is correct way to reference?
by AnomalousMonk (Archbishop) on May 22, 2017 at 20:48 UTC | |
by 1nickt (Canon) on May 22, 2017 at 21:30 UTC |