# From what Anonymous monk writes, it seems the task is: # replace a field (in double quotes) of a comma # separated record in a file called guidpair.txt with # something else. # He gives me the line, the text of the last field, and # the replacement text which he somehow gets from another # file. # The line # "Web","rad","INPUT","onclick","746B97B8-486A-094F-9426292F0C0BB644 F","" # should be # "Web","rad","INPUT","onclick","5C1DAEF0-9386-44a5-B92A-31FE2C79236A","" # # Given that information, the program could look like this: my $infile = 'guidpair.txt'; my $tempfile = "$infile.new"; # =================================================== # CAVEAT: if $infile.new exists, it will be clobbered # XXX Better use File::Temp here? # =================================================== open(I,"<$infile") or die "Can't open $infile: $!\n"; open(O,">tempfile") or die "Can't write $tempfile: $!\n"; while() { if (/"Web","rad","INPUT","onclick","746B97B8-486A-094F-9426292F0C0BB644 F",""/) { s/746B97B8-486A-094F-9426292F0C0BB644 F/5C1DAEF0-9386-44a5-B92A-31FE2C79236A/; } print O; } close(I) or die "Can't close input file $infile: $!\n"; close(O) or die "Can't close temp file $tempfile: $!\n"; rename($tempfile,$infile) or die "Can't rename $tempfile to $infile: $!\n"; __END__