in reply to problem with variable scoping

What would the purpose of switching on and off by alternating the values of $i between 0 and 1 ??, I could not see through it clearly but well, I thought of a simplistic approach guaranteed that your string contains data that can be accommodated uniformly...
#!/usr/local/bin/perl use strict; use warnings; my $hashRef = {}; my $string = "Tom, 18, Jack, 22, Tim, 30"; populateHash($hashRef,$string); sub populateHash{ my ($hashRef,$scopedString) = @_; my @stringArray = split (', ',$scopedString); %$hashRef = @stringArray; return $hashRef; } use Data::Dumper; print Dumper(\%$hashRef);


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.