LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-29-2003, 08:11 PM   #1
joesbox
Member
 
Registered: Feb 2003
Location: hampton va
Distribution: ubuntu
Posts: 502

Rep: Reputation: 30
problem splitting a $ in perl


here is the background:
i am trying to write a web-based program that will work as a journal. i have the section that will write to the file; i have the section that will read the entire file and print it to the screen; now i am working on getting the search section working and am running into a prob.

journal file ex.:
Code:
Journal date:  Fri Aug 29 19:34:12 EDT 2003
I had a bla bla day and spent bla bla dollars getting bla a bla.
The bla yelled at me due to the fact that I am bla at bla.
subroutine snippit:
Code:
sub SEARCH {

	open (SEARCH, "</var/www/cgi-bin/journal.txt") ||
	print "<h1>Sorry, But your journal cannot be  found</h1>";
	$searchjournal = <SEARCH>;
	close (SEARCH);
	print $searchjournal;
}
the output to the browser is
Code:
Journal date:  Fri Aug 29 19:34:12 EDT 2003
when you would think that it would be
Code:
Journal date:  Fri Aug 29 19:34:12 EDT 2003 I had a bla bla day and spent bla bla dollars getting bla a bla. The bla yelled at me due to the fact that I am bla at bla.
i am trying to split on the "Journal date:\s\s" and leave each date and entry all in one element of the array

what i am planning on doing:
[code]
sub SEARCH {

open (SEARCH, "</var/www/cgi-bin/journal.txt") || print "<h1>Sorry, But your journal cannot be found</h1>";
$searchjournal = <SEARCH>;
close (SEARCH);
@entries = split (/Journal\sdate\:\s\s/, $searchjournal)
}

my theory should work but isn't. can someone point out what is wrong or where i should go with this??
thanks
 
Old 08-29-2003, 08:23 PM   #2
vanquisher
Member
 
Registered: Aug 2003
Location: Hyderabad, India
Posts: 126

Rep: Reputation: 15
that is because
Code:
       $searchjournal = <SEARCH>;
reads only the first line of the file, by default. however, you can fix it by removing the new-line character between the two entries, i.e between
Journal date: Fri Aug 29 19:34:12 EDT 2003 and
I had a bla bla day and spent bla bla dollars getting bla a bla.
The bla yelled at me due to the fact that I am bla at bla.


That should work. I made similar mistake many times and spent hours and hours banging my head as I couldn't see anything that went wrong. Tell me if it works out or not.
 
Old 08-29-2003, 08:24 PM   #3
GabeF
Member
 
Registered: Mar 2002
Location: New Hampshire, US
Distribution: Mandrake 8.0, Redhat 8.0
Posts: 101

Rep: Reputation: 15
You have to set one of perl's special variables to null before you can use the line
Code:
$searchjournal = <SEARCH>;
or else it stops with the \n. This link should help:
http://tlc.perlarchive.com/articles/perl/ts0001.shtml

Just a note...I found that on my first google search (hint hint)
 
Old 08-29-2003, 08:47 PM   #4
joesbox
Member
 
Registered: Feb 2003
Location: hampton va
Distribution: ubuntu
Posts: 502

Original Poster
Rep: Reputation: 30
AAAAAAAAAAAAAAAAAHHHHHHHHHHHHH!
**bang {ouch} bang{ouch}**

i knew that rule GabeF. i just forgot about it. %$#@%$#@ i am a dork. i normally do look at the web and prior posts but i didn't know what to look for. thanks

and for your response vanquisher; that is a good idea but i wanted to make the prog able to have hard returns within the journal entry so that the writer could make different paragraphs. thanks anyway.

thanks for the quick response
 
Old 08-30-2003, 12:33 AM   #5
zekko
Member
 
Registered: Aug 2003
Location: Canada
Distribution: Slackware, debian
Posts: 76

Rep: Reputation: 15
@searchjournal = <SEARCH>;

print "@searchjournal\n";

or even:

foreach (@searchjournal) {
print "$_\n";
}

Kinda late response
 
Old 08-30-2003, 08:51 AM   #6
joesbox
Member
 
Registered: Feb 2003
Location: hampton va
Distribution: ubuntu
Posts: 502

Original Poster
Rep: Reputation: 30
i tried that but that splits the file on the \n. i want the ability to put hard returns into the entry so that the person could place paragraphs into the entry. and i wanted the entire entry witht the date to be in one (1) element of an array.

btw, i got it to work using "undef $/;".

Last edited by joesbox; 08-30-2003 at 08:54 AM.
 
Old 08-30-2003, 09:00 AM   #7
GabeF
Member
 
Registered: Mar 2002
Location: New Hampshire, US
Distribution: Mandrake 8.0, Redhat 8.0
Posts: 101

Rep: Reputation: 15
That's great! You didn't sound like the type who doesn't do his homework Don't hit your head too hard or you might forget again!
 
Old 08-30-2003, 11:11 AM   #8
joesbox
Member
 
Registered: Feb 2003
Location: hampton va
Distribution: ubuntu
Posts: 502

Original Poster
Rep: Reputation: 30
thanks for making me feel better GabeF. i feel bad when i have to ask the question before i can search for the answer.
 
  


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
split command in perl not splitting / linuxmandrake Programming 1 11-03-2005 03:28 PM
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
file splitting???? spideywebsling Linux - General 4 07-19-2004 06:42 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
Splitting my 6o Madmanator Linux - Newbie 1 01-03-2002 11:21 PM

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

All times are GMT -5. The time now is 11:35 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