Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Loops and my

by mrbbking (Hermit)
on May 18, 2002 at 12:56 UTC ( #167496=note: print w/ replies, xml ) Need Help??


in reply to Loops and my

Can I undef ($v1, $v2, $vX); or does this only affect the first value in the array?
If it's an array, then you can just do @array = (); to undefine it. If they're really scalars, then you can shortcut it a little bit with $v1 = $v2 = $vX = undef;

Example:

#!/usr/bin/perl -w use strict; print "\nWith scalars..\n"; my ($var1, $var2, $var3) = (1, 2, 3); foreach( $var1, $var2, $var3 ){ print "$_, "; } print "\nundef them...\n"; $var1 = $var2 = $var3 = undef; foreach( $var1, $var2, $var3 ){ print "$_, "; # -w will complain about this. } print "\nWith an array..\n"; my @stuff = qw(a b c); foreach( @stuff ){ print "$_, "; } print "\nundef it...\n"; @stuff = (); foreach( @stuff ){ print "$_, "; # -w won't complain about this, because # @stuff is empty, so this line does not # execute }


Comment on Re: Loops and my
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://167496]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-12-22 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls