Reputation: 57
I inherited a script and I need to be able to access some data from a hash. I want to be able to access the MB_Path value from the following.
$VAR1 = bless(
{
'ME_Parts' => [
bless(
{
'ME_Bodyhandle' => bless(
{
'MB_Path' => '/tmp/msg-15072-1.txt'
},
'MIME::Body::File'
),
'ME_Parts' => [],
'mail_inet_head' => bless(
{
'mail_hdr_foldlen' => 79,
'mail_hdr_modify' => 0,
'mail_hdr_list' => [
'Content-Type: text/plain; charset="us-ascii"',
'Content-Transfer-Encoding: quoted-printable'
],
'mail_hdr_hash' => {
'Content-Type' => [
\$VAR1->{'ME_Parts'}[0]{'mail_inet_head'}
{'mail_hdr_list'}[0]
],
'Content-Transfer-Encoding' => [
\$VAR1->{'ME_Parts'}[0]{'mail_inet_head'}
{'mail_hdr_list'}[1]
]
},
'mail_hdr_mail_from' => 'KEEP',
'mail_hdr_lengths' => {}
},
'MIME::Head'
)
},
'MIME::Entity'
),
bless(
{
'ME_Bodyhandle' => bless(
{
'MB_Path' => '/tmp/msg-15072-2.html'
},
'MIME::Body::File'
),
'ME_Parts' => [],
'mail_inet_head' => bless(
{
'mail_hdr_foldlen' => 79,
'mail_hdr_modify' => 0,
'mail_hdr_list' => [
'Content-Type: text/html;charset="us-ascii"',
'Content-Transfer-Encoding: quoted-printable'
],
'mail_hdr_hash' => {
'Content-Type' => [
\$VAR1->{'ME_Parts'}[1]{'mail_inet_head'}
{'mail_hdr_list'}[0]
],
'Content-Transfer-Encoding' => [
\$VAR1->{'ME_Parts'}[1]{'mail_inet_head'}
{'mail_hdr_list'}[1]
]
},
'mail_hdr_mail_from' => 'KEEP',
'mail_hdr_lengths' => {}
},
'MIME::Head'
)
},
'MIME::Entity'
)
],
'ME_Epilogue' => [],
'ME_Preamble' => [],
'mail_inet_head' => bless(
{
'mail_hdr_foldlen' => 79,
'mail_hdr_modify' => 0,
'mail_hdr_list' => [
'Content-Type: multipart/alternative;boundary="----_=_NextPart_002_01CEB949.DC6B0180"'
],
'mail_hdr_hash' => {
'Content-Type' =>
[ \$VAR1->{'mail_inet_head'}{'mail_hdr_list'}[0] ]
},
'mail_hdr_mail_from' => 'KEEP',
'mail_hdr_lengths' => {}
},
'MIME::Head'
)
'MIME::Entity'
);
I thought I could simply do the following
print $ent->parts->($i)->{ME_Bodyhandle}->{MB_Path};
However when I do that I get and error that the value is not initialized. But when I do dump of just $ent->parts->($i)
I get the above code.
I am just stuck on this one. Thanks, Leo C
Upvotes: 1
Views: 281
Reputation: 126722
Until you have exhausted the possibilities of the documentation, there is no excuse for dumping the underlying data structure that represents a Perl object and hard-coding access to its components. The rules of encapsulation apply to Perl object-oriented programming just as much as any other language.
The documentation for
MIME::Entity
and
MIME::Body
is quite clear, and the code you need is something like this
for my $part ($ent->parts) {
my $path = $part->bodyhandle->path;
print $path, "\n";
}
output
/tmp/msg-15072-1.txt
/tmp/msg-15072-2.html
Upvotes: 4
Reputation: 62099
You don't have a hash, you have an object (which happens to be implemented as a hash). That's why the Data::Dumper output keeps saying bless(...)
. You shouldn't be poking into its internals.
I think you're looking for
$ent->parts($i)->bodyhandle->path;
Upvotes: 5
Reputation: 2308
This:
print $ent->parts->($i)->{ME_Parts}->[$i]->{ME_Bodyhandle}->{MB_Path};
Upvotes: 0