go ahead... be a heretic | |
PerlMonks |
Re^4: Is 'use vars' really obsolete?by perl-diddler (Chaplain) |
on Sep 22, 2017 at 20:16 UTC ( [id://1199934]=note: print w/replies, xml ) | Need Help?? |
Did you catch the last line of my post: FWIW, the module being used, exported variable names with values corresponding to found paths of their lower-case names as executables, so any EXPORT list would be variable per usage (though fixed per program invocation). I didn't think Exporter would work in this case because, 1) I'm not exporting anything, and 2) the programs using the module get differently named IMPORTS based on what they pass (not based on anything in the used module -- i.e. I'm not exporting any package variables. Example: I had a program that created file-system snapshots. In main I needed to call ~10 external programs, so I had: In places in the program where I wanted to call a program, I'd construct a command. Since the program ran part-time as root, I wanted to make sure that common commands resolved to the real commands in the right places. Additionally, I didn't want it to fail unpredictably -- but instead fail at startup there would be no changes to the system state. In the above usage, Cmds uses a safe internal path and then puts variables containing the absolute paths of the commands into the caller's package name space. The variables never exist in Cmds, so I don't see that Exporter would even work in this case. The calling program would reference the external command paths by using the up-cased name of the command as a variable. Example: So Cmds allows me to call external commands, safely, using builtin paths, allows me to use those paths via variables that can be used in strings, and ensures presence of needed external commands before running the program. As for the use case being complicated, it was easier to make work 7 years ago than other methods. I just ran across it when checking something out in the module and it seemed like an interesting case where 'our' wasn't an easy replacement for use vars.
In Section
Seekers of Perl Wisdom
|
|