Connecting Tech Pros Worldwide Help | Site Map

Help with appending text to file

  #1  
Old August 1st, 2008, 03:26 AM
Newbie
 
Join Date: Aug 2008
Posts: 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. }

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

re: Help with appending text to file


Have a look at Tie::File on CPAN.

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

re: Help with appending text to file


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

--Kevin
Excellent suggestion.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with file opening freddukes answers 2 September 24th, 2008 10:42 PM
Help with streamwriter ukgrl_yr79@yahoo.com answers 1 March 9th, 2007 07:25 PM
writing text to text files in vb. need help =?Utf-8?B?am9obmFicmFoYW0xMDE=?= answers 3 February 22nd, 2007 10:35 AM
Appending Text file with a header record Michael answers 16 November 12th, 2005 03:45 PM