#!/usr/bin/perl -w $TIOCGWINSZ = 0x5413; use POSIX qw(ttyname); $tty = ttyname(0); $tty = ttyname(1) if (!$tty); $tty = ttyname(2) if (!$tty); $pattern = "SS"; $pattern = "S" if ($0 =~ /rows$/); $pattern = "xxS" if ($0 =~ /cols$/); $result=""; open (TERM, "< " . $tty) or die "could not open terminal \"" . $tty . "\""; ioctl (TERM, $TIOCGWINSZ, $result) or die "ioctl failed"; print join (' ', unpack ($pattern, $result)) . "\n";