[comp.lang.perl] Packages Question

tomb@viusys.uucp (Tom L. Baitz) (05/31/90)

I guess I'm totally missing the boat, but why doesn't this work?

$val1 = 1;
$val2 = 2;
print "$val1 $val2\n";
&testsub;
print "$val1 $val2\n";
exit;

package abc;

sub main'testsub {
	$valx = 3;
	main'$val2 = $valx;
}

The error I get is:
EOF in string at test2.pl line 12.

perl -v
$Header: perly.c,v 3.0.1.5 90/03/27 16:20:57 lwall Locked $
Patch level: 18

Copyright (c) 1989, 1990, Larry Wall

Perl may be copied only under the terms of the GNU General Public License,
a copy of which can be found with the Perl 3.0 distribution kit.


Thanks,
--
---
tomb@viusys   |   UUCP: ..uunet!viusys!tomb  |  ARPA: McLean-Unisys.ARMY.MIL

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (05/31/90)

In article <1990May30.212950.26190@viusys.uucp> tomb@viusys.uucp (Tom L. Baitz) writes:
: I guess I'm totally missing the boat, but why doesn't this work?
: 
: $val1 = 1;
: $val2 = 2;
: print "$val1 $val2\n";
: &testsub;
: print "$val1 $val2\n";
: exit;
: 
: package abc;
: 
: sub main'testsub {
: 	$valx = 3;
: 	main'$val2 = $valx;
: }
: 
: The error I get is:
: EOF in string at test2.pl line 12.

You've misplaced your dollars.  :-)

12c12
<       main'$val2 = $valx;
---
>       $main'val2 = $valx;

The name of the variable is actually val2, not $val2.  The $ is just
sort of a type mark that says you are referring to a scalar value.  Package
name modifiers (and subscripts) bind more tightly.

Larry