Sponsored Content
Full Discussion: PERL script loop problem
Top Forums Shell Programming and Scripting PERL script loop problem Post 302936397 by chris01010 on Wednesday 25th of February 2015 07:56:29 AM
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..
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
struct::queue(n)						Tcl Data Structures						  struct::queue(n)

__________________________________________________________________________________________________________________________________________________

NAME
struct::queue - Create and manipulate queue objects SYNOPSIS
package require Tcl 8.2 package require struct::queue ?1.4.1? queueName option ?arg arg ...? queueName clear queueName destroy queueName get ?count? queueName peek ?count? queueName put item ?item ...? queueName unget item queueName size _________________________________________________________________ DESCRIPTION
The ::struct namespace contains a commands for processing finite queues. It exports a single command, ::struct::queue. All functionality provided here can be reached through a subcommand of this command. Note: As of version 1.4.1 of this package a critcl based C implementation is available. This implementation however requires Tcl 8.4 to run. The ::struct::queue command creates a new queue object with an associated global Tcl command whose name is queueName. This command may be used to invoke various operations on the queue. It has the following general form: queueName option ?arg arg ...? Option and the args determine the exact behavior of the command. The following commands are possible for queue objects: queueName clear Remove all items from the queue. queueName destroy Destroy the queue, including its storage space and associated command. queueName get ?count? Return the front count items of the queue and remove them from the queue. If count is not specified, it defaults to 1. If count is 1, the result is a simple string; otherwise, it is a list. If specified, count must be greater than or equal to 1. If there are not enoughs items in the queue to fulfull the request, this command will throw an error. queueName peek ?count? Return the front count items of the queue, without removing them from the queue. If count is not specified, it defaults to 1. If count is 1, the result is a simple string; otherwise, it is a list. If specified, count must be greater than or equal to 1. If there are not enoughs items in the queue to fulfull the request, this command will throw an error. queueName put item ?item ...? Put the item or items specified into the queue. If more than one item is given, they will be added in the order they are listed. queueName unget item Put the item into the queue, at the front, i.e. before any other items already in the queue. This makes this operation the comple- ment to the method get. queueName size Return the number of items in the queue. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category struct :: queue of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
graph, list, matrix, pool, prioqueue, record, set, skiplist, stack, tree struct 1.4.1 struct::queue(n)
All times are GMT -4. The time now is 04:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy