[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] A doubt of a beginner



According to Daniele Nencini:
  
> The instructions are simples , and i really have some problems to exit
> the panic of the moment

Hmmmmm..... I have done something similar in the past
without a problem.  But what it sounds like is happening is
that MacPerl is changing the "$fruit" to "\$fruit"
internally.  This is probably because MacPerl thinks you
really want to print out the string "$fruit".

What I would suggest doing is to use the substitution
command.  Try this:

1. Read in the lines.
2. Substitute rather than equate.

#!perl

	open( THEFILE, "myFruits.dat" ) || die $!;
	@theLines = <THEFILE>;
	close( THEFILE );

	for( $i=0; $i<=$#theLines; $i++ ){
		$theLines[$i] =~ s/$fruit/strawberries/;
		print $theLines[$i];
		}

	exit( 0 );

You can also try using the EVAL statement in MacPerl.  Try:

	$theLines[$i] = eval( $theLines[$i] );

instead up there.  This should evaluate the $fruit and
substitute in the word "strawberries".  However, my
personal preference is for the substitution.  Mainly
because I think it is a bit clearer on what is going on
with the information.  But that's just me.  :-)

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch