On Saturday, June 7, 2003, at 10:28 PM, Harry Putnam wrote:

James Edward Gray II <[EMAIL PROTECTED]> writes:

This, on the other hand is a search/replace and probably works exactly
as you expect.  The lines are preforming two different operations,
thus the different results.

My point here is that in both cases , regardless of them being different actions, the value returned is the same: '',

Okay, I think I understand your question better, so let me try again.


The two lines you showed do not return the same think, unfortunately. That's where you're getting hung up, I think.

Let me simplify the example to the relevant lines only:

my $string = 'ABC'; # declare a string

$string =~ s/^ABC//;

# Replace ABC at the beginning with nothing. (Note: $string is altered here,
# so we don't need another variable.) The value is still 'initialized' in Perl lingo
# even though we removed the characters from it.


$string = 'ABC'; # restore test string

$string = (split /^ABC/, $string)[1]; # $string is now 'uninitialized'

# This is the line that's throwing you, so let me change it just a little to show
# what's really going on here


$string = 'ABCD';

$string = (split /^ABC/, $string)[1]; # $string 'uninitialized', doesn't contain 'D'!

# Here you are splitting the string into multiple parts. In this case, one part. The 'D'.
# Then you are asking for the second part in the returned list, but like I said, there
# is only one. Perl gives you undef for that, which is why you see the 'uninitialized'
# warning as soon as you try to use it.


Hope that clears it up a little.

James


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



Reply via email to