This may be just as objectionable as accessing a private variable, but thought I would throw it out there.

Add the filename as a private part of the XML:

#!/usr/bin/perl use strict; use warnings; use XML::Simple; &main(@ARGV); sub main { my $filename = shift; my $xml = XMLin($filename); $xml->{__SUPER_SECRET_FILENAME_PARAMETER__} = $filename; &printName($xml); } sub printName { my $xml = shift; print $xml->{__SUPER_SECRET_FILENAME_PARAMETER__}; }

Also, I don't think that it is wise to use an exit at the end of a script. I believe that it is better to just return.

UPDATE

Further, the return of XMLin isn't a XML::Simple instance. It's just a hash. So if the item you're looking for isn't in the hash, then it isn't available. There isn't any private data.

Hazah! I'm Employed!


In reply to Re: XML::Simple private members by osunderdog
in thread XML::Simple private members by Solostian

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.