List Info

Thread: Again query with hashes!!!




Again query with hashes!!!
user name
2006-07-05 15:17:41
Hello All,
 
I was working with hashes and came up with a queer-looking problem.
This is my code.
 
%hash = (a=>a1,
           ;    b=>a2
         ;      );

print %hash . "\n";
The O/p comes as 2/8. This is as expected showing the used and allocated buckets. But the problem occurs when I change the value of b from "a2" to "2a".
 
Perl shows me the following error/div>
 
C:\Documents and Settings\Owner\Desktop\ukhas\perlprgrms>perl del.pl
Bareword found where operator expected at del.pl line 2, near "2a"
 ;       (Missing operator before a?)
syntax error at del.pl line 3, near "2a
   ;      "
Execution of del.pl aborted due to compilation errors.
 
I understand its asking me to put quotes in this case; when I did that the error vanishes and the O/p is same as before.
 
My question/div>
Why is Perl reporting an error for the value "2a" and not for "a2"?? 
I am using Perl v 5.8 and WinXP
 
Have a great day and GOD bless!!!
Thanks and Regards,
Ukhas Jean

;


Sneak preview the all-new Yahoo.com. It's not radically different. Just radically better.
Again query with hashes!!!
user name
2006-07-05 15:51:03
On 7/5/06, ukhas jean <ukh_dtlyahoo.com> wrote:
>
> I was working with hashes and came up with a
queer-looking problem.
> This is my code.
>
> %hash = (a=>a1,
>                b=>a2
>                );
>
> print %hash . "\n";
>
> The O/p comes as 2/8. This is as expected showing the
used and allocated
> buckets. But the problem occurs when I change the value
of b from "a2" to
> "2a".
>
> Perl shows me the following error:-
>
> C:\Documents and
> Settings\Owner\Desktop\ukhas\perlprgrms>perl
del.pl
> Bareword found where operator expected at del.pl line
2, near "2a"
>         (Missing operator before a?)
> syntax error at del.pl line 3, near "2a
>          "
> Execution of del.pl aborted due to compilation errors.
>
> I understand its asking me to put quotes in this case;
when I did that the
> error vanishes and the O/p is same as before.
>
> My question:-
> Why is Perl reporting an error for the value
"2a" and not for "a2"??

The short answer is that your script is missing the
following at the start:

use strict;
use warnings;

The long involves Perl's processing of barewords, why it
allows it at
all (for backward compatibility, but dangerous), and how the
language's syntax is defined (e.g., subroutine names can't
begin with
a digit).

HTH

-- 
pDale Campbell
Desperation = A Rope Ends It
_______________________________________________
ActivePerl mailing list
ActivePerllistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )