#!/usr/bin/perl -w use strict; my $need_update; my ($maxcols, $maxrows); sub getwinsize () { sub TIOCGWINSZ () {0x5413} #from ioctls.ph, which wouldn't include return ($maxcols,$maxrows) if $maxcols && $maxrows && !$need_update; my $winsize=0; my $err = ioctl (STDOUT, TIOCGWINSZ, $winsize); if ($err) { print "ioctl err: $?\n"; } my ($rows, $cols, $xpix, $ypix) = unpack "s!*", $winsize; printf STDERR "r=%d, c=%d, xp=%d, yp=%d\n", $rows//0, $cols//0, $xpix//0, $ypix//0; $need_update = undef; ($maxcols, $maxrows) = ($cols ? $cols : -1, $rows ? $rows : -1); } #main my ($rows,$cols) = getwinsize; print "rows=$rows, cols=$cols\n";