in reply to Interesting unary - oddity

I guess my question is "But why???". This doesn't seem to serve any useful purpose, does it? For instance, if you change the script to read

It's used mostly for unordered function parameters:

$x = Dog->new( -size => 'small', # ok, this would be -aggresiveness => 'low', # quoted by =>, and -hair_style => 'curly', # ... -hair_lenght => 'short', ) package Dog; sub new { my %args = @_; my $size = $args{-size}; # ... these would be my $age = $args{-age}; # quoted by the {}, but ... my %hair_properties = @args{ -hair_style, # ... these would need -hair_lenght, # quoting without -hair_colour, # unary-'-'. }; ... }

Replies are listed 'Best First'.
Re^2: Interesting unary - oddity
by hardburn (Abbot) on Aug 27, 2004 at 18:14 UTC

    I'd write that as:

    my %hair_properties = @args{qw( hair_style hair_length hair_color )}; # ^^^^^ Blasted Brits who can't accept # a simplification of the language . . .

    That way your users won't have to type the extra '-' char. Further, this method is actually shorter when your list starts growing (four-char overhead of qw() stays constant).

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

      oh I agree. I've never used this type of '-'. But CGI.pm uses it that way, for example.

      ps - I'm not a brit.