Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

You've commented out an essential statement :)

$_[0]=$handle unless defined $_[0]; # pass up to caller

This sets the $fh in open my $fh, ...  Without it, $fh won't be the handle created in *CORE::GLOBAL::open.

Putting this near the end of that routine should suffice, but if you want the overridden open() to work for other forms too (not only 3-args open with lexical file handle), you should also re-enable the qualify_to_ref(...), i.e. the routine should then look like

*CORE::GLOBAL::open=sub (*;$@) { use Symbol(); my $handle; if (defined $_[0]) { $handle = Symbol::qualify_to_ref($_[0], scalar caller); } if (@_ == 1) { CORE::open $handle or warn $! and return 0; } elsif (@_ == 2) { CORE::open $handle, $_[1] or warn $! and return 0; } elsif (@_ == 3) { if (defined $_[2]) { CORE::open $handle, $_[1], $_[2] or warn $! and return 0; } else { CORE::open $handle, $_[1], undef # special case or warn $! and return 0; }; } else { CORE::open $handle, $_[1], $_[2], @_[3..$#_] or warn $! and return 0; }; $_[0]=$handle unless defined $_[0]; # pass up to caller tie *$handle,"TieInput",*$handle; };

With this change, I get the following output:

$ ./953722.pl opening in1.txt: TieInput: $_s = \'in1 A '; $s = \'in1 A '; at ./953722.pl line 107, <$In> line 1. TieInput: @_a = ( 'in1 B ', 'in1 C ' ); @a = ( 'in1 B ', 'in1 C ' ); at ./953722.pl line 109, <$In> line 3. opening in1.txt and in2.txt: TieInput: $_s = \'in1 A '; $s = \'in1 A '; at ./953722.pl line 118, <$In> line 1. TieInput: $_s = \'in2 A '; $s = \'in2 A '; at ./953722.pl line 120, <$In> line 1. TieInput: @_a = ( 'in1 B ', 'in1 C ' ); @a = ( 'in1 B ', 'in1 C ' ); at ./953722.pl line 122, <$In> line 3. TieInput: @_a = ( 'in2 B ', 'in2 C ' ); @a = ( 'in2 B ', 'in2 C ' ); at ./953722.pl line 124, <$In> line 3.

In reply to Re: Implicitly file tying ... by Eliya
in thread Implicitly file tying ... by clueless newbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2015-07-05 08:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (61 votes), past polls