develooper Front page | perl.perl6.users | Postings from January 2019

Re: **@args question

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
January 4, 2019 19:50
Subject:
Re: **@args question
Message ID:
4f03a67b-491e-84fc-dfda-ec51d44fad5e@zoho.com
On 1/3/19 12:43 AM, Richard Hainsworth wrote:
> <snip>
>>>
>>> The term "slurpy" did help a lot.
>>>
>>> :-)
>>>
>>> I am writing your explanation down for my records.
>>
>>
>> Well Golly!
>>
>> $ p6 'sub printx(**@args){print(@args)}; printx("abc",1,"def\n");'
>> abc 1 def
>>
>> $ p6 'sub printx(**@args){print @args, "\n"}; printx("abc",1,"def");'
>> abc 1 def
>>
>> Question:
>> $ p6 'sub printx(**@args){print(@args)}; printx("abc","xyz","def\n");'
>> abc xyz def
>>
>> Are the spaces suppose to be there?
> 
> In each case you are using 'print @args', then `printx` adds on a "\n" 
> either to the last item or the final string, which in each case results 
> in exactly the same string. The way 'print' handles an array is to put a 
> space between each item, which can be very confusing when dealing with 
> items that are themselves strings with spaces.
> 
> For other "stringifications" of an array, try 'print @args.fmt("%s,")' 
> if you want a comma, or 'print @args.perl'.
> 
> I find '.say for @args' is better because I get an item on each line.
> 
> Also 'dd @args' is quite useful.


Thank you!

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About