LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-06-2006, 03:08 PM   #1
PB0711
Member
 
Registered: Aug 2004
Location: London, UK
Distribution: Ubuntu 10.10, ubuntu 11.04, suse 9.2, OSX
Posts: 259

Rep: Reputation: 30
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!
 
Old 10-06-2006, 03:24 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.

Last edited by acid_kewpie; 10-06-2006 at 03:26 PM.
 
Old 10-06-2006, 06:13 PM   #3
PB0711
Member
 
Registered: Aug 2004
Location: London, UK
Distribution: Ubuntu 10.10, ubuntu 11.04, suse 9.2, OSX
Posts: 259

Original Poster
Rep: Reputation: 30
Lightbulb

oh my gosh. 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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl split ShaqDiesel Programming 5 08-17-2006 08:02 PM
split command in perl not splitting / linuxmandrake Programming 1 11-03-2005 03:28 PM
Perl Help (possible split) fooforon Programming 2 02-19-2004 05:53 AM
PERL: split on html tag? ocularbob Programming 12 09-08-2003 05:52 PM
problem splitting a $ in perl joesbox Programming 7 08-30-2003 11:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration