Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Doubt in usage of join function

by Athanasius (Archbishop)
on Jan 07, 2019 at 07:17 UTC ( [id://1228128]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1228128]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-23 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found