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:
STDOUT didn't work for me, nor &TIOCGWINSZ, nor $winsize; instead, I tried it like this:my $err = ioctl STDOUT, &TIOCGWINSZ, $winsize;
But &TIOCGWINSZ came back undefined. Define it:my $err = ioctl(TTY, &TIOCGWINSZ, $winsize = "");
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:sub TIOCGWINSZ { 0x40087468 }
#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |