Hi experts, I am stuck trying to figure out how to satisfy a global symbol requires explicit package name error. My beginning Perl program specifies 'use Cos::rxi;' and then calls a subroutine in the rxi.pm package called 'generate_rxi' using eval {} as follows:
sub send_order_rxi { my($aOrder) = @_; my($order) = $aOrder->{orders_pending_id}; eval { ### here's where I call the subroutine ### located in the rxi.pm package my($base) = generate_rxi($Dir, $aOrder); if ($Mail) { queue_via_mail($base, $aOrder); tag_order($order, 'I'); unlink($base . '.rxi'); unlink($base . '.oma'); } }; if ($@) { warn "rxi send $order failed: $@\n"; } }
There is a big 'if' statement in the subroutine generate_rxi which I have dropped in below. I have put ### comments above the places where Perl complains about needing an explicit package name for a global symbol. Could someone help me understand this. Below the 'if' block I have dropped the small subroutine (convertPrismData) which is called from the 'if' block and below that I have dropped the beginning of the rxi.pm package file. Once you tell me what I did wrong feel free to recommend a good book on Perl basics as I apparently need it. Thank you and warm regards,
################################################### # this is the 'if' block where the global symbol # complaints occur # this 'if' block is in the subroutine 'generate_rxi' # which is part of the package rxi.pm #################################################### if (length($aOrder->{rx_OD_Prism_Diopters}) ne 0 || length($aOrder->{rx_OS_Prism_Diopters}) ne 0) { my @array1 = qw($aOrder->{rx_OD_Prism_Diopters} $aOrder->{rx_OD_Prism} $aOrder->{rx_OD_Prism_Angle_Val} $aOrder->{rx_OD_Prism2_Diopters} + $aOrder->{rx_OD_Prism2}); my @array2 = qw($aOrder->{rx_OS_Prism_Diopters} $aOrder->{rx_OS_Prism} $aOrder->{rx_OS_Prism_Angle_Val} $aOrder->{rx_OS_Prism2_Diopters} $aOrder->{rx_OS_Prism2}); # if values are specified as Angles, convert them to direction if ($array1[1] == 'Angle') {convertPrismData(0, \@array1);} if ($array2[1] == 'Angle') {convertPrismData(1, \@array2);} my $ODP1Val = $array1[0]; my $ODP1Dir = $array1[1]; my $ODP2Val = $array1[3]; my $ODP2Dir = $array1[4]; my $OSP1Val = $array2[0]; my $OSP1Dir = $array2[1]; my $OSP2Val = $array2[3]; my $OSP2Dir = $array2[4]; # Innovations only expresses prism as IN or UP # reverse anthing that is OUT or DOWN if ($ODP1Dir == "OUT" || $ODP1Dir == "DOWN") { if (length($ODP1Val != 0) {$ODP1Val = '-' . $ODP1Val);} if ($ODP1Dir == "OUT") { $ODP1Dir = "IN"); } else { $ODP1Dir = "UP"); } } ### first global symbol complaint is on $ODP2Dir if ($ODP2Dir == "OUT" || $ODP2Dir == "DOWN") { ### second global symbol complaint is on $ODP2Val if (length($ODP2Val != 0) {$ODP2Val = '-' . $ODP2Val);} if ($ODP2Dir == "OUT") { $ODP2Dir = "IN"); } else { $ODP2Dir = "UP"); } } ### third global symbol complaint is on $OSP1Dir if ($OSP1Dir == "OUT" || $OSP1Dir == "DOWN") { ### fourth (and final) global symbol complaint is on $OSP1Val if (length($OSP1Val != 0) {$OSP1Val = '-' . $OSP1Val);} if ($OSP1Dir == "OUT") { $OSP1Dir = "IN"); } else { $OSP1Dir = "UP"); } } if ($OSP2Dir == "OUT" || $OSP2Dir == "DOWN") { if (length($OSP2Val != 0) {$OSP2Val = '-' . $OSP2Val);} if ($OSP2Dir == "OUT") { $OSP2Dir = "IN"); } else { $OSP2Dir = "UP"); } } my $PIN_String; my $PUP_String; if (length($ODP1Val) > 0) { if ($ODP1Dir == "IN") { $PIN_String = $ODP1Val; $PUP_String = (length($ODP2Val) > 0) ? $ODP2Val : " 0.00"); } else { #UP $PUP_String = $ODP1Val; $PIN_String = (length($ODP2Val) > 0) ? $ODP2Val : " 0.00"); } } else { $PIN_String = " 0.00"; $PUP_String = " 0.00"; } if (length($OSP1Val) > 0) { if ($OSP1Dir == "IN") { $PIN_String .= (" " . $OSP1Val); $PUP_String .= length($OSP2Val) > 0) ? (" " . $OSP2Val) : " +0.00"); } else { $PUP_String .= (" " . $OSP1Val); $PIN_String .= (length($OSP2Val) > 0) ? (" " . $OSP2Val) : " + 0.00"); } } else { $PIN_String .= " 0.00"; $PUP_String .= " 0.00"; } print FH "PIN " . $PIN_String; print FH "PUP " . $PUP_String; }
######################################################## # convert prism angle to its vertical and horizontal components ######################################################## sub convertPrismData { my($lr) = $_[0]; my($q2q3,$q1q4); if ($lr == 0) { # OD setup $q2q3 = "OUT"; $q1q4 = "IN"; } else { # OS setup $q2q3 = "IN"; $q1q4 = "OUT"; } my $vertical_component = round($_[1]->[0] * sin($_[1]->[2] * PI/180. +0) * 100.0) / 100.0; my $horizontal_component = round($_[1]->[0] * cos($_[1]->[2] * PI/18 +0.0) * 100.0) / 100.0; $_[1]->[0] = abs($vertical_component); $_[1]->[1] = (($vertical_component < 0) ? "DOWN" : "UP"); $_[1]->[3] = abs($horizontal_component); $_[1]->[4] = (($horizontal_component < 0) ? $q2q3 : $q1q4); return; }
############################################# # This is the beginning of the rxi.pm package # the subroutine generate_rxi is in this # package. I thought this may help in fixing # the global symbol issue ############################################# #!/usr/bin/perl -w package Cos::rxi; use strict; use Getopt::Std; use DBI; use Cos::Constants; use Cos::Dbh; use Math::Trig; BEGIN { use Exporter (); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); # set the version for version checking $VERSION = 1.00; # if using RCS/CVS, this may be preferred $VERSION = do { my @r = (q$Revision: 1.6 $ =~ /\d+/g); sprintf + "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker @ISA = qw(Exporter); @EXPORT = qw(generate_rxi); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], # your exported package globals go here, # as well as any optionally exported functions @EXPORT_OK = qw(); } use vars @EXPORT_OK;

In reply to global symbol...explict package name by rightfield

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.