Sponsored Content
Top Forums Shell Programming and Scripting Perl: Problem in retaining values after each loop Post 302706657 by anurupa777 on Thursday 27th of September 2012 06:16:04 AM
Old 09-27-2012
Perl: Problem in retaining values after each loop

Code:
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?
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
STREAM_WRAPPER_REGISTER(3)						 1						STREAM_WRAPPER_REGISTER(3)

stream_wrapper_register - Register a URL wrapper implemented as a PHP class

SYNOPSIS
bool stream_wrapper_register (string $protocol, string $classname, [int $flags]) DESCRIPTION
Allows you to implement your own protocol handlers and streams for use with all the other filesystem functions (such as fopen(3), fread(3) etc.). PARAMETERS
o $protocol - The wrapper name to be registered. o $classname - The classname which implements the $protocol. o $flags - Should be set to STREAM_IS_URL if $protocol is a URL protocol. Default is 0, local stream. RETURN VALUES
Returns TRUE on success or FALSE on failure. stream_wrapper_register(3) will return FALSE if the $protocol already has a handler. CHANGELOG
+--------+------------------------------+ |Version | | | | | | | Description | | | | +--------+------------------------------+ | 5.2.4 | | | | | | | Added the $flags parameter. | | | | +--------+------------------------------+ EXAMPLES
Example #1 How to register a stream wrapper <?php $existed = in_array("var", stream_get_wrappers()); if ($existed) { stream_wrapper_unregister("var"); } stream_wrapper_register("var", "VariableStream"); $myvar = ""; $fp = fopen("var://myvar", "r+"); fwrite($fp, "line1 "); fwrite($fp, "line2 "); fwrite($fp, "line3 "); rewind($fp); while (!feof($fp)) { echo fgets($fp); } fclose($fp); var_dump($myvar); if ($existed) { stream_wrapper_restore("var"); } ?> The above example will output: line1 line2 line3 string(18) "line1 line2 line3 " SEE ALSO
The "streamWrapper" prototype class, "Example class registered as stream wrapper", stream_wrapper_unregister(3), stream_wrapper_restore(3), stream_get_wrappers(3). PHP Documentation Group STREAM_WRAPPER_REGISTER(3)
All times are GMT -4. The time now is 01:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy