Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: what should length(@array) do ? Message-ID: <1991Jan10.063409.7185@iwarp.intel.com> Date: 10 Jan 91 06:34:09 GMT References: Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 54 In-Reply-To: emv@ox.com (Ed Vielmetti) In article , emv@ox (Ed Vielmetti) writes: | $obodylen = length(@obody); | but that gets me "3", probably the size of some symbol table entry. My wild guess is that @obody has between 100 and 999 entries in it, and you are looking at the length of the number of entries as converted to a string! Am I right? | The solution I now have does | | body: while () { | push(@obody,$_) ; | $obodylen += length($_); | } | | seems to work fine, but in the tradition of perl hacking, there's | probably a better way. If you don't like that, but you don't mind concat-ing the whole mess once just to throw it away, try: body: { @obody = ; $obodylen = length(join("",@obody)); } If you think that obody is huge, try something like: body: { @obody = ; $obodylen = 0; for (@obody) { $obodylen += length; } } Yeah, actually, that's close to your solution. You could also do it with a grep() (my formerly favorite operator, until I got tired of it :-) as in: body: { @obody = ; $obodylen = 0; grep($obodylen += length, @obody); } which probably isn't any faster than the previous code. (Larry?) print join("", "Just a", "nother P", "erl ha", "cker,") -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/