Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Splitting arrays

by BillKSmith (Deacon)
on Jun 04, 2013 at 13:43 UTC ( #1036979=note: print w/ replies, xml ) Need Help??


in reply to Splitting arrays

It is probably a bad idea to split such closely related data into separate arrays. Use a hash of arrays.

my %location_data; foreach (@values) { my @vals = split /,/, $_; push @{$location_data{lat}}, $val[0]; push @{$location_data{lon}}, $val[1]; }

Depending on how you use the data, it may be more convenient to have an array of coordinate pairs. (Like you already have except each pair would be stored as a two element numeric array rather than as a string.

my @locations = [map {split /,/, $_]} @values;
Bill


Comment on Re: Splitting arrays
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036979]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2015-07-31 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls