A Perl function gets an array of argumnents.
That array is referenced by @_.
I usually do the following:
sub FunctionName {
my ($arg1, $arg2, ... ) = @_;
...
}
In your case, you want to split the first argument of the argument array (@_).
You have several options:
sub arrayMkr {
my $arg = shift;
my @splitUpIn = split(" ", $arg);
...
}
or
sub arrayMkr {
my ($arg) = @_;
my @splitUpIn = split(" ", $arg);
...
}
or
sub arrayMkr {
my $arg = $_[0];
my @splitUpIn = split(" ", $arg);
...
}
1st Hint: make sure you know when to use $ and when to use @ (or %). You might want to consult some Perl tutorial on variables and familiarize yourself with the terms scalar/array/list/hash.
2nd Hint: try to avoid $_ an make it explicit. $_ has different meaning depending on the context it is used in. You have less problems if you avoid its usage, especially if you are not an expert on Perl.
You might also consider to re-write the whole function again, e.g.:
sub splitFn {
my ($line) = @_;
my $rHash = {}; # reference to a hash
if ($line =~ m/^\s*(.*?)\s*;\s*(.*?)\s*$/) {
$rHash = {name=>$1, FirstRange=>$2};
}
elsif ($line =~ m/^\s*(.*?)\s*;\s*(.*?)\s*;\s*(.*?)\s*$/) {
my ($nm, $a, $b) = ($1, $2, $3);
$rHash = {name=>$nm,
FirstRange=>arrayMkr($a),
SecondRange=>arrayMkr($b)};
}
else {
die("Failure in '$line' ($!)\n");
}
return $rHash;
}
sub arrayMkr {
my ($range) = @_;
my @range = split("\s+", $range);
#...
}
Cheers
Andi