I want to split the specific words in "result" varaible which comes after "transaction","user:" and "#" .I could achieve it through the below code. But at times there wont be the line start with "#"(Its an optional one). I am not able to handle such cases (when $3 is blank)
The code works fine with the 1st transaction, but shows prints nothing for 2nd oneforeach my $number(@transaction_numbers) { my $result =`command to get result`; print $result; while ($result =~ /transaction (\d+).*user:\s*(\S+)\s*#\s*(.*)/g) +{ my ($transaction, $user, $comment) = ($1, $2, $3); printf "%-12s %-10s %s\n", $1, $2, $3; } }
output of $result is :
transaction 1234567; promote; 2014/08/01 10:22:37 ; user: john # Performing a "promote" on file. /./abc/desf/test.pl 138699/1 (138700/1) transaction 4578643; promote; 2014/08/01 10:22:37 ; user: sam /./abc/desf/test.pl 138699/1 (138700/1)
Curent output is
Transaction User Comments 1234567 john Performing a "promote" on file.
Desired output is
Transaction User Comments 1234567 john Performing a "promote" on file. 4578643 sam
In reply to Reg the split expression by sravs448
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |