in reply to Don't understand why can't get 'size' assoc w/STDOUT
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 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Don't understand why can't get 'size' assoc w/STDOUT
by Anonymous Monk on Apr 17, 2011 at 17:36 UTC | |
|
Re^2: Don't understand why can't get 'size' assoc w/STDOUT
by perl-diddler (Chaplain) on Apr 17, 2011 at 23:12 UTC | |
by perl-diddler (Chaplain) on Apr 17, 2011 at 23:37 UTC |