William Olbrys wrote:

> I've started writing a simple perl script for a web site so I can update
> it more quickly, but as I have a bit of a problem.
>
> Here is what I have:
>
> #!c:/Perl/bin/perl
> print "Content-type: text/html\n\n";
> $game = open (TEXT, "../htdocs/gameplow/game");

What do you think you are dong here? As far as I know, open is a void function.
perldoc -f open

> $index = open (TEXT, "../htdocs/gameplow/index");

> $index =~ s/inpoint/$game/;

What do iyu want $game to contain at this point? Or $index?  My best guess is that 
they are both null.

> print $barf;
> while ($index = <TEXT>) {
>     foreach $line($index){
>         print $line
> }
> }
> close(TEXT);
>
> The problem is my search and replace does not work.  I'm new to perl and
> I find the perlre syntax very confusing.  I simply want to replace one
> word(a string) with a much bigger string! How are files accessed
> differently than regular strings? I don't receive an error though. It
> just doesn't replace the string... any help would be appreciated.
>
> Will Olbrys.

The problem is probably not with the regex syntax.  That tends to be straightforward.  
I think the problem is that you are trying to apply the open syntax from some other 
language to Perl.  Perl open works like:

open HANDLE_NAME, "< fileName";

Which creates an input handle to fileName accessible via HANDLE_NAME

while (<HANDLE_NAME>) {print;}
would essentially print the file contents, line by line to the screen..
while (<HANDLE_NAME>) {
   s/geegaw/doodad/g;
   print;
}
would do the same, but before printing, would replace any instance of the string 
"geegaw" with "doodad".

There is alot going on under the surface in the code above.  Let's look a little 
closer.
while (<HANDLE_NAME>) {print;}
Actually does this:
while ($_ = <HANDLE_NAME>) {print $_;}
The angle brackets around the file handle behave in a context-sensitive manner.  Each 
line of input is treated as a scalar, a string literal.  By default, Perl assumes the 
default scalar $_ is the target.  To specify another scalar variable to contain the 
value of each line, assign explicitly:
my $line = <HANDLE_NAME>;
In an array context, the angle brackets will load all lines of the file into the 
target array:
my @lines = <HANDLE_NAME>;
Now @lines contains the entire file as an array.

Read up on open, maike sure that you are getting the right values into your variables, 
perhaps by printing each out on a line of its own, and then try the regex again.

Joseph





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to