Simple Substition Question

2005-10-13 Thread Dave Adams
My Code:
--
#!/usr/bin/perl -w
use strict;
my $text= 'hello';
my $text2 = 'bye';
my $text3 =~ s/$text/$text2/g;
print $text3;

My Error:
---
F:\perlex\findpara.pl line 5.
Use of uninitialized value in print at F:\perlex\findpara.pl line 6.

My Questions:
---
Should perl give me a true or false? I am confused by this error.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Simple Substition Question

2005-10-13 Thread Jeff 'japhy' Pinyan

On Oct 13, Dave Adams said:


my $text= 'hello';
my $text2 = 'bye';
my $text3 =~ s/$text/$text2/g;
print $text3;


What are you expecting to happen?  There is NOTHING in $text3, so trying 
to substitute all hellos for byes will result in Perl telling you that 
you're using an uninitialized value ($text3).


Perhaps if you put something in $text3 FIRST, and THEN tried s///'ing it.

--
Jeff japhy Pinyan%  How can we ever be the sold short or
RPI Acacia Brother #734%  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %-- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Simple Substition Question

2005-10-13 Thread Timothy Johnson

If you break down what you've written into an English approximation, you
get something like this:

#

Create a variable $text, then assign $text the value 'hello';

Create a variable $text2, then assign $text2 the value 'bye';

Create a variable $text3, then substitute all instances of 'hello'
inside of $text3 with 'bye';

Print the contents of $text3

#

You are getting a warning because Perl is wondering why you want to
print an empty variable.

I'm wondering what you were expecting to happen.  It sounds like you
haven't gotten the hang of the s/// operator.  You might want to reread
the section of 'perldoc perlop' about quotes and quote-like operators.




-Original Message-
From: Dave Adams [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 13, 2005 11:51 AM
To: beginners perl
Subject: Simple Substition Question

My Code:
--
#!/usr/bin/perl -w
use strict;
my $text= 'hello';
my $text2 = 'bye';
my $text3 =~ s/$text/$text2/g;
print $text3;

My Error:
---
F:\perlex\findpara.pl line 5.
Use of uninitialized value in print at F:\perlex\findpara.pl line 6.

My Questions:
---
Should perl give me a true or false? I am confused by this error.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response