ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
15.4. Determining Terminal or Window SizeProblemYou need to know the size of the terminal or window. For instance, you want to format text so that it doesn't pass the right-hand boundary of the screen. SolutionEither use the use Term::ReadKey; ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize(); Discussion
Here's how you'd graph the contents of use Term::ReadKey; ($width) = GetTerminalSize(); die "You must have at least 10 characters" unless $width >= 10; $max = 0; foreach (@values) { $max = $_ if $max < $_; } $ratio = ($width-10)/$max; # chars per unit foreach (@values) { printf("%8.1f %s\n", $_, "*" x ($ratio*$_)); } See AlsoThe documentation for the Term::ReadKey module from CPAN; Recipe 12.14 |