Vahid wrote: > Hi all, > I have the following code to sort UNIX's password file, it works fine > but can only display on stdout. How can I make it write the output to > a file? > Thanks, > > #!/bin/perl -w > # > use strict; > open(myFILE, '|-','awk','-F:','s[$1]++==0' ) or die $!; > open(passwdFH, "passwd"); > while (<passwdFH>) { print myFILE; } > close(myFILE);
here's one way (untested): open (NEW_FILE, "> /foo/bar") or die "Failed to write to /foo/bar : $! \n"; open (passwdFH, "passwd"); while (<passwdFH>) { print NEW_FILE $_; } close (passwdFH); close (NEW_FILE); cheers Yogesh -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/