log data::dumper output to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting log data::dumper output to file
# 1  
Old 09-27-2010
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....
Code:
sub postEvent {

        my $this = shift;
        #  print "Passed parameters, " . Dumper(\@_) . "\n" >>/lcl/apps/esm/bin/debugevent.log;
           my %parms = @_;

But that throws an error. Could somebody show me an example of how to redirect the output to a log file?

Thanks
# 2  
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
# 3  
Old 09-28-2010
This is what I came up with...
Code:
        open(LOGF, ">>/lcl/apps/esm/bin/eventlogger.log");
        print LOGF "Passed parameters: " . Dumper(\@_) . "\n";
        close(LOGF);
        my %parms = @_;

Look right?
# 4  
Old 09-28-2010
Yes. Try it and see.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

9. 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
Login or Register to Ask a Question