Sponsored Content
Top Forums Shell Programming and Scripting log data::dumper output to file Post 302457336 by durden_tyler on Monday 27th of September 2010 08:16:14 PM
Old 09-27-2010
Quote:
Originally Posted by LRoberts
... Could somebody show me an example of how to redirect the output to a log file?
...
Here's how you'd write the output (of Dumper or anything) to a file:

Code:
$ 
$ # show the content of the Perl program
$ cat -n tst.pl
     1    #!/usr/bin/perl -w
     2    use Data::Dumper;
     3    
     4    $x = "the quick brown fox jumps over the lazy dog"; # a scalar
     5    @y = qw(10 20 30 40);                               # an array
     6    %z = qw(ruby red emerald green sapphire blue);      # a hash
     7    
     8    # open a file to write the output of Dumper
     9    $file = "dumper.log";
    10    open (F, ">", $file) or die "Can't open $file for writing: $!"; 
    11    print F Dumper $x;
    12    print F Dumper @y;
    13    print F Dumper %z;
    14    # and we're done; close the file now
    15    close (F) or die "Can't close $file: $!";
$ 
$ 
$ # run the Perl program
$ perl tst.pl
$ 
$ # and now check the "dumper.log" file
$ cat dumper.log
$VAR1 = 'the quick brown fox jumps over the lazy dog';
$VAR1 = '10';
$VAR2 = '20';
$VAR3 = '30';
$VAR4 = '40';
$VAR1 = 'sapphire';
$VAR2 = 'blue';
$VAR3 = 'emerald';
$VAR4 = 'green';
$VAR5 = 'ruby';
$VAR6 = 'red';
$ 
$ 

tyler_durden
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

2. Shell Programming and Scripting

How to fill data from other file and get some output

Greetings, I have a hard time creating a large number of user profiles in a database. The data file looks like this : 01/01/80 Mitch Conley . . . . And I need to put the output into: Name: Mitch Surname: Conley Birthday: 01/01/80 Thanks in advance! (3 Replies)
Discussion started by: hemo21
3 Replies

3. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

4. Shell Programming and Scripting

Displaying log file pattern output in tabular form output

Hi All, I have result log file which looks like this (below): from the content need to consolidate the result and put it in tabular form 1). Intercomponents Checking Passed: All Server are passed. ====================================================================== 2). OS version Checking... (9 Replies)
Discussion started by: Optimus81
9 Replies

5. 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

6. Shell Programming and Scripting

Help with add existing file name as new data column in new output file

Input File 1 cat S1.txt MI0043 2731 miR-1 Input File 2 cat S4.txt MI006 310 CiR-1 MI057 10 CiR-24 MI750 5 CiR-24 Desired Output File 1 cat S1.txt.out MI0043 2731 miR-1 S1.txt Desired Output File 2 cat S4.txt.out MI006 310 CiR-1 S4.txt (3 Replies)
Discussion started by: perl_beginner
3 Replies

7. Shell Programming and Scripting

Extra data in output file

Gents, I did a small scritp called make_file It read file1.txt file and generate an output as attached.. But the script is showing more extra information not needed. I have attached the output file as desired. Could you please help to fix this scrip to get the correct output Thanks... (4 Replies)
Discussion started by: jiam912
4 Replies

8. Shell Programming and Scripting

Perl : reading data from dumper variable

Hi team, # PERL I have Dumper variable in perl and containing the below data and trying to fetch value and name from the reference variable. $VAR1 = { 'retainSysIds' => 'true', 'variables' => , 'name' => , ... (4 Replies)
Discussion started by: giridhar276
4 Replies

9. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies
Template::Plugin::Dumper(3)				User Contributed Perl Documentation			       Template::Plugin::Dumper(3)

NAME
Template::Plugin::Dumper - Plugin interface to Data::Dumper SYNOPSIS
[% USE Dumper %] [% Dumper.dump(variable) %] [% Dumper.dump_html(variable) %] DESCRIPTION
This is a very simple Template Toolkit Plugin Interface to the Data::Dumper module. A "Dumper" object will be instantiated via the following directive: [% USE Dumper %] As a standard plugin, you can also specify its name in lower case: [% USE dumper %] The "Data::Dumper" "Pad", "Indent" and "Varname" options are supported as constructor arguments to affect the output generated. See Data::Dumper for further details. [% USE dumper(Indent=0, Pad="<br>") %] These options can also be specified in lower case. [% USE dumper(indent=0, pad="<br>") %] METHODS
There are two methods supported by the "Dumper" object. Each will output into the template the contents of the variables passed to the object method. dump() Generates a raw text dump of the data structure(s) passed [% USE Dumper %] [% Dumper.dump(myvar) %] [% Dumper.dump(myvar, yourvar) %] dump_html() Generates a dump of the data structures, as per dump(), but with the characters <, > and & converted to their equivalent HTML entities and newlines converted to <br>. [% USE Dumper %] [% Dumper.dump_html(myvar) %] AUTHOR
Simon Matthews <sam@tt2.org> COPYRIGHT
Copyright (C) 2000 Simon Matthews. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Template::Plugin, Data::Dumper perl v5.16.3 2011-12-20 Template::Plugin::Dumper(3)
All times are GMT -4. The time now is 02:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy