#! /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;