Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: File::Rsync output functions and global variables

by sandfly (Beadle)
on Oct 08, 2003 at 21:07 UTC ( #297738=note: print w/replies, xml ) Need Help??


in reply to File::Rsync output functions and global variables

What you've done is perfectly acceptable. You have used 'my' to declare the output variable, so it isn't global, it's lexically scoped. In the example above, it is only visible to code within the file you declare it in.

If you need to limit the scope further, you can put braces around the code which needs to see it.

package MyModule; use File::Rsync; my $rsync; { my %rsync_out; $rsync=File::Rsync->new( { outfun => &rsync_out, errfun => &rsync_out, } ); sub rsync_out { my ($message, $type)=shift; $rsync_out{$type}.="$message\n"; } sub outmsg { $rsync_out{out} } sub errmsg { $rsync_out{err} } } # ... # code here has no clue about %rsync_out # (but it can still see $rsync because I declared # it outside the braces.) # ... # Access the output using the outmsg and errmsg subs my $output = outmsg;

The code not tested. In most cases, you don't need to bother with this anyway.

Replies are listed 'Best First'.
Re: Re: File::Rsync output functions and global variables
by sandfly (Beadle) on Oct 09, 2003 at 07:34 UTC
    > In most cases, you don't need to bother with this anyway.
    I mean you don't need to bother with the braces - you do have to test!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2022-01-22 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (62 votes). Check out past polls.

    Notices?