####
#$VAR1 = {
# 'count' => '5509',
# 'sms' => [
# {
# 'protocol' => '0',
# 'locked' => '0',
# 'status' => '0',
# 'date' => '1288194026703',
# 'subject' => 'null',
# 'toa' => 'null',
# 'sc_toa' => 'null',
# 'body' => 'You should come to dinner with us! :)',
# 'read' => '1',
# 'address' => '(123) 456-7890',
# 'type' => '2',
# 'service_center' => 'null'
# },
# {
# 'protocol' => '0',
# 'locked' => '0',
# 'status' => '64',
# 'date' => '1288224316833',
# 'subject' => 'null',
# 'toa' => 'null',
# 'sc_toa' => 'null',
# 'body' => 'INVADER ZIM!!',
# 'read' => '1',
# 'address' => '0987654321',
# 'type' => '2',
# 'service_center' => 'null'
# },
####
#! /usr/bin/env perl
use XML::Simple;
use Data::Dumper;
use strict;
use warnings;
########
########### Variables
########
# List of info we want for each message entry
my @keysToKeep = ('date', 'body', 'address', 'type');
# 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]);
# Clean our hash
for my $textRef ( @{$xmlRef->{sms}} )
{
foreach my $key (keys %{$textRef})
{
# If your $key is *not* what we're looking for, remove it from the hash
if ( !grep ($key, @keysToKeep) )
{
delete $textRef->{$key};
}
}
}
# Return our hash ref
return $xmlRef;
}
my $hashRef = loadFileToHashRef("xml/sms-20110704030000.xml");
print Dumper $hashRef;
####
#! /usr/bin/env perl
use XML::Simple;
use Data::Dumper;
use strict;
use warnings;
use 5.012;
########
########### Variables
########
# List of info we want for each message entry
my @keysToKeep = ('date', 'body', 'address', 'type');
# 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 (($key, $value) = each %{$xmlRef})
{
print "Key: $key, Value: $value \n";
}
# Return our hash ref
return $xmlRef;
}
my $hashRef = loadFileToHashRef("xml/sms-20110704030000.xml");
print Dumper $hashRef;
####
Global symbol "$key" requires explicit package name at ./parse.pl line 29.
Global symbol "$value" requires explicit package name at ./parse.pl line 29.
Global symbol "$key" requires explicit package name at ./parse.pl line 31.
Global symbol "$value" requires explicit package name at ./parse.pl line 31.
Execution of ./parse.pl aborted due to compilation errors.