On Fri, 4 Jan 2002, Connie Chan wrote: > I 've read some doc about the difference of require and use... > but I don't know what exactly that all means ?... what is run > time and what is compile time ? all I hope to know is..... > which one will be faster and cost the minium loading vs time & > to the system, for a 1 time process. >
One cool thing about 'require' is that you can read in files with it (like config files), that may have been created with real perl data structures, like Data::Dumper. Example: create a mysql.config file: #!/usr/bin/perl -w use strict; use Data::Dumper; my $href = { db_database_dsn => 'dbi:mysql:database=FOO;host=localhost', db_user => 'foo', db_pass => 'bar' }; open (F, ">mysql.config") or die "couldn't open file: $!"; print F Dumper $href; ---- then run this script and it creates a file that looks like this: $VAR1 = { 'db_user' => 'foo', 'db_pass' => 'bar', 'db_database_dsn' => 'dbi:mysql:database=FOO;host=localhost' }; ---- then (and this is the cool part), you can 'require' this file and assign it to a scalar (which actually becomes a hash_ref because that's what your data structure is: #!/usr/bin/perl -w use strict; #require 'eval's the file my $config = require "mysql.config"; #now $config is a hashref with your config directives print $config->{'db_user'}; print $config->{'db_pass'}; this of course one small useful feature of 'require'. I would say, in general though, you want to use 'use'. And of course, read the perldocs on both :) Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]