'\0' like in C

Discussion in 'Perl Misc' started by robertospara, Nov 20, 2006.

  1. robertospara

    robertospara Guest

    Question to Tad McLellan:
    Is there something in Perl like '\0' in C????????

    U seams to be smart????????
    So??????????????????????????????
    Chill out guys :)
     
    robertospara, Nov 20, 2006
    #1
    1. Advertising

  2. robertospara wrote:
    > Question to Tad McLellan:
    > Is there something in Perl like '\0' in C????????


    Yes.


    John
    --
    Perl isn't a toolbox, but a small machine shop where you can special-order
    certain sorts of tools at low cost and in short order. -- Larry Wall
     
    John W. Krahn, Nov 20, 2006
    #2
    1. Advertising

  3. robertospara wrote:
    > Question to Tad McLellan:
    > Is there something in Perl like '\0' in C?


    You mean a character with all bits zero? Yes, there is.

    > ???????


    Your keyboard needs some repairs.

    > U seams to be smart????????


    Who/what is U?

    > So??????????????????????????????


    Your keyboard needs some serious repairs.

    jue
     
    Jürgen Exner, Nov 20, 2006
    #3
  4. robertospara

    robertospara Guest

    But for me '\0' is the mark of the end of the array (or string we can
    say when the type is char).
    So when I have >>>$string = "abcd"<<< is there somewhere '\0' in the
    end???????????????????
    Ex.
    char a[10] = "abcd";
    and then we have
    a[0] = 'a' a[1]='b' a[2]='c' a[3]='d'
    >>>>>>>>>>>>>a[4]='\0'<<<<<<<<<<<<<<<<<<<


    >>>>>>>>>>>>>a[4]='\0'<<<<<<<<<<<<<<<<<<<
    >>>>>>>>>>>>>a[4]='\0'<<<<<<<<<<<<<<<<<<<
    >>>>>>>>>>>>>a[4]='\0'<<<<<<<<<<<<<<<<<<<

    So this is what I am talking about.
    Greetings to all:)
    Jürgen Exner napisal(a):
    > robertospara wrote:
    > > Question to Tad McLellan:
    > > Is there something in Perl like '\0' in C?

    >
    > You mean a character with all bits zero? Yes, there is.
    >
    > > ???????

    >
    > Your keyboard needs some repairs.
    >
    > > U seams to be smart????????

    >
    > Who/what is U?
    >
    > > So??????????????????????????????

    >
    > Your keyboard needs some serious repairs.
    >
    > jue
     
    robertospara, Nov 20, 2006
    #4
  5. robertospara

    Mirco Wahab Guest

    robertospara schrieb:
    > Question to Tad McLellan:
    > Is there something in Perl like '\0' in C????????


    No.

    No if you mean '\0' as a "signal"
    for string library functions.

    This is mainly because a "string" (scalar) "$text"
    in perl isn't the address of the character array
    (as in C) but its a pointer to a structure which
    contains (among others) the address of this
    character array in question.

    In C, you have a "string" concept that uses
    an extra character (\0) at the end of the data,
    in Perl you have an extra integer at another
    place in the said struct which says how long
    it is.

    Regards

    Mirco
     
    Mirco Wahab, Nov 20, 2006
    #5
  6. [Please do not top post, trying to repair]
    [Please do not blindly fullquote]

    robertospara wrote:
    > Jürgen Exner napisal(a):
    >> robertospara wrote:
    >>> Is there something in Perl like '\0' in C?

    >>
    >> You mean a character with all bits zero? Yes, there is.

    >
    > But for me '\0' is the mark of the end of the array


    In Perl the 'end' of an array is managed internally and is accessible to the
    programmer in two different ways:
    - $#array indicates the last used index in the array @array
    - scalar(@array) indicates the number of elements in the array (usually
    $#array+1 unless someone messed around with the start index of the array)

    > (or string we can say when the type is char).


    An array of char has nothing to do with a string. Those are two totally
    disjunct and unrelated data structures.

    > So when I have >>>$string = "abcd"<<< is there somewhere '\0' in the
    > end?


    No, why should there be? Opposite to C in Perl that horrible crutch is not
    needed. If you need the length of an array then use one of the two methods
    mentioned above. If you need the length of a string then just use the
    length() function.
    Note: of course the first has nothing, nothing at all, to do with the
    second.

    > ??????????????????


    Would you mind fixing your keyboard?

    > Ex.
    > char a[10] = "abcd";
    > and then we have
    > a[0] = 'a' a[1]='b' a[2]='c' a[3]='d'
    >>>>>>>>>>>>>> a[4]='\0'<<<<<<<<<<<<<<<<<<<

    >
    >>>>>>>>>>>>>> a[4]='\0'<<<<<<<<<<<<<<<<<<<
    >>>>>>>>>>>>>> a[4]='\0'<<<<<<<<<<<<<<<<<<<
    >>>>>>>>>>>>>> a[4]='\0'<<<<<<<<<<<<<<<<<<<

    > So this is what I am talking about.


    Yes, it is amazing how primitive C is when it comes to data structures. It
    doesn't even know about strings and forces the programmer not only to use an
    array of characters instead, but to manually(!) manage even the length of
    the string. And if you are not very careful you can screw up really badly,
    e.g. char a[10] = "abcdabcdabcdabcd";

    Luckily Perl is far advanced in this regard:
    $a = 'abcd';
    is all you need to declare and define a string that contains the first 4
    latin letters. And if you want to enlarge the string, then just do so:
    $a = $a . 'abcdabcsabcdabcd'.

    There may or may not be an array @a, too, but it would be totally unrelated
    to the scalar $a.

    jue
     
    Jürgen Exner, Nov 20, 2006
    #6
    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. Alex
    Replies:
    0
    Views:
    407
  2. Blmn
    Replies:
    0
    Views:
    447
  3. Ittay Dror
    Replies:
    1
    Views:
    440
    Ittay Dror
    Jul 29, 2004
  4. KB
    Replies:
    5
    Views:
    772
    Steven D'Aprano
    Jul 31, 2005
  5. Patrick Kowalzick
    Replies:
    5
    Views:
    477
    Patrick Kowalzick
    Mar 14, 2006
Loading...

Share This Page