Gary Stainburn wrote:

> Hi all,
> 
> I've got a problem understanding a scoping issue I've got.
> 
> I've got 2 hashes which I defined inside the sub that generates the form
> thus:
> 
> sub do_form() {
>   my ($error)=@_;
>   my %dships=('X'=>'<Any>','L'=>'Leeds','D'=>'Doncaster');
>   my %depts=('X'=>'<Any>','S'=>'Service','P'=>'Parts','T'=>'Rapid-Fit',
>              'B'=>'Bodyshop','C'=>'Commercial','N'=>'New Cars',
>              'U'=>'Used Cars');
> .....
>    print $query->popup_menu('dealer',['X','L','D'],'X',\%dships);
>   print qq{</td></tr><tr><td>Department</td><td>};
>   print $query->popup_menu('dept',['X','P','S','B','T','C','N','U'],'X',
>          \%depts);
> .....
> }
> 
> This worked fine until I needed the same 2 hashes in other sub's so I
> moved
> them to the top of the script - outside any sub{} blocks.  I thought that
> this would then make those hashed available to everyone.
> 
> What actually happened was that the hashed became unavailable and on the
> form I simply saw the single letters as defined in the array.

there are a couple reasons why i think this might happen. first, make sure 
you really move them out of any block. out of any sub{} block might not be 
enough since you can create any block with a bare {}. make sure they are 
not inside the BEGIN{},eval{}.. etc of course. if you don't have 'use 
strict' or warning enabled, enable them and see if there is any warning. 
second, you are passing the hash as a reference to the subs, make sure the 
subs do not modify them. is it possible that your subs are actually 
clearing out those hashes since they are passed by ref?

david
david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to