Uri,

On Sun, Aug 4, 2013 at 6:58 AM, Uri Guttman <u...@stemsystems.com> wrote:

> On 08/04/2013 01:44 AM, timothy adigun wrote:
>
>
>> OR some like to write it like so:
>> {
>>   local $" = '][';
>>   print '[', "@fruits", ']';
>> }
>>
>
> that is a poor idea. setting $" isn't needed to do a simple join.
>

 Yes I agree with you that setting $" is a "bad" idea, but I only mentioned
it. That was why I wrote "some like to write it like so..."

>
> but what no one has said is a more direct way to do this. you need map and
> join but it is much cleaner and easier to understand and without the
> bracket or precedence issues:
>
> my @fruits = qw( apple pear banana ) ;
> print join '', map "[$_]", @fruits ;
>
> now you can see each element surrounded by [] and then joined into one
> string for printing.
>
> you don't even need the join if you are just printing it but i put it
> there so you can use the same concept if you are going to save the string.
>
> print map "[$_]", @fruits ;
>
> that is very clear what is going on and should be the code used to print
> such a string. use the join '' form if you need to keep the string.
>
> uri
>
> --
> Uri Guttman - The Perl Hunter
> The Best Perl Jobs, The Best Perl Hackers
> http://PerlHunter.com
>



-- 
Tim

Reply via email to