Welcome to the Monastery PerlMonks

### Re^2: map and undef - odd behaviour with an array of arrays

by Melly (Hermit)
 on Dec 22, 2012 at 08:45 UTC ( #1009985=note: print w/replies, xml ) Need Help??

But why did map{undef \$_}(@x) behave differently than undef @x?

Edit to add - oh, I'm being stupid - it's undefining each element rather than @x. When I was testing this, for some reason I concluded that perl -e "@x=qw(a);map{undef \$_}(@x);print 1 if defined @x;" didn't print 1 (but it does).

One of those days...

```map{\$a=1-\$_/10;map{\$d=\$a;\$e=\$b=\$_/20-2;map{(\$d,\$e)=(2*\$d*\$e+\$a,\$e**2
-\$d**2+\$b);\$c=\$d**2+\$e**2>4?\$d=8:_}1..50;print\$c}0..59;print\$/}0..20
Tom Melly, pm (at) cursingmaggot (stop) co (stop) uk

Replies are listed 'Best First'.
Re^3: map and undef - odd behaviour with an array of arrays
by eyepopslikeamosquito (Chancellor) on Dec 22, 2012 at 08:53 UTC

But why did map{undef \$_}(@x) behave differently than undef @x?
"undef @x" empties the array while "map{undef \$_}@x" sets each element in the array to the value undef. Since your array had one element in it, that element was not deleted, rather its value was set to undef.

Create A New User
Node Status?
node history
Node Type: note [id://1009985]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2017-08-24 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (367 votes). Check out past polls.

Notices?