Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^5: Possible useless use of map

by Anonymous Monk
on Mar 18, 2010 at 10:57 UTC ( [id://829383]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Possible useless use of map
in thread Possible useless use of map

:D You're not paying attention
$ perl -MDDS -w -le " my $hr; $hr->{stuff}; Dump($hr)" $HASH1 = {}; $ perl -MDDS -Mwarnings -le " my $hr; $hr->{stuff}; Dump($hr)" Useless use of hash element in void context at -e line 1. $HASH1 = {};
$hr used to be undef, after $hr->{stuff} it is a hashref.

Curiously, my little test reveals Data::Dump::Streamer breaks the -w switch .

Replies are listed 'Best First'.
Re^6: Possible useless use of map
by almut (Canon) on Mar 18, 2010 at 11:23 UTC

    I see what you mean.  So, one could conclude that getting no warning in the OP's case (with map) is in fact the appropriate behavior (as the $hr->{$_} is not useless), while getting the warning with for seems more questionable  (in which case I wouldn't consider it a bug to silence a useless "Useless use of..." warning :)

      One could if you ignore intent, but I wouldn't support that conclusion. The warning deals with return value and where it ends up. perldiag says:
      ... Very often this points not to stupidity on your part, but a failure of Perl to parse your program the way you thought it would...
      so if you were to adapt perldiag example with andreas' example you get
      #~ perl -MDDS -Mstrict -Mwarnings -le " my $hr; map { @{$hr->{$_}}{qw' + a b c '} = $_,$_,$_ ; } 1; Dump($hr) " #~ perl -MDDS -Mstrict -Mwarnings -le " my $hr; map { @{$hr->{$_}}{qw' + a b c '} = ( $_,$_,$_ ); } 1; Dump($hr) " #~ perl -MDDS -Mstrict -Mwarnings -le " my $hr; $_ = 1; @{$hr->{$_}}{q +w' a b c '} = $_,$_,$_ ; Dump($hr) " #~ perl -MDDS -Mstrict -Mwarnings -le " my $hr; $_ = 1; @{$hr->{$_}}{q +w' a b c '} = ( $_,$_,$_ ); Dump($hr) " $ perl -MDDS -Mstrict -Mwarnings -le " my $hr; map { @{$hr->{$_}}{qw' +a b c '} = $_,$_,$_ ; } 1; Dump($hr) " $HASH1 = { 1 => { a => 1, b => undef, c => undef } }; $ perl -MDDS -Mstrict -Mwarnings -le " my $hr; map { @{$hr->{$_}}{qw' +a b c '} = ( $_,$_,$_ ); } 1; Dump($hr) " $HASH1 = { 1 => { a => 1, b => 1, c => 1 } }; $ perl -MDDS -Mstrict -Mwarnings -le " my $hr; $_ = 1; @{$hr->{$_}}{qw +' a b c '} = $_,$_,$_ ; Dump($hr) " Useless use of a variable in void context at -e line 1. Useless use of a variable in void context at -e line 1. $HASH1 = { 1 => { a => 1, b => undef, c => undef } }; $ perl -MDDS -Mstrict -Mwarnings -le " my $hr; $_ = 1; @{$hr->{$_}}{qw +' a b c '} = ( $_,$_,$_ ); Dump($hr) " $HASH1 = { 1 => { a => 1, b => 1, c => 1 } }; $ $

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found