builtin - How can I redefine 'open' properly in Perl? -


Some time ago, I ask a question:

And the answer served me well I have a package that overrides Pearl's 'Open' function, which enables me to enter file access.

Now I have come to a case that breaks the basic code's functionality.

  Use strict; Use warnings; Use data: Dumper; Sub MyOpen (*; @) {my $ p; My $ retval = CORE :: open ($ p, $ _ [1]); {No hard; * {"Main :: $ _ [0]"} = $ p; } Return $ return; } BEGIN {* CORE :: Global :: open = * myopen; }; My @ a = (1, 2, 3); Open (check, "> dump") or print "open the dumper file: $! \ N"; Print check "\ n"; Print Check Data :: Dumper- & gt; Dump (\ A); Close check  

Now I get this message:

  Object method can not be found "Check" package "Data :: Dumper" / Code>  

How do I fix this?

Try using another name from "check"

"check" is a special function that is said during the compile time, and in fact it should not be used.

  $ open check, '', 'foo.txt'; 0.00224494934082031 seconds runtime error: Undefined sub-routine and devell :: REPL :: plugin :: package :: default circuitpad :: check (eval 329) is called on line 5. $ Open checks, '& lt;', 'foo.txt'; 0.00155806541442871 seconds taken $  

Why that specific error?

  perl - MO = Deparse -e 'print check data :: Dumper 1'; Print 'Data :: Dumper' - & gt; Check (1);  

In addition to this, you are using global file handle , which are problematic

Use this notation:

  Open my $ FH, '& lt;' , $ Foo; Print & lt; $ Fh & gt ;; About $ FH;  

These are more beneficial, when they go out of the area themselves are closed.


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%? -