Re: Why wont this work? Package require question
Luinrandir wrote: $Player{Location}=Inn You are missing a semi-colon, and there is no reason to use double quotes above. require '$Player{Location}.pl'; #no error here, I think. Single quotes don't interpolate. '$Player{Location}'::HTML(); #error occurs here I'd hate to have to make a big if then else just to do this... Not sure what that would be aimed at. http://danconia.org Thanks Luinrandir -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why wont this work? Package require question
Ok.. and i'm actually going to top post for this... when done is should read $Player{Location}=Inn; require '$Player{Location}.pl'; whixh is the same as require 'Inn.pl'; and then '$Player{Location}'::HTML(); which is the same as Inn::HTML(); Do i have the vars correct so that if I want to change $Player{Location}=Inn; to $Player{Location}=Gate; the program would require the correct package require Gate.pl and the call on the sub HTML in that package? Gate::HTML(); - Original Message - From: Wiggins d'Anconia [EMAIL PROTECTED] To: Luinrandir [EMAIL PROTECTED] Cc: beginners@perl.org Sent: Wednesday, September 14, 2005 9:22 AM Subject: Re: Why wont this work? Package require question Luinrandir wrote: $Player{Location}=Inn You are missing a semi-colon, and there is no reason to use double quotes above. require '$Player{Location}.pl'; #no error here, I think. Single quotes don't interpolate. '$Player{Location}'::HTML(); #error occurs here I'd hate to have to make a big if then else just to do this... Not sure what that would be aimed at. http://danconia.org Thanks Luinrandir -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why wont this work? Package require question
No need to top post, please don't. Luinrandir wrote: Ok.. and i'm actually going to top post for this... when done is should read $Player{Location}=Inn; require '$Player{Location}.pl'; whixh is the same as require 'Inn.pl'; Same problems exist. Single quotes do NOT interpolate, meaning the value of the variable is not replaced, the variable name itself is being used. So Perl is looking for a file called $Player{Location}.pl which probably doesn't exist. Double quotes DO interpolate, but when you don't need to interpolate use single quotes. So, $Player{Location} = 'Inn'; # single quotes are fine require $Player{Location}.pl; # double quotes for interpolation Theoretically this should work if I remember 'require's specs correctly. Though these days I would switch to 'use' and bring in both libraries unless they are really huge, and not worry about the run time consequences. and then '$Player{Location}'::HTML(); Again, you would need to use double quotes, but in the above you might be able to get away with or may be required to avoid stringification. So either, $Player{Location}::HTML(); or $Player{Location}::HTML(); Either way single quotes will NOT work. The above also assumes that you have included the proper package statements in the required library. perldoc -f package which is the same as Inn::HTML(); Do i have the vars correct so that if I want to change $Player{Location}=Inn; to $Player{Location}=Gate; the program would require the correct package require Gate.pl and the call on the sub HTML in that package? Gate::HTML(); Not the vars that matter, it is the quoting. http://danconia.org [snip old messages] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why wont this work? Package require question
OK I got this to work require $Player{Location}.pl; but not $Player{Location}::HTML(); #error or $Player{Location}::HTML(); # ignored completely! or '$Player{Location}::HTML()';# ignored completely! or '$Player{Location}'::HTML(); #error or $Player{Location}::HTML(); #error now what? hey.. and thanks for the help! Lou Bareword found where operator expected at C:\WWW\MYSTIC~1\CGI-BIN\MYSTIC~1\GAMETE~1.CGI line 36, near }::HTML (Missing operator before ::HTML?) syntax error at C:\WWW\MYSTIC~1\CGI-BIN\MYSTIC~1\GAMETE~1.CGI line 36, near }::HTML Execution of C:\WWW\MYSTIC~1\CGI-BIN\MYSTIC~1\GAMETE~1.CGI aborted due to compilation errors. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why wont this work? Package require question
Now you want to call the Inn::HTML() function, right? You can't easily do it if strict is turned on. Here's one way, though: my $glob = $main::{$Player{Location} . ::}{HTML}; $glob-(); ah yes.. must bottom post ok in the first line you set the var $glob to equal the package call and then the next line $glob-(); calls it? is $glob a reserved var? or one you made up.. like the $foo $bar ones I see? thanks Lou -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why wont this work? Package require question
Now you want to call the Inn::HTML() function, right? You can't easily do it if strict is turned on. Here's one way, though: my $glob = $main::{$Player{Location} . ::}{HTML}; $glob-(); Ok.. that works.. why? what is -() -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why wont this work? Package require question
I also got this to work: $Player{Location}=Inn; $Player{Action}=Sell; require $Player{Location}.pl; # this code calls on the package # my $glob = $main::{$Player{Location} . ::}{$Player{Action}}; # $glob-(); # ## but what if I want to pass a var? then $glob-($foo,$bar); ? Thanks for the help Lou -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why wont this work? Package require question
but what if I want to pass a var? then $glob-($foo,$bar); ? Yes sir.. we have a winner But I still have no clue as to why this works... esp. $glob-(); just looked in my book.. am I dereferencing a reference? but hey! thanks anyway! Lou $Player{Location}=Inn; $Player{Action}=Sell; $Item=Blueberry; require $Player{Location}.pl; # this code calls on the package # my $glob = $main::{$Player{Location} . ::}{$Player{Action}}; # $glob-($Item); # ## -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Why wont this work? Package require question
Jeff 'japhy' Pinyan wrote: Now you want to call the Inn::HTML() function, right? You can't easily do it if strict is turned on. Here's one way, though: my $glob = $main::{$Player{Location} . ::}{HTML}; $glob-(); Or just turn off strict for a sec: { no strict 'refs'; {$Player{Location}::HTML}() } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Why wont this work? Package require question
On Sep 14, Luinrandir said: but what if I want to pass a var? then $glob-($foo,$bar); ? But I still have no clue as to why this works... esp. $glob-(); just looked in my book.. am I dereferencing a reference? Basically, yes. $glob ends up being a glob, a reference to everything with that name (in your case, a reference to everything named 'HTML' in the Inn:: or Castle:: or Whatever:: class). When you do $foo-(...), you're saying that $foo holds a reference to a function, and you want to call the function. Since what's in $glob is a glob, a reference to every type (scalar, array, hash, etc.), we do $glob-(ARGS). -- Jeff japhy Pinyan% How can we ever be the sold short or RPI Acacia Brother #734% the cheated, we who for every service http://www.perlmonks.org/ % have long ago been overpaid? http://princeton.pm.org/ %-- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response