in reply to Retrieve "ps -ef" strings using regex
you should print the captured string instead of $PREMATCH.
# $PREMATCH
# $`
see perlvar (search for "PREMATCH") and perlretut (search for "Extracting matches")
updated solution, the old one was insufficient:
chomp( my $logname = qx{logname} ); my @output = qx{ps -ef | grep $logname}; for my $line ( @output ) { if ( $line =~ m{/export/home/$logname/(.+)/bin/} ) { print $1, "\n"; } }
update1: edited perldoc hints
update2: updated insufficient code; thanks psini for inspiration of array usage and jethro for pointing out my mistake in the previous code version
update3: fixed typo in code
|
|---|