Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6667413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:55:50+00:00 2026-05-26T02:55:50+00:00

I’ve been testing use of XML::Simple with perl. I am able to print out

  • 0

I’ve been testing use of XML::Simple with perl. I am able to print out some of the data, but cannot print out the file name and byte size in my sample. Can someone show me how to extract the following information from this xml file?

I would like to get:

  • file directory: /storage/foobar/test/queues/20110731
  • file name: myfilename-00
  • file size: 1234567891

So far I can get the file directory, but file name is giving me a hash value and getting file size isn’t working.

Here is code so far:

use strict;
use warnings;
use XML::Simple;
use Data::Dumper;

my $xml = $ARGV [0]; 
for my $xs ($xml) {
    #my $data = XMLin($xs, ForceArray => 0);
    my $data = XMLin($xs, ForceArray => 1);
    #my $data = XMLin($xs, ForceArray => [ qw (directory file path ) ]);
    print Dumper ($data);
    print "This is the DIRECTORY: $data->{path}\n"; 
    print "This is the FILE:      $data->{file}\n";
    print "This is the FILE SIZE: $data->{size}\n";
}

Result:

This is the DIRECTORY: /storage/foobar/test/queues/20110731
This is the FILE:      ARRAY(0x8265c38)
Use of uninitialized value in concatenation (.) or string 
This is the FILE SIZE: 

Dumper:

sample xml:

<?xml version="1.0" encoding="UTF-8"?>
<listing time="2011-10-04T02:33:44+0000" recursive="no" path="/storage/foobar/test/queues/20110731" exclude="" filter=".*" version="0.20.202.1.1101050227">
    <directory path="/storage/foobar/test/queues/20110731" modified="2011-10-04T02:32:11+0000" accesstime="1970-01-01T00:00:00+0000" permission="drwx------" owner="unix_act" group="foobar"/>
    <file path="/storage/foobar/test/queues/20110731/myfilename-00" modified="2011-10-03T04:47:46+0000" accesstime="2011-10-03T04:47:46+0000" size="123456789" app="3" blocksize="134217728" permission="-rw-------" owner="unix_act" group="foobar"/>
    <file path="/storage/foobar/test/queues/20110731/myfilename-01" modified="2011-10-03T04:48:04+0000" accesstime="2011-10-03T04:48:04+0000" size="987654321" app="3" blocksize="134217728" permission="-rw-------" owner="unix_act" group="foobar"/>
</listing>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:55:51+00:00Added an answer on May 26, 2026 at 2:55 am

    The file record will correspond to eahc <file...> tag in your XML. So you effectively need some kind of loop. Remember, $data is effectively pointing at your <listing...> tag

    I have not tested it, but this is the gist of what you want

    foreach my $file( @{ $data->{file} } )
    {
        my( $dir, $fname );
        if( $file->{path} =~ /^(.*)\/([^\/]+)$/ )
        {
            $dir = $1;
            $fname = $2;
        }
        else 
        {
            $dir = "";
            $fname = $file->{path};
        }
        print "This is the DIRECTORY: $dir\n"; 
        print "This is the FILE:      $fname\n";
        print "This is the FILE SIZE: $file->{size}\n";
    }
    

    Edit: I’m a little confused by your output. With forcearray => 1 I would have expected $data->{file} to be an arrayref, not a hashref

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm parsing an XML file, the creators of it stuck in a bunch social
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.