2008-10-21 19 views

उत्तर

70
perldoc -f length 

    length EXPR 
    length Returns the length in characters of the value of EXPR. If EXPR is 
      omitted, returns length of $_. Note that this cannot be used on an 
      entire array or hash to find out how many elements these have. For 
      that, use "scalar @array" and "scalar keys %hash" respectively. 

      Note the characters: if the EXPR is in Unicode, you will get the num- 
      ber of characters, not the number of bytes. To get the length in 
      bytes, use "do { use bytes; length(EXPR) }", see bytes. 
+0

धन्यवाद! आपके लिए आसान प्रतिनिधि! :) – Kip

+0

बस मुझे "त्वरित ड्रा" कहते हैं। –

+17

यदि आपका कोई उदाहरण था तो आपका उत्तर बेहतर होगा। –

41

हालांकि 'लंबाई()' सही जवाब है कि किसी भी समझदार कोड में इस्तेमाल किया जाना चाहिए है, Abigail's length horror, उल्लेख किया जाना चाहिए अगर पर्ल विद्या की खातिर ही।

असल में, चाल कैच-ऑल लिप्यंतरण ऑपरेटर की वापसी मूल्य का उपयोग कर के होते हैं: (धन्यवाद पूरक विकल्प के लिए 'सी')

print "foo" =~ y===c; # prints 3 

y /// ग खुद के साथ सभी पात्रों की जगह, और चरित्र की संख्या को प्रतिस्थापित करता है (इसलिए प्रभावी रूप से, स्ट्रिंग की लंबाई)।

+5

ओह, यह प्यारा है। भयानक, लेकिन प्यारा। –

+1

वाई के गिनती मोड वास्तव में स्ट्रिंग को संशोधित नहीं करते हैं, इसलिए वे केवल पढ़ने योग्य मानों पर भी ठीक काम करेंगे। – ysth

+4

यह एक भयानक तरीके से भयानक है। –

-2

length() समारोह:

$string ='String Name'; 
$size=length($string); 
संबंधित मुद्दे