[31453] in Perl-Users-Digest
Perl-Users Digest, Issue: 2705 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 3 18:09:43 2009
Date: Thu, 3 Dec 2009 15:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 3 Dec 2009 Volume: 11 Number: 2705
Today's topics:
Re: Good Golly Miss Molly Perl. Been so long. <m@rtij.nl.invlalid>
Re: i18n? <ben@morrow.me.uk>
Re: Join every two lines of a file <jurgenex@hotmail.com>
Re: Join every two lines of a file <nickli2000@gmail.com>
Re: Join every two lines of a file <tadmc@seesig.invalid>
Re: Join every two lines of a file <someone@example.com>
passing argument to a subroutine <cartercc@gmail.com>
Re: passing argument to a subroutine <jurgenex@hotmail.com>
Re: passing argument to a subroutine <willem@stack.nl>
Re: passing argument to a subroutine <glennj@ncf.ca>
Re: passing argument to a subroutine (Randal L. Schwartz)
Re: passing argument to a subroutine <OJZGSRPBZVCX@spammotel.com>
Re: passing argument to a subroutine <willem@stack.nl>
Re: passing argument to a subroutine <rvtol+usenet@xs4all.nl>
Re: passing argument to a subroutine <ben@morrow.me.uk>
Re: passing argument to a subroutine <OJZGSRPBZVCX@spammotel.com>
Re: passing argument to a subroutine <jurgenex@hotmail.com>
Re: passing argument to a subroutine <jurgenex@hotmail.com>
Re: perl compilers <john@castleamber.com>
Re: perl compilers <willem@stack.nl>
Re: perl compilers <ben@morrow.me.uk>
Re: perl compilers <spamtrap@shermpendley.com>
Scripts & Modules <a_person@anyolddomain.fake>
Re: Scripts & Modules <OJZGSRPBZVCX@spammotel.com>
Re: Scripts & Modules <a_person@anyolddomain.fake>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 3 Dec 2009 23:11:22 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Good Golly Miss Molly Perl. Been so long.
Message-Id: <alplu6-9le.ln1@news.rtij.nl>
On Thu, 03 Dec 2009 14:01:48 -0500, Shmuel (Seymour J.) Metz wrote:
> In <l51ju6-9le.ln1@news.rtij.nl>, on 12/02/2009
> at 10:01 PM, Martijn Lievaart <m@rtij.nl.invlalid> said:
>
>>Breaking out of multi level loops with next or last does not warrant
>>such
>> a comment imho.
>
> Do you consider those to be gotos? I don't.
This was about commenting all labels. Maybe the OP meant all labels
referred by a goto.
M4
------------------------------
Date: Thu, 3 Dec 2009 20:33:30 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: i18n?
Message-Id: <qtjlu6-sl31.ln1@osiris.mauzo.dyndns.org>
Quoth Klaus <klaus03@gmail.com>:
> On 2 déc, 11:52, Martin Str|mberg <a...@sister.ludd.luth.se> wrote:
> > I've been looking for i18n for perl so that I can't get error messages
> > in Swedish. I haven't found anything, not _any_ other language.
> >
> > Is there no such thing? Or have I just searched the wrong places or
> > for the wrong things?
>
> Have you looked on CPAN ?
>
> http://search.cpan.org/~audreyt/i18n-0.10/lib/i18n.pm
That is for module authors to use to internationalise their modules. It
doesn't help with the messages perl generates itself.
Ben
------------------------------
Date: Thu, 03 Dec 2009 08:33:02 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Join every two lines of a file
Message-Id: <4vpfh5l3jgu68n65308abgku5qvdhs3tbk@4ax.com>
Ninja Li <nickli2000@gmail.com> wrote:
>Hi,
>
> I am trying to join every two lines of the following using perl:
><td align="center" width="50"><nobr>AWR
> </nobr></td>
><td align="center" width="50"><nobr>ANH
> </nobr></td>
><td align="center" width="50"><nobr>ACAP
> </nobr></td>
>
> The output should be as follows:
> <td align="center" width="50"><nobr>AWR</nobr></td>
> <td align="center" width="50"><nobr>ANH</nobr></td>
> <td align="center" width="50"><nobr>ACAP</nobr></td>
>
> Is there an easy way to join every two lines while at the same time
>remove the " " characters in the line?
Pretty trivial. Which part do you have problems with? Designing the
algorithm? Translating the algorithm into Perl? Debugging the Perl
program? ...?
jue
------------------------------
Date: Thu, 3 Dec 2009 09:24:28 -0800 (PST)
From: Ninja Li <nickli2000@gmail.com>
Subject: Re: Join every two lines of a file
Message-Id: <7ec55850-336e-42e4-b354-d33a7bf29732@31g2000vbf.googlegroups.com>
I can join the lines by doing the following in awk:
awk '{ if ( ( NR % 2 ) == 0 ) { printf("%s\n",$0) } else { printf("%s
",$0) } }' filename
I am wondering if there is any one-liner similar to this in perl to
accomplish it.
Thanks.
Nick
------------------------------
Date: Thu, 03 Dec 2009 11:34:19 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Join every two lines of a file
Message-Id: <slrnhhftet.726.tadmc@tadbox.sbcglobal.net>
Ninja Li <nickli2000@gmail.com> wrote:
> I am trying to join every two lines of the following using perl:
><td align="center" width="50"><nobr>AWR
>  </nobr></td>
><td align="center" width="50"><nobr>ANH
>  </nobr></td>
><td align="center" width="50"><nobr>ACAP
>  </nobr></td>
>
> The output should be as follows:
> <td align="center" width="50"><nobr>AWR</nobr></td>
> <td align="center" width="50"><nobr>ANH</nobr></td>
> <td align="center" width="50"><nobr>ACAP</nobr></td>
>
> Is there an easy way to join every two lines while at the same time
> remove the " " characters in the line?
perl -pe 'chomp if $. % 2; s/ //g' somefile.html
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 03 Dec 2009 09:37:52 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: Join every two lines of a file
Message-Id: <UHSRm.78908$Xf2.32674@newsfe12.iad>
Ninja Li wrote:
> I can join the lines by doing the following in awk:
>
> awk '{ if ( ( NR % 2 ) == 0 ) { printf("%s\n",$0) } else { printf("%s
> ",$0) } }' filename
>
> I am wondering if there is any one-liner similar to this in perl to
> accomplish it.
perl -lpe'$\ = $. % 2 ? "" : "\n"' filename
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
------------------------------
Date: Thu, 3 Dec 2009 08:43:39 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: passing argument to a subroutine
Message-Id: <3fcde3da-6611-4db3-a755-a023512d93f1@g23g2000vbr.googlegroups.com>
If you call a sub like this:
some_sub($arg);
You can copy the argument like this:
sub some_sub
{
my $arg_copy = shift;
...
}
However, I've noticed that some BIG NAMES in the Perl community do
this:
my ($arg_copy) = @_;
Is there any real difference between the two? If so, what is the
difference?
CC.
------------------------------
Date: Thu, 03 Dec 2009 08:56:57 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: passing argument to a subroutine
Message-Id: <pbrfh5tf340o5jgt7sodnhfvc1qii8cngn@4ax.com>
ccc31807 <cartercc@gmail.com> wrote:
>If you call a sub like this:
>some_sub($arg);
>
>You can copy the argument like this:
>sub some_sub
>{
> my $arg_copy = shift;
> ...
>}
>
>However, I've noticed that some BIG NAMES in the Perl community do
>this:
> my ($arg_copy) = @_;
>
>Is there any real difference between the two? If so, what is the
>difference?
The first version consumes the first argument, i.e. it is gone from @_
after the shift.
The second version preserves the first argument, i.e. it is still
present in @_ after the assignment.
jue
------------------------------
Date: Thu, 3 Dec 2009 17:03:26 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: passing argument to a subroutine
Message-Id: <slrnhhfrqu.2fbl.willem@turtle.stack.nl>
ccc31807 wrote:
) If you call a sub like this:
) some_sub($arg);
)
) You can copy the argument like this:
) sub some_sub
) {
) my $arg_copy = shift;
) ...
) }
)
) However, I've noticed that some BIG NAMES in the Perl community do
) this:
) my ($arg_copy) = @_;
)
) Is there any real difference between the two? If so, what is the
) difference?
Technically speaking, the second form preserves the @_ array.
But I think the main reason is for consistency. Think about
the two above conventions in the case of, say, a five-arg function.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: 3 Dec 2009 17:05:23 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: passing argument to a subroutine
Message-Id: <slrnhhfruk.fc5.glennj@smeagol.ncf.ca>
At 2009-12-03 11:56AM, "Jürgen Exner" wrote:
> ccc31807 <cartercc@gmail.com> wrote:
> >If you call a sub like this:
> >some_sub($arg);
> >
> >You can copy the argument like this:
> >sub some_sub
> >{
> > my $arg_copy = shift;
> > ...
> >}
> >
> >However, I've noticed that some BIG NAMES in the Perl community do
> >this:
> > my ($arg_copy) = @_;
> >
> >Is there any real difference between the two? If so, what is the
> >difference?
>
> The first version consumes the first argument, i.e. it is gone from @_
> after the shift.
> The second version preserves the first argument, i.e. it is still
> present in @_ after the assignment.
I find the second version more maintainable: e.g. you find you need to
pass a second parameter to the sub.
Consider:
sub some_sub
{
my $first = shift;
my $second = shift;
# ...
versus
sub some_sub
{
my ($first, $second) = @_;
# ...
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Thu, 03 Dec 2009 09:29:58 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: passing argument to a subroutine
Message-Id: <86skbsaru1.fsf@blue.stonehenge.com>
>>>>> "ccc31807" == ccc31807 <cartercc@gmail.com> writes:
ccc31807> Is there any real difference between the two? If so, what is the
ccc31807> difference?
I use:
my $self = shift;
or
my $class = shift;
on instance and class methods, simply because the first parameter
is special. For the remaining arguments, I'm all over the map. :)
print "Just another Perl hacker,"; # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Thu, 03 Dec 2009 19:11:45 +0100
From: "Jochen Lehmeier" <OJZGSRPBZVCX@spammotel.com>
Subject: Re: passing argument to a subroutine
Message-Id: <op.u4djhvkqmk9oye@frodo>
On Thu, 03 Dec 2009 18:29:58 +0100, Randal L. Schwartz
<merlyn@stonehenge.com> wrote:
>>>>>> "ccc31807" == ccc31807 <cartercc@gmail.com> writes:
>
> ccc31807> Is there any real difference between the two? If so, what is
> the
> ccc31807> difference?
The difference is that "shift" is changing the array, while the assignment
does not.
So, if you're pedantic, you might ask why all those bytes have to be
shifted around just to get at the first argument.
I prefer "my ($a,$b,$c)=@_;" as well, because it does exactly what is
meant without any side effects or superflous shuffling of RAM. Also, it
looks *just* like the argument declarations in other languages ("void
xyz(int a,int b,int c)"), so is very clear to understand.
In class methods, I use
sub fn
{
my $self=shift @_;
my ($args...)=@_;
for no particular technical reason except that by doing this, after the
shift, @_ looks just like what the caller saw.
------------------------------
Date: Thu, 3 Dec 2009 19:36:09 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: passing argument to a subroutine
Message-Id: <slrnhhg4p9.2igk.willem@turtle.stack.nl>
Jochen Lehmeier wrote:
) In class methods, I use
)
) sub fn
) {
) my $self=shift @_;
) my ($args...)=@_;
)
) for no particular technical reason except that by doing this, after the
) shift, @_ looks just like what the caller saw.
And, additionally, you can do $self->foobar(@_) which (I think ?) will
find the method in a child object which inherited your package.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Thu, 03 Dec 2009 21:36:48 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: passing argument to a subroutine
Message-Id: <4b182160$0$22933$e4fe514c@news.xs4all.nl>
Willem wrote:
> Jochen Lehmeier wrote:
> ) In class methods, I use
> )
> ) sub fn
> ) {
> ) my $self=shift @_;
> ) my ($args...)=@_;
> )
> ) for no particular technical reason except that by doing this, after the
> ) shift, @_ looks just like what the caller saw.
>
> And, additionally, you can do $self->foobar(@_) which (I think ?) will
> find the method in a child object which inherited your package.
Variant:
shift->foobar(@_)
--
Ruud
------------------------------
Date: Thu, 3 Dec 2009 20:43:38 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: passing argument to a subroutine
Message-Id: <qgklu6-sl31.ln1@osiris.mauzo.dyndns.org>
Quoth "Jochen Lehmeier" <OJZGSRPBZVCX@spammotel.com>:
> On Thu, 03 Dec 2009 18:29:58 +0100, Randal L. Schwartz
> <merlyn@stonehenge.com> wrote:
>
> >>>>>> "ccc31807" == ccc31807 <cartercc@gmail.com> writes:
> >
> > ccc31807> Is there any real difference between the two? If so, what is
> > the
> > ccc31807> difference?
>
> The difference is that "shift" is changing the array, while the assignment
> does not.
>
> So, if you're pedantic, you might ask why all those bytes have to be
> shifted around just to get at the first argument.
All which bytes? shift on @_ is special-cased, since it's so common, to
do nothing more than adjust a pointer.
It is worth being aware that using any *other* array operation on @_
will mess up the stacktraces you get from Carp, sometimes in rather
strange ways:
~% perl -MCarp -e'sub foo { confess } foo 1, 2'
at -e line 1
main::foo(1, 2) called at -e line 1
~% perl -MCarp -e'sub foo { shift; confess } foo 1, 2'
at -e line 1
main::foo(1, 2) called at -e line 1
~% perl -MCarp -e'sub foo { pop; confess } foo 1, 2'
at -e line 1
main::foo(1) called at -e line 1
~% perl -MCarp -e'sub foo { unshift @_, 3; confess } foo 1, 2'
at -e line 1
main::foo(undef, 3, 1, 2) called at -e line 1
This also applies to the arguments received by any sub called with ⊂
or goto ⊂.
Ben
------------------------------
Date: Thu, 03 Dec 2009 22:01:01 +0100
From: "Jochen Lehmeier" <OJZGSRPBZVCX@spammotel.com>
Subject: Re: passing argument to a subroutine
Message-Id: <op.u4drbzjumk9oye@frodo>
On Thu, 03 Dec 2009 21:43:38 +0100, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth "Jochen Lehmeier" <OJZGSRPBZVCX@spammotel.com>:
>> On Thu, 03 Dec 2009 18:29:58 +0100, Randal L. Schwartz
>> <merlyn@stonehenge.com> wrote:
>>
>> >>>>>> "ccc31807" == ccc31807 <cartercc@gmail.com> writes:
>> >
>> > ccc31807> Is there any real difference between the two? If so, what is
>> > the
>> > ccc31807> difference?
>>
>> The difference is that "shift" is changing the array, while the
>> assignment
>> does not.
>>
>> So, if you're pedantic, you might ask why all those bytes have to be
>> shifted around just to get at the first argument.
>
> All which bytes? shift on @_ is special-cased, since it's so common, to
> do nothing more than adjust a pointer.
I love perl.
Performance aside, let me rephrase my answer:
"So, if you're pedantic, you might ask why the @_ array should be
modified just to get at the first argument."
Which is be the reason why I (and possibly others) use "my (...)=@_"
instead of "my $x=shift @_".
------------------------------
Date: Thu, 03 Dec 2009 13:05:44 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: passing argument to a subroutine
Message-Id: <bv9gh5tfb8908vct4p5881410cv1efqvfb@4ax.com>
"Jochen Lehmeier" <OJZGSRPBZVCX@spammotel.com> wrote:
>The difference is that "shift" is changing the array, while the assignment
>does not.
>
>So, if you're pedantic, you might ask why all those bytes have to be
>shifted around just to get at the first argument.
What bytes do you mean when talking about "bytes have to be shifted
around"?
>I prefer "my ($a,$b,$c)=@_;" as well, because it does exactly what is
>meant without any side effects or superflous shuffling of RAM. Also, it
What shuffling of RAM are you talking about?
jue
------------------------------
Date: Thu, 03 Dec 2009 13:15:08 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: passing argument to a subroutine
Message-Id: <l7agh550qn2h69curh2sbj0i7dcpin4bif@4ax.com>
"Jochen Lehmeier" <OJZGSRPBZVCX@spammotel.com> wrote:
>"So, if you're pedantic, you might ask why the @_ array should be
>modified just to get at the first argument."
A valid question. And depending upon your style an answer may be:
Because I got the first argument, I dealt with it, and now I want to
move on to the next argument.
This is particularly useful when you are dealing with a list of unknown
length, let's say an arbitrary number of filenames and each file needs
to be treated the same. Then just loop over shift(@_) until @_ is empty.
>Which is be the reason why I (and possibly others) use "my (...)=@_"
>instead of "my $x=shift @_".
Which is IMO a nice way to assign a meaningful name to each argument for
a known number of arguments.
jue
------------------------------
Date: Thu, 03 Dec 2009 14:01:27 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: perl compilers
Message-Id: <87vdgnaktk.fsf@castleamber.com>
Robin <robin1@cnsp.com> writes:
> Anyone know of any good perl compilers for windows. I have searched
> and found no good ones.
> robin
Maybe because there isn't any compiler (that I know of, other than the
perl built in one, which doesn't output an exe).
If you want to bundle your Perl program, modules, and other resources
into an exe, check out PAR: http://par.perl.org/wiki/Main_Page
--
John Bokma
Read my blog: http://johnbokma.com/
Hire me (Perl/Python): http://castleamber.com/
------------------------------
Date: Thu, 3 Dec 2009 20:26:12 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: perl compilers
Message-Id: <slrnhhg7n4.2jjd.willem@turtle.stack.nl>
John Bokma wrote:
) Robin <robin1@cnsp.com> writes:
)
)> Anyone know of any good perl compilers for windows. I have searched
)> and found no good ones.
)> robin
)
) Maybe because there isn't any compiler (that I know of, other than the
) perl built in one, which doesn't output an exe).
I thought ActiveState Perl outputted exe-s,
Or am I mistaken ?
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Thu, 3 Dec 2009 20:46:18 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: perl compilers
Message-Id: <qlklu6-sl31.ln1@osiris.mauzo.dyndns.org>
Quoth Willem <willem@stack.nl>:
> John Bokma wrote:
> ) Robin <robin1@cnsp.com> writes:
> )
> )> Anyone know of any good perl compilers for windows. I have searched
> )> and found no good ones.
> )> robin
> )
> ) Maybe because there isn't any compiler (that I know of, other than the
> ) perl built in one, which doesn't output an exe).
>
> I thought ActiveState Perl outputted exe-s,
> Or am I mistaken ?
ActiveState sell a program called perl2exe, which will make an exe from
a perl program. It's neither free nor Free, and I believe it does
essentially the smae thing as PAR.
Ben
------------------------------
Date: Thu, 03 Dec 2009 16:09:26 -0500
From: Sherm Pendley <spamtrap@shermpendley.com>
Subject: Re: perl compilers
Message-Id: <m2vdgnpxx5.fsf@shermpendley.com>
Willem <willem@stack.nl> writes:
> John Bokma wrote:
> ) Robin <robin1@cnsp.com> writes:
> )
> )> Anyone know of any good perl compilers for windows. I have searched
> )> and found no good ones.
> )> robin
> )
> ) Maybe because there isn't any compiler (that I know of, other than the
> ) perl built in one, which doesn't output an exe).
>
> I thought ActiveState Perl outputted exe-s,
> Or am I mistaken ?
You're not mistaken, but neither is that a compiler in the normal sense
of the word. It doesn't compile Perl into native machine code, it just
compresses and packages it into a standalone form that one can give to
a Windows user who hasn't installed Perl.
sherm--
------------------------------
Date: Thu, 3 Dec 2009 17:53:26 -0000
From: "Bigus" <a_person@anyolddomain.fake>
Subject: Scripts & Modules
Message-Id: <KWSRm.23404$gd1.16724@newsfe05.iad>
Hello
I would just like some clarification on "use"ing modules. Say we have the
following files on our system:
script1.cgi
module1.pm [contains sub - mod1function1()]
module2.pm [contains subs - mod2function1() and mod2function2()]
sciprt1.cgi has "use module1;" in it because it needs to call
mod1function1().
However, mod1function1() needs to call mod2function1(), so "use module2;" is
placed inside mod1function1().
At a later date script1.cgi needs to use mod2function2(). in addition to
mod1function1(), so "use module2;" is placed directly into script1.cgi.
So we now have a scenario where script1.cgi is loading both modules but when
mod1function1() is called it loads module1.pm again (or does it?)
That is a simple case but in reality our system has a dozen modules and
scores of scripts so it can be difficult keeping track of what modules are
loaded at any one time.
Is there a "best practise" in this kind of situation, when it comes to
loading modules?
Regards
Bigus
------------------------------
Date: Thu, 03 Dec 2009 19:06:28 +0100
From: "Jochen Lehmeier" <OJZGSRPBZVCX@spammotel.com>
Subject: Re: Scripts & Modules
Message-Id: <op.u4di82eqmk9oye@frodo>
On Thu, 03 Dec 2009 18:53:26 +0100, Bigus <a_person@anyolddomain.fake>
wrote:
> Is there a "best practise" in this kind of situation, when it comes to
> loading modules?
http://www.google.de/search?q=perldoc+use
"The ... makes sure the module is loaded into memory if it hasn't been
yet."
So, don't worry, just use "use" as much as you want to.
And, the usual way is to put the "use" statements at the top of the file,
not inside a function. Not that it matters, it just makes it easier to
read.
------------------------------
Date: Thu, 3 Dec 2009 22:21:58 -0000
From: "Bigus" <a_person@anyolddomain.fake>
Subject: Re: Scripts & Modules
Message-Id: <vSWRm.51520$X01.26633@newsfe07.iad>
"Jochen Lehmeier" <OJZGSRPBZVCX@spammotel.com> wrote in message
news:op.u4di82eqmk9oye@frodo...
> On Thu, 03 Dec 2009 18:53:26 +0100, Bigus <a_person@anyolddomain.fake>
> wrote:
>
>> Is there a "best practise" in this kind of situation, when it comes to
>> loading modules?
>
> http://www.google.de/search?q=perldoc+use
>
> "The ... makes sure the module is loaded into memory if it hasn't been
> yet."
>
> So, don't worry, just use "use" as much as you want to.
>
> And, the usual way is to put the "use" statements at the top of the file,
> not inside a function. Not that it matters, it just makes it easier to
> read.
Blimey, yes it's clicked now.. that perldoc doesn't make it all that clear
to me.
However, I created a test script with the lines:
use MyModule;
print time2str("%d %m %Y",time);
Then created MyModule.pm with these lines:
sub func1 {
use Date::Format;
}
1;
and ran the test script and it worked! So, basically modules loaded via
"use" have a kind of a global scope :-)
Thanks
Bigus
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2705
***************************************