swissknife has asked for the wisdom of the Perl Monks concerning the following question:

Hello Experts,

I have a array which has only one element in it. To use it further I need this value in string. i understand that function join can convert an array into string but i have to specify delimiter. Since there is only one element there is no delimiter.

 print "@myarray \n";

prints "1234-23-56:567" and i need this complate value in string

Could someone help me in putting such array value in string. ? swissknife

Replies are listed 'Best First'.
Re: put a array value into string.
by frozenwithjoy (Priest) on Mar 18, 2014 at 10:31 UTC

    Access the first element of the array like this:

    my $string = $array[0];
Re: put a array value into string.
by tosaiju (Acolyte) on Mar 18, 2014 at 10:40 UTC
    you can still use join with null delimiter.
                     join("", @arr1);

    or you may refer to specific array index.
                     $str1 = $arr1[0];
Re: put a array value into string.
by clueless newbie (Curate) on Mar 18, 2014 at 12:46 UTC

    In your context I'm rather fond of the special variable $". Quoting from the docs

    When an array or an array slice is interpolated into a double-quoted string or a similar context such as /.../ , its elements are separated by this value. Default is a space. For example, this:

    print "The array is: @array\n";

    is equivalent to this:

    print "The array is: " . join($", @array) . "\n";
Re: put a array value into string.
by llancet (Friar) on Mar 18, 2014 at 13:20 UTC
    the initiative of join() function is to concatenate arbitrary length of list using one same delimiter. It seems your requirement is in reverse: you want to concatenate fixed length of list using different delimiter. So instead of using join(), you can just format them into a string by accessing the items in fixed position.
      Thanks for your response and explanation. it helped me a lot.