develooper Front page | perl.perl5.porters | Postings from August 2001

Re: pack "b*" isn't dwim enough

Thread Previous | Thread Next
Graham Barr
August 23, 2001 10:07
Re: pack "b*" isn't dwim enough
Message ID:
On Thu, Aug 23, 2001 at 06:49:36PM +0200, H.Merijn Brand wrote:
> Though I did read the doc's and used it more than once, I keep trying to do
> use integer;
> my @bar = map { rand 1 } ( 0 .. 100 );
> my $foo = pack "b*", @bar;
> where I should have used
> my $foo = pack "b*", join "", @bar;
> Why not support the first?

Because pack "b*" should be the exact opposite of unpack "b*",
which will only return a single string.

Also, if we did this for "b*" what about others like A* and what
should this do

  pack "b* A*", join("",@bar), "A string";

Sure you can probably come up with some answers, but DWIM can introduce
ambiguity if you are not careful.

Possibly what you want is a warning if there are more arguments given
than are needed.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About