Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: removing perldata , hashref from XML file

by SaraMirabi (Novice)
on May 13, 2020 at 10:45 UTC ( [id://11116748]=note: print w/replies, xml ) Need Help??


in reply to Re: removing perldata , hashref from XML file (updated)
in thread removing perldata , hashref from XML file

Many Thanks for your quick response. My exact problem is about introducing each tag in perl code, i mean:

my $data = { employee => [ { "************" => "M", age => { dob => "10-02-1917" }, department => { departmentname => "Operations", title => "Manager" }, location => { town => { county => "East Ay1", name => "Auchinleck" } }, name => { forename => "John", surname => "Doe" },

My xml file is more than 2000 lines with different tags and also it is encoded, I decode it and make it as XML file, introducing each tag in my perl code is not possible.

Replies are listed 'Best First'.
Re^3: removing perldata , hashref from XML file
by choroba (Cardinal) on May 13, 2020 at 11:01 UTC
    You don't have to introduce the structure. Just use the return value of $tap3->structure.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Hi,

      Many Thanks for answering me, would you mind please give me a guide where in the code i should add the return value?

      !/usr/bin/perl -w use strict; use warnings; use Data::Dumper; use XML::Dumper; use TAP3::Tap3edit; $Data::Dumper::Indent=1; $Data::Dumper::Useqq=1; my $dump = new XML::Dumper; use File::Basename; my $perl=''; my $xml=''; my $tap3 = TAP3::Tap3edit->new(); foreach my $file(glob 'X*') { my $files= basename($file); my $filename=$files.".xml\n"; print $filename; $tap3->decode($files) || die $tap3->error; $perl = $tap3->structure; $dump->pl2xml($perl, $filename); }
        ... where ... i should add ...

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        You misunderstand. This is choroba's code "signature" on PerlMonks.

        c:\@Work\Perl\monks>perl -wMstrict -e "print map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1], +[{}],[sub{}^*ARGV,3] " JApH,
        JApH stands for Just Another Perl Hacker. :) Please consider the advice given in the body of choroba's reply.


        Give a man a fish:  <%-{-{-{-<

        You've just re-posted the code from your first node, it looks like you haven't even tried to incorporate the suggested code. You'll tend to get better responses if you show your efforts. Also, see this: when you edit a node, make sure to mark your updates, so that replies aren't confusing.

        Anyway, as choroba and I said, the code I showed is a replacement for XML::Dumper, and my example $data can be removed and your $perl variable can be used instead.

Re^3: removing perldata , hashref from XML file
by haukex (Archbishop) on May 13, 2020 at 11:03 UTC
    My exact problem is about introducing each tag in perl code ... introducing each tag in my perl code is not possible.

    Sorry, I don't understand what you mean here. Please see Short, Self-Contained, Correct Example and I know what I mean. Why don't you?. As I said, you can adapt the code I've posted (which I just updated) however you need, but you also haven't shown your expected output.

    Update: Ah, I see choroba may have interpreted your issue better than I have. Yes, my $data is meant to be the same thing as the $perl variable from your previous node.

      Yes, You are right.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116748]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-25 10:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found