Hi,
I really need some help with a concatenation problem I am having.
I have tried all possible ways of concatenating two strings. For instance, I am trying to concatenate
$old = "1844" and $new = "1866"
by the expression ":" (or any other expression)
I have tried:
$joined_pattern = $old.":".$new;
$joined_pattern = join ":", $old, $new;
$old .= ":".$new;
The result is
:18441860
with the expression ":" first, and $old and $new attached to the other. ?!?!?!
The input file looks like this:
1870 South(\s|_)African?
1400 1860
1400 1844
where 1870 and 1400 are id numbers
The code is this:
---------------
#!/usr/bin/perl
my($doc) = $ARGV[0];
my(%ID2patterns) = ();
open (P_FILE, "<$doc") || die "Can't open $doc\n";
while(<P_FILE>){
my ($line) = ($_);
chomp($line);
my($id, $pattern) = ($line =~ /^(\d+)\s+(.*)/);
if (!exists ($ID2patterns{$id}) ) {
$ID2patterns{$id} = $pattern;
} else {
$old = $ID2patterns{$id};
$new = $pattern;
$joined_pattern = $old.":".$new;
$ID2patterns{$id} = $joined_pattern;
print "DOPO $joined_pattern\n";
undef $old, $new;
}
}
close(P_FILE);