Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^2: scope and declaration in local packages

by december (Pilgrim)
on Jan 31, 2011 at 13:42 UTC ( #885272=note: print w/replies, xml ) Need Help??

in reply to Re: scope and declaration in local packages
in thread scope and declaration in local packages

I realised that I could use a BEGIN block, but I was basically wondering why Perl didn't complain about the functions, yet did so with the variables.

  • Comment on Re^2: scope and declaration in local packages

Replies are listed 'Best First'.
Re^3: scope and declaration in local packages
by ikegami (Patriarch) on Jan 31, 2011 at 15:40 UTC

    So you think the function exists and the variable doesn't exist? That's not the case. The function and the variables are all declared at compile time. It's not complaining about the variables not existing. It's complaining that you didn't put a value in them, and that's because you didn't execute the assignment.

    my $sound1 = "knor1";

    is the same as

    my $sound1; $sound1 = "knor1";

    Many language have a special declaration syntax that allows for the initialisation of variables, but Perl does not. my always initialise the variable it creates to undef* (scalars) or empty (arrays and hashes). If you want it to have another value, you need to assign a value to it.

    * — Implementation differs slightly, but you're not suppose to ever encounter that.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2023-04-01 11:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found