Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Unsplit An Array

by virtualweb (Sexton)
on Sep 22, 2008 at 19:17 UTC ( #713079=perlquestion: print w/ replies, xml ) Need Help??
virtualweb has asked for the wisdom of the Perl Monks concerning the following question:

Hi: I splitted an array containig a word because I needed to change some of the elements, (some letters): $Tne_Word = 'antidisestablishmentarianism'; @splitted_word = split(//, $Tne_Word); when I print to the browser @splitted_word it reads: a n t i d i s e s t a b l i s h m e n t a r i a n i s m How do I make it look whole again, (without the spaces) Thanx VirtualWeb

Comment on Unsplit An Array
Re: Unsplit An Array
by FunkyMonk (Canon) on Sep 22, 2008 at 19:19 UTC
Re: Unsplit An Array
by hexcoder (Hermit) on Sep 22, 2008 at 19:52 UTC
    Set the list seperator to the empty string
    use strict; use warnings; my $Tne_Word = 'antidisestablishmentarianism'; my @splitted_word = split(//, $Tne_Word); { local $"=''; print @splitted_word, "\n"; }
    Update (thanks to jwkrahn and ikegami)
    use strict; use warnings; my $Tne_Word = 'antidisestablishmentarianism'; my @splitted_word = split(//, $Tne_Word); { local $"=''; print "@splitted_word\n"; }

      You changed the value of the $" variable but  print @splitted_word, "\n"; doesn't use the $" variable.   It does however use the $, and $\ variables.

      Not quite. That should be

      { local $,=''; local $\="\n"; print( @splitted_word ); }

      or

      { local $"=''; print( "@splitted_word\n" ); }

      See $,, $\ and $".

      However, using join is less error-prone, more natural, shorter and more versatile (you can use it when you don't want to print).

      print( join( '', @splitted_word ), "\n" );
        Ikegami: Thanx for your input a variation ofyourline of code did the trick @Make_Whole = join( '', @splitted_word ); I had tried the following prior to posting for help and hadnt work: @Make_Whole = join( //, @splitted_word ); It did work with commas however thanx again VirtualWeb
      Thanks for the correction jwkrahn and ikegami. The above response was obviously a bit too hasty. I intended ikegami's second variant. But it is probably better to use join, since the behavior does not rely on interpolation.
      I updated the code to correct the error.
Re: Unsplit An Array
by jwkrahn (Monsignor) on Sep 22, 2008 at 20:13 UTC
    I splitted an array containig a word because I needed to change some of the elements, (some letters)

    You actually split a scalar containing a word into an array.

    Have you tried using the substitution or transliteration operators?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://713079]
Approved by andyford
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2015-03-28 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:









    Results (625 votes), past polls