in reply to Basic Seek
If I understand this correctly...
# open the input file open(IN,"file") or die; # # open a temporary output file ( you could also use the # -i "inplace edit feature", see perldoc perlrun ) # open(OUT,">file.$$") or die; # # print the contents of IN to OUT, # adding your additional line if we # see $dom as the first chars of the line # \Q and \E to quotemeta the domain since # it probably contains metachars like "." # while (<IN>) { print OUT; if (/^\Q$dom\E\s/) { print OUT "$user\@$dom\t$user\n"; } } # close both files and overwrite # IN with OUT via rename(). close IN; close OUT; rename("file.$$","file") or die;
Update: Regarding the reply...other than the fact that it's opening a file called "file", the above is doing what you are asking. I think perhaps you are focused on the word seek. The seek() operator doesn't look for strings, it's given a byte offset and moves the file pointer.
Also, you seem fixated on editing the file in place. This isn't really possible in your situation. Perl can make it appear that way with it's "-i" feature. See perlrun.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Basic Seek
by lostperls (Initiate) on Sep 08, 2002 at 16:45 UTC | |
by Arien (Pilgrim) on Sep 09, 2002 at 04:45 UTC | |
Re: Re: Basic Seek
by Anonymous Monk on Sep 08, 2002 at 16:19 UTC | |
Re: Re: Basic Seek
by Anonymous Monk on Sep 08, 2002 at 16:27 UTC |
In Section
Seekers of Perl Wisdom