Login or Register to Ask a Question and Join Our Community

Perl: Problem in retaining values after each loop

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: Problem in retaining values after each loop
# 1  
Old 09-27-2012
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
our $p1=0;
our $p2=0;
our $line1;
our $line2;
open(my $read, "<2.txt");#file where pattern would be present
my @e = <$read>;
my $d = join('', @e );
$d =~ s/\s+//g;
while ($line1 = <$fhConditions>) #while each line in input file 1
chomp $line1;
my @info = split("\t" , $line1);
my $match1 = substr($d,$info[3],$l);#in $d from the position specified by $info[3] till $l characters get all characters stored as $match1
print "$match1\n";
$p1=index($match1, $site);#get the index where it is actually matching
print  "$p1 \n";
print $line1;
while ($line2 = <$fhConditions1>)#while each line in input file 2
chomp $line2;
print $line2;
my @info = split("\t" , $line2);
my $a = $info[3]-$l;
my $match2 = substr($d,$a,$l);#in $d from the position specified by $info[3] -$l characters get all characters stored as $match2
print "$match2\n";
$p2=index($match2, $site);
print  "$p2 \n";
print $line2;  
if($p1+$p2<=30)#if the sum of the indexes is less than 30 then print those lines from input files to output 
print $w1 $line1;
print $w2 $line2;

i am unable to get the values for $p1 and $p2 . how do i make it proper?
# 2  
Old 09-27-2012
Without seeing your input data it's impossible to guess what you're trying to do here.

What input do you have, and, what output do you want?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retaining value outside loop

Hi, I m new to shell scripting. I did some research and understand that unix treats while and other loops as new shell and hence the variable loose its value outside of the loop. I found solution for integer variable but in mycase this is a string variable. here variable loc is a... (6 Replies)
Discussion started by: knowyrtech
6 Replies

2. Shell Programming and Scripting

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... (0 Replies)
Discussion started by: chris01010
0 Replies

3. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

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

5. Shell Programming and Scripting

Return multiple values using for loop in perl

I am using a for loop to copy files from say DIR1 and DIR2 to DIR3.I have to check whether files are copied from DIR1 and DIR2 and print the respective message. @path=("$DIR1","$DIR2"); foreach (@path) { $rc=system("cp $_/*xml $DIR3"); if ($rc == 0) { print "Files were copied... (1 Reply)
Discussion started by: liyakathali
1 Replies

6. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

7. Shell Programming and Scripting

Get values from 2 files - Complex "for loop and if" awk problem

Hi everyone, I've been thinking and trying/changing all day long the below code, maybe some awk expert could help me to fix the for loop I've thought, I think I'm very close to the correct output. file1 is: <boxes content="Grapes and Apples"> <box No.="Box MT. 53"> <quantity... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

8. Shell Programming and Scripting

Retaining Pipeline values

Hi, I am trying to calculate a few values using the below code but it dosent seem to be working. for i in 1 2 3 4 5 6 7 8 do j=`expr $i + 3` x =`head -$j temp1|tail -1|cut -f24 -d","` y =`head -$j temp1|tail -1|cut -f25 -d","` c =`expr $x / $y` echo "$c" >> cal_1 done I am not... (4 Replies)
Discussion started by: sachinnayyar
4 Replies

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

10. UNIX for Dummies Questions & Answers

retaining null values in ftp transfer

I am trying to ftp a file to a Unix server that contains null values. The file is on a Unisys system. It contains null values between data but when I look at the file on the Unix server, the nulls are gone and the data is compressed together. How do I not lose those null values? TIA, Betty (1 Reply)
Discussion started by: betty
1 Replies
Login or Register to Ask a Question

Featured Tech Videos