How do I disable autovivification in Perl? -


Suppose a large team of your "develoopped" is;) by a large team. Here is a simplified model of the potential disaster, which can happen when someone examines a very deeply in the data structure. If it is not possible to disable autowaking completely or to the extent, how should it work? Thanks a lot :) !!!!

  Use strict; use caution; Use data: Dumper; My $ some_ref = {akey = & gt; {Deep = gt; 1}}; Print dumper ($ some_ref); If ($ some_ref-> {}} {doot} == 1) {Print 'too deep' $ /; } If ($ some_ref-> {}} {print 'Already a deep douche' $ /; } Print dumper ($ some_ref);  

It outputs to:

  $ VAR1 = {'akey' = & gt; {'Deep' = & gt; 1}}; Use the initial value in the numeric eq (==) present at Autovivify_test.pl. 5. Already a deep dot $ VAR1 = {'deep' => {}, 'Eki' = & gt; {'Deep' = & gt; 1}};  

Yes, I know that there is a warning, but ... it may be too late.

O people, can help in saying that my Hashuf can be referenced.

It may be that if I apply a good FETCH method which examines deeper investigation into the structure, then will I easily solve my problem?


I saw, and more. Here is a simplified version of my solution:

  #! / Usr / bin / env perl; # Test_tie.pl Package StrictHash; Strict use; Use warnings; Use tie: hash; Our @ ISA = QW (tie :: stadium); Use carp; SubTyahash {my $ class = shift; My $ hash = bless {@_}, $ square; Return $ hash; } ## =============================================== ================================= If applied for a member who is not currently present then FETCH Fail ## ================================================ ======================== Sub FET {My ($ hash, $ key) = @_; Carp :: Confirm "key" $ key "does not exist" as long as $ hash- & gt; {$ Key} does not exist; Return $ hash- & gt; {$ Key}; } ## =============================================== ========================= Package main; Use strict; Use precautions; Data :: use dumper; #Imagine is StrictHash. / StrictHash.pm #use StrictHash; My% hash; Tie% hash, 'Stinthash', Eki = & gt; {Deep = gt; 1}; My $ some_ref = \% hash; Print dumper ($ some_ref); If ($ some_ref-> {}} {doot} == 1) {Print 'too deep' $ /; }  

What I have achieved to touch only one place in the app. Now all places like ($ some_ref -> {deep} {doot}) will die with stack-trace. So I will find them easily and fix them. And this type of new writing will not be possible. Pearl is great for big apps too, you just need to know more;).

Thank you all! I hope this helps others too.

You may want to use an object instead of a hash (see) or use one or You can change the alerts to errors, if you really want:

  Use warnings = NONFATAL = & gt; 'All', FATAL = & gt; 'Uninitialized';  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -