Sponsored Content
Top Forums Shell Programming and Scripting Perl : reading data from dumper variable Post 302984698 by greet_sed on Sunday 30th of October 2016 06:17:19 AM
Old 10-30-2016
Hi ,

According to your dumper output , i think xmlref is hashreference to start with.

You can consider below one as a starting point depends on your xmlref.

Code:
#!/usr/bin/perl -w
use Data::Dumper;

my $xmlref = {
    'retainSysIds' => 'true',
    'variables'    => [
        {
            'variable1' => [
                {
                    'value' => ['server1'],
                    'name'  => ['db'],
                },
                {
                    'value' => ['server2'],
                    'name'  => ['application'],
                }
            ],
            'variable2' => "src2",
        }
    ],
    'temp' => 'xyz',
};

#print Dumper($xmlref);
foreach my $okey ( keys %$xmlref ) {
    print "Mainkey: $okey: value is: ${$xmlref}{$okey}\n";
    if ( $okey eq "variables" ) {
        print "first level key 'variables' matching\n";
        foreach my $hash ( @{ $$xmlref{$okey} } ) {
            if ( exists $hash->{'variable1'} ) {
                print "second level key 'variable1' exists\n";
                foreach my $inarr ( @{ $hash->{'variable1'} } ) {
                    print "** value: $inarr->{'value'}[0] \n";
                    print "** name: $inarr->{'name'}[0] \n";
                }
            }
        }
    }
}

Gives following output:
Quote:
Mainkey: temp: value is: xyz
Mainkey: retainSysIds: value is: true
Mainkey: variables: value is: ARRAY(0x10aee60)
first level key 'variables' matching
second level key 'variable1' exists
** value: server1
** name: db
** value: server2
** name: application
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading data into muti-dimentional array - in perl

Just want to learn how these are read into array but I don't seem to get it right what do I go wrong? Below is the sample Thanks input 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 #!/usr/bin/perl open (InFILE,"input"); while (<InFILE>) { @ar = split ; (5 Replies)
Discussion started by: zap
5 Replies

2. Shell Programming and Scripting

perl not reading my variable

I'm trying to make changes in a file using the following bash script: #!/bin/bash MYHOME=`echo $HOME` README=$MYHOME"/environment" IAM=`whoami` CHANGEPATHLIST="TALOG TACONFIG TAINFO TAWORK TMPSPACE" for var in $CHANGEPATHLIST do perl -pi -e 's/sacuser1/$IAM/ if m/$var/' $README... (3 Replies)
Discussion started by: yoonixq4u
3 Replies

3. Shell Programming and Scripting

PERL: reading 2 column data into Hash file

I am trying to read in a 2 column data file into Perl Hash array index. Here is my code. #!/usr/bin/perl -w use strict; use warnings; my $file = "file_a"; my @line = (); my $index = 0; my %ind_file = (); open(FILE, $file) or die($!); while(<FILE>) { chomp($_); if ($_ eq '') { ... (1 Reply)
Discussion started by: subhap
1 Replies

4. Shell Programming and Scripting

Reading data from file and assigning to variable

I was trying to store the number of lines in a file and store it in a file.after that i want to store the information in a file to a variable which is further used in the if loop to check certain condition. #!/bin/bash cat <file> | wc -l > count.txt x="$count.txt"; i=10; if ; then cat... (10 Replies)
Discussion started by: sudhakaryadav
10 Replies

5. Shell Programming and Scripting

Perl: Reading data from other file

Hi, I am writting some perl scripts for daily backup process. In which I want to pass some data/referance from another txt file. Text file contains only one column and multiple rows. I want to pass this data to variables of another perl script. e.g. Refdoc.txt file contains data as: perl1... (3 Replies)
Discussion started by: n.dba
3 Replies

6. Shell Programming and Scripting

log data::dumper output to file

I am new to Perl and just started using the data::dumper. i have been unable to figure out how to take the output that comes from the data::dumper and redirect it to a file. I tried this.... sub postEvent { my $this = shift; # print "Passed parameters, " . Dumper(\@_) .... (3 Replies)
Discussion started by: LRoberts
3 Replies

7. Shell Programming and Scripting

Data extraction in perl variable

HI, i have variable in perl like below $tmp="/home/sai/automation/work/TFP_GN.txt" it can conatain any path its filled from config file. now i want extarct the path upto this /home/sai/automation/work/ and put it in another variable say... (4 Replies)
Discussion started by: raghavendra.nsn
4 Replies

8. Shell Programming and Scripting

Perl Script for reading table format data from file.

Hi, i need a perl script which reads the file, content is given below. and output in new file. TARGET DRIVE IO1 IO2 IO3 IO4 IO5 ------------ --------- --------- --------- --------- --------- 0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies

9. Shell Programming and Scripting

Perl :: reading values from Data Dumper reference in Perl

Hi all, I have written a perl code and stored the data into Data structure using Data::Dumper module. But not sure how to retreive the data from the Data::Dumper. Eg. Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies

10. Shell Programming and Scripting

Error while reading variable from a file in perl script

I have a file abc.ini and declared many variables in that file, one of the variable(DBname) value I am trying to read in my perl script but getting error. File abc.ini content # database name DBname =UATBOX my $ex_stat; my $cmd_output; $ex_stat = "\Qawk '/^DBname/{print... (2 Replies)
Discussion started by: Devesh5683
2 Replies
HTML::Template::Dumper(3pm)				User Contributed Perl Documentation			       HTML::Template::Dumper(3pm)

NAME
HTML::Template::Dumper - Output template data in a test-friendly format SYNOPSIS
# Switch the module used to the regular HTML::Template when you're # finished testing # #use HTML::Template; use HTML::Template::Dumper; my $tmpl = #HTML::Template HTML::Template::Dumper ->new( . . . ); $tmpl->set_output_format( 'YAML' ) if $tmpl->isa( 'HTML::Template::Dumper' ); # Do processing for the template $tmpl->output(); DESCRIPTION
This module helps you to test HTML::Template-based programs by printing only the information used to fill-in the template data. This makes it much easier to automatically parse the output of your program. Currently, data can be outputed by "Data::Dumper" (default) or "YAML". Note that the underlieing HTML::Template methods are still called, so options like "strict" and "die_on_bad_params" will still throw errors. USAGE
new Called just like the "HTML::Template->new()" method. set_output_format $tmpl->set_output_format( 'YAML', @extra_params ); Set the output format. Currently known formats are: Format Name Module ------------- -------- Data_Dumper HTML::Template::Dumper::Data_Dumper YAML HTML::Template::Dumper::YAML The module is found by applying the following rules: 1. If the name has a "::" anywhere, then it is taken as the full name of the module. 2. Otherwise, the module is loaded from "HTML::Template::Dumper::$NAME", where $NAME is what you passed to "set_output_format". 3. If the name didn't have a "::" in it, but it didn't pass rule #2, then take it as the full name of the module. 4. If none of the above work, then call "die". In any of the cases, the module returned must inheirt from "HTML::Template::Dumper::Format". Otherwise, "die" is called. Any parameters you pass after the format will be put directly into the formatter's "new()" method. output Called just like the regular "HTML::Template->output()", but will return a simplified view of the template data instead of the full object. The "print_to" parameter is respected as specified in the "HTML::Template" documentation. set_output_filter Called with a reference to a subroutine. Before "output" returns, this subroutine will be called with a scalar reference to the data that would otherwise have been directly returned by "output". Your filter subroutine can do any modification on the value it wants. For instance, if you want the output to be (almost) valid HTML, you could write: $tmpl->set_output_filter( sub { my $ref = shift; $$ref = q{ <html> <head> <title>Debugging Output</title> </head> <body bgcolor="#FFFFFF"> <pre> } . $$ref . q{ </pre> </body> </html> } }); Note that the result may or may not work with "parse", depending on your filter and the format used by your dumper. parse Called with the data that was returned by "output()". Returns a hashref of all the parameters. This can also be called as a class method, in which case it can take a second paramter containing the data format that the first paramter is in. This second parameter has the same rules applied to it as "set_output_format()". WRITING NEW FORMATTERS
Formaters must inheirt from "HTML::Template::Dumper::Format". There are two methods that need to be overridden. new Not called with anything. Returns a blessed reference. The default implementation blesses a scalar reference in order to save a little memory. This should be sufficient for most formatters, but you can always override this method if you need it. dump All formatters must override this method. It is called with a single reference which is formatted and returned. parse All formaters must override this method. It is called with a single scalar that holds the complete data returned by this formatter's "dump" method. It returns a hashref of all the parameters held in that dump. BUGS
Yes. AUTHOR
Timm Murray <tmurray@agronomy.org> http://www.agronomy.org CPAN ID: TMURRAY COPYRIGHT
Copyright 2003, American Society of Agronomy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of either: a) the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version, or b) the "Artistic License" which comes with Perl. SEE ALSO
perl(1). HTML::Template(3). Data::Dumper(3). YAML(3). perl v5.10.1 2010-04-26 HTML::Template::Dumper(3pm)
All times are GMT -4. The time now is 12:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy