On Wed, 27 Jun 2001, jaya kumaran <[EMAIL PROTECTED]> wrote,

> Hi all,
>
>    I used this instruction to clear the screen on NT
>
>    system(cls);
>    print "Hello";
>
>   the same instruction is not working on unix. I modified the instruction to
>
>   system(clear);
>   print "hello";
>
> This works fine on unix. Is there any instruction in perl to perfom clear
> screen and it works on both windows and Unix

First of all, if you're thinking about portable code, your first
resource to read will be the perlport manual page.  As said there,
nearly all Perl is already portable (one strategy is to emulate
missing functions for some poor system).

There will be a point that you really need to code in different ways
for different systems.  And you need the $^O special variable to
inspect the OS the script is running under.  Additionally, if you're
going to use this a lot, you better save the clear character in the
variable and print it later many times.

    my $clear;
    if ($^O =~ /mswin/i || $^O =~ /dos/i) {
        $clear = `cls`;
    } elsif ($^O eq 'linux') {
        $clear = `clear`;
    }
    # add other checking here to support more systems
    # (this is of course not a complete way for all needs)

Other strategy is by evaluating the expression to see if the function
is supported in the particular system.

    eval {
        is_this_function_supported();
    };
    die $@ if $@; # or you can just skip the function
                  # and let the program continues

More in 'perldoc -f eval' on this.


__END__
-- 
s::a::n->http(www.trabas.com)

Reply via email to