LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   strange split not splitting perl (https://www.linuxquestions.org/questions/programming-9/strange-split-not-splitting-perl-490096/)

PB0711 10-06-2006 03:08 PM

strange split not splitting perl
 
Umm, so I'm trying to do a routine add to mysql. First I'm parsing a file with perl to find the parts that I want. Well when I go to split the file I get nothing.

Code:

#usr/bin/perl -w
use strict;
#use DBI:

my $HMP_mol = "mcard_sdf_all.txt";
open HMP_SDF, ($HMP_mol) or die "Couldn't open file $HMP_mol; $! \n";
#-----Globals-----
my (@sdf,@HMP);
#-----sdf -> mol conversion------
while (my $line =<HMP_SDF>){
        my $everything.=$line;
        @sdf = split(/End of SDF File of HMDB/, $everything);
}
print "@sdf\n<-sdf\n"; # debug line


#-----Capturing lines from file-----
my $MET= "metabocards_all-noformat.txt";
open MET, ($MET) or die "Could not open file; $! \n";
while (my $row = <MET>){
        #print "$row\n";
        @HMP =split(/\n/, $row);
}
print "$HMP[2]\n<-HMP\n";
print "@HMP <-everything\n";

and the txt file is
Code:

Beginning of HMDB00001
# Accession_No:
HMDB00001

# Creation_Date:
2005-11-16 15:48:42

# Update_Date:
2006-09-20 15:58:12

# biospider_lastupdate:
0000-00-00 00:00:00

# Common_Name:
1-Methylhistidine

lots of stuff in the middle!!!!!!!

# Metabolic_Enzyme_4_References:
8182053; 8595053; 2217167; 8144586

End of HMDB00002

so there are two txt files to be honest but I've given just one. Whats odd is it doesn't matter if I split by new line or anything else I get nothing! :confused:

acid_kewpie 10-06-2006 03:24 PM

i can't for the life of me work out what you're trying to achieve from that split... you're splitting based on a regex that enver even appears in your test data, and looping through thte text file growing a string longer and longer and splitting it every time... ???

it's not exactly elegant (or even correct) perl, but i wouldimagine that you;re main problem is that you are reeinitializing "$ewverything" on every single loop. you need to pull the "my $everything;" line out to before the loop starts due to the scoping of the variable declarations.

PB0711 10-06-2006 06:13 PM

oh my gosh. :rolleyes: I'm so sorry. I'm really embarrassed that I made such a mistake. All I can say is that i must be tired. After I read your reply I saw that $everything was inside the while loop.

Thanks and sorry for the mistake.

PB


All times are GMT -5. The time now is 07:34 AM.