Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!ogicse!iWarp.intel.com!news From: merlyn@iWarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: unpack('x10','') Message-ID: <1991Jun27.195016.29385@iWarp.intel.com> Date: 27 Jun 91 19:50:16 GMT References: Sender: news@iWarp.intel.com Reply-To: merlyn@iWarp.intel.com (Randal L. Schwartz) Distribution: comp Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 41 In-Reply-To: mayer@sono.uucp (Ronald &) Nntp-Posting-Host: se.iwarp.intel.com In article , mayer@sono (Ronald &) writes: | | Inconsistancy with man page. | | Quoting from the man page: | > Here's a subroutine that does substring: | > sub substr { | > local($what,$where,$howmuch) = @_; | > unpack("x$where a$howmuch", $what); | > } | > | | however using the builtin: | print "##",substr('hi',10,10),"##" | gives me "####". | but using the procedure as printed in the man page: | print "##",&substr('hi',10,10),"##" | dies with an error "x outside of string at - line 3." | | Could someone tell me which behavior is 'correct'? You're gonna hate me for saying that they're both *correct*. The line from the manpage could be annotated to read "... does substring for well-behaved arguments:". You passed substring some of its exceptional argument values, for which it does defined (and nice) things, like return null strings. Pack and unpack, on the other hand, are typically used to transmogrify data of known shapes and sizes. A slight difference in philosophy, and I'm *glad* it's a fatal error to select outside the boundaries. Yeah, both could fatal, or both could return null, but it's *this* way instead. Why do you think it takes a while to become a Perl guru? :-) print unpack("x24"."aX2"x 24."a",",rekcah lreP rehtona tsuJ") -- /=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'..."====/