I am using perl and I want to append a substring with in a string.
what I have is this.
<users used_id="222" user_base="0" user_name="Mike" city="Chicago"/>
<users used_id="333" user_base="0" user_name="Jim Beans" city="Ann Arbor"/>
What I want is append word Mr. after the user name like this.
<users used_id="222" user_base="0" user_name="Mike, Mr" city="Chicago"/>
<users used_id="333" user_base="0" user_name="Jim Beans, Mr" city="Ann Arbor"/>
problem is I don't know how to do that? This is what I have so far. Please no XML libraries.
#!/usr/bin/perl
use strict;
use warnings;
print "\nPerl Starting ... \n\n";
while (my $recordLine =<DATA>)
{
chomp($recordLine);
#print "$recordLine ...\n";
if (index($recordLine, "user_name") != -1)
{
#Found user_name tag ... now appeand Mr. after the name at the end ... how?
$recordLine =~ s/user_name=".*?"/user_name=" Mr"/g;
print "recordLine: $recordLine ...\n";
}
}
print "\nPerl End ... \n\n";
__DATA__
<users used_id="222" user_base="0" user_name="Mike" city="Chicago"/>
<users used_id="333" user_base="0" user_name="Jim Beans" city="Ann Arbor"/>