Click to See Complete Forum and Search --> : Perl annoyance


Hena
10-22-2002, 02:14 AM
I have two things that are bothering me in perl. I don't seem to be able to get them solved just right, only near so.

1. When using predefined subroutines. How can i change scalar/array/hash thats passed to it without needing to return it as well?

2. How can i find out a screen size that being used? I 'm trying to make a scrollable text, but i need to make it the same size the the console screen that being used (40*80, 60*120 etc in row*col). Little like pine and such progs.

TIA

furrycat
10-22-2002, 08:21 AM
1) You can use a reference:#!/usr/bin/perl

sub doit {
my $var = \$_[0];
$$var++;
}

$x = 1;
&doit($x);
print "$x\n";This prints 2.

2) Not sure. The curses module would probably be your best bet. You COULD use the environment variables $LINES and $COLUMNS but these are set by the shell and so can't be relied upon after your script has started. ie if the terminal is resized the change will not show up.

There may actually be a way to do it with standard Perl code but I'd say you need the curses module.

Hena
10-23-2002, 02:15 AM
Originally posted by furrycat
2) Not sure. The curses module would probably be your best bet. You COULD use the environment variables $LINES and $COLUMNS but these are set by the shell and so can't be relied upon after your script has started. ie if the terminal is resized the change will not show up.

There may actually be a way to do it with standard Perl code but I'd say you need the curses module.
Which is somewhat harder then if a person is using win with this script. Sod. Well perhaps there is something in CPAN. Back to searching.

Also i tried to use refs but something failed in chaging the orig number. Back to testing them again as well :).