On Fri Aug 07 2009 @  4:03, 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";
The function join works on lists not scalars. This would do what you want:

  my @important_numbers = (1..5);
  my $out = join ':', @important_numbers;
  print $out, "\n";

Alternatively, if for some reason your application gets the string '1 2 3 4
5' as a single item, you could split it first (on whitespace) and then join
the list that split produces:

  my $string = '1 2 3 4 5';
  my $out = join ':', split /\s/, $string;
  print $out, "\n";

My guess is that you don't really want the data in a string to begin with,
but sometimes you are getting it from somewhere else.

Hope this helps, T

-- 
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