In sub init_event { ... }
{
"name" => "snowville",
"date" => $date_str,
"time" => $time_str,
"location" => { lon => -112.7105234, lat => 41.9655701 },
42.152429, -112.9842191
},
Is the 42.152429, -112.9842191 key/value pair from the posted code perhaps a tyop? It's syntactically correct, but looks semantically fishy. Looks like it escaped from the following event record anonymous hash.
(Update: OTOH, it looks quite harmless since you're unlikely to ever encounter a "42.152429" key in your code. :)
Also, if init_event() isn't just stub code for the SSCCE, a more succinct way to write it would be
c:\@Work\Perl\monks>perl
use strict;
use warnings;
use Data::Dump qw(dd);
sub init_event {
# define unique event records as anonymous hash refs.
my $ar_events = [
{ "name" => "Boise",
"location" => { lon => -116.2, lat => 43.61 },
},
{ "name" => "near sublett",
"location" => { lon => -113.2104084, lat => 42.3278114 },
},
{ "name" => "snowville",
"location" => { lon => -112.7105234, lat => 41.9655701 },
},
{ "name" => "juniper",
"location" => { lon => -112.9842191, lat => 42.152429 },
},
# and so on...
];
# add standard date/time to each event record.
my $date_str = "2021-10-14";
my $time_str = "03:22:31";
@{$_}{ qw(date time) } = ($date_str, $time_str) for @$ar_events;
return $ar_events;
}
my $ar_ev = init_event();
dd $ar_ev;
^Z
[
{
date => "2021-10-14",
location => { lat => "43.61", lon => "-116.2" },
name => "Boise",
"time" => "03:22:31",
},
{
date => "2021-10-14",
location => { lat => "42.3278114", lon => "-113.2104084" },
name => "near sublett",
"time" => "03:22:31",
},
{
date => "2021-10-14",
location => { lat => "41.9655701", lon => "-112.7105234" },
name => "snowville",
"time" => "03:22:31",
},
{
date => "2021-10-14",
location => { lat => "42.152429", lon => "-112.9842191" },
name => "juniper",
"time" => "03:22:31",
},
]
Give a man a fish: <%-{-{-{-<
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.