Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with appending text to file

Newbie
 
Join Date: Aug 2008
Posts: 1
#1: Aug 1 '08
Hi,

I have a file which store my grouping follow by the group members.
My codes will read in the new member name and the group. Then i will search for the group, ensure that the new member is not under the group and append the new member under the group. The problem is how do i append the name to that line?

File Sample
------------------
GrpA:xavi,jon,gwen
GrpB:ben,edward
GrpC:mary,ashley

My codes:
Expand|Select|Wrap|Line Numbers
  1. $file='grouping';
  2. open(GRP, '>>'.$file)
  3. @lines=<INFO>;
  4. foreach $line (@lines)
  5. {
  6.    $grp=substr($line,0,4);
  7.    if($grp eq $grpinput)
  8.    {
  9.      seek(INFO,0,SEEK_CUR);
  10.      print INFO $line.','.$nameinput;
  11.    }
  12. }

eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 900
#2: Aug 1 '08

re: Help with appending text to file


Have a look at Tie::File on CPAN.

--Kevin
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Aug 1 '08

re: Help with appending text to file


Quote:

Originally Posted by eWish

Have a look at Tie::File on CPAN.

--Kevin

Excellent suggestion.
Reply