Split is not working (Perl)

Viewed 3234

I have been trying to execute the following code; however @ans ends up with the entire contents of $answer in it.

$answer = "6.9 4012 top 5.6 2868 top 5.0 3686 top 4.7 5128 top 4.5 3120 top";
@ans = split('/ /',$answer);
foreach (@ans) {
    print "$_\n";
}

In this case I want to split based on white spaces. Please could you tell me what is wrong with this code?

4 Answers
Related