By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,541 Members | 1,476 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,541 IT Pros & Developers. It's quick & easy.

Help with appending text to file

P: 1
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. }
Aug 1 '08 #1
Share this Question
Share on Google+
2 Replies


eWish
Expert 100+
P: 971
Have a look at Tie::File on CPAN.

--Kevin
Aug 1 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
Have a look at Tie::File on CPAN.

--Kevin
Excellent suggestion.
Aug 1 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.