
Zhris
Enthusiast
Jul 8, 2014, 5:45 PM
Post #2 of 6
(1670 views)
|
Re: [leviculus] need help with returning list from subroutine
[In reply to]
|
Can't Post
|
|
Hi, Here are some issues I picked up on: 1) you should always use strict and warnings. This means you'll also have to ensure you declare all your variables with the likes of my. 2) not necessary but you might want to chomp your input to ensure the newline on the end is removed i.e. chomp(my $line = <STDIN>);. Either way, this knowledge is useful for the future. 3) your split regexp ?|s+/ is invalid. You probably meant /\s+/, or better ' '. 4) you assign the result of your split to a scalar which will hold the number of elements returned. You meant to assign to an array, specifically @values. 5) I don't understand your intention of doing push (@array, $item); in your half function. Note that when you modify the number of elements of the array you are looping, you will cause a segmentation fault. Any adjustments to $item will directly be reflected in @array, therefore remove the push line. Hope these help. And just for fun:
$, = "\n"; print map { $_/2 } split ' ', <STDIN>; Chris
(This post was edited by Zhris on Jul 8, 2014, 6:04 PM)
|