Re: Odd sort() problem

From: Paul Lalli (mritty_at_gmail.com)
Date: 09/29/04


Date: Wed, 29 Sep 2004 20:19:43 GMT


"187" <bigal187@invalid.rx.eastcoasttfc.com> wrote
> Paul Lalli wrote:
> > "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote
> >> A. Sinan Unur wrote:
> >>> "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote
> >>
> >> But what I really don't understand is why it doesn't result in a
> >> compile error? lc{$a}, one would think, is not a valid statement.
> >
> > The warning below answers this question.
>
> But shouldn't it be complaining either that lc{ } is an undefined hash
> or lc being a bareword?

Of course not. lc is a built in function. it's taking whatever comes
after "lc" as the parameter you're passing to lc. In this case, what
follows is an anonymous hash, signified by the { }

> Even if I add 'use strict;' before the print statement (or -Mstrict).
>
> >
> > You're passing to the lc() function an anonymous hash. That
anonymous
> > hash is poorly constructed, containing an odd number of elements.
So
> > it is not invalid syntax, it's just not at all what you meant.
>
> But should it not interpret lc{} as a bareword hash, and therefore
issue
> an error about bareword? I'm askign in case this is actually a bug.

No. It's not a bug. It's a problem with your belief that { } are used
only to get at an elment of an existing hash. What you did was
equivalent to this:
$ref = {$a}; #assign a poorly-constructed hashref to $ref;
lc $ref; #pass that hash reference as a parameter to the lc function.

Paul Lalli



Relevant Pages

  • Re: %USERACL Is Empty?!
    ... On Fri, 9 Dec 2005, Paul Lalli wrote: ... >> basically %USERACL is a hash containing the key and values read from the ... >> sub initAuthMgr { ...
    (comp.lang.perl.misc)
  • Re: Adding values to anon hash of hash while looping...
    ... There was absolutely no trace of sarcasm when I wrote that. ... I hadn't realised I needed to declare the hash ... Paul Lalli ...
    (comp.lang.perl.misc)
  • Re: Question on File::Find
    ... Paul Lalli wrote: ... You didn't include the wanted option in your %findoption hash. ... what you think your push statement is doing ... sorry for the mistake, I presume I modified during posting, my mistake, ...
    (comp.lang.perl.misc)
  • Re: I need a host.
    ... > IF they allow clients to view error logs they do not provide ... > http://www.mamaloca.net/perl/ Hash and Hash with errors) the warnings ... just printing the names of the colors, ... Paul Lalli ...
    (perl.beginners)
  • Re: format output for loop help
    ... Paul Lalli wrote: ... So, obviously, s/he didn't bother to use strict; ... %MYHASH is a terrible name for a hash. ... now (or, God forbid, somebody else needs to modify your code). ...
    (perl.beginners)