Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Updating hash of subroutines

by Thelonius (Priest)
on Mar 11, 2006 at 04:19 UTC ( [id://535869]=note: print w/replies, xml ) Need Help??


in reply to Updating hash of subroutines

Although runrig and Zaxo are probably right that it would be better to pass the parameters explicity, I think what you're looking for is local.

For example:

#!perl -w use strict; our (@minor_frame_data); my (%frame_lookup_by) = ( 21 => { desc => "S/W Status", value => sub { $minor_frame_data[0]*256 + $minor_frame_data[1]} , + }, 33 => { desc => "HK Subcom", value => sub { $minor_frame_data[1] % 16 } , #modulo 16 of w12 }, 117 => { desc => "General Status", value => sub {$minor_frame_data[0]*256 + $minor_frame_data[1] }, + }, 129 => { desc => "Sensor Status", value => sub {$minor_frame_data[0]*256 + $minor_frame_data[1] }, + }, ); foo(\%frame_lookup_by); bar(\%frame_lookup_by); sub foo { my ($ref) = @_; local (@minor_frame_data) = (3, 2); print "foo 21 -> ", $ref->{21}->{value}->(), "\n"; } sub bar { my ($ref) = @_; local (@minor_frame_data) = (2, 5); print "bar 21 -> ", $ref->{21}->{value}->(), "\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-06-15 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.