uday_sagar has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I generally use "my $system = XMLin('/hello/uday_sagar/system.xml');". But I want to give as XMLin('$ARGV[0]/system.xml') and pass /hello/uday_sagar as an agrument from the commandline. How can I achieve this? Please also tell me the way to pass the file handle to the XMLin() method. Thanks in Advance, Uday Sagar.

  • Comment on Giving the input file to XMLin() from the command line as an argument

Replies are listed 'Best First'.
Re: Giving the input file to XMLin() from the command line as an argument
by Eliya (Vicar) on Jan 24, 2012 at 12:36 UTC
    XMLin('$ARGV[0]/system.xml')

    That should work just fine if you use double quotes instead of single quotes.  (Single quotes don't interpolate...)

    As for passing a file handle, you can say

    my $parser = XML::Simple->new(); my $data = $parser->XMLin($fh); # or my $data = $parser->XMLin(\*FH);

    where $fh is a lexical file handle (i.e. open my $fh, ...), or an IO::File file handle, and \*FH is a ref to an old-style glob file handle.

      Thanks a lot Eliya! Its working and cool!!