Connecting Tech Pros Worldwide Help | Site Map

Help with appending text to file

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 1st, 2008, 02:26 AM
Newbie
 
Join Date: Aug 2008
Posts: 1
Default Help with appending text to file

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. }

Last edited by eWish; August 1st, 2008 at 02:30 AM. Reason: Please use [code][/code] tags
Reply
  #2  
Old August 1st, 2008, 04:10 AM
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 898
Default

Have a look at Tie::File on CPAN.

--Kevin
Reply
  #3  
Old August 1st, 2008, 07:09 AM
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,031
Default

Quote:
Originally Posted by eWish
Have a look at Tie::File on CPAN.

--Kevin
Excellent suggestion.
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.