On Thu, 28 Jun 2001, jaya kumaran <[EMAIL PROTECTED]> wrote,

> Hi,
>
>   I need the o/p of
>      perl -v
>    to be redirected to a file test.txt
>
>   open(FILEHANDLE,"> test.txt") || die can't open the file";
                                         ^
                                         |
I hope this is just a typo, you missed the opening double-quote.
But you need to include $! as well so you know exactly the reason
when the open() fails.

> print FILEHANDLE perl -v ;
>
> one executing this , I get the following error
>
> Unrecognized file test: -v at D:\test\perl\TEST1.PL line 6.
>
> How to write the o/p of 'perl -v' in the file(test.txt).

You must treat 'perl -v' as shell command by enclosing it in the
backticks to get the output,

    print FILEHANDLE `perl -v`;

More on this is in the Quote and Quote-like Operators entry in perlop
manpage.


Otherwise, bare '-v' will be treated as file test operator.
Perl has a plenty of file test operator in this form, -f to
test if the argument is a file, -d if a directory, -s to get
the size, etc.  perldoc -f -X for more on this.

Anyway, is it really hard to do,

    perl -v > test.txt

from the command line?


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


Reply via email to