home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!ftpbox!mothost!merlin.dev.cdx.mot.com!merlin.dev.cdx.mot.com!lezz
- From: lezz@merlin.dev.cdx.mot.com (Lezz Giles)
- Subject: Re: What's wrong with system command?
- Message-ID: <1992Aug26.170740.1334@merlin.dev.cdx.mot.com>
- Sender: news@merlin.dev.cdx.mot.com (USENET News System)
- Nntp-Posting-Host: monarch.dev.cdx.mot.com
- Reply-To: lezz@merlin.dev.cdx.mot.com (Lezz Giles)
- Organization: Motorola Codex, Canton, MA
- References: <l8qmm3INNoli@jethro.Corp.Sun.COM> <BtK9vp.J79@acsu.buffalo.edu>
- Date: Wed, 26 Aug 1992 17:07:40 GMT
- Lines: 52
-
- In article <BtK9vp.J79@acsu.buffalo.edu>, yli@acsu.buffalo.edu (Yanhong Li) writes:
- |>I used a system command in the following perl script, to my suprise, the
- |>print command was not executed, if I remove the system command, print will
- |>be executed, why? and how can I make the print command successful without
- |>removing the system command?
- |>
- |>#!/usr/local/bin/perl
- |>
- |>open(LEX, "/imagesG/yli/G02.ex" );
- |>
- |>while(<LEX>){
- |>
- |>print $_;
- |>
- |>($word1, $word2)=split;
- |>
- |>system "/users/usps/yli/stem $word2";
- |>
- |>}
- |>close LEX
-
- I can't answer your question but I can suggest that you rewrite it slightly...
-
- #!/usr/local/bin/perl
-
- open(LEX, "/imagesG/yli/G02.ex") || die "Cannot open /imagesG/yli/G02.ex, $!";
-
- while (<LEX>) {
-
- print $_; # or even just `print;`
-
- ($word1, $word2) = split;
-
- $word2 || die "Unsplittable line at $.\n$_";
-
- $retval = system "/users/usps/yli/stem $word2";
-
- if (($retval >> 8) != 0) {
- die "Execution of /users/usps/yli/stem $word2 failed - $retval\n";
- }
-
- }
-
- close LEX;
-
- (sorry about the indentation!) One of the major joys of perl (in my mind)
- is that it is incredibly easy to add error-checking/handling. In my experience
- it has almost always proved worth-while adding as much error-checking as
- possible even for short scripts - no program works first time, and comprehensive
- error checking really helps you narrow down problems quickly.
-
- Lezz "GIGO" Giles
-