On Monday, July 15, 2002, at 11:53 , Vishal Kapoor wrote:
> thanx for the previous help .... > can we use system commands in a perl program , commands such as ls or grep > ???? > im sure we can , can someone point out how ??? there are really two issues here you will want to resolve, a) which way do I want to use standard unix commands b) which ones can i do internally in perl. note that 'ls' as is basically works like $dir = "."; # there are other ways this can be played - and hence # passing in patterns a la "ls *.foo" or " ls /tmp/drieux" opendir(DIR, $dir) or die "unable to open $dir :$!\n"; my @allfiles = grep { $_ ne "." && $_ ne ".." } readdir DIR; close DIR or die "strange, can not close $dir :$!\n"; print "$_ \n" for (@allfiles); which is basically what you would get with say my @allfiles = `ls`; print $_ for (@allfiles); but for which you may want to avoid, and go with the opendir() approach at some time - since you may want to do other things with which files, patterns, decending through directories.... notice also that we did the 'grep' there as the 'perl grep command' to do the filtering in our piece of demo code... Likewise you may want to get in touch with say open(CMD, "$cmd $args |") or die "unable to open $cmd $args : $!\n"; while(<CMD>) { # # cope with the output of the command # ..... } close CMD or die "strange, can not close $cmd $args : $!\n"; rather than the usual sorts of horrors like my @pid_list = `ps -aef | grep $user | egrep -v grep | awk '{print $1}'` direct translation from shell scripting... since in the perl one might try setting it up with my @pids; my $cmd = 'ps'; my $args = '-aef'; open(CMD,...)..... while(<CMD>) { next unless /$user/; chomp; push @pids, (split)[1]; } close CMD or die "strange, can not close $cmd $args : $!\n"; So..... which exactly were you trying to solve???? ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]