Hi, [EMAIL PROTECTED] wrote:
>I have a text file with a records like: > >smith, James, Dr., 115 Fourth Street, Chicago, IL, 32012, $20.00: >[EMAIL PROTECTED] > >and another text file with placeholders like: > >Hello $last_name, $first_name: > >I want to read the first textfile and update the second one. > >Any ideas! This is a very general question. Have you already tried something? Have your read an Introduction to Perl (O'Reilly's "Learning Perl" is highly recommended)? Basically, what you have is a data file and a template file. You should open the data file and read the data into a hash (using pattern matching), then merge the hash and the template file (replacing your placeholders), putting out a scalar variable for each set of data. A very simple solution (once you established the hash) could be a subroutine like this: my $build_page = sub { # takes a parameter hash as its argument my %param = ( @_, ); open TEMPLATEFILE, $templatepath or die "could not open file '$templatepath': $!"; my $template = join '', <TEMPLATEFILE>; # now replace %%placeholders%% in $template with values from %param hash $template =~ s{ %% ( .*? ) %% }{ exists( $param{$1} ) ? $param{$1} : ''}gex; return $template; } It is not a good idea to choose strings like $last_name as your placeholders, since such strings are considered variable names in Perl. This might not sound too helpful, but if you deliver a piece of code, one of the Perl wizards on this list will certainly help you. - Jan -- If all else fails read the instructions. - Donald Knuth -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>