From: Robin on
how can I make a structure where you have a variable call sometjhing
in a package for exmaple print $a -> $v prints the variable $v in a
package called c.....the closest I could do was the
following....thanks everyone,
robin


package a;
$v = 1;

package main;
$a = bless \$z, "a";
print $a::v;
From: Ben Morrow on

Quoth Robin <robin1(a)cnsp.com>:
> how can I make a structure where you have a variable call sometjhing
> in a package for exmaple print $a -> $v prints the variable $v in a
> package called c.....the closest I could do was the
> following....thanks everyone,

This makes no sense. What are you trying to do?

> package a;
> $v = 1;
>
> package main;
> $a = bless \$z, "a";
> print $a::v;

You do realise that the '$a' in this line has nothing whatever to with
the '$a' in the line above, right?

Ben

From: Tad McClellan on
Robin <robin1(a)cnsp.com> wrote:

> how can I make a structure where you have a variable call


A variable is "data".

A function call is "code".

data cannot "call" anything only code can issue a function call.


> sometjhing
> in a package for exmaple print $a -> $v prints the variable $v in a
> package called c.....the closest I could do was the
> following


There IS NO package called c in your code.


> package a;
> $v = 1;


There are no functions in package a, so you cannot call anything
in package a, as there is nothing to call.

You should always enable strict in all of your Perl programs:

use strict;

so then, that last line needs to be:

our $v = 100;

(1 is often used for other things in Perl (eg true) so it is not
a good test value to use.
)


> package main;
> $a = bless \$z, "a";


Why do you include this line?

What do you think it does for you?

It is not needed, so you have a misunderstanding of the fundamentals
somewhere...


> print $a::v;

That prints the variable named $v in the package named a.

You do not need objects to access a variable that is declared
in another package.

--------------------
#!/usr/bin/perl
use warnings;
use strict;

package a;
our $v = 100;

package main;
print $a::v, "\n";
--------------------


Look Ma! No OO involved!


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.