Strange behaviour while string concatenation

Discussion in 'Perl Misc' started by Rajpreet, Feb 12, 2008.

  1. Rajpreet

    Rajpreet Guest

    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
    Rajpreet, Feb 12, 2008
    #1
    1. Advertising

  2. Rajpreet

    J. Gleixner Guest

    Rajpreet wrote:
    > 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");
    J. Gleixner, Feb 12, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    3
    Views:
    4,785
    walala
    Sep 18, 2003
  2. karthikbalaguru

    Strange behaviour of while loop !!

    karthikbalaguru, Feb 13, 2009, in forum: C Programming
    Replies:
    14
    Views:
    560
    David Thompson
    Mar 3, 2009
  3. khany
    Replies:
    6
    Views:
    1,095
    Dave Angel
    Oct 19, 2009
  4. PaulR
    Replies:
    11
    Views:
    462
  5. Andrew Berg
    Replies:
    13
    Views:
    1,266
    Andrew Berg
    Jul 11, 2011
Loading...

Share This Page