Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I catch changes to %ENV?

I have a bunch of scripts that run tool flows. Like a Makefile does but in Perl.

As part of those flows, the Perl scripts set environment vars and it's not always easy to know when they happen and hence it can be hard to reproduce individual stages of the flow.

Is there a way to hook into %ENV such that I can register a callback when the environment changes?

Can I just tie to it? %ENV is already behaving like a tie.

Follow-up: Yes. You just tie to it.

like image 601
mmccoo Avatar asked Mar 25 '09 23:03

mmccoo


1 Answers

Ow. I just got my butt whooped. Anyway, there supposedly exists a monitor package that lets you monitor changes, via tie, to existing variables. This sounded like an interesting problem, so when I started digging into the "tie" documentation in The Blue Camel, there was no definition for what happens to an existing variable (i.e. - is a reference saved somewhere?). SO, I googled for "perl tie "existing variable"". Unfortunately, the link I found was socially unacceptable (pirated material), so I got pretty much slapped out of existence, reputation wise.

Good luck, though.

Anyway, just to clarify, it's in chapter 9 of "Advanced Perl Programming", the chapter on "Tie". Make sure you buy your copy from a reputable site :-)

like image 69
Roboprog Avatar answered Sep 23 '22 01:09

Roboprog