"Raistlin Majere" <> wrote in
news: oups.com:
#!/usr/bin/perl
use strict;
use warnings;
missing
> print "Content-type: text/html\n\n";
>
> open(OLDLIST, "<link list.txt");
Always, yes, always check if the open call succeeded.
What do you think this call is supposed to do?
> open(NEWLIST, ">link list.tmp");
Ditto.
>
> $count=1;
>
> $line1="";
> $line2="";
>
> foreach $line(<OLDLIST>)
By using the for loop, you have already slurped the whole file. Then you
go and process it line-by-line. Do it right from the get go:
while ( my $oldline = <OLDLIST> ) {
chomp($oldline);
> if($count==1)
> {
> $line1=$line;
> };
Perl already has a builtin variable keeping track of the line count.
Read perldoc perlvar for $.
>
> if($count==2)
> {
> $line2 =~ s/Suggested Text/$line1/;
Where is $line2 initialized?
>
> print NEWLIST $line2."\n";
> };
>
> if($count==3)
> {
> $count=0;
> };
>
> $count++;
> };
>
> close(NEWLIST);
> close(OLDLIST);
>
> # what is wrong?
Many things. Make sure that the program works from the command line
before trying it as CGI.
I think this is what you are trying to do:
#!/usr/bin/perl
use strict;
use warnings;
my ( $suggestion );
while ( <DATA> ) {
chomp;
if ( $. % 2 ) {
$suggestion = $_ if $. % 2;
} else {
s/Suggested Text/$suggestion/g;
print $_, "\n";
}
}
__DATA__
read
I will Suggested Text the posting guidelines
help
Posting guidelines Suggested Text me Suggested Text myself,
help
and Suggested Text others Suggested Text me.
C:\Home\asu1\src> perl t.pl
I will read the posting guidelines
Posting guidelines help me help myself,
and help others help me.
C:\Home\asu1\src>
|