Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

$p{"Bryan"}{"age"} = 31

Is there anything wrong with out of the blue making a statement like this:

$p{"Bryan"}{"age"} = 31;

I thought perl required me to use the anonymous hash composer:

$p{"Bryan"} = { "age" => 31 };

... but the first example seems to work.  So I was just wondering if that's
okay, or if it's a no-no.

(I'm learning PHP now, and there seem to be a lot of no-nos in PHP that
aren't intuitive.)

- B



Report this thread to moderator Post Follow-up to this message
Old Post
Bryan R Harris
05-31-05 08:57 PM


RE: $p{"Bryan"}{"age"} = 31
Bryan R Harris wrote:
> Is there anything wrong with out of the blue making a statement like
> this:
>
> $p{"Bryan"}{"age"} = 31;

That's fine, as long as $p{Bryan} doesn't exist or is already a hashref.
See: http://c2.com/cgi/wiki?AutoVivification.

For safety, be sure to "use strict" so you don't end up treating $p{Bryan}
as a soft reference:

$p{Bryan} = 'foo';
$p{Bryan}{age} = '31';    # this is like $foo{age} = 31

Also, the quotes are not strictly required.

>
> I thought perl required me to use the anonymous hash composer:
>
> $p{"Bryan"} = { "age" => 31 };

That's fine too, but not exactly equivalent.

Report this thread to moderator Post Follow-up to this message
Old Post
Bob Showalter
05-31-05 08:57 PM


Re: $p{"Bryan"}{"age"} = 31
>>>>> "Bob" == Bob Showalter <Bob_Showalter@taylorwhite.com> writes:

Bob> That's fine, as long as $p{Bryan} doesn't exist or is already a hashref
.
Bob> See: http://c2.com/cgi/wiki?AutoVivification.

And <http://www.stonehenge.com/merlyn/UnixReview/col44.html>.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training
!

Report this thread to moderator Post Follow-up to this message
Old Post
Randal L. Schwartz
06-03-05 01:56 AM


Re: $p{"Bryan"}{"age"} = 31

Excellent!  Perl is so !

Thanks, Randal.

- B

 
>
> Bob> That's fine, as long as $p{Bryan} doesn't exist or is already a hashr
ef.
> Bob> See: http://c2.com/cgi/wiki?AutoVivification.
>
> And <http://www.stonehenge.com/merlyn/UnixReview/col44.html>.



Report this thread to moderator Post Follow-up to this message
Old Post
Bryan R Harris
06-03-05 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:36 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.