| Author |
How to undine a value
|
|
| Richard Heintze 2004-05-22, 11:31 am |
| I find I'm undefining variables my assigning an
unitialized variable to defined value to make it
undefined (as exemplified below).
Is there a better way to do this?
my $k;
for($i = 0; $i < $c; $i++){
if ( defined $k ){
print $x[$k];
my $t; # intentionally undefined
$k = $t; # undefine $k
} else {
$k = $i;
}
}
__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/
| |
| Randy W. Sims 2004-05-22, 11:31 am |
| On 4/1/2004 11:46 PM, Richard Heintze wrote:
> I find I'm undefining variables my assigning an
> unitialized variable to defined value to make it
> undefined (as exemplified below).
>
> Is there a better way to do this?
>
> my $k;
> for($i = 0; $i < $c; $i++){
> if ( defined $k ){
> print $x[$k];
> my $t; # intentionally undefined
> $k = $t; # undefine $k
> } else {
> $k = $i;
> }
> }
undef $k;
see 'perldoc -f undef'
Regards,
Randy.
| |
| Wc -Sx- Jones 2004-05-22, 11:31 am |
| Richard Heintze wrote:
> my $t; # intentionally undefined
> $k = $t; # undefine $k
Just for clarity -
This isn't "undefining" it is
assignment of nothing to $k;
my $nothing;
print "\n\$nothing's Value: $nothing and
\$nothing's length ". length $nothing;
my $somthing = 100;
$somthing = $nothing;
print "\n\$somthing's Value: $somthing and
\$somthing's length ". length $somthing;
-Sx-
| |
| Wiggins D Anconia 2004-05-22, 11:31 am |
|
> I find I'm undefining variables my assigning an
> unitialized variable to defined value to make it
> undefined (as exemplified below).
>
> Is there a better way to do this?
>
> my $k;
> for($i = 0; $i < $c; $i++){
> if ( defined $k ){
> print $x[$k];
> my $t; # intentionally undefined
> $k = $t; # undefine $k
> } else {
> $k = $i;
> }
> }
>
Unless this is a contrived example, just increment $i by 2 each loop.
If it is contrived then the other answers should work...
http://danconia.org
| |
| Wc -Sx- Jones 2004-05-22, 11:31 am |
| Wiggins d Anconia wrote:
>
>
> Unless this is a contrived example, just increment $i by 2 each loop.
> If it is contrived then the other answers should work...
Well, $c and @x were never defined/explained
by the time this contruct was presented.
--
-Sx-
[This message contains no user serviceabe code.]
use strict;
use warnings;
use diagnostics;
my (@x) = qw% But for sanities sake %;
my ($c, $i, $k, $t) = 2**32+1;
undef $k;
for($i=0, $c=2; $i<$c; $i=0) {
if ( defined $k ) {
print $x[$k];
$k = $t;
} else {
$k = $c;
}
}
__END__
|
|
|
|