Re: comments in the middle of a hash variable ?



Joe Smith wrote:
nadsinoz wrote:

I have a hash variable that I would like to modify
each time the script is run


That's reasonable.

by commenting out fields that I am not interesed in.


But that is not.

How can I make this work?
%fields = (
    lastname => $fieldnum++,
    firstname => $fieldnum++,
#    middlename => $fieldnum++,
    userid => $fieldnum++,
    rscname => $fieldnum++,
    email => $fieldnum++,
    roleid => $fieldnum++,
)


Remove the '#' and add some code to remove the keys you don't
want.  That is, change the hash dynamically at runtime instead
of constantly editing the source code.

delete $fields{middlename} if $ignore_middle_name;

Wouldn't it be easier not to create the value in the first place?

%fields = (
    $do_lastname  ? (lastname => $fieldnum++)  : (),
    $do_firstname ? (firstname => $fieldnum++) : (),
    ...
)

Thomas

--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
.



Relevant Pages