Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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:

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

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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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?

    What's my password?
    Create A New User
    [Discipulus]: the winner is..
    [Discipulus]: Mr haukex from Germany! thanks a lot to the other parteciapant our dear Mr afoken.. ;=)
    [Discipulus]: no, seriously thanks both, i missed 'scientist' and 'floating point' and the resarche was imposible..
    Discipulus go to his cell to bookmark this
    [haukex]: Well to be honest I just did a super search for "every should know floating" ;-)
    [Discipulus]: floating was the keyword and.. to use supersearch is plus sign not a (plus) sin

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (10)
    As of 2017-06-26 20:54 GMT
    Find Nodes?
      Voting Booth?
      How many monitors do you use while coding?

      Results (594 votes). Check out past polls.