Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple question 1

Status
Not open for further replies.

PhoenixDown

Programmer
Jul 2, 2001
279
CA
For my script control panel, I'm making the guestbook entries settings part and I'm having a little problem.

On my data file It prints a new line at the top. It looks like:

Code:
"
1|Calvin|<A HREF=&quot;mailto:calvin@puremadnezz.com&quot;>|<A HREF=&quot;[URL unfurl="true"]http://www.puremadnezz.com/&quot;>||12345678|xcloud0|xcloud2000x@hotmail.com|xcloud2000x|||||Test|06-22-2001|00:47:45|216.130.72.133|c-72-133-res1.mts.net&quot;[/URL]

To call all the entries I use:

Code:
open(DATA,&quot;<$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;) or die (&quot;Unable to open guestbook entry file.&quot;);
@line = <DATA>;
close(DATA);
foreach $line (@line) {
 $line =~ s/\n//g;
 ($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12,$var13,$var14,$var15,$var16,$var17,$var18) = split(/\|/,$line);
if ( $line =~ //) {
	$line =~ s/\n//g;
} else {
	$line =~ s/\n//g;
}

It converts the new line to table format and I've tried using that if statement to strip it out of there and it's not working.

Here is an image of what it looks like:

gif.gif


Please tell me what I'm doing wronf! Thank you! :) - Go there!
 
One more question. Also, for the edit entry sub I use

Code:
open(DATA,&quot;<$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;) or die (&quot;Unable to open guestbook entry file.&quot;);
@line = <DATA>;
close(DATA);
foreach $line (@line) {
 $line =~ s/\n//g;
 ($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12,$var13,$var14,$var15,$var16,$var17,$var18) = split(/\|/,$line);

But it prints all the entries on the page including the field items. But when I remove the foreach statement it doesn't show the field data, but it shows the entries individually as I want it to. How can I fix this?

Thanks again! :) - Go there!
 
First of all, to get rid of the newline at the end of each data line the simplest way is to add this line right after your for loop:
Code:
chomp $line;
That will remove any trailing newline (and only newline).

As for the second question, I don't understand what you mean. Could you explain a little better what the problem is?
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Code:
open(DATA,&quot;<$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;) or die (&quot;Unable to open guestbook entry file.&quot;);
@line = <DATA>;
close(DATA);
foreach $line (@line) {
 $line =~ s/\n//g;
 chomp $line;
 ($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12,$var13,$var14,$var15,$var16,$var17,$var18) = split(/\|/,$line);

It didn't work. I could have put it in the wrong place, right?

Second question:

I don't think I can explain my problem any better. I don't want to post all my code here, it's rather large. But if you still have the control panel and login information, you can see what's wrong.

If you forgot it, I'm on Yahoo Messenger right now and I'll give it to you. - Go there!
 
ditto Tracy's comment. I don't understand the question either. ;-)


keep the rudder amid ship and beware the odd typo
 
Okay...

I have a sub rountine edit which is called by &quot;gb.cgi?action=edit?number=&quot;gbnumber&quot;

The picture I posted about is the control panel for the guestbook entries. I use:

Code:
open(DATA,&quot;<$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;) or die (&quot;Unable to open guestbook entry file.&quot;);
@line = <DATA>;
close(DATA);
foreach $line (@line) {
 $line =~ s/\n//g;
($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12,$var13,$var14,$var15,$var16,$var17,$var18) = split(/\|/,$line);

As the for each for the edit guestbook entries.

Now, this for each looks for everyline on the database file and returns the variables ($var1-$var18).

The sub looks kind of like:

Code:
sub edit {

$Copyright = &Copyright;
$Menu = &Menu;
$CPHeader = &CPHeader;

open(DATA,&quot;<$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;) or die (&quot;Unable to open guestbook entry file.&quot;);
@line = <DATA>;
close(DATA);
foreach $line (@line) {
 $line =~ s/\n//g;
 chomp $line;
($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12,$var13,$var14,$var15,$var16,$var17,$var18) = split(/\|/,$line);

print<<THIS;

<<--HTML-->>

THIS

}

}

So, it displays all entries and their forms in one giant page. Let's say I clicked on gb.cgi?action=edit&number=5 then it would still do the same thing. I want these to be individual pages.

I tried removing the for each statement, it kind of works but it doesn't display the variables ($var1-$var18)

How can I fix this??

I hope this helps. :)

I'll be back on Yahoo Messenger in about an hour. - Go there!
 
Move the chomp up to right after the foreach, and don't do the substitutions on \n.

It looks like you only want to process ONE entry of @line, not ALL of them. Instead of a foreach on @line, try:
Code:
$number = 5; #the number of the entry to edit
$line = $line[$number];
chomp $line;
then do your split.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Okay, I changed it to:

Code:
open(DATA,&quot;<$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;) or die (&quot;Unable to open guestbook entry file.&quot;);
@line = <DATA>;
close(DATA);
$number = 5; #the number of the entry to edit
$line = $line[$number];
chomp $line;
($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12,$var13,$var14,$var15,$var16,$var17,$var18) = split(/\|/,$line);

It kind of works again. It prints the fifth entry in each of the forms. How can I make it so it will print the entries in all forms? - Go there!
 
Where I said $number = 5, you would need to specify the line you want to edit. The url you gave as an example was: gb.cgi?action=edit&number=5. I assumed this meant that you wanted to edit the 5th record, so that what I coded as an example. You would need to use the CGI module to get the parameter &quot;number&quot; (like you get the parameter &quot;action&quot;) and assign that value to $number. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
The chomp $line; should be added as the first line INSIDE the foreach:
Code:
foreach $line (@line) {
   chomp $line;
   # split and whatever
}
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Code:
open(DATA,&quot;<$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;) or die (&quot;Unable to open guestbook entry file.&quot;);
@line = <DATA>;
close(DATA);
foreach $line (@line) {
 chomp $line;
 ($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12,$var13,$var14,$var15,$var16,$var17,$var18) = split(/\|/,$line);

It STILL didn't work... :-( - Go there!
 
&quot;It looks like you only want to process ONE entry of @line, not ALL of them. Instead of a foreach on @line, try:&quot;

I want it to read the entire file by the FIRST &quot;|&quot;. Then I have the entry where you click and it goes to admin.cgi?action=edit&number=5. It will print ALL data in the fields. I want it to do that for EVERY entry. So if you lick on maybe admin.cgi?action=edit&number=1, it will print the first field. The code you made prints the fifth entry in all places (admin.cgi?action=edit&number=1-5) and I don't know how to fix it.

&quot;You would need to use the CGI module to get the parameter &quot;number&quot; (like you get the parameter &quot;action&quot;) and assign that value to $number.&quot;

Do you think you could show me how...? :-s - Go there!
 
Cloud2: you should probably start a new thread and describe what you're trying to accomplish better. I think by this point this thread has gotten a little confused. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I have a file to parse with entries over multiple lines.
I only want half of the lines for each entry and each sub entry has a prefix on the line above. What I can't seem to grasp is how to run through a file extracting the bits I want and disgarding the bits I don't. With what little I know of JAVA the problem is quite simple as there is usually a getNext method for this kind of thing. Meaning that you can get a line of text, test it then keep it or dump it and then call the next line. In Perl you seem to be able to get the next line in a while loop but what if you don't want that line how do you force the next one to be pulled down form the file handle.

EG


TEST
I want this line
LEVEL
I Don't want this line
DETAIL
I want all of this and
this and this
and this as well and then
I want everything until here
END
And then I want to stop here with out the above line (TEST)

Does this make sense ???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top