Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: What is the difference between $array[1] and @array[1]?

by salazar (Scribe)
on Apr 08, 2009 at 11:34 UTC ( [id://756313]=note: print w/replies, xml ) Need Help??


in reply to Re: What is the difference between $array[1] and @array[1]?
in thread What is the difference between $array[1] and @array[1]?

I can't speak for anything other than PHP and JavaScript (I know, I know... extremely ugly languages), but they both use the same symbol to represent what we know in Perl as scalars, lists, and hashes.

I also could add that this allows for extremely messy and poor practices in code. I've seen this many times:
<?php $foo = 'bar'; $foo['bar'] = 'ding'; ?>

I'm assuming (as I've never looked at the PHP source code) that there are actually two separate variables here, one an array and one a scalar. But then, what happens when you try to do "if ($foo)"?

Naming two variables the same, @foo and $foo, isn't the best practice in Perl, but at least it's possible ;) .

Replies are listed 'Best First'.
Re^3: What is the difference between $array[1] and @array[1]?
by JavaFan (Canon) on Apr 08, 2009 at 15:06 UTC
    It used to be that in Perl, a '$' introduced a scalar value/variable (1 value), a '@' a list value/array (0, 1 or more values) and a '%' a hash variable. Life was simple, and sigils easy to explain.

    Then we got perl5 and objects, and expressions like $obj->method, where the sigil is '$' even if the method is going to return multiple values. Life no longer is simple, and people got the feeling sigils are wrong and Perl6 will change how sigils are used.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://756313]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (1)
As of 2025-01-15 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (46 votes). Check out past polls.