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: '',
> 
> Yet one crys foul and the other silently keeps on trucking.  Both
> print the same `<>'.
> 
> In both techniques all that is left to be passed to $trimmed_line is
> ''.
> 
> In trying to defeat you explanation I think I proved to myself why it
> is right... (I hate when that happens .... hehe) But finally I've
> been made to see the difference between a null value and an
> uninitiallized one.
> 
> This kind of shows the story:
> 
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> #!/usr/local/bin/perl -w
> $line3 = '';
> 
> @ar2 = split(/ /,$line3); ## set to null
> print "[EMAIL PROTECTED] = <@ar2>\n" ;
> print "\$ar2[0] = <$ar2[0]>\n";  ## uninitiallized
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> OUT>>>
> ./sptest
> @ar2 = <>
> Use of uninitialized value in concatenation (.) or string at ./sptest line 6.
> $ar2[0] = <>

Using split and list slices can be tricky sometimes.  Maybe these examples will help:

$ perl -e'
$x = ",a,b,c,,";
print defined $_ ? "<$_> " : "undefined " for  split /,/, $x;             print "\n";
print defined $_ ? "<$_> " : "undefined " for (split /,/, $x)[0..8];      print "\n";
print defined $_ ? "<$_> " : "undefined " for  split /,/, $x, 4;          print "\n";
print defined $_ ? "<$_> " : "undefined " for (split /,/, $x, 4)[0..8];   print "\n";
print defined $_ ? "<$_> " : "undefined " for  split /,/, $x, 9;          print "\n";
print defined $_ ? "<$_> " : "undefined " for (split /,/, $x, 9)[0..8];   print "\n";
print defined $_ ? "<$_> " : "undefined " for  split /,/, $x, -1;         print "\n";
print defined $_ ? "<$_> " : "undefined " for (split /,/, $x, -1)[0..8];  print "\n";
'
<> <a> <b> <c> 
<> <a> <b> <c> undefined undefined undefined undefined undefined 
<> <a> <b> <c,,> 
<> <a> <b> <c,,> undefined undefined undefined undefined undefined 
<> <a> <b> <c> <> <> 
<> <a> <b> <c> <> <> undefined undefined undefined 
<> <a> <b> <c> <> <> 
<> <a> <b> <c> <> <> undefined undefined undefined 



John
-- 
use Perl;
program
fulfillment

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

Reply via email to