Lenght of scalar, sizeof scalar

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arepi
    New Member
    • Sep 2008
    • 62

    Lenght of scalar, sizeof scalar

    Hi!

    1, How can I quevery the stringlenght of a scalar
    (like in C the function : strlen() )
    2,How can I quevery the sizeof a scalar
    (like in C the operator: sizeof )

    Thanks!
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    1) Try perldoc -f length

    2) Not sure.

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      I think that the two are one in the same. Length is size. With regards to arrays, you could be speaking of the length of the array (which would be the number of elements in the array) and the size (length) of each element.

      Regards,

      Jeff

      Comment

      • Arepi
        New Member
        • Sep 2008
        • 62

        #4
        Originally posted by numberwhun
        I think that the two are one in the same. Length is size. With regards to arrays, you could be speaking of the length of the array (which would be the number of elements in the array) and the size (length) of each element.

        Regards,

        Jeff
        Thanks but I dont think they are same.

        Example:

        Code:
        print($strlen=length($string=232));
        it give at display 3,(3number), but the number 232 take from memory only 2 bytes.
        when you think so the two is same

        Thanks
        Last edited by Arepi; Oct 12 '08, 05:00 PM. Reason: code

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          perl has no builtin function that is the same as the C sizeof function. Perl handles all memory management for you, you don't have to allocate memory with perl or manage it.

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            If you want to know variable sizes this module should help you:

            Devel::Size

            But like I said, you don't have to manage memory or allocate memory with perl.

            Comment

            Working...