Perl report problem...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl report problem...
# 15  
Old 07-04-2008
Yes, the script adds the output file Smilie.

Add this line:

Code:
next if $_ eq $report_dir.$outfile;

Like this:

Code:
#!/usr/bin/perl

# you should always use these in a script
use warnings;
use strict;

my %data;
my @flds=();
my $report_dir = '/export/home/L86898/MYDATA/PREREQUISITS/20080430/REPORTS/';
my ($ext, $outfile) = ('.csv', 'Summary_by_TestScript.csv');
while (<$report_dir*$ext>) {
  next if $_ eq $report_dir.$outfile;
  open IN, $_ or warn "Error openning $_: $!\n" and next;
  while (<IN>) {
    @flds[1,2] = split ';';
    $data{$flds[1]} += $flds[2];
    }
  close IN;
}

open OUT, '>', $report_dir.$outfile or die "Error creating output file: $!\n";
print OUT map {"$_;$data{$_}\n"} sort keys %data;

# 16  
Old 07-04-2008
MySQL

Great, thats why I trust you...Smilie

Thanks again (pls dont get bored for these thanks) Radoulov.

With Best Regards / Mysore Ganapati
# 17  
Old 07-04-2008
I'm glad to be of help and to exercise my newly acquired Perl skills Smilie
# 18  
Old 07-07-2008
Hi Radoulov,

Sorry for my stupid question. But I failed understand the answers from the perl study material regarding "map" function.

Could you please explain me what exactly the below code of line is doing using map() ? Are there any other ways to do the same thing without using map() ?
One of my friend has asked this question, but I's failed to answer him also failed to understand from perl book...

print OUT map {"$_;$data{$_}\n"} sort keys %data;

Sorry for the pain again and again...

Last edited by ganapati; 07-07-2008 at 09:07 AM..
# 19  
Old 07-07-2008
Quote:
Could you please explain me what exactly the below code of line is doing using map() ? Are there any other ways to do the same thing without using map() ?
I'm not able to give better explanation than this one,
it answers both questions (also check ghostdog74's code above):

(perldoc -fmap):

Quote:
map BLOCK LIST
map EXPR,LIST
Evaluates the BLOCK or EXPR for each element of LIST (locally setting $_ to each element)
and returns the list value composed of the results of each such evaluation. In scalar con‐
text, returns the total number of elements so generated. Evaluates BLOCK or EXPR in list
context, so each element of LIST may produce zero, one, or more elements in the returned
value.

@chars = map(chr, @nums);

translates a list of numbers to the corresponding characters. And

%hash = map { getkey($_) => $_ } @array;

is just a funny way to write

%hash = ();
foreach $_ (@array) {
$hash{getkey($_)} = $_;
}
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Report generation using perl script

Hi, I have a perl script to read the log file and create a report from it. I have the script file and log file in a different directories. Now i have pipe the log file data to the perl script to create the report (HMTL file). I am using the below command this isn't working tail -f... (4 Replies)
Discussion started by: vel4ever
4 Replies

2. Shell Programming and Scripting

Help in modifying existing Perl Script to produce report of dupes

Hello, I have a large amount of data with the following structure: Word=Transliterated word I have written a Perl Script (reproduced below) which goes through the full file and identifies all dupes on the right hand side. It creates successfully a new file with two headers: Singletons and Dupes.... (5 Replies)
Discussion started by: gimley
5 Replies

3. Web Development

problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect. Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is redirected to welcome page. My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies

4. Shell Programming and Scripting

Disk report generation problem

Hello everyone, I have a list of inputs as below. My logic is to get the particular powerdisk which matches for ASM disk which means take the major & minor number of each asm disk and matches with powerdisk info then get the particular powerdisk $ ls -l /dev/asm_* ---> ASM disk info... (11 Replies)
Discussion started by: kannan84
11 Replies

5. Shell Programming and Scripting

perl script for generates a report for backup times

Hi all, we do have daily oracle database backups and i need to generate report of each database start point and end point we are using netapp snapshot(filer level) for backups. all backups logs will be come in one directory /u01/app/oracle/backup/hostname/log/* here... (7 Replies)
Discussion started by: prakashdba2010
7 Replies

6. Programming

Problem with perl ~ tr///

I am trying to run the following script which is a file format converter. The frame variable in the input file has a file of 3,2,1 which needs to be 0,1,2 respectively i.e. 3 =0 etc. I have included the tr/// function into the script to do this, however it does not seem to be working input its... (2 Replies)
Discussion started by: fordie
2 Replies

7. Shell Programming and Scripting

problem with perl

hi, i have a script that coverts the file time in epoch time.but the problem is perl is not working inside the k-shell ---------------------------------------------------------------- #!/bin/ksh echo "Enter the file" read n perl -e 'print ((stat("n")))'... (6 Replies)
Discussion started by: ali560045
6 Replies

8. Shell Programming and Scripting

Perl problem

I have been recently given a PERL script to develop, but the main problem is that the perl version that I have to use is old, also I cant download modules from CPAN. Perl version 5.0005 I didnt realise this untill I had the script ready to be tested, so there are a few modules that I have... (6 Replies)
Discussion started by: meevagh
6 Replies

9. Shell Programming and Scripting

Problem getting data to a report file.

Hi all, I'm trying in vain to workout how I can generate a report from a months worth of files that get created every day. There is one file per day and each daily file contain the output from a df -v command. With the following section of code ... for xdffile in $1$2/df?? do ... (4 Replies)
Discussion started by: Cameron
4 Replies
Login or Register to Ask a Question