in reply to Hash: Removing a specific value from a multi-valued key
The q/11.5/ syntax is a type of a Perl quote and it just means '11.5'. There are a bunch of these short-cut quote operators in Perl (q(single quote),qq (double quote), qw (quote word),etc). If you are going to write more Perl, buy "Programming Perl" by Larry Wall, Tom Christiansen and Jon Orwant and look at page 63 which has a table about this "quoting" subject.
I prefer the below synatx.
First, @{$hashA{q/11.5/}}, the q/11.5/ just means '11.5'.$hashA{q/11.5/} = [ grep { $_ != 1734789 } @{$hashA{q/11.5/}} ];
See below code.
1734789 was in the anonymous array assigned to $hashA{'11.5'} and it is no longer there.#!/usr/bin/perl -w use strict; use Data::Dumper; my %hashA = ( '11.5' => [ 1723478, 1734789, 1798761, ], '11.12' => [ 1700123, ], '11.01' => [ 1780345, ] ); print Dumper (\%hashA); $hashA{q/11.5/} = [ grep { $_ != 1734789 } @{$hashA{q/11.5/}} ]; print Dumper (\%hashA); __END__ Prints: $VAR1 = { '11.01' => [ 1780345 ], '11.12' => [ 1700123 ], '11.5' => [ 1723478, 1734789, 1798761 ] }; $VAR1 = { '11.01' => [ 1780345 ], '11.12' => [ 1700123 ], '11.5' => [ 1723478, 1798761 ] };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hash: Removing a specific value from a multi-valued key
by eshwar (Novice) on Oct 01, 2009 at 10:00 UTC |