<> wrote:
> I am doing this module where I am gonna change the following sentence
>
> "1:action=commit:user=joe:date=2005-02-02:"
> "2:action=checkout:user=mark:date=2005-02-03:"
^^^^
> to something like
> " 1. Commits by user Joe on date 2005-02-02 "
> " 2. Checkouts by user Joe on date 2005-02-03"
^^^
Why did mark's name change to Joe?
Why a trailing space in the 1st one but not in the 2nd one?
Why one space in the 1st one but 2 spaces in the 2nd one?
Are those double quotes actually in your data, or are they
meant to be "meta"?
> pseudocode only
Why?
It takes only a tiny bit of effort to bypass the confusion
caused by the pseudoness.
The value of the answer you can expect to receive is directly
proportional to the effort you put into forming your question...
> if(hash{action}=='commit') <---this is a mandatory field
if( $hash{$action} eq 'commit' ) <---this is a mandatory field
There, that wasn't very hard now was it?
> Any suggestions or ideas on how to better
> achieve what I want to do above.
----------------------------------
#!/usr/bin/perl
use warnings;
use strict;
while ( <DATA> ) {
chomp;
chop; # don't need final colon
my($num, %attrs) = split /[:=]/;
$attrs{action} .= 's'; # pluralize
s/(.)/\u$1/ for values %attrs; # upper case 1st letter
printf "%2d. %s by user %s on date %s\n",
$num, @attrs{ qw/action user date/ };
}
__DATA__
1:action=commit:user=joe:date=2005-02-02:
2:action=checkout:user=mark:date=2005-02-03:
----------------------------------
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas