On 3/11/09 Wed  Mar 11, 2009  11:36 AM, "neckha...@penntraffic.com"
<neckha...@penntraffic.com> scribbled:

> Hi guys,
> 
> I am starting to learn Perl as the ksh scripting language (which I
> don't know either) looks less than powerful.
> 
> I have used C many years ago, and write my stuff in REXX on a
> mainframe, so Perl looks like the best of both worlds.
> 
> My environment is AIX 5.3 running some sort of 5.8 PERL. Oh hell, let
> me check..... 5.8.2.
> 
> Most of the documentation and tutorials I find are for version 5.10 so
> I am running into the stuff in the manuals and tutorials that do not exist
> in 5.8.

That would be peculiar, as 5.10 only recently came out. I have no books that
cover 5.10. There were only a few things added, so most tutorial material
will cover both 5.8 and 5.10. Just use 'print' instead of 'say', avoid the
'given/when' and 'state' statements, and you should be OK. You can always
download, build, and install 5.10.

> 
> As a starting project to learn the language, I want to execute an AIX
> command and be able to read the output of the command in the script.

The usual way to execute an external program and capture the output is to
use backticks (`program`) or qx(program).

> 
> EXEC doesn't work, because the program ends at the EXEC statement.

exec (case matters) substitutes the specified program for your Perl program
and never returns to it.

> 
> SYSTEM does not appear to be available at the 5.8.2 level.

system has been available in all recent perls (and maybe forever).

> 
> I tried what usually works in other scripting languages of just
> putting the command in quotes. Putting "ls" in the script actually
> executes the command, and sends the output to the terminal. I want the
> output in a file, so I tried "ls > out" and I get an error (shown
> below).

"ls" is just a string. `ls` will execute the ls command and return its
output.

> 
> I also tried to OPEN, PRINT then CLOSE a file, but the OPEN appears to
> fail as if the function is not recignized, and no form of the OPEN
> statement seems to work. I have included the script and results below.

All of those should be in lower case.

> 
> This seems like it should be simple, but something escapes me.
> 
> Thanks,
> Neal
> 
> Script:
> 
> #/usr/bin/env perl -w
>         "ls > out";
> print "RC = $?";
> open OUTFILE, '< out' or die 'problem';

You should include the reason why the open failed:

open OUTFILE, '< out' or die "problem: $!";

> print while <OUTFILE>;
> close (OUTFILE);
> 
> 
> Results:
> 
> test.pl[2]: ls > out:  not found.
> RC = 127
> test.pl[4]: open:  not found.
> test.pl[5]: 0403-057 Syntax error at line 6 : `;' is not expected.

Those look like shell errors. Are you sure you are callilng the perl
interpreter? Try a different first line (and always include the next two
lines shown):

#/path/to/perl
use strict;
use warnings;
...



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to