Sponsored Content
Top Forums Shell Programming and Scripting Perl Script issue. What am I doing wrong? Post 302298791 by SkySmart on Wednesday 18th of March 2009 02:31:16 PM
Old 03-18-2009
Quote:
Originally Posted by pludi
Code:
#!/usr/local/bin/perl

open (MYFILE, 'logs_report');
open (MYF, '>data.txt');

while ($rec = <MYFILE>) {
    chomp($rec);
    @arr = split(/ /,$rec);
    if ($arr[12] !~ /OK/) {
        print $rec, "\n";
        print MYF $red, "\n";
    }
}
close (MYF);
close (MYFILE);

This is probably what you want. The way you wrote it, you'd overwrite your data.txt every time you find something, plus opening and closing repeatedly in a loop can be quite I/O cost intensive.

And the next time you post listings or source, enclose it in [ code][/code ] tags (sans the spaces), to preserve formatting for readability.

thank you. sorry for not including the codes. would you happen to know how to include a code in ur code that will email the file to a set of email addresses? i mean the file that is written to? your help or input is greatly appreciated. thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Script Issue - Please Help * Thanks!!!

Please help me with my script please. I am trying to do the following: 1. Read files for the current directory 2. Open and read from nbe files files only 3. Read only the lines with the results pattern 4. Split the line and print 3rd field Please indicate what line I need to modify. ... (8 Replies)
Discussion started by: jroberson
8 Replies

2. Shell Programming and Scripting

Perl script issue: print

Can someone tell me what I'm doing wrong with my perl script? I am new to Perl. This isn't even the final script, I'm just testing to see if it will print the directories with the files in it. For some reason my output is only printing the 1st, 6th, and last entries of the @sub_dir array. Each... (3 Replies)
Discussion started by: man
3 Replies

3. Shell Programming and Scripting

wrong output in perl script

Hi, Here is my piece of code-- #!/usr/bin/perl my $Time_Stamp ; my $User_Name; my $Success; my $Failure; my $ErrorCode; my $ErrorMsg; my $logDir = $ARGV; my $logPrefix = $ARGV; die "usage: $0 <logDir> <logPrefix>" unless $logDir and $logPrefix; die "Log dir $logDir doesn't... (2 Replies)
Discussion started by: namishtiwari
2 Replies

4. Web Development

Accessing a Perl CGI script, security issue

Hi Everybody, I was wondering if it was possible for someone to gain access to my Perl CGI scripts before they are interpreted by Perl (mod_perl on apache2) i.e. getting a hold of my raw scripts and not the html output? Let's say I use the DBI module where I have the hostname, user and... (2 Replies)
Discussion started by: z1dane
2 Replies

5. Shell Programming and Scripting

Perl...getting wrong output?

Good morning! Im trying to write and learn at the same time a simple script. fTHe script should tell me if a number is odd or even/ #!/usr/bin/perl $num = 10; $string1 = "This number is odd"; $string2 = "This number is even"; if ($num /= 2) { print "$string1\n"; }else{ ... (3 Replies)
Discussion started by: bigben1220
3 Replies

6. Shell Programming and Scripting

Simple issue, what is wrong?

I had this working a few days ago but I since changed it. Heres the code x=1 while 1 2 3 4 5 6 1=$(ps -ef | grep process | awk '{ print $2}') if then echo "The database is accepting connections..." echo "Now I will check the next process" 2=$(ps -ef | grep process1 |... (10 Replies)
Discussion started by: jeffs42885
10 Replies

7. Shell Programming and Scripting

Perl script issue

Hi All, I have a perl script which I am using in Windows environment. There is one more file called "functions.txt" which is having all the functions defined to used in my perl script. And the path for this function file is defined in my perl script. Howeever sometimes I am getting below error... (4 Replies)
Discussion started by: gr8_usk
4 Replies

8. Shell Programming and Scripting

Issue regarding dos2unix perl script

Hi All, I have pearl script which will check and convert the file: INFO("dos2unix_cmds".$#{$dos2unix_cmds}); if ( $#{$dos2unix_cmds} == 0 ) { my $convert_cmd = $$dos2unix_cmds; my $rename_cmd = $$dos2unix_cmds; --conversion going here else INFO ("No need to... (8 Replies)
Discussion started by: saps19
8 Replies

9. Shell Programming and Scripting

What is wrong with my perl script?

i managed to write a perl script for nagios. now, the script works. but i think there's somethign wrong with the exit codes. because the script doesn't show the output of the results in nagios, it instead shows null. please tell me what i'm doing wrong here: #!/usr/local/bin/perl use... (2 Replies)
Discussion started by: SkySmart
2 Replies

10. Shell Programming and Scripting

Executing perl script in Linux gives :Exec format error. Wrong Architecture

i have perl script that used to be working great , once i edit it in windows and convert it to UTF-8 and then via FTP return it . also did: chmod +x foo.pl and then when i try to run it : ./foo.pl im getting this error: ./foo.pl: Exec format error. Wrong Architecture.... (4 Replies)
Discussion started by: umen
4 Replies
HTTP::OAI::ListIdentifiers(3pm) 			User Contributed Perl Documentation			   HTTP::OAI::ListIdentifiers(3pm)

NAME
HTTP::OAI::ListIdentifiers - Provide access to an OAI ListIdentifiers response SYNOPSIS
my $r = $h->ListIdentifiers; while(my $rec = $r->next) { print "identifier => ", $rec->identifier, " ", print "datestamp => ", $rec->datestamp, " " if $rec->datestamp; print "status => ", ($rec->status || 'undef'), " "; } die $r->message if $r->is_error; METHODS
$li = new OAI::ListIdentifiers This constructor method returns a new OAI::ListIdentifiers object. $rec = $li->next Returns either an HTTP::OAI::Header object, or undef, if there are no more records. Use $rec->is_error to test whether there was an error getting the next record (otherwise things will break). If -resume was set to false in the Harvest Agent, next may return a string (the resumptionToken). @il = $li->identifier([$idobj]) Returns the identifier list and optionally adds an identifier or resumptionToken, $idobj. Returns an array ref of HTTP::OAI::Headers. $dom = $li->toDOM Returns a XML::DOM object representing the ListIdentifiers response. $token = $li->resumptionToken([$token]) Returns and optionally sets the HTTP::OAI::ResumptionToken. perl v5.12.4 2007-06-28 HTTP::OAI::ListIdentifiers(3pm)
All times are GMT -4. The time now is 03:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy