in reply to Re: Re: external subroutine
in thread external subroutine

Ah k, in cases where you want to print out a value only if it is 'blank', you want to test for a defined value rather than a blank one:

print "<th>$WasonE{HSName}</th>\n" if ( defined( $WasonE{'HSName'} ) );

This will get rid of the warnings you are seeing in your log file, though this will not fix any actual errors. When you run the script in the browser, does it still work as expected, even though you have a lot of warnings in the error log?

Replies are listed 'Best First'.
Re: Re^3: external subroutine
by Anonymous Monk on May 20, 2004 at 20:40 UTC
    That worked, as far as getting rid of the errors. However The variables ARE defined. Here is the code:

    DATA99.pm
    package DATA99; require Exporter; our @ISA = ("Exporter"); our @EXPORT_OK = qw(WasonE); sub WasonE { $WasonE{"time"} = ""; $WasonE{"HSname"} = "E Wason"; $WasonE{"cName"} = "E Wason"; $WasonE{"nickName"} = ""; $WasonE{"yearsHS"} = "4"; $WasonE{"gender"} = "Male"; $WasonE{"wiptabor"} = "I am an accomplished tattooer currently tattooi +ng out of Lucky Draw Tattoo in Glendale. I plan on furthering my care +er, getting some travelling in, and possibly getting a house with my +girlfriend."; $WasonE{"online"} = "I'm on quite a bit actually. I'm currently rebuil +ding the Lucky Draw website offline. Look for it in a few months. I'm + on AIM constantly, and frequent Livejournal. IM me anytime. "; $WasonE{"yahoo"} = ""; $WasonE{"aim"} = ""; $WasonE{"msn"} = ""; $WasonE{"Last4"} = "I've been tattooing since early 2000. I almost got + engaged to a prior girlfriend, but that fell through. I moved to Gle +ndale, to Tempe, and then back to Glendale when I was offered a posit +ion at Lucky Draw. I met a nice English girl named Lee-Ann and we've +been dating for just over a year now."; $WasonE{"Relationship"} = "Yes"; $WasonE{"family"} = "I hang out with my family quite a bit."; $WasonE{"kids"} = "Not Yet"; $WasonE{"hobbies"} = "tattooing, drawing, watching movies..."; $WasonE{"School"} = ""; $WasonE{"Major"} = ""; $WasonE{"Graduation"} = ""; $WasonE{"SchoolLife"} = ""; $WasonE{"jobs"} = "see above"; $WasonE{"military"} = ""; $WasonE{"Memories"} = "lunches on the steps behind the 400 building wi +th Brandon and everybody. Classes with Mr Nielsen."; $WasonE{"fTeacher"} = "Mr Nielsen"; $WasonE{"Clubs"} = ""; $WasonE{"bFriend"} = ""; $WasonE{"friends"} = ""; $WasonE{"Dated"} = "nobody of significance"; @WasonE = values(%WasonE); } 1;
    WasonE.cgi
    #!/usr/bin/perl -wT use strict; use CGI qw(:standard); use lib "/home/bgregory/public_html/cgi-bin"; use DATA99 qw(WasonE); my $q = new CGI; my %WasonE; my $key; my $WasonE; my $name; my $value; my @WasonE; WasonE(); print $q->header( "text/html" ); print "<html>\n<head>\n"; print <<END_OF_HEADER; </head> <body> <table id="top"> <thead> <tr> END_OF_HEADER print <<END_OF_th; </tr> </thead> <tbody> <tr> <td> <h4 id=\"info\">Quick Info:</h4> END_OF_th print "<th>$WasonE{HSName}</th>\n" if ( defined( $WasonE{'HSname'} ) ); print <<END_OF_page; </td> </tr> </tbody> </table> </body> </html> END_OF_page exit;
    thx
      However The variables ARE defined.
      No, they're not. Your subroutine is frobbing %Data99::WasonE, which is a different variable than the lexical hash %WasonE in the main program. Welcome to namespaces.

      Read perldoc -f package, perldoc -f my, "Packages" in perlmod, and "Private Variables via my()" in perlsub. To see what's happening, try using Data::Dumper to dump the values of your variables at various points.

        Wow, you just took that to the next level. I'll take a look at namespaces, packages, private variables and data dumper. Haven't heard much about any of that.