Strange behaviour while string concatenation

R

Rajpreet

Greetings,

I am trying to append an alphabetical counter to a string. But
concatenation shows a very strange behaviour in this case. Can some
one please help?

The piece of code looks like :

$self->{"log"}->debug(" In Function _process_array_data. ");
$self->{"log"}->debug(" temp 4,data[11],ctr value s are : $temp-
[4], $data->[11],$ctr ");

$temp->[4] = substr($data->[11],0,2).substr($data-
[11],-8)."$ctr";
$self->{"log"}->debug(" temp 4 value is : $temp->[4] ");

And output in debug file is something like this :


DEBUG: temp 4,data[11],ctr value s are : , NX200802118966, the
counter value is : AA
DEBUG: temp 4 value is : NX02118966 the counter value is : AA

And in output file the record comes like :

211012 00003855 1992 NX02118966
th


I am not able to understand the root cause as one thing being string
not geting appended and second thing is from where " th" coming?

TIA.

Regards,
Rajpreet
 
J

J. Gleixner

Rajpreet said:
Greetings,

I am trying to append an alphabetical counter to a string. But
concatenation shows a very strange behaviour in this case. Can some
one please help?

The piece of code looks like :

$self->{"log"}->debug(" In Function _process_array_data. ");
$self->{"log"}->debug(" temp 4,data[11],ctr value s are : $temp-
[4], $data->[11],$ctr ");

$temp->[4] = substr($data->[11],0,2).substr($data-
[11],-8)."$ctr";

No need to double quote $ctr..
$self->{"log"}->debug(" temp 4 value is : $temp->[4] ");

And output in debug file is something like this :


DEBUG: temp 4,data[11],ctr value s are : , NX200802118966, the
counter value is : AA
DEBUG: temp 4 value is : NX02118966 the counter value is : AA

And in output file the record comes like :

211012 00003855 1992 NX02118966
th


I am not able to understand the root cause as one thing being string
not geting appended and second thing is from where " th" coming?

If you actually debug the issue by printing the variable next
to its value, you'll probably see that the issue is with
your assumption of their values.

The 'th' is coming from 'the counter value is.."
^^

e.g. provided $self->{"log"} is correct..

$self->{"log"}->debug("temp->[4]=$temp->[4] data->[11]=$data->[11]
ctr=$ctr\n");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top