I am having problems concatenating variables and
printing the concatenated string.
I really hope you can help me because I have never seen this behavior in
Perl
and my only explanation is that there is something in Perl 5.8 that I do
not
know how to use.
Input file (ID, pattern pairs) looks like this
1412 Owens
1412 (Roy_)?Romer
1418 1951
1419 1959
1419 1958
and as you can see some IDs are the same: I am putting it into a hash, with
the ID being the key. When the same ID has multiple values, then I want to
concatenate its values and store them at the same ID.
Piece of code in question is an easy hash formation:
open (P_FILE, "<$p_file") || die "Can't open $p_file\n";
while(<P_FILE>){
my($line) = $_;
chomp($line);
($id, $pattern) = ($line =~ /^(\d+)\s+(.*)/);
if (!exists ($ID2patterns{$id}) ) {
$ID2patterns{$id} = $pattern;
} else {
my($old) = $ID2patterns{$id};
my($new) = $pattern;
my($joined_patterns) = $old."<=>".$new;
$ID2patterns{$id} = $joined_patterns;
}
print "HELLO $ID2patterns{$id}\n";
}
close(P_FILE);
When I go to print things, this is what I get:
HELLO Owens
<=>(Roy_)?Romer
HELLO 1951
HELLO 1959
<=>1958959
The output looks bizarre to me.
Is this an encoding problem ?!
Thank you,
Grazia
printing the concatenated string.
I really hope you can help me because I have never seen this behavior in
Perl
and my only explanation is that there is something in Perl 5.8 that I do
not
know how to use.
Input file (ID, pattern pairs) looks like this
1412 Owens
1412 (Roy_)?Romer
1418 1951
1419 1959
1419 1958
and as you can see some IDs are the same: I am putting it into a hash, with
the ID being the key. When the same ID has multiple values, then I want to
concatenate its values and store them at the same ID.
Piece of code in question is an easy hash formation:
open (P_FILE, "<$p_file") || die "Can't open $p_file\n";
while(<P_FILE>){
my($line) = $_;
chomp($line);
($id, $pattern) = ($line =~ /^(\d+)\s+(.*)/);
if (!exists ($ID2patterns{$id}) ) {
$ID2patterns{$id} = $pattern;
} else {
my($old) = $ID2patterns{$id};
my($new) = $pattern;
my($joined_patterns) = $old."<=>".$new;
$ID2patterns{$id} = $joined_patterns;
}
print "HELLO $ID2patterns{$id}\n";
}
close(P_FILE);
When I go to print things, this is what I get:
HELLO Owens
<=>(Roy_)?Romer
HELLO 1951
HELLO 1959
<=>1958959
The output looks bizarre to me.
Is this an encoding problem ?!
Thank you,
Grazia