in reply to Unknow number show up
Extending the replies above:
re Re: Unknown numbers show up: An alternate to Athanasius' look-ahead assertion would be to insert an anchor in $replace (which would also require you to use a "quote-like" operator, qr/ ... /;)
...thus: $search = qr/$temp[0],$temp[1]$/;
You might also want to read perldoc perlretut and/or perldoc perlre for a better understanding of the impact your quotes, dots, etc have on Ln 18,
$command_line = "perl -pi\.bak -e s\/".$search."\/".$replace."\/g\; CombineDie1Die2.txt";And, re flexvault's note: definitely, don't call another instance of Perl to execute your s/// and especially, don't call it in a loop. Do rewrite it so the substitution is executed without system..... That's left as an exercise for the Seeker.
I'm not sure that writing to a third file is necessary, though... but that may well be merely my blindspot.
#!/usr/bin/perl use 5.010; # 1123214 #Copy Die2 as Output file use File::Copy; copy ("Die2.txt","CombineDie1Die2.txt") or die "copy failed: $!"; #Open Die1 Input file open (Label, "Die1.txt") or die "can't open Die1: $!"; #Search and replace using 1 liner command while (<Label>) { $replace = $_; chomp ($replace); @temp = split (/,/, $replace); $search = qr/$temp[0],$temp[1]$/; # using an anchor print "\t search is $search"; $command_line = "perl -pi\.bak -e s\/$search/$replace/g\; CombineD +ie1Die2.txt"; # NB the removal of numerous dots, quotes and backslashes system ($command_line); }
|
|---|