Hi, Do the following set of codes does the same thing?
FYI, am more interested on whether I can use CODE 03 to pipe/re-direct output from the OS commands, i.e. ps, df etc. Will using | works on Windows as well? Am very new to Perl and has mostly done UNIX shell scripting. Am wanting to write Perl scripts where a UNIX script/command has to run and am having to grep for things that I need to check, for example, ps -ef | grep ora_pmon_TEST1 to check for the pmon process of the Oracle TEST1 database. For example: open(PS,"ps -e -o pid,stime,args |") || die "ps command failed $! \n"; while ( <PS> ) { print $_; --- Check what $_ is and do some work, perhaps I should be doing regex's and if $_ =~ /searchstring/ ??? --- } close PS; Response/feedback will be much appreciated. Thanks in advance. -------- CODE 01: -------- open(FILE, "x.txt") or die("Unable to open file"); while ( <FILE> ) { print $_; } close FILE; -------- CODE 02: -------- system('ls x.txt 1>/dev/null 2>/dev/null'); $result=$?; if ( $result eq 0 ) { print "File exist ... open the file and put into an array \n"; open(FILE, "x.txt"); while ( <FILE> ) { print $_; } close FILE; } else { print "File does not exist ... exiting \n"; exit 9; } -------- CODE 03: -------- open(CAT,"cat x.txt |") || die "Unable to open file $! \n"; while ( <CAT> ) { print $_; } close CAT; exit 0;