in reply to Regex to Array lookup question
Thank you everyone for your responses. Sorry for my delayed response.
I've looked at your examples and I have tried a few different things.
I think I am going to go with a bit simpler approach looking at some other similar code, that so far in testing seems to be working for what I need.
# Remove leading url $icon =~ s/https:\/\/api.weather.gov\/icons\/land\///; # Split at / my @iconSplit = split(/\//, $icon); my $dayNight = $iconSplit[0]; # Split at ? to remove size info $icon = $iconSplit[1]; my @iconSplit2 = split(/\?/, $icon); $icon = $iconSplit2[0]; # Split at , for % of precip if present my @iconSplit3 = split(/\,/, $icon); $icon = $iconSplit3[0]; my $poP = $iconSplit3[1]; if (not defined $poP) { $poP = 0; # null } my %newIcons= ( 'skc' => "clear-day.png", 'few' => "partly-cloudy-day.png", 'sct' => "partly-cloudy-day.png", 'bkn' => "cloudy.png", 'ovc' => "cloudy.png", 'wind_skc' => "wind.png", 'wind_few' => "wind.png", 'wind_sct' => "wind.png", 'wind_bkn' => "wind.png", 'wind_ovc' => "wind.png", 'snow' => "snow.png", 'rain_snow' => "sleet.png", 'rain_sleet' => "sleet.png", 'snow_sleet' => "sleet.png", 'fzra' => "sleet.png", 'rain_fzra' => "sleet.png", 'snow_fzra' => "sleet.png", 'sleet' => "sleet.png", 'rain' => "rain.png", 'rain_showers' => "rain.png", 'rain_showers_hi' => "rain.png", 'tsra' => "thunderstorm.png", 'tsra_sct' => "thunderstorm.png", 'tsra_hi' => "thunderstorm.png", 'tornado' => "tornado.png", 'hurricane' => "thunderstorm.png", 'tropical_storm' => "thunderstorm.png", 'dust' => "fog.png", 'smoke' => "fog.png", 'haze' => "fog.png", 'hot' => "clear-day.png", 'cold' => "clear-day.png", 'blizzard' => "snow.png", 'fog' => "fog.png" ); $icon = $newIcons{$icon};
With DarkSky shutting down their API later this year, I need to move over to NWS API, and match current build parameters and icon sets as close as possible.
Then later I can go back and add more icons to the existing sets, and clean up some of the other smaller details that are changing because of this move.
Thanks again!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex to Array lookup question
by AnomalousMonk (Archbishop) on Apr 13, 2020 at 07:16 UTC |