$Bill Luebkert wrote: > karthikeyan wrote: > >> Dear All, >> >> Hope you are all having a great day. >> >> I have a problem. I m running a java program through perl like this : >> >> $cmd = 'java SSLTest'; >> >> It returns output like this : >> >> Using ClearCommerce SSL Java API Version: release-3-8-3-17 Shipping: >> 10.0 Tax: 0.0 Time - Sat Jun 22 07:28:42 2002 Ref# - 12345678 Appr - >> APPROVED Code - 123456 AVSCode - PayServ - Err - Ord# - >> 12.45.92.15-1024748922-901932-1575-14 >> >> when you run the program in the command line mode I would get >> something like this so that you don't get confused >> >> Using ClearCommerce SSL Java API Version: release-3-8-3-17 >> >> Shipping: 10.0 >> Tax: 0.0 >> Time - Sat Jun 22 07:28:42 2002 >> Ref# - 12345678 >> Appr - APPROVED >> Code - 123456 >> AVSCode - >> PayServ - >> Err - >> Ord# - 12.45.92.15-1024748922-901932-1575-14 >> >> Now what I want to do here is get each name and value in a separate >> separate variable like : >> >> $Shipping will contain 10.0, $Tax will contain 0.0, $Time will >> contain Sat Jun 22 07:28:42 2002 >> how do I parse those string and store it in a variable. >> >> Any help regarding this would be greatly appreciated. > > > I would split on :- (assuming a line at a time as your fixed example > shows). > Then use a hash to store the fields. > > my %hash; > > foreach (@lines) { > my @f = split /\s*[:-]\s*/, $line;
Because of the : and - in other places in the line, better limit the split to 2 fields (all untested): my ($name, $value) = split /\s*[:-]\s*/, $line, 2; $hash{$name} = $value; > $hash{$f[0]} = $f[1]; > } > > I'm assuming you have the newline problem in hand. -- ,-/- __ _ _ $Bill Luebkert ICQ=162126130 (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl) -/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/ _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs