There's no bug---the error messages mean exactly what they say. To find the way that you got there, let's start at the beginning.

The first mistake was not using strictures. Always use them. I noticed that you didn't use a module. There are a bunch of them that can help you with this. In my example, I use Term::ReadKey.

Next, I took out the $SIG{__WARN__}. You won't need it here because perl will adamantly tell you that it can't find sys/ioctl.ph, at least it does that on my system. I used the full path to ioctl.ph, but then perl complained that it couldn't find _h2ph_pre.ph. I ended up deleting the block.

Now for the errors:

my $err = ioctl STDOUT, &TIOCGWINSZ, $winsize;
STDOUT didn't work for me, nor &TIOCGWINSZ, nor $winsize; instead, I tried it like this:
my $err = ioctl(TTY, &TIOCGWINSZ, $winsize = "");
But &TIOCGWINSZ came back undefined. Define it:
sub TIOCGWINSZ { 0x40087468 }
Now it's workable. Then the next line I used if and used unless in the block. I wasn't able to use your row and col, so I deleted that part. Here's the result:
#!/usr/bin/perl use strict; use Term::ReadKey; use Data::Dumper::Concise; sub getwinsize (;$) { my $recheck = $_[0]; my $winsize = 0; my ( $maxrow, $maxcol ); return ( $maxrow, $maxcol ) if $maxrow && $maxcol && !$recheck; my $err = ioctl(TTY, &TIOCGWINSZ, $winsize = ""); if ($err) { print STDERR "ERROR: ioctl on STDOUT: $!\n"; unless ( ioctl( TTY, &TIOCGWINSZ, $winsize = "" ) ) { print STDERR "ERROR: ioctl on fileno(STDOUT): $!\n"; } else { printf STDERR "ioctl on fileno(STDOUT) worked\n"; } } else { printf STDERR "ioctl on STDOUT worked\n"; } return; } print Dumper(GetTerminalSize()); print getwinsize(); sub TIOCGWINSZ { 0x40087468 }

In reply to Re: Don't understand why can't get 'size' assoc w/STDOUT by Khen1950fx
in thread Don't understand why can't get 'size' assoc w/STDOUT by perl-diddler

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!
  • 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, details, 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, summary, 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.