Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concatenation problems

Status
Not open for further replies.

Graziella

Programmer
Jul 8, 2004
38
AT

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);
 
$joined_pattern = $old.":".$new;
print "$joined_pattern\n":

--Paul

cigless ...
 
Yes, now it works in the small test code I posted here, but it does not in the real code.
I wonder whether it has something to do with "print" in perl 5.8 which I am using.

Grazia
 
I doubt if has anything to do with print

$old="1844";
$new="1766";
Code:
$joined_pattern = $old.":".$new;
print "$joined_pattern\n";
$joined_pattern = join ":", $old, $new;
print "$joined_pattern\n";
$old .= ":".$new;
print "$old\n";
prints
Code:
1844:1766
1844:1766
1844:1766

on Activestate 5.8.2
HTH
--Paul

cigless ...
 
I got it.
It has to do with the encoding of the input file.
I copied it into a text .txt file and had no problems. Perl did what it was expected to do.

I do not know exactly what kind of encoding problems it had.

Thank you,

Grazia

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top