![]() |
|
Keep It Simple, Stupid | |
PerlMonks |
comment on |
( #3333=superdoc: print w/replies, xml ) | Need Help?? |
You can use overload to simulate this behavior. But SetDualVar lets you build scalars the same way that $! is built, which it quite a bit less overhead (as if that matters). The module lets you set both the numeric and string value of a scalar without the two having to agree. Note that tie can't distinguish string and numeric "sub-contexts" and so isn't enough by itself to accomplish this. But you can use tie in conjunction with either overload or SetDualVar to do this (or just use overload by itself). And, if you really want to have it act just like $!, then a handy way to look up error strings from error numbers:
But that also made me realize that you don't even need a module to create a dual-valued scalar that duplicates $! since prints something like "5 Input/output error". Also note that getting the type of "copy semantics" you want may be the determining factor in which method to use. - tye (but my friends call me "Tye")In reply to (tye)Re: $! context behavior
by tye
|
|