PERL script loop problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PERL script loop problem
# 1  
Old 02-25-2015
PERL script loop problem

I have written the below PERL script to reprocess messages from a failure queue.

It basically browses all the messages in the failure queue to individual files in a directory and then scans those files to determine the originating queue. The script will then move each message in turn from the failure queue to their respective originating queue.

The problem I currently have is that if the value meets the FROM_BOB condition then any subsequent messages gets assigned the same $queue value regardless.

Code:
#!/usr/bin/perl
 
use strict;
 
my $count;
my $queue;
my $var;
my $tancCheck;
my $numOfFilesTMP;
my $numOfFiles;
my $suffix;
 
browseMsgs();
messageMove();
exit(0);
sub browseMsgs 
{
`rm -f MQSIFailMsgs*`;
`./mqcapture -f parmcapt -o MQSIFailMsgs -d`;
}
sub messageMove 
{
       $count=0;
       `rm -f output`;
       $numOfFilesTMP=`ls MQSIFailMsgs* | wc -l`;
       $numOfFiles = $numOfFilesTMP - 1;
       if ( -z './MQSIFailMsgs' ) {
       print "MQSIFailMsgs is empty!\n";
       }
       if ( $count == 0 ){
       $suffix = "";
       } elsif ( $count != 0 ){
       $suffix = $count;
       }
       while ( $count <= $numOfFiles )
       {
       open FAILED, "./MQSIFailMsgs$suffix";
       while(<FAILED>)
             {
              my $queue;
              my $tancCheck;
              ##local $/ = undef;
              $var = $_;
              ($var) =~ m/OPT_APP_GRP(.*)OPT_MSG_TYPE/s;
                     print "line 48 $1\n";
                     if ($1 eq " FROM_BOB ") {
                        open NEXTCHECK, "./MQSIFailMsgs$suffix";
                        $tancCheck =$_;
                        ($tancCheck) =~ m/OPT_MSG_TYPE(.{7})/s;
                              print "line 55 $1\n";
                              if ($1 eq " A_ABCD") {
                              $queue = "FROM_BILL";
                              } else {
                                     $queue = "FROM_BOB";
                                     }
                              close NEXTCHECK;
                     print "line 57 $queue\n";
                     } elsif ($1 eq " SANDRA ") {
                     $queue = "FROM_SANDRA_PP";
                     print "line 60 $1\n";
                     } elsif ($1 eq " BEN_MSGS ") {
                     $queue = "FROM_BEN";
                     print "line 63 $1\n";
                     } elsif ($1 eq " FROM_SUSAN ") {
                     $queue = "FROM_SUSAN";
                     print "line 66 $1\n";
                     } elsif ($1 eq "") {
                     print "line 68 $1\n";
                     $queue ="noQueue";
                     }
              if ($queue eq "noQueue") {
              print "no queue defined!\n"; exit(1);
              }
              `/a/b/c/d/e/f -IMQSI_FAIL -o$queue -mQM_F -L1`;
              $count = $count + 1;
              print "$queue\n";
              open FILE, ">>./output\n";
              print FILE "Message number $count has been put to $queue\n"; close FILE;
 
              }
      close FAILED;
      }
}

Any ideas?

Last edited by chris01010; 02-26-2015 at 05:28 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling an interactive perl script from within a while-read loop

Hi, I have a perl script that prompts for a user to enter a password before doing what it does. This works well if I call it directly from a bash script #!/bin/bash /path/to/perl/script $arg1 $arg2 But, when I try to enclose this within a while read loop, the perl script is called but... (1 Reply)
Discussion started by: prafulnama
1 Replies

2. Shell Programming and Scripting

Need help with perl script with a while loop reading file

Good morning, I appreciate any assistance that I can get from the monks out there. I am able to get this to work for me so that I can do a hostname lookup if I only specify one hostname in the script. What I want to do is have a file with hostnames and do lookups for each name in the file. Here is... (1 Reply)
Discussion started by: brianjb
1 Replies

3. Shell Programming and Scripting

Perl: Problem in retaining values after each loop

use strict; use warnings; open (my $fhConditions, "<input1.txt"); #open input file1 open (my $fhConditions1, "<input2.txt");#open input file2 open (my $w1, ">output1"); open (my $w2, ">output2"); our $l = 10;#set a length to be searched for match our $site="AAGCTT";#pattern to be matched... (1 Reply)
Discussion started by: anurupa777
1 Replies

4. Shell Programming and Scripting

while loop problem in c shell script

Hi all, i write a script c shell set i = 1 while ( $i <= $#array ) echo "$array" @ i++ end i want to set it to i = i +2 in that statement . Can anybody help me? ---------- Post updated at 02:46 PM ---------- Previous update was at 02:35 PM ---------- anybody not how to solve it??? (2 Replies)
Discussion started by: proghack
2 Replies

5. Infrastructure Monitoring

Perl Loop Problem

Another newbie question... I can not figure out how to get this running using a loop. Here is what I have now. #!/usr/bin/perl use SNMP::Info; $list="list.list"; open(DAT, $list) || die("Can't Open List"); @raw_data=<DAT>; close(DAT); foreach $dest (@raw_data) {... (2 Replies)
Discussion started by: mrlayance
2 Replies

6. Shell Programming and Scripting

while loop in perl script

#! /usr/bin/perl $exp = "y"; while ($exp !="n") { system "clear"; # clear the window print "\nEnter the number of Widgets ordered: "; $widgetcount = <STDIN>; #vairable to save the number of total widgerts ordered chop $widgetcount; print "\nEnter the number of Gidgets ordered:... (2 Replies)
Discussion started by: navjot99cheema
2 Replies

7. UNIX for Dummies Questions & Answers

Foreach loop to run a perl script on multiple files

Hi, I have thousands of files in a directory that have the following 2 formats: 289620178.aln 289620179.aln 289620180.aln 289620183.aln 289620184.aln 289620185.aln 289620186.aln 289620187.aln 289620188.aln 289620189.aln 289620190.aln 289620192.aln.... and: alnCDS_1.fasta (1 Reply)
Discussion started by: greptastic
1 Replies

8. Shell Programming and Scripting

Creating loop for a script -Perl

Hi Guyz I designed a script that can compare 2 columns(values) of single file and gives the closest numbers to the first column by comparing the numbers in first column with second and it works in a single file. Now I'm trying to design a new script with 2 objectives for 2 files (not a single... (4 Replies)
Discussion started by: repinementer
4 Replies

9. Shell Programming and Scripting

problem in while loop in a script

i have a script that will read each line and then grep a particular pattern and do some_stuff. Below the script while read j do q1=0 q1=`$j | grep 'INFO - LPBatch:' | wc -l` if then $j | tr -s " " | cut -d " " -f8,42,43 >> nav1.txt fi q2=0 q2=`$j | grep 'INFO - Number of Intervals... (12 Replies)
Discussion started by: ali560045
12 Replies

10. Shell Programming and Scripting

Shell Script loop problem

I am writing a shell script that simulates the `wc -w` command without actually using wc itself. My problem is that the script will only read the first line of the file and just keep looping through it. I have tried both while and for loops and got the same result. Can anyone help? ... (1 Reply)
Discussion started by: MaxMouse
1 Replies
Login or Register to Ask a Question