On Sun, Aug 04, 2013 at 12:59:29PM +0800, *Shaji Kalidasan* wrote:
> Greetings,
> 
> I am facing some difficulty using join to display the array elements
> 
> Here is the code snippet
> 
> [code]
> use strict;
> use warnings;
> 
> my @fruits = qw/apple mango orange banana guava/;
> 
> print '[', join '][', @fruits, ']';
> [/code]
> 
> How can I make the output to eliminate the last empty square brackets [] 
> using a single print statement. I used two print statements as shown in the 
> code snippet above (#lines are commented out)
 
Limit what join acts on by using parenthesis.
   print '[', join ( '][', @fruits ), ']';

This keeps your closing bracket from being part of the list that join is acting 
upon.

-- 
            Michael Rasmussen, Portland Oregon  
          Be Appropriate && Follow Your Curiosity
  Other Adventures: http://www.jamhome.us/ or http://gplus.to/MichaelRpdx
A special random fortune cookie fortune:
Follow the carrot.
    ~ http://someoneoncetoldme.com/gallery/14052010

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to