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 October 18th, 2001, 10:14 AM
Maglight Maglight is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 67 Maglight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Getting data into an array from config-file?

Hi,

i do have a config-file with various single variables like:

$config{'name'} = "name";
$config{'city'} = "city";

and all works fine.

Now i need to enter more than one value into such a var like:

$config{'domains'} = "'yahoo.com','hotmail.com'";

If i use this hardcoded like:

my @domains = ('yahoo.com','hotmail.com');

everything works but if i use

my @domains = ($config{'domains'});

it fails ...

Where's my fault?

Reply With Quote
  #2  
Old October 18th, 2001, 10:43 AM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
Re: Getting data into an array from config-file?

Quote:
Originally posted by Maglight
Hi,

i do have a config-file with various single variables like:

$config{'name'} = "name";
$config{'city'} = "city";

and all works fine.

Now i need to enter more than one value into such a var like:

$config{'domains'} = "'yahoo.com','hotmail.com'";

If i use this hardcoded like:

my @domains = ('yahoo.com','hotmail.com');

everything works but if i use

my @domains = ($config{'domains'});

it fails ...

Where's my fault?


Need to make a few changes. In your config file change this:
$config{'domains'} = "'yahoo.com','hotmail.com'";
to this:
$config{'domains'} = ['yahoo.com','hotmail.com'];

then you can call you domains by
for my $domain (@{$config{'domains'}}) {
# do something here with each $domain
}
or
my @domain = @{$config{'domains'}};

but not necessary, arrays tend to use alot of resources if the array is large.. stores everything in direct memory.

this is know as referencing, works well for hash/array referencing.

Hope this helps

Mickalo
__________________

Thunder Rain Internet Publishing

Custom Programming & Database development
Providing Personal/Business
Internet Solutions that work!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Getting data into an array from config-file?


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