[Omaha.pm] Getopt::Long and opt_ variables

Jeff Bisbee omaha-pm at jbisbee.com
Sun May 29 06:12:04 PDT 2005


* Dave Thacker (dthacker9 at cox.net) wrote:
> my $opt_place;

It works, just need

    our $opt_place;

"my" restricts you to only set/access the value within the class, "our"
lets you set/access the value outside of the class.  Also, when it
doubt, "use the source"

    perldoc -m Getopt::Long

Thats what I did and just looked for "opt_" and found  the following, so
knew the code did as you explained...

    else {
	# Link to global $opt_XXX variable.
	# Make sure a valid perl identifier results.
	my $ov = $orig;
	$ov =~ s/\W/_/g;
	if ( $opctl{$name}[CTL_DEST] == CTL_DEST_ARRAY ) {
	    print STDERR ("=> link \"$orig\" to \@$pkg","::opt_$ov\n")
		if $debug;
	    eval ("\$linkage{\$orig} = \\\@".$pkg."::opt_$ov;");
	}
	elsif ( $opctl{$name}[CTL_DEST] == CTL_DEST_HASH ) {
	    print STDERR ("=> link \"$orig\" to \%$pkg","::opt_$ov\n")
		if $debug;
	    eval ("\$linkage{\$orig} = \\\%".$pkg."::opt_$ov;");
	}
	else {
	    print STDERR ("=> link \"$orig\" to \$$pkg","::opt_$ov\n")
		if $debug;
	    eval ("\$linkage{\$orig} = \\\$".$pkg."::opt_$ov;");
	}
    }

-- Jeff Bisbee / omaha-pm at jbisbee.com / jbisbee.com


More information about the Omaha-pm mailing list