• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

PERL SIMPLE HELP

Hey,
        I have a problem... when i do this piece of code:

open (stats, "ID.txt")|| die "SORRY CANT OPEN\n";
my ($stats) = (<stats>);
close(stats);
my ($ID) = $stats +1;  
open (save, ">ID.txt")|| die "SORRY CANT OPEN";
select(save);
print "$ID";
close(save);
########################
anything that i put after it, does nothing... its like it doesnt do anything after that CODE.. Why, and what can i do
0
markyello
Asked:
markyello
  • 21
  • 12
  • +1
1 Solution
 
zerofillCommented:
This is because you have selected "save" as default filehandle on line 6: select(save);

Put this line at the end of code - after close(save):

select (STDOUT);

and everything will be fine.

Or just dont select default filehandle and do it this way:
open (save, ">ID.txt");
print save "$ID";
close (save);
0
 
manniakkCommented:
it will be more simple just to put select(STDOUT) after the given example...
0
 
markyelloAuthor Commented:
Thanks... now i have another problem
i wanna click on a ad that has an ID number,
then it goes to the next page which opens a file adn searches for that ID number and then strippes it...
then i want it to override the file with the new file that doesnt have that id number anymore...
here is my code, all it does it take the ID number out...
but im having trouble saving it to a variable and then overriding the file with the variable with the new stuff...
here's my code:

#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
print $q->header();


my $line;
my ($id) = ($q->param("id"));
my ($delete) = ($q->param("delete"));
my ($type) = ($q->param("type"));
my $file;



if($type eq 'Wanted To Buy'){
$file = "buy.txt";
}elsif($type eq 'For Sale'){
$file = "sell.txt";
}else{
print "We Cant Determine if this ad is, Wanted -or- Selling<br> Please Email Site Admin... Or Try Again Later";
}

if($delete eq 'yes'){
delyes();
}elsif($delete eq 'no'){
delno();
}


sub delyes{
open(file, "$file")|| die "Cant freaking Open File";
my $line;
my @line = (<file>);
while ($line = pop @line){
unless($line =~ /$id/){
print "File: $line<br><br>";
close(file);
}
}
}

sub delno{
print "AN ERROR HAS OCCURRED";
}





WHAT IS THE PROBLEM WITH THAT AND HOW DO I SAVE(OVERRIDE) EVERYTHING THAT DOESNT CONTAIN THE ID NUMBER, TO THE FILE..???
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
riceriCommented:
with:

sub delyes{
open(file, "$file")|| die "Cant freaking Open File";
my $line;
my @line = (<file>);
while ($line = pop @line){
unless($line =~ /$id/){
print "File: $line<br><br>";
close(file);
}
}
}

Do you what to remove only the line that have the id and save all the rest in the file?
0
 
riceriCommented:
If thats what you want then this is something that can do it.

sub delyes {
  open (File,"+<$file") || die "Cant freaking Open File";
  seek (File,0,0);
  my @in = <File>;
  my @out;

  foreach $row (@in) {
    chomp($row);
    if ($row ne $id) {
      push @out, "$row\n";
    }
  }

  seek (File,0,0);
  print (File @out);
  close (File);
}

0
 
markyelloAuthor Commented:
riceri:
thats what i want...
i want it for my computer posting site called eposting

www.yeago.net/eric

goto it.. and see, but ill try your advice and see if it works...
THANKs
0
 
markyelloAuthor Commented:
Riceri:
That didnt work...
something weird happened thought...
it didnt do nothing when it was like this:

push @out, "$row\n";
but did something when you replace the \n with a <br>

push @out, "$row<br>";
but that that did was put everything on the same line... and still didnt delete the ID number from the file


Weird Huh...
 Any More Suggestions.. please adn thankyou
Please BE ASAP if possible
0
 
markyelloAuthor Commented:
Riceri:
That didnt work...
something weird happened thought...
it didnt do nothing when it was like this:

push @out, "$row\n";
but did something when you replace the \n with a <br>

push @out, "$row<br>";
but that that did was put everything on the same line... and still didnt delete the ID number from the file


Weird Huh...
 Any More Suggestions.. please adn thankyou
Please BE ASAP if possible
0
 
riceriCommented:
A <br> is HTML and only works in webbrowsers.
\n is a line feed in a text file.

If you want it on more then one row you need to have the \n there.

My code looks for the value $id.
I don't know how your textfile looks like you have never told .

I think you want it like this: (random values)
4234234
4242342
4253466
6456456
6456456
6765657
7567465

If $id is any of those values it will be removed.
0
 
markyelloAuthor Commented:
hey do you have an Email address or an AOL s/n
cause im online right now and it seems that you are too
and i have some questions
0
 
riceriCommented:
You can find me on IRC or ICQ
0
 
markyelloAuthor Commented:
Ok here's how it works...
my  website is a posting, a computer posting website...
the first one is what type of ad it is (Buying, or For Sale), the next one is the name, then the computer type, then the location, then the date(timestamp) then the description then the picture URL, then the ID number...
if you goto my website...
www.yeago.net/eric
and post an ad then you will understand more... then when you view the ads, you can press delete, adn it will send you an email and some other stuff ill figure out later... but the last thing on the line is the ID number... and i want when you click on the ad it takes that whole line away(or the posted ad) away...

this is what my textfile looks like
##############################
##############################
For Sale~NEW~Eric~NEW~Desktop PC~NEW~someone@somewere.com~NEW~Region/Other~NEW~March-28-2003~NEW~Descriptions~NEW~http://www.yeago.net/eric/Images/elogo.jpg~NEW~167
##############################
##############################


you probably didnt get any of taht
so whats your AOL or AIM, s/n so i can talk to you
im only 14yrs old.. and alittle stuck on my site's improvement and i thank you for helping me
0
 
markyelloAuthor Commented:
whats IRC adn the other thing??
0
 
markyelloAuthor Commented:
were do i do that at?
0
 
riceriCommented:
Don't got any AIM and no AOL.

I still don't get this....

Why do you have the sales and buy in the same file??
Why not one file for one thing?
0
 
markyelloAuthor Commented:
i do have it like that... if the ad is a buying ad then the ad gets saved into buy.txt
and if its a sell ad it gets sent to sell.txt
0
 
riceriCommented:
http://www.mirc.com - A windows IRC client(I don't got time to help you learn it)
http://www.icq.com - What Microsoft Messanger is a copy of.
0
 
markyelloAuthor Commented:
whats IRC, can i talk to u there
0
 
riceriCommented:
So the goal of this is to collect data from a web form and then later display it once?
0
 
markyelloAuthor Commented:
im telling you... goto www.yeago.net/eric
adn u will understand alittle more


either that or i can send u every one of my files, for the website and u can look at them


that IRC will take to long
i have Microsoft instant messanger
0
 
riceriCommented:
You can find me on Efnet with the nick Greyh0und.
0
 
markyelloAuthor Commented:
well, my post.cgi, displayes whats inside the files, buy or sell and when a new post is submitted and u refresh the posts page it will show the new ad at the top..
so pretty much yea u got it
0
 
markyelloAuthor Commented:
well, my post.cgi, displayes whats inside the files, buy or sell and when a new post is submitted and u refresh the posts page it will show the new ad at the top..
so pretty much yea u got it
0
 
riceriCommented:
I have checked your site, and i DON'T see the scripts there only the result.

How shall i see what you do in your scripts?
0
 
markyelloAuthor Commented:
Which Server Are You On??
0
 
riceriCommented:
I am on the Efnet network.
0
 
markyelloAuthor Commented:
here is my post.cgi file

#################################


#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
print $q->header();

my ($day, $month, $year, $tm, $count, $file);
my ($input_type) = $q->param("what");

print "<html>";

require "Includes/head.txt";

my ($title);

if($input_type eq "buy"){
  $file= "buy.txt";
  $title = "Buying";
}elsif($input_type eq "sell"){
  $file= "sell.txt";
  $title= "Selling";
}else{
  print "
<center>
<font color='green' size='6'>Viewing Ads</font><br>
<a href='posts.cgi?what=sell'>View Selling Ads</a>
&nbsp;&nbsp;&nbsp; || &nbsp;&nbsp;&nbsp;
<a href='posts.cgi?what=buy'>View Buying Ads</a>

";
exit();
}

my ($line, @line) ;
my (@raw_data);
my ($buying,$name,$accessory,$email,$state,$description,$post,$date,$picture);
my (@INCLUDE_TAGS, $html);

@INCLUDE_TAGS = ( "I", "SUP", "FONT", "P" );

print "
<LINK href='style.css' rel=stylesheet type=text/css>
<center>
<font size=5 color='green' face='Verdana'><b>You Are Viewing Ads That People Are $title</b></font>
<br><br>
";

open(DAT, $file) || die("Could not open file!\n");

print "<table width='90%'>";
@line = <DAT>;
#@line = (pop @line);

my $count = 0;
#($line = pop @line) &&

#while ( ($line = pop @line) && ($count < 2) ) {
foreach $line (@line) {
unless($line = pop @line){
}
          $line =~ s/-br-/<p>/gi;
       unless($line =~ /#/){
if($line =~ / /){


       chomp($line);

($buying,$name,$accessory,($email),$state,$date,$description,$picture)=split(/\~NEW~/,$line);

print " 
  <tr>
    <td bgcolor='#999999'>
      &nbsp;&nbsp;&nbsp;<font class='words'><b>Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></font><font class='orange_sm'>$name</font>
      <br>
     &nbsp;&nbsp; <font class='words'><b>Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></font><font class='orange_sm'>$date</font>
      <br>
     &nbsp;&nbsp; <font class='words'><b>Item:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></font><font class='orange_sm'>$accessory</font>
      <br>
    &nbsp;&nbsp;  <font class='words'><b>E-mail:&nbsp;&nbsp;&nbsp;</b></font><a href='mailto:$email'><font class='email'>$email</font></a>
      <br>
    &nbsp;&nbsp;  <font class='words'><b>Location:&nbsp;</b></font><font class='orange_sm'>$state</font>
      <br>
     &nbsp;&nbsp; <font class='words'><b>Description:\n</b></font>
      <hr width=250 align=left>
     
    &nbsp;&nbsp;  <font class='orange_sm'>$description</font>  
      <hr width='250' align='left'>
     
";
#$pic = ' <a href='picture.cgi?picture=$picture'><font size='3'>View Picture</font></a> ';
my ($picture) = ($picture);
print "
  &nbsp;&nbsp;<font size='2' color='white' face='verdana'>Interested about this Ad?</font><br>

<a href='mail.cgi?email=$email'><font class='green_a'>Email Them</font></a>

&nbsp;&nbsp;&nbsp; <font color='white' face='verdana' size='2'> OR </font> &nbsp;&nbsp;&nbsp;
<a href='picture.cgi?type=$buying&name=$name&accessory=$accessory&email=$email&state=$state&date=$date&description=$description&picture=$picture'><font class='green_a'>View Picture</font></a>
</td></tr>
";

  $count++;
      #}
    }
  }  
}
print "
  </table>
</center>
</BODY></HTML>
";

open (stats, "Status/posted.txt")|| die "SORRY CANT OPEN\n";
my ($stats) = (<stats>);
close(stats);
my ($add) = $stats +1;  
open (save, ">Status/posted.txt")|| die "SORRY CANT OPEN";
select(save);
print "$add";
close(save);
0
 
markyelloAuthor Commented:
if u want any more files then just tell me...
0
 
markyelloAuthor Commented:
ooo wait..
hang on thats the old file...
let me update it, cause i forgot i did something last night and i erased it and forgot to put the new post.cgi and other stuff

0
 
markyelloAuthor Commented:
OK everythign is up and running if you wanna goto...
http://www.yeago.net/eric/posts.cgi?what=sell

or here is the new code for posts.cgi

##################

#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
print $q->header();

my $id;
my ($day, $month, $year, $tm, $count, $file);
my ($input_type) = $q->param("what");

print "<html>";

require "Includes/head.txt";

my ($title);

if($input_type eq "buy"){
  $file= "buy.txt";
  $title = "Buying";
}elsif($input_type eq "sell"){
  $file= "sell.txt";
  $title= "Selling";
}else{
  print "
<center>
<font color='green' size='6'>Viewing Ads</font><br>
<a href='posts.cgi?what=sell'>View Selling Ads</a>
&nbsp;&nbsp;&nbsp; || &nbsp;&nbsp;&nbsp;
<a href='posts.cgi?what=buy'>View Buying Ads</a>

";
exit();
}

my ($line, @line) ;
my (@raw_data);
my ($buying,$name,$accessory,$email,$state,$description,$post,$date,$picture);
my (@INCLUDE_TAGS, $html);

@INCLUDE_TAGS = ( "I", "SUP", "FONT", "P" );

print "
<LINK href='style.css' rel=stylesheet type=text/css>
<center>
<font size=5 color='green' face='Verdana'><b>You Are Viewing Ads That People Are $title</b></font>
<br><br>
";

open(DAT, $file) || die("Could not open file!\n");

print "<table width='90%'>";
@line = <DAT>;
#@line = (pop @line);

my $count = 0;
#($line = pop @line) &&

#while ( ($line = pop @line) && ($count < 2) ) {
foreach $line (@line) {
unless($line = pop @line){
}
           $line =~ s/-br-/<p>/gi;
        unless($line =~ /#/){
if($line =~ / /){


        chomp($line);

($buying,$name,$accessory,($email),$state,$date,$description,$picture, $id)=split(/\~NEW~/,$line);

print " 
  <tr>
    <td bgcolor='#999999'>
      &nbsp;&nbsp;&nbsp;<font class='words'><b>Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></font><font class='orange_sm'>$name</font>
      <br>
     &nbsp;&nbsp; <font class='words'><b>Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></font><font class='orange_sm'>$date</font>
      <br>
     &nbsp;&nbsp; <font class='words'><b>Item:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></font><font class='orange_sm'>$accessory</font>
      <br>
    &nbsp;&nbsp;  <font class='words'><b>E-mail:&nbsp;&nbsp;&nbsp;</b></font><a href='mailto:$email'><font class='email'>$email</font></a>
      <br>
    &nbsp;&nbsp;  <font class='words'><b>Location:&nbsp;</b></font><font class='orange_sm'>$state</font>
      <br>
     &nbsp;&nbsp; <font class='words'><b>Description:\n</b></font>
      <hr width=250 align=left>
     
    &nbsp;&nbsp;  <font class='orange_sm'>$description</font>  
      <hr width='250' align='left'>
     
";
#$pic = ' <a href='picture.cgi?picture=$picture'><font size='3'>View Picture</font></a> ';
my ($picture) = ($picture);
print "
  &nbsp;&nbsp;<font size='2' color='white' face='verdana'>Interested about this Ad?</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  &nbsp;&nbsp;<font size='2' color='white' face='verdana'>Did You Post Ad?</font><br>
<a href='mail.cgi?email=$email'><font class='green_a'>Email Them</font></a>

&nbsp;&nbsp;&nbsp; <font color='white' face='verdana' size='2'> OR </font> &nbsp;&nbsp;&nbsp;
<a href='picture.cgi?type=$buying&name=$name&accessory=$accessory&email=$email&state=$state&date=$date&description=$description&picture=$picture'><font class='green_a'>View Picture</font></a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='deletead.cgi?delete=yes&type=$buying&id=$id'><font class='green_a'>Delete Ad</font></a>
</td></tr>
";
  $count++;
      #}
    }
  }  
}
print "
  </table>
</center>
</BODY></HTML>
";

open (stats, "Status/posted.txt")|| die "SORRY CANT OPEN\n";
my ($stats) = (<stats>);
close(stats);
my ($add) = $stats +1;  
open (save, ">Status/posted.txt")|| die "SORRY CANT OPEN";
select(save);
print "$add";
close(save);
0
 
markyelloAuthor Commented:
HOW DO U SIGN UP FOR that eris network ??? i cant find a register thing
0
 
riceriCommented:
You don't have to!!!!

The result of all this is shall be a ad rotate system or?
0
 
riceriCommented:
I got sleep....

I think you shall get on book on HTML and one on Perl.
I will check back here later.

http://validator.w3.org/check?uri=http%3A%2F%2Fwww.yeago.net%2Feric%2Findex.cgi&charset=%28detect+automatically%29&doctype=HTML+4.01+Transitional
0
 
markyelloAuthor Commented:
i know 2 years of HTML
and 1 year of Perl
i dont need that...

email me directly here:
markyello@hotmail.com


and i dont get what that last thing u said was:

You don't have to!!!!

The result of all this is shall be a ad rotate system or?


anyways, why doesnt it work
0
 
markyelloAuthor Commented:
Hey thanks...
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 21
  • 12
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now