develooper Front page | perl.beginners | Postings from August 2009

Re: 'Join' query

Thread Previous
From:
Jim Gibson
Date:
August 7, 2009 08:13
Subject:
Re: 'Join' query
Message ID:
C6A1929B.7781%JimSGibson@gmail.com
On 8/7/09 Fri  Aug 7, 2009  8:03 AM, "jet speed" <speedjet5@googlemail.com>
scribbled:

> Hi,
> 
> I would like to join the $abc with ':'  the final desired output 1:2:3:4:5
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> my $abc = "1 2 3 4 5";
> my $out = join ':', $abc;
> print "$out";
> 
> executing the above, i get the same output 1 2 3 4 5, not sure were am going
> wrong.
> 
> Any help on this would be much appreciated.

You first need to split $abc on whitespace:

    my $out = join( ':', split(/ /,$abc) );

join only inserts its first argument between successive members of its
subsequent arguments. Since you only gave join one argument after the first
one, it does nothing.



Thread Previous


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