String split into an array

Hi,

is it possible to do something like that in ruby?

(Perl-Code)
($run_number, $iteration, $day, @nodes) = split /\s+/;

String looks like the first 3 numbers for run, iteration and day
followed by n numbers for each node.
I want to bind those n nodes to an array @nodes.

run_number, iteration, day, nodes = line.split(" ")
does not work, nodes only get the first node and the rest of the line is
ignored.

Okay, found the solution:

just write *nodes like

run_number, iteration, day, *nodes = line.split(" ")

is it possible to do something like that in ruby?

ignored.
The fix is easy:

run_number, iteration, day, *nodes = line.split(" ")

(note “*” in front of nodes).

Regards,
Rimantas

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs