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

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

Thread Previous
From:
H . Merijn Brand
Date:
August 24, 2001 01:17
Subject:
Re: pack "b*" isn't dwim enough
Message ID:
20010824101340.E0C7.H.M.BRAND@hccnet.nl
On Thu 23 Aug 2001 19:06, Graham Barr <gbarr@pobox.com> wrote:
> 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*",

OK. sounds sane.

> which will only return a single string.

I know, but that's not DWIM (IMHO)

> Also, if we did this for "b*" what about others like A* and what
> should this do
> 
>   pack "b* A*", join("",@bar), "A string";

ignore the A* and give a warning that A* has no arguments ;)

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

Right.

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

Who for a patch?

> Graham.

Thanks for the comments. I knew I was overlooking the obvious.

-- 
H.Merijn Brand    Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)
using perl-5.6.1, 5.7.1 & 628 on HP-UX 10.20 & 11.00, AIX 4.2, AIX 4.3,
     WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About