Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 8th, 2001, 12:47 PM
Acid Reign Acid Reign is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 190 Acid Reign User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 57 m 52 sec
Reputation Power: 8
Send a message via ICQ to Acid Reign
Question Referring variables in other places

How do you refer to variables that are in another file

For example, vars.sub conatins this line:

Code:
...
$WebsiteName = "foo";
...


And the file im using has this:

Code:
...
require 'vars.sub'
...
print $WebsiteName;
...


The only problem is that, with 'use strict' in there it doesn't work. Taking this out and it does. Having $vars.sub::WebsiteName just makes it print out ".sub::WebsiteName" (without the quotes).

Reply With Quote
  #2  
Old September 9th, 2001, 01:41 PM
Atrus's Avatar
Atrus Atrus is offline
yet another member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 262 Atrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Re: Referring variables in other places

Hi!

I've not tested this example, but I use a similar method in my projects.... What you do is introducing package names.

Code:
package Yoursite::Variables;
...
$WebsiteName = "foo";
...



Code:
package Yoursite::Printing;
...
require 'vars.sub'
...
print $Yoursite::Variables::WebsiteName;
...



You should continue requiring the subs by filename, this is less ambiguous. Package names you assign don't need to be hierarchical also they don't need to resemble your directory structure. Just be creative. This should allow using strict again.

Regards,

Atrus.
__________________
Webmaster - Stefan Meier KG TABAKWAREN - Pfeifen, Premium-Zigarren, ... (_Ger)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Referring variables in other places


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT