Front page | perl.beginners |
Postings from August 2009
Re: 'Join' query
Thread Previous
|
Thread Next
From:
jet speed
Date:
August 7, 2009 09:21
Subject:
Re: 'Join' query
Message ID:
b43e0e600908070921l7c59e497qe137775187cacb21@mail.gmail.com
On Fri, Aug 7, 2009 at 4:46 PM, Shawn H. Corey <shawnhcorey@gmail.com>wrote:
> jet speed wrote:
>
>> 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.
>>
>> Thanks
>> Sj
>>
>>
> $abc is a string; join works with arrays. Two solutions: make it @abc or
> just replace the spaces.
>
> my @abc = qw( 1 2 3 4 5 );
> my $out = join( ':', @abc );
>
> or
>
> my $abc = "1 2 3 4 5";
> ( my $out = $abc ) =~ s{ \s+ }{:}gmsx;
>
>
>
>
> --
> Just my 0.00000002 million dollars worth,
> Shawn
>
> Programming is as much about organization and communication
> as it is about coding.
>
> I like Perl; it's the only language where you can bless your
> thingy.
>
---------------------
Hi Guys,
I just want to thank everyone for their contribution, i have tested all the
suggestion, it all works.
Many Thanks
Sj
Thread Previous
|
Thread Next