[31068] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2313 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 1 16:09:47 2009

Date: Wed, 1 Apr 2009 13:09:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 1 Apr 2009     Volume: 11 Number: 2313

Today's topics:
    Re: bareword question <tzz@lifelogs.com>
    Re: database advice <klaus03@gmail.com>
    Re: database advice <a_person@anyolddomain.fake>
    Re: database advice <bugbear@trim_papermule.co.uk_trim>
    Re: database advice <bugbear@trim_papermule.co.uk_trim>
    Re: database advice <smallpond@juno.com>
    Re: database advice <cartercc@gmail.com>
    Re: database advice <cartercc@gmail.com>
    Re: finding maximum <tzz@lifelogs.com>
    Re: finding maximum <nospam@nospam.com>
    Re: finding maximum (hymie!)
    Re: finding maximum <dcorbit@connx.com>
    Re: Interpreting terminal codes in Perl <m@rtij.nl.invlalid>
    Re: Script Execution time and Use <a_person@anyolddomain.fake>
    Re: Script Execution time and Use <matteo.corti@gmail.com>
    Re: Script Execution time and Use <noreply@gunnar.cc>
    Re: Script Execution time and Use <a_person@anyolddomain.fake>
    Re: Script Execution time and Use <a_person@anyolddomain.fake>
    Re: Script Execution time and Use <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 01 Apr 2009 13:19:42 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: bareword question
Message-Id: <86vdpo9qyp.fsf@lifelogs.com>

On Mon, 30 Mar 2009 09:39:25 -0700 (PDT) DaLoverhino <DaLoveRhino@hotmail.com> wrote: 

D> I have a function that takes an array of quoted words:

D> use strict;
D> use warnings;
D> my_function( "hello", "world!");

D> I can do this:

D> my_function qq(hello world!);

D> is there anyway to tell perl, that any barewords after my_function
D> (and my_function alone) should be treated as quoted words?  So that I
D> can just simply do this:

D> my_function(hello world!);

Make the parameters a string and split it on space in the function.

use Data::Dumper;

my_function("hello world!");
my_function(qw/hello world/);

sub my_function
{
 my $p = shift @_;
 my @p;
 if (scalar @_)
 {
  @p = ($p, @_);
 }
 else
 {
  @p = split ' ', $p;
 }

 print "Parameters = " . Dumper(\@p);
}

Produces:

Parameters = $VAR1 = [
          'hello',
          'world!'
        ];
Parameters = $VAR1 = [
          'hello',
          'world'
        ];

Doing it the way you suggest is unnecessary obfuscation.

Ted


------------------------------

Date: Wed, 1 Apr 2009 08:30:49 -0700 (PDT)
From: Klaus <klaus03@gmail.com>
Subject: Re: database advice
Message-Id: <cf42c187-a050-41a7-90f0-f43209d44b0f@f19g2000yqo.googlegroups.com>

On Apr 1, 4:49=A0pm, ccc31807 <carte...@gmail.com> wrote:
> I'm building a database app (in Perl) and ...

[ snip non-perl related stuff ]

> ... I will append values
> to this colum in a CSV format, such as (e.g.) "broken finger|headache|
> sprained ankle|influenza". I can then access this cell as a string,
> split on the pipe, and manipulate the resulting list as an array.
>
> Has anyone done this? Does it work? What are the disadvantages?
> Comments in general?

perldoc -f split

--
klaus


------------------------------

Date: Wed, 1 Apr 2009 16:27:47 +0100
From: "Bigus" <a_person@anyolddomain.fake>
Subject: Re: database advice
Message-Id: <rTLAl.131683$RJ7.89549@newsfe18.iad>


"ccc31807" <cartercc@gmail.com> wrote in message 
news:82b7e6a3-68ec-4f4c-afc3-b74119bf7ae7@z19g2000yqe.googlegroups.com...

> My client insists on using MySQL. I'm about to create a table, which
> has a column 'diagnoses' and a datatype of text. I will append values
> to this colum in a CSV format, such as (e.g.) "broken finger|headache|
> sprained ankle|influenza". I can then access this cell as a string,
> split on the pipe, and manipulate the resulting list as an array.

My only comment is an alternative suggestion to the above bit. That is, 
rather than storing as a string and splitting up etc, you could freeze the 
array and store in a binary blob.

e.g. something like this:

use Storable qw(freeze thaw);
my @array = (1,2,3,4);
my $frozenarray = freeze(@array);
[code to store $frozenarray in the blob field]

then after you've retrieved the frozen array from the database and back into 
$frozenarray

my $thawedarrayref = thaw($frozenarray);
my @array = @$thawedarrayref;

at least that way you are preserving your array structure and I guess a blob 
is more space efficient than a text field?

Regards
Bigus 




------------------------------

Date: Wed, 01 Apr 2009 16:58:27 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: database advice
Message-Id: <Bf-dnVZih6G-Ek7UnZ2dnUVZ8s-WnZ2d@posted.plusnet>

ccc31807 wrote:
> I'm building a database app (in Perl) and have a database question.
> 
> Ordinarily, when you have a many to many relationship, such as patient/
> diagnosis, you deal with it by having a conversion table, where (for
> example) patients are not unique, diagnoses are not unique, but a
> patient/diagnosis combination is unique.
> 
> I my app, I have this situation, but this approach seems to cumbersome
> and I quite frankly think it will take too much of an effort for the
> little bit of utility that I need

It sounds trivial - I would simply spend the effort to "do it right"
(which in this case means the three tables you mention)
rather than expend effort in trying to find a shortcut.

    BugBear


------------------------------

Date: Wed, 01 Apr 2009 16:59:29 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: database advice
Message-Id: <Bf-dnVFih6H8Ek7UnZ2dnUVZ8s8LAAAA@posted.plusnet>

ccc31807 wrote:
> I'm building a database app (in Perl) and have a database question.
> 
> Ordinarily, when you have a many to many relationship, such as patient/
> diagnosis, you deal with it by having a conversion table, where (for
> example) patients are not unique, diagnoses are not unique, but a
> patient/diagnosis combination is unique.
> 
> I my app, I have this situation, but this approach seems to cumbersome
> and I quite frankly think it will take too much of an effort for the
> little bit of utility that I need, because I don't need to access
> diagnoses, just display them, and only display them on infrequent
> occasions. I've been using Postgres and have been spoiled by the array
> datatype that PG has. If I were using PG, I'd use the array datatype.
> (One problem is that the diagnoses are free form and it's just too
> difficult to shoe-horn a multiplicity of diagnoses into a manageable
> number.)
> 
> My client insists on using MySQL. I'm about to create a table, which
> has a column 'diagnoses' and a datatype of text. I will append values
> to this colum in a CSV format, such as (e.g.) "broken finger|headache|
> sprained ankle|influenza". I can then access this cell as a string,
> split on the pipe, and manipulate the resulting list as an array.


How would you find all patients who've had (e.g.) "headache" ?

Or (harder) had headache AND influenza ?

   BugBear


------------------------------

Date: Wed, 1 Apr 2009 09:06:31 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: database advice
Message-Id: <2d2f833a-b156-4029-8f73-6087d9d0a37c@f32g2000vbf.googlegroups.com>

On Apr 1, 10:49=A0am, ccc31807 <carte...@gmail.com> wrote:
> I'm building a database app (in Perl) and have a database question.
>
> Ordinarily, when you have a many to many relationship, such as patient/
> diagnosis, you deal with it by having a conversion table, where (for
> example) patients are not unique, diagnoses are not unique, but a
> patient/diagnosis combination is unique.
>

Wow.  A patient can never get the same injury or illness
twice?  That's news to me.  You might want to ask a few
folks with chronic illnesses about that.  I know people
who have been in the emergency room twice in the same
day for the same thing.

Why do you care if it's unique?  Surely you aren't making
the beginner mistake of not creating unique keys for your
DB rows are you?


<snip>
>
> My client insists on using MySQL. I'm about to create a table, which
> has a column 'diagnoses' and a datatype of text. I will append values
> to this colum in a CSV format, such as (e.g.) "broken finger|headache|
> sprained ankle|influenza". I can then access this cell as a string,
> split on the pipe, and manipulate the resulting list as an array.
>
> Has anyone done this? Does it work? What are the disadvantages?
> Comments in general?
>
> Thanks, CC.


What happens when they enter "sprained  ankle"?
Is that different from "sprained ankle"?
(the first one has two spaces)

Do you ever expect to select on diagnosis?
fuhgeddaboutit with this scheme.
Searching every record for a matching text string
is much slower than selecting just records with a
matching field.

How about three tables:
  Diagnoses - row created every time a new value is used
  Patient - created by whatever form creates a patient
  Ailments - row created for each patient/diagnosis event

The poor guy in your example would get one Patients record
and 4 Ailments rows linked to existing or newly
created Diagnoses.  The key for the Diagnoses would be the
standard insurance company billing codes.  They don't
want to see "sprained ankle" they want something
like "3772".


------------------------------

Date: Wed, 1 Apr 2009 09:08:14 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: database advice
Message-Id: <4757bbc0-d328-4bec-8d65-36fd66645621@r37g2000yqn.googlegroups.com>

On Apr 1, 11:58=A0am, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> It sounds trivial - I would simply spend the effort to "do it right"
> (which in this case means the three tables you mention)
> rather than expend effort in trying to find a shortcut.

I wish I could show you the data. The diagnoses are sometimes codes,
but more often transcribed from the physician notes. There possibly
could be more(!) discrete, individual diagnoses than patients!

In this case, IMO, 'doing it right' means doing it simply and cheaply
rather than following the rules.

Thoughts? Thanks for your input. CC


------------------------------

Date: Wed, 1 Apr 2009 11:17:10 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: database advice
Message-Id: <064f9d10-2d34-41c7-8121-33cfa6bbfbe2@y13g2000yqn.googlegroups.com>

On Apr 1, 12:06=A0pm, smallpond <smallp...@juno.com> wrote:
> Wow. =A0A patient can never get the same injury or illness
> twice? =A0That's news to me. =A0You might want to ask a few
> folks with chronic illnesses about that. =A0I know people
> who have been in the emergency room twice in the same
> day for the same thing.

Actually, these are 'accounts.' The unique datum is the account
balance, and that's tied to an an admission rather than a diagnosis or
an admit date. In fact, sometimes the data comes in with ALL(!) of the
data identical except for a diagnosis, so that the patient name,
hospital name, hospital account ID, etc., occupy multiple rows in the
data file, the only difference being the diagnosis.

> Why do you care if it's unique? =A0Surely you aren't making
> the beginner mistake of not creating unique keys for your
> DB rows are you?

I very frequently create tables without unique keys in my job, and I
don't consider that a beginner mistake. If you're processing data and
using a database to help, it doesn't matter if each row is distinct,
frex, if you're counting values, you expect many of the rows to be
identical so you can count them. Like anything else, how you handle
the data depends on what you want to do with it.


> What happens when they enter "sprained =A0ankle"?
> Is that different from "sprained ankle"?
> (the first one has two spaces)

Doesn't matter. The diagnosis is merely informational, and very rarely
accessed. I don't programatically manipulate this data, just display
it when requested. Actually, the app would probably work better
without the diagnosis, but the client wants it available to look at.

> Do you ever expect to select on diagnosis?

Never.

> fuhgeddaboutit with this scheme.
> Searching every record for a matching text string
> is much slower than selecting just records with a
> matching field.

As I said, they just want to look at it. I read records into a
hashref, so I can do something like this: $hashref->{$acctno}
{$diagnosis}.

> How about three tables:
> =A0 Diagnoses - row created every time a new value is used
> =A0 Patient - created by whatever form creates a patient
> =A0 Ailments - row created for each patient/diagnosis event

Yeah, this is the textbook solution. But it's much too much effort for
the reward, since I would never actually need to query the Ailments
table for anything -- except if I implemented the textbook solution.
As I said, I have used the PG array datatype to 'violate' first normal
form, such as by having columns like 'office hours' or 'academic
degrees.' Being able to violate first normal form can be quite helpful
on those occasions when you need to.

> The poor guy in your example would get one Patients record
> and 4 Ailments rows linked to existing or newly
> created Diagnoses. =A0The key for the Diagnoses would be the
> standard insurance company billing codes. =A0They don't
> want to see "sprained ankle" they want something
> like "3772".

Not a requirement for my app. The central component is something
called the 'original balance' which is tied to a particular
individual, hospital, and hospital account number. The diagnosis or
diagnoses are irrelevant to the purpose of the app, except they want
the info in the database.

I'm just being lazy and hubristic. ;-)

CC



------------------------------

Date: Wed, 01 Apr 2009 13:14:34 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: finding maximum
Message-Id: <86zlf09r79.fsf@lifelogs.com>

On Tue, 31 Mar 2009 23:13:09 +0100 sandeep <nospam@nospam.com> wrote: 

s> How would you find the maximum of
s> (a) two numbers
s> (b) a set of numbers
s> in idiomatic C? How would you do it in idiomatic Perl? 

In any language, you put the numbers in an array, sort the array, and
return the element at the top.  Similarly, to get the average, you sort
the array and then return the middle number (AKA the "median average").

In Perl sorting is even built into the language; in C unfortunately you
have to embed the Perl interpreter to get that kind of simplicity.

s> Use this as a basis for a discussion of the differences in expressive
s> power of the two languages.

We are programmers, sir.  Discussion does not become us.  We are always
right, even when we're wrong.

Ted


------------------------------

Date: Wed, 01 Apr 2009 19:15:44 +0100
From: sandeep <nospam@nospam.com>
Subject: Re: finding maximum
Message-Id: <gr0av7$7ti$1@aioe.org>

Friends ~

Thanks for the answers. Actually this is not a homework, I am just curious.

Anyways, here is my solution:

(a) in C:

int max(int a, int b)
{
  if(a>b)
    return a;
  return b;
}

in Perl:

sub max
{
  my $max = shift;
  for(@_) {
    $max=$_ if($_>$max) 
  }
  $max;
}


(b) in C:

#define NUMMAX (10)
int max(int a[NUMMAX])
{
  int max = -1;
  for(int i=0; i < NUMMAX;)
    if(a[i++]>max)
       max = a[i-1];
  return max;
}


In Perl: the solution for (a) still works.

Conclusion: Perl is more expressive as a simple function for two arguments
often generalizes to any list.

Best greetings
Sandeep


On Wed, 01 Apr 2009 01:18:57 +0300, Phil Carmody wrote:
> sandeep <nospam@nospam.com> writes:
>> Hello Friends ~
>>
>> How would you find the maximum of
>> (a) two numbers
>> (b) a set of numbers
>> in idiomatic C? How would you do it in idiomatic Perl? Use this as a basis
>> for a discussion of the differences in expressive power of the two
>> languages.
> 
> Can you let us have your teacher's email address, so that we
> can get your homework answers to him directly, to save you the 
> effort.
> 
> Phil



------------------------------

Date: Wed, 01 Apr 2009 18:26:21 GMT
From: hymie@lactose.homelinux.net (hymie!)
Subject: Re: finding maximum
Message-Id: <hlOAl.19040$qt1.7782@newsfe10.iad>

In our last episode, the evil Dr. Lacto had captured our hero,
  sandeep <nospam@nospam.com>, who said:
>>> (b) a set of numbers

>(b) in C:
>
>#define NUMMAX (10)

a "set of numbers" is not defined as having less than 10 elements

>  int max = -1;

I hope at least one of your numbers is positive.

>  for(int i=0; i < NUMMAX;)
>    if(a[i++]>max)
>       max = a[i-1];

Surely there's a more convoluted way to do this?

--hymie!    http://lactose.homelinux.net/~hymie    hymie@lactose.homelinux.net
------------------------ Without caffeine for 883 days ------------------------


------------------------------

Date: Wed, 1 Apr 2009 11:31:15 -0700 (PDT)
From: user923005 <dcorbit@connx.com>
Subject: Re: finding maximum
Message-Id: <c8d022f7-8fcc-42c3-8f66-66754c2c7e9f@b6g2000pre.googlegroups.com>

On Apr 1, 11:15=A0am, sandeep <nos...@nospam.com> wrote:
> Friends ~
>
> Thanks for the answers. Actually this is not a homework, I am just curiou=
s.
>
> Anyways, here is my solution:
>
> (a) in C:
>
> int max(int a, int b)
> {
> =A0 if(a>b)
> =A0 =A0 return a;
> =A0 return b;
>
> }
>
> in Perl:
>
> sub max
> {
> =A0 my $max =3D shift;
> =A0 for(@_) {
> =A0 =A0 $max=3D$_ if($_>$max)
> =A0 }
> =A0 $max;
>
> }
>
> (b) in C:
>
> #define NUMMAX (10)
> int max(int a[NUMMAX])
> {
> =A0 int max =3D -1;
> =A0 for(int i=3D0; i < NUMMAX;)
> =A0 =A0 if(a[i++]>max)
> =A0 =A0 =A0 =A0max =3D a[i-1];
> =A0 return max;
>
> }
>
> In Perl: the solution for (a) still works.
>
> Conclusion: Perl is more expressive as a simple function for two argument=
s
> often generalizes to any list.

If performance matters, C will probably be a little faster.
If your programmers who maintain the code are Perl programmers, then
Perl is the logical choice, and vice-versa.
In either case, unless you are processing a billion items, the
language choice does not matter much.
If a language is Turing complete (and most of them are) then something
simple like finding the max from a list can be done without much fuss.

Which language to choose to solve some programming problem usually
turns into a pissing match, especially when cross-posted to multiple
language groups.

For my opinion, I don't think either one is a better choice.

IMO-YMMV


------------------------------

Date: Wed, 1 Apr 2009 22:01:23 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Interpreting terminal codes in Perl
Message-Id: <pan.2009.04.01.20.01.23@rtij.nl.invlalid>

On Wed, 01 Apr 2009 09:20:46 +0100, RedGrittyBrick wrote:

> Martijn Lievaart wrote:
>> On Tue, 31 Mar 2009 08:07:39 +0200, Martijn Lievaart wrote:
>> 
> [translating terminal control codes to human readable descriptions]
>> 
>> I am currently encoding the full xterm set, I need to cover all the
>> cases, not just those described by terminfo/termcap (although that
>> covers 99.99% of the cases). In the end I hope to fully cover
>> xterm*/ansi*/vt*, and will do the rest through reversing the termcap.
>> 
>> 
> Yikes. ansi, sco-ansi, old sco-ansi, ansic, dosansi, hpansi ... vt52,
> vt102, vt105, vt125, ... vt220 ... what about all the emulators? That's
> hundreds, perhaps thousands of variants.
> 
> May I ask why you want to take on this enormous task? There must be a
> good reason, but I'm having trouble imagining what it might be.

Interpreting logged streams of terminal data. The emulation need not be 
perfect and many terminals can be grouped together. I guess that all 
ansi*/vt*/*xterm* can use one emulation or a few at most. Commands not 
implemented on a certain terminal are unlikely to occur in a stream using 
that terminal.

And yes, I know, it'll never be perfect. And I probably need to implement 
those few encountered in practice only which are for me probably 10 at 
most and all probably are some vt variant.

M4


------------------------------

Date: Wed, 1 Apr 2009 16:39:06 +0100
From: "Bigus" <a_person@anyolddomain.fake>
Subject: Re: Script Execution time and Use
Message-Id: <AULAl.131684$RJ7.80484@newsfe18.iad>


"Peter Makholm" <peter@makholm.net> wrote in message 
news:8763howq7o.fsf@vps1.hacking.dk...
> "Bigus" <a_person@anyolddomain.fake> writes:
>
>> use Devel::Timer;
>> my $t = Devel::Timer->new();
>> $t->mark("inits");
>> use strict;
>> use Modules::Init;
>> $t->mark("done init");
>> print $t->report();
>
> use-statements happens at compile time, so you really havn't any
> operations between you two marks.

I'm not sure I understand. I'm probably being thick but I thought Perl did 
the compilation first, so that it can check for syntax errors etc, and then 
subsequently runs the script which is when the timer command would be 
reporting at? 




------------------------------

Date: Wed, 1 Apr 2009 09:19:34 -0700 (PDT)
From: Teo <matteo.corti@gmail.com>
Subject: Re: Script Execution time and Use
Message-Id: <1cbcb6b8-f2a6-47e7-bb48-b6e1bb5315bd@y9g2000yqg.googlegroups.com>

On Apr 1, 5:39=A0pm, "Bigus" <a_per...@anyolddomain.fake> wrote:
> "Peter Makholm" <pe...@makholm.net> wrote in message
>
> news:8763howq7o.fsf@vps1.hacking.dk...
>
> > "Bigus" <a_per...@anyolddomain.fake> writes:
>
> >> use Devel::Timer;
> >> my $t =3D Devel::Timer->new();
> >> $t->mark("inits");
> >> use strict;
> >> use Modules::Init;
> >> $t->mark("done init");
> >> print $t->report();
>
> > use-statements happens at compile time, so you really havn't any
> > operations between you two marks.
>
> I'm not sure I understand. I'm probably being thick but I thought Perl di=
d
> the compilation first, so that it can check for syntax errors etc, and th=
en
> subsequently runs the script which is when the timer command would be
> reporting at?

Exacly: and when it compiles it also loads the modules specified by
'use'. Which means that when you execute the code the modules are
already loaded.

Matteo


------------------------------

Date: Wed, 01 Apr 2009 18:21:33 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Script Execution time and Use
Message-Id: <73hikmFuquiaU1@mid.individual.net>

Bigus wrote:
> 
> In Init.pm there are about 30 "use ..." lines. Using a basic test script 
> (test.pl) I enclosed the two lines above with a timer, ie:
> 
> use Devel::Timer;
> my $t = Devel::Timer->new();
> $t->mark("inits");
> use strict;
> use Modules::Init;
> $t->mark("done init");
> print $t->report();
> 
> That tells me that it took about 10 microseconds to run, which would be 
> great,

Exchange the line

     use Modules::Init;

for

     require Modules::Init;

and Devel::Timer will probably report a significantly longer time.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Wed, 1 Apr 2009 18:05:25 +0100
From: "Bigus" <a_person@anyolddomain.fake>
Subject: Re: Script Execution time and Use
Message-Id: <y9NAl.49781$mF1.41990@newsfe23.iad>

"Teo" <matteo.corti@gmail.com> wrote in message 
news:1cbcb6b8-f2a6-47e7-bb48-b6e1bb5315bd@y9g2000yqg.googlegroups.com...
>> I'm not sure I understand. I'm probably being thick but I thought Perl 
>> did
>> the compilation first, so that it can check for syntax errors etc, and 
>> then
>> subsequently runs the script which is when the timer command would be
>> reporting at?
>
> Exacly: and when it compiles it also loads the modules specified by
> 'use'. Which means that when you execute the code the modules are
> already loaded.

Oh I see, so it's already loaded the modules before it gets to running the 
script and thus the timer.. got it.. phew :-)

Thanks
Bigus 




------------------------------

Date: Wed, 1 Apr 2009 18:23:59 +0100
From: "Bigus" <a_person@anyolddomain.fake>
Subject: Re: Script Execution time and Use
Message-Id: <6rNAl.56758$eT1.38732@newsfe20.iad>


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message 
news:73hikmFuquiaU1@mid.individual.net...
> Bigus wrote:
>>
>> In Init.pm there are about 30 "use ..." lines. Using a basic test script 
>> (test.pl) I enclosed the two lines above with a timer, ie:
>>
>> use Devel::Timer;
>> my $t = Devel::Timer->new();
>> $t->mark("inits");
>> use strict;
>> use Modules::Init;
>> $t->mark("done init");
>> print $t->report();
>>
>> That tells me that it took about 10 microseconds to run, which would be 
>> great,
>
> Exchange the line
>
>     use Modules::Init;
>
> for
>
>     require Modules::Init;
>
> and Devel::Timer will probably report a significantly longer time.

Yes, you are quite right. So, 'require' loads the modules at run time, 
whereas 'use' loads them at compile time.

Thanks
Bigus 




------------------------------

Date: Wed, 01 Apr 2009 10:37:40 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Script Execution time and Use
Message-Id: <bg97t49in968jilgp6oe14l2kdc92n6nau@4ax.com>

"Bigus" <a_person@anyolddomain.fake> wrote:
>Yes, you are quite right. So, 'require' loads the modules at run time, 
>whereas 'use' loads them at compile time.

Why don't you simply check it out?

	perldoc -f use


jue


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2313
***************************************


home help back first fref pref prev next nref lref last post