in reply to Doubt in usage of join function

Hello Perl_Programmer1992,

Your problem is not with the join function, but with the array assignment. The statement my @input = "1,2,3,4,5"; is not doing what you think it is. It is in fact assigning a single element to the @input array, namely the string "1,2,3,4,5".

If you want instead to assign 5 separate elements to the array, you have two options:

  1. my @input = (1, 2, 3, 4, 5); or, even better, my @input = (1 .. 5);
  2. my @input = split /,/, "1,2,3,4,5";

Note: a module such as Data::Dumper or Data::Dump is useful to show you the actual contents of an array (or hash), so you can easily check that its contents are what you expect them to be.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Doubt in usage of join function
by Perl_Programmer1992 (Sexton) on Jan 07, 2019 at 07:22 UTC

    Thanks @Athanasius , that was really a silly mistake from my side.