Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!jato!csi.jpl.nasa.gov!mwette From: mwette@csi.jpl.nasa.gov (Matt Wette) Newsgroups: comp.lang.perl Subject: problem: open(OUT, "| more") doesn't work for me Message-ID: <1991Jun12.141508.6026@jato.jpl.nasa.gov> Date: 12 Jun 91 14:15:08 GMT Sender: news@jato.jpl.nasa.gov Reply-To: mwette@csi.jpl.nasa.gov (Matt Wette) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 117 Nntp-Posting-Host: mr-ed.jpl.nasa.gov After receiving a couple of replies that open(OUT, "| more") works and still not being able to get my code to work I've decided to post my code. The command (`whom') just dumps the NIS password file, in formatted form, to the screen. The option "-m" attempts to pipe through more. But the program just dies at the first --more-- prompt. If someone is willing to check it out and tell me what's wrong, I'd appreciate it. (also, anyone is certainly welcomed to use the code) perl: 4.003 mach: SunOS 4.1.1 on sun3 #!/usr/local/bin/perl # # whom - print out the NIS password file, formatted # # usage - # whom [-m] [-s (last | login)] [-v] # -m Pipe output through more. # -s opt Sort by last name (last) or by login name (login) # Default is last. # -v Show version and quit. # # history - # 04Jun91 M.Wette: created. # 05Jun91 M.Wette: added sortby # version - # $Id: whom,v 1.3 1991/06/05 23:21:39 mwette Exp $ $Version="1.01"; $Dated="04Jun91"; $sortby = "last"; $out = STDOUT; while ($arg = shift(@ARGV)) { if ($arg eq "-v") { print("whom Version $Version Dated $Dated\n"); exit(0); } elsif ($arg eq "-s") { $arg = shift(@ARGV); if ($arg eq "login") { $sortby = "login"; } } elsif ($arg eq "-m") { open(MOREOUT, "| more"); $out = MOREOUT; } } if ($sortby eq "last") { select((select($out), $^='LASTTOP', $~='LASTOUT', $|=1)[0]); } elsif ($sortby eq "login") { select((select($out), $^='LOGINTOP', $~='LOGINOUT', $|=1)[0]); } if (system("ypcat passwd > /tmp/passwd.$$")/256) { die "whom: ypcat failed\n"; } if (!open(PASSWD, "/tmp/passwd.$$")) { die "whom: can't open temporary password file\n"; } while () { chop; ($login,$passwd,$uid,$gid,$gcos,$home,$shell) = split(/:/); ($name,$office,$phone) = split(/,/,$gcos); if ($uid < 30) { next; } if (length($phone)>0) { $phone = "4-$phone"; } $pos = rindex($name,' '); if ($pos < 0) { $pos = 0; } $last = substr($name,$pos); $last =~ tr/A-Z/a-z/; if (length($last) == 0) { $last = "zzz$i"; $i++; } if ($sortby eq "login") { $entries{$login} .= "$name:$login:$office:$phone:"; } else { $entries{$last} .= "$name:$login:$office:$phone:"; } } @sortedkeys = sort alphabetically keys(%entries); while ($key = shift(@sortedkeys)) { ($name,$login,$office,$phone) = split(/:/,$entries{$key}); write($out); } system("rm -f /tmp/passwd.$$"); sub alphabetically { $a gt $b; } format LASTTOP = Name Login Office Phone ------------------------------------------------- . format LASTOUT = @<<<<<<<<<<<<<<<<<<< @<<<<<<<< @<<<<<<< @<<<<<< $name, $login, $office, $phone . format LOGINTOP = Login Name Office Phone ------------------------------------------------- . format LOGINOUT = @<<<<<<<< @<<<<<<<<<<<<<<<<<<< @<<<<<<< @<<<<<< $login, $name, $office, $phone . # --- last line of whom --- -- _________________________________________________________________ Matthew R. Wette | Jet Propulsion Laboratory, 198-326 mwette@csi.jpl.nasa.gov | 4800 Oak Grove Dr, Pasadena,CA 91109 -----------------------------------------------------------------