karthikeyan wrote: > > May be I didn't put my question properly. When I run the following code. > > <snip> > > #!d:/karthikeyan/programs/perl/bin/perl -w > print "Content-type:text/html\n\n"; > use strict; > my $line = 'Using ClearCommerce SSL API Version: release-3-8-3-17 Thu Mar > 15 10:33:06 CST 2001 > Charge Total: 20.00 > Time - Sat Jun 29 15:32:19 2002 > Ref# - 12345678 > Appr - APPROVED > Code - 12345612345678 > Err - > Ord# - 12.45.92.15-1025382739-376645-13757-21'; > my @colon = $line =~ /(\S+):\s+(\S+[^:])/g; > my @hyphen = $line =~ > /(\S+)\s-\s([^-]+)(?:\s[^-]+){2}|(\S+)\s-\s(\S+)\s*$/g; > for (@hyphen) { > next unless defined; > push @colon, $_; > } > my %hash = @colon; > for (sort keys %hash) { > print "$_ == $hash{$_}\n" > } > exit 0; > > </snip> > > I am getting the following output > > <output> > Code == 12345612345678 Ord# == 12.45.92.15-1025382739-376645-13757-21 Time > == Sat Jun 29 15:32:19 Total == 20.00 Version == release-3-8-3-17 > </output> > > These are the name along with its value missing > > <missing> > Ref# - 12345678 > Appr - APPROVED > </missing>
[ snip ] OK, the arbitrary use of whitespace and delimiters makes this messier. However, if your two (2) examples make explicit an exhaustive list of labels and their corresponding delimiters, then it maybe simpler to understand the problem thusly: #! perl -w use strict; my $line = 'Using ClearCommerce SSL API Version: release-3-8-3-17 Thu Mar 15 10:33:06 CST 2001 Charge Total: 20.00 Time - Sat Jun 29 15:32:19 2002 Ref# - 12345678 Appr - APPROVED Code - 12345612345678 Err - Ord# - 12.45.92.15-1025382739-376645-13757-21'; my @line = $line =~ /^.+ (Version:\s+\S+) .+ (Total:\s+\S*)\s* (Time\s+-\s+(?:\S.+\S)?)\s* (Ref\#\s+-\s+(?:\S.+\S)?)\s* (Appr\s+-\s+(?:\S.+\S)?)\s* (Code\s+-\s+(?:\S.+\S)?)\s* (Err\s+-\s+(?:\S.+\S)?)\s* (Ord\#\s+-\s+(?:\S.+\S)?)\s* $/x; my %hash; for (@line) { $hash{$1} = $2 if /^([^:]+):\s(.*)$/ or /^(\S+)\s+-\s+(.*)$/; } for (sort keys %hash) { print "$_ == $hash{$_}\n" } exit 0; hth -- Best Regards, mds mds resource 888.250.3987 Dare to fix things before they break . . . Our capacity for understanding is inversely proportional to how much we think we know. The more I know, the more I know I don't know . . . _______________________________________________ Perl-Win32-Web mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs