in reply to Re: Parsing an Array of Hashes, Modifying Key/Value Pairs
in thread Parsing an Array of Hashes, Modifying Key/Value Pairs
NetWallah,
Thank you for the tips! I've managed to dig through a bit further and make more sense of what was confusing me. I wound up benching your suggestion against removing key pairs and you were right. Marginally more memory usage, but pretty well moot.
I've got two follow-up questions though
Minus the error I'm getting, this is the solution to my initial query.
#! /usr/bin/env perl use XML::Simple; use Data::Dumper; use strict; use warnings; use 5.012; ######## ########### Variables ######## # Array that we'll be holding our cleaned and unique texts in my @textsToKeep; # XML Parser my $xml = new XML::Simple; ######## ########### Subroutines ######## # Filepath is passed to load a hashref # a CLEANED Hashref is returned of the xml we've loaded sub loadFileToHashRef { my $xmlRef = $xml->XMLin($_[0]); while (my ($smsKey, $smsHash) = each @{$xmlRef->{sms}}) { # Each KEY now holds a single HASH. Clone the data we +WANT into @textsToKeep push @textsToKeep, (${$smsHash->{date}}, ${$smsHash->{ +body}}, ${$smsHash->{address}}, ${$smsHash->{type}}); } # Destroy our hashref to free memory undef $xmlRef; } my $hashRef = loadFileToHashRef("xml/sms-20110704030000.xml"); print Dumper @textsToKeep;
As I'm still uncertain about strict references, the solution to this doesn't jump out at me (as I *think* I'm pretty strict about what data I want and in which order) ☺
Can't use string ("1288032888762") as a SCALAR ref while "strict refs" in use at ./parse.pl line 33.
Cheers!
-- Libra
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Parsing an Array of Hashes, Modifying Key/Value Pairs (references)
by LanX (Saint) on May 12, 2013 at 22:01 UTC | |
|
Re^3: Parsing an Array of Hashes, Modifying Key/Value Pairs
by NetWallah (Canon) on May 13, 2013 at 01:42 UTC |