Ask a Question related to Perl / CGI, Design and Development.
-
acmbruin #1
Perl nested loops
Hello,
I have the following code, but it seems that the first array can't be used in the second while loop for comparison. Can someone tell me how this array can be used in the second while loop?
# !/usr/bin/perl
#use strict;
use warnings;
###############################
######### FUNCTIONS ###########
###############################
#Input: Inserted tab delimited text files.
#Output: Corrected file.
#Function: Reads the inserted files and corrects the descriptions.
sub file_handling{
my $column;
my $general;
my @results;
my @results1;
my @results2;
#Opening the files.
my $filename1 = "LlactisKF147_annotation.csv";
open(FILE1, '<', $filename1) or die "Can't open file: $filename1";
my $filename2 = "LlactisKF147_annotation+IGS_versie2.csv";
open(FILE2, '<', $filename2) or die "Can't open file: $filename2";
my $filename3 = "Translated_file.csv";
open(FILE3, '>', $filename3) or die "Can't open file: $filename3";
my $filename4 = "Not_in_translationlist.csv";
open(FILE4, '>', $filename4) or die "Can't open file: $filename4";
#Reads file number 2 and skipping the first line.
my $first_line2 = <FILE2>;
while(my $line = <FILE2>) {
my $line2 .= $line;
#Check if column is defined.
if (! defined $column) {
$column = $line2;
}else {
#Split the lines to form arrays.
@results = split("\t", $line);
if ($results[1] =~ m/Original/ && $line2 !~ /^\s*$/ ){
$general = $results[10];
}elsif ($results[9] =~ m/\*/ || $results[9] =~ m/\@/ || $results[9] =~ m/ts/ || $results[9] =~ m/ns/ ){
if ($results[6] eq ''){
$results[10] = "Hypothetical protein"
}else{
$results[10] = $general;
}
}
}
#Reads file number 1 and skipping the first line.
my $first_line1 = <FILE1>;
while(my $line = <FILE1>){
my $line1 .= $line;
#Split the lines to form an array.
@results1 = split ("\t", $line1);
#Check if description of file 1 is in file 2.
# Is this true then change the discription to the description in file 2.
if ($results1[6] eq $results[6]){
$results1[6] = $results[10];
print FILE3 Dumper (\@results1);
}else{
print FILE4 "hoi";
}
}
}
close(FILE1);
close(FILE2);
close(FILE3);
}
file_handling();
Junior Member
- Join Date
- Jan 2011
- Posts
- 1
-
Nested loops?
Hi, I've been adapting a script which parses HTML and creates an RSS feed (http://www.perl.com/lpt/a/2001/11/15/creatingrss.html). Now I want... -
Possible Bug w/ nested loops and queries
May have found a possible bug... can someone please verify? In a database I have two tables, temp1 and temp2 These tables can contain anything,... -
Using 'my' within nested loops
I am curious about the amount of overhead created with the first example below as compared to the second example below: Example 1: my $this;... -
[PHP] nested for loops
your syntax is correct, just need to change for ($j=0: $j < 5; $j++) to for ($j=0; $j < 5; $j++) Anyone ever do a nested for loop? $i =0; $j... -
nested for loops
Anyone ever do a nested for loop? $i =0; $j =0; for ($x=0; $x < 50; $x++){ echo ("1 to 50"); for ($j=0: $j < 5; $j++) { echo ("less than...



Reply With Quote

