RE: Input redirection

2001-06-28 Thread John Edwards

You could print the verion like this

open(FILEHANDLE,test.txt) or die Can't open the file: $!;
print FILEHANDLE $]\n; # $] is the special variable that holds the running
version of Perl
close FILEHANDLE;

or if you really want the output of perl -v

$returned = `perl -v`;

open(FILEHANDLE,test.txt) or die Can't open the file: $!;
print FILEHANDLE $returned\n;
close FILEHANDLE;

HTH

John

-Original Message-
From: jaya kumaran [mailto:[EMAIL PROTECTED]]
Sent: 28 June 2001 11:16
To: [EMAIL PROTECTED]
Subject: Input redirection




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;
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).

Thanks in advance,
jaya

_
Get Free Fast Easy email from indiya.com: SIGNUP NOW : http://www.indiya.com


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.





Re: Input redirection

2001-06-28 Thread Hasanuddin Tamir

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)