[30068] in Perl-Users-Digest
Perl-Users Digest, Issue: 1311 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 26 16:09:49 2008
Date: Tue, 26 Feb 2008 13:09:11 -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 Tue, 26 Feb 2008 Volume: 11 Number: 1311
Today's topics:
a very simplistic example of a perl module <Benson.Hoi@googlemail.com>
Re: a very simplistic example of a perl module xhoster@gmail.com
Re: a very simplistic example of a perl module <Benson.Hoi@googlemail.com>
Re: a very simplistic example of a perl module xhoster@gmail.com
basic use of modules <Benson.Hoi@googlemail.com>
Re: basic use of modules <ben@morrow.me.uk>
Re: basic use of modules <Benson.Hoi@googlemail.com>
Re: basic use of modules <tzz@lifelogs.com>
Re: How to quote a semicolon? <thanatos@tartaros>
How to set file attributes <John.Smith@invalid.com>
Re: How to set file attributes <glex_no-spam@qwest-spam-no.invalid>
Re: How to set file attributes <joost@zeekat.nl>
Re: How to set file attributes <jimsgibson@gmail.com>
Re: How to set file attributes <tony_curtis32@yahoo.com>
Re: Processing workload distribution <smallpond@juno.com>
Re: Threading NOT working as expected <tzz@lifelogs.com>
Re: uc() and utf8 <ben@morrow.me.uk>
Re: uc() and utf8 <stoupa@practisoft.cz>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 26 Feb 2008 11:02:04 -0800 (PST)
From: BH <Benson.Hoi@googlemail.com>
Subject: a very simplistic example of a perl module
Message-Id: <210f59c6-c2ec-4289-b073-26713270bf4b@c33g2000hsd.googlegroups.com>
Hi,
I would like to move some subroutines into a module, perlmod and other
tutorials online seem to provide too much detail. Can someone
demonstrate with a simple Module.pm which only have one subroutine and
how this module can be used please?
Regards,
BH
------------------------------
Date: 26 Feb 2008 19:18:12 GMT
From: xhoster@gmail.com
Subject: Re: a very simplistic example of a perl module
Message-Id: <20080226141814.681$Vw@newsreader.com>
BH <Benson.Hoi@googlemail.com> wrote:
> Hi,
>
> I would like to move some subroutines into a module, perlmod and other
> tutorials online seem to provide too much detail. Can someone
> demonstrate with a simple Module.pm which only have one subroutine and
> how this module can be used please?
>
> Regards,
>
> BH
Sure. But without without knowing some of the details (like package
namespaces, at least) you miss most of the benefit to be had from using
modules in the first place.
$ cat Foo.pm
sub foobar {
return "This is the return value";
};
1;
__END__
$ cat foo.pl
use strict;
use warnings;
use Foo;
print foobar();
__END__
$ perl -l foo.pl
This is the return value
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 26 Feb 2008 11:37:22 -0800 (PST)
From: BH <Benson.Hoi@googlemail.com>
Subject: Re: a very simplistic example of a perl module
Message-Id: <01009950-6fd6-421f-829e-0ae8322d8f47@e23g2000prf.googlegroups.com>
Thanks.
Can you add to the simple example another subroutine not to be
exported, as well as 2 variables, one to exported and one not to be?
Regards,
BH
On Feb 26, 7:18=A0pm, xhos...@gmail.com wrote:
> BH <Benson....@googlemail.com> wrote:
> > Hi,
>
> > I would like to move some subroutines into a module, perlmod and other
> > tutorials online seem to provide too much detail. Can someone
> > demonstrate with a simple Module.pm which only have one subroutine and
> > how this module can be used please?
>
> > Regards,
>
> > BH
>
> Sure. =A0But without without knowing some of the details (like package
> namespaces, at least) you miss most of the benefit to be had from using
> modules in the first place.
>
> $ cat Foo.pm
> sub foobar {
> =A0 return "This is the return value";};
>
> 1;
> __END__
>
> $ cat foo.pl
> use strict;
> use warnings;
> use Foo;
> print foobar();
> __END__
>
> $ perl -l foo.pl
> This is the return value
>
> Xho
>
> --
> --------------------http://NewsReader.Com/--------------------
> The costs of publication of this article were defrayed in part by the
> payment of page charges. This article must therefore be hereby marked
> advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate=
> this fact.
------------------------------
Date: 26 Feb 2008 19:51:15 GMT
From: xhoster@gmail.com
Subject: Re: a very simplistic example of a perl module
Message-Id: <20080226145117.301$KE@newsreader.com>
BH <Benson.Hoi@googlemail.com> wrote:
> Thanks.
>
> Can you add to the simple example another subroutine not to be
> exported,
No. Exporting is one of those details you didn't want to bother with.
If you now want to bother with it, then go back to reading the docs
you gave up on. I'm going to read them to you.
> as well as 2 variables, one to exported and one not to be?
Who will receive credit for your homework, me or you?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 26 Feb 2008 07:28:19 -0800 (PST)
From: BH <Benson.Hoi@googlemail.com>
Subject: basic use of modules
Message-Id: <e897a909-fea5-4ae8-9256-75c279434c7f@u69g2000hse.googlegroups.com>
Hi,
I am reading from a spreadsheet using Spreadsheet::BasicRead, I have
got a big list of variables using saying which header is in which
column. I want to store these in another file.
How do I do this?
e.g.
require "constants.pl";
use spreadsheet_constrants;
Which one is better practice?
I tried the 2nd option, however I got the error "variable xxx is not
imported". Why? What does it mean? What's the usual cause?
Regards,
BH
------------------------------
Date: Tue, 26 Feb 2008 15:47:38 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: basic use of modules
Message-Id: <qtod95-us5.ln1@osiris.mauzo.dyndns.org>
Quoth BH <Benson.Hoi@googlemail.com>:
>
> I am reading from a spreadsheet using Spreadsheet::BasicRead, I have
> got a big list of variables using saying which header is in which
> column. I want to store these in another file.
>
> How do I do this?
>
> e.g.
> require "constants.pl";
>
> use spreadsheet_constrants;
>
> Which one is better practice?
The second. However, you may find it more awkward if you really want a
big list of variables to import. A better option would be to put these
constants into a single hash, instead, and then import that; a third
would be to use the 'constant' module to define proper named constants.
> I tried the 2nd option, however I got the error "variable xxx is not
> imported". Why? What does it mean? What's the usual cause?
You need to read perldoc perlmod, and then probably perldoc Exporter.
Post again if you don't understand those two documents.
Ben
------------------------------
Date: Tue, 26 Feb 2008 07:54:21 -0800 (PST)
From: BH <Benson.Hoi@googlemail.com>
Subject: Re: basic use of modules
Message-Id: <1aafa139-0d48-4293-a2ea-289f4f7bc689@d4g2000prg.googlegroups.com>
Thanks a lot.
On Feb 26, 3:47=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth BH <Benson....@googlemail.com>:
>
>
>
> > I am reading from a spreadsheet using Spreadsheet::BasicRead, I have
> > got a big list of variables using saying which header is in which
> > column. I want to store these in another file.
>
> > How do I do this?
>
> > e.g.
> > require "constants.pl";
>
> > use spreadsheet_constrants;
>
> > Which one is better practice?
>
> The second. However, you may find it more awkward if you really want a
> big list of variables to import. A better option would be to put these
> constants into a single hash, instead, and then import that; a third
> would be to use the 'constant' module to define proper named constants.
>
> > I tried the 2nd option, however I got the error "variable xxx is not
> > imported". Why? What does it mean? What's the usual cause?
>
> You need to read perldoc perlmod, and then probably perldoc Exporter.
> Post again if you don't understand those two documents.
>
> Ben
------------------------------
Date: Tue, 26 Feb 2008 12:35:03 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: basic use of modules
Message-Id: <86ir0btvl4.fsf@lifelogs.com>
On Tue, 26 Feb 2008 15:47:38 +0000 Ben Morrow <ben@morrow.me.uk> wrote:
BM> Quoth BH <Benson.Hoi@googlemail.com>:
>>
>> I am reading from a spreadsheet using Spreadsheet::BasicRead, I have
>> got a big list of variables using saying which header is in which
>> column. I want to store these in another file.
>>
>> How do I do this?
>>
>> e.g.
>> require "constants.pl";
>>
>> use spreadsheet_constrants;
>>
>> Which one is better practice?
BM> The second. However, you may find it more awkward if you really want a
BM> big list of variables to import. A better option would be to put these
BM> constants into a single hash, instead, and then import that; a third
BM> would be to use the 'constant' module to define proper named constants.
The OP could put all that data in a file (YAML, XML, CSV, etc). It
would be faster on load too, if the list is big. I can't tell the OP
what format to use since I don't know how the header name and the column
name are defined, but probably even something as simple as
1 name
2 address
3 zip code
in a plain text file would work, to be processed with
split " ", $line, 2;
I've said it before and I'll say it again, storing pure data in code is
a bad idea, especially if the data structure is simple.
Ted
------------------------------
Date: Tue, 26 Feb 2008 14:22:32 +0100
From: Thanatos <thanatos@tartaros>
Subject: Re: How to quote a semicolon?
Message-Id: <47c41299$0$12088$e4fe514c@dreader30.news.xs4all.nl>
The sentient life form BH posted the following:
> How to quote a semicolon?
Don't...
--
T.
------------------------------
Date: Tue, 26 Feb 2008 22:25:45 +0200
From: John <John.Smith@invalid.com>
Subject: How to set file attributes
Message-Id: <38t8s3550b7tipdjlg66u2ddmv8683k15v@4ax.com>
I have set up my own counter.pl on my web page.
The counter saves the visitation count to a text file called "count.txt".
How do I create the file (and later open) with file attributes that prevent
others reading the file, ie. going to www.johnsmith.com/count.txt (the www here
is not real).
------------------------------
Date: Tue, 26 Feb 2008 14:37:13 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: How to set file attributes
Message-Id: <47c4787a$0$37682$815e3792@news.qwest.net>
John wrote:
> I have set up my own counter.pl on my web page.
Congratulations, you've just wasted a few hours of your time. :-)
perldoc -q "I still don't get locking."
>
> The counter saves the visitation count to a text file called "count.txt".
> How do I create the file (and later open) with file attributes that prevent
> others reading the file, ie. going to www.johnsmith.com/count.txt (the www here
> is not real).
Nothing to do with perl. Only files under the DOCUMENT_ROOT are
typically viewable, so write 'count.txt' to another directory,
like /tmp.
------------------------------
Date: Tue, 26 Feb 2008 21:40:47 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: How to set file attributes
Message-Id: <87ir0b8n8w.fsf@zeekat.nl>
John <John.Smith@invalid.com> writes:
> I have set up my own counter.pl on my web page.
>
> The counter saves the visitation count to a text file called
> "count.txt". How do I create the file (and later open) with file
> attributes that prevent others reading the file, ie. going to
> www.johnsmith.com/count.txt (the www here is not real).
Unless you've got some special setup, evey visitor to the site runs as
the same user (whatever the webserver runs at). That means that if your
server code can read and write the file, then so can the webserver
itself.
What you want to do is prevent the file from being served to the
web. One way to do that is to put it outside the publically accessible
file tree(s). Another is to explicitly block it using whatever
mechanism your webserver provides.
For the latter approach on apache, you can use mod_access. See also:
<http://www.ducea.com/2006/07/21/apache-tips-tricks-deny-access-to-
certain-file-types/>
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Tue, 26 Feb 2008 12:46:15 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: How to set file attributes
Message-Id: <260220081246153203%jimsgibson@gmail.com>
In article <38t8s3550b7tipdjlg66u2ddmv8683k15v@4ax.com>, John
<John.Smith@invalid.com> wrote:
> I have set up my own counter.pl on my web page.
>
> The counter saves the visitation count to a text file called "count.txt".
> How do I create the file (and later open) with file attributes that prevent
> others reading the file, ie. going to www.johnsmith.com/count.txt (the www
> here
> is not real).
It depends upon the operating system. Under Unix, you would create the
file with an editor, the cat command, or the touch command (see 'man
cat', etc.). File permissions are set with the chmod command. You want
to set the file so that it is readable and writable only by the owner:
chmod 0600 count.txt
The problem is that for this to work, the file needs to be owned by the
web server process, and that may not be your own user id. Some web
servers use the user 'nobody', for example. As a result, you sometimes
have to set data files to be world writable:
chmod 0666 count.txt
So it also depends upon your user id, the web server's id, and whether
or not you have root privilege.
If you do have root privilege, then you can set the owner of the file
as well as the file permissions (as above):
chown nobody:nobody count.txt
chmod 0600 count.txt
But this is for Unix, not necessarily other operating systems.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Tue, 26 Feb 2008 15:48:26 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: How to set file attributes
Message-Id: <fq1tur$mc7$1@knot.queensu.ca>
J. Gleixner wrote:
> Nothing to do with perl. Only files under the DOCUMENT_ROOT are
> typically viewable, so write 'count.txt' to another directory,
> like /tmp.
Off-topic, but.../tmp could easily be memory-based, so I wouldn't write
there.
hth
t
------------------------------
Date: Tue, 26 Feb 2008 06:23:27 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Processing workload distribution
Message-Id: <1432e64c-c7ac-4e26-a15a-7264e10ba8ae@n75g2000hsh.googlegroups.com>
On Feb 26, 1:45 am, xhos...@gmail.com wrote:
> smallpond <smallp...@juno.com> wrote:
> > On Feb 25, 5:44 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > > Quoth smallpond <smallp...@juno.com>:
>
> > The post is about this exact problem and a poster suggests
> > checking usemultiplicity.
>
> I was that poster, and what I tentatively suggested was that
> multiplicity looked kind of odd and perhaps should be looked into
> as we had run out of more concrete ideas. Sometimes we bounce
> ideas off each other here, which are intended to be less than the Word
> of God.
>
> Xho
>
> --
> --------------------http://NewsReader.Com/--------------------
> The costs of publication of this article were defrayed in part by the
> payment of page charges. This article must therefore be hereby marked
> advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
> this fact.
and it looked like a good shot to me since the perl docs weren't
much help.
--S
------------------------------
Date: Tue, 26 Feb 2008 10:39:31 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Threading NOT working as expected
Message-Id: <86bq63vfi4.fsf@lifelogs.com>
On Mon, 25 Feb 2008 12:05:09 -0800 (PST) Ted <r.ted.byers@rogers.com> wrote:
T> Yes, I have done enough multithreaded programming (in C++ and Java) to
T> know that on a single core single processor machine, only one thread
T> runs at a time. There is, then, little advantage, for most of my
T> programming to do multithreaded development. However, my present
T> development machine has a dual core processor, and the server I'm
T> working with has a quad core processor. So, on my own machine, two
T> threads ought to be running concurrently and on the server, that would
T> be four concurrent threads.
This is incorrect. A modern single processor will perform well in a
multithreaded application. Just because a single thread will run
doesn't mean a single thread is doing work at any time.
Most of the time in a modern system is spent waiting for I/O and memory
access. There are some very special cases where the CPU is actually
tied up while the application runs, but memory and disk speeds have
fallen far behind CPU speeds so the CPU will usually be waiting for
something to happen. This is why modern CPUs have ridiculously large L1
and L2 caches and many prefetching optimizations.
In a multithreaded setup, the CPU has a chance to run several threads
while memory and I/O fetches are happening.
Equating threads with number of processors is both inefficient and
misguided. Let the OS worry about scheduling resources, processes, and
threads. Just write your code to use as many threads as it absolutely
needs.
Ted
------------------------------
Date: Tue, 26 Feb 2008 11:40:27 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: uc() and utf8
Message-Id: <bead95-ds2.ln1@osiris.mauzo.dyndns.org>
Quoth Alex <check.sig@for.email.invalid>:
>
> I suggest you also look into, and play around with, the functions
> is_utf8(), _utf8_on(), _utf8_off() and from_to(). This will give you a
> good overall picture of how Perl does UTF-8, but you probably won't need
> these here.
No, don't touch any of the functions in the utf8:: namespace. They are
part of the internals of perl's Unicode implementation, and shouldn't be
used by ordinary Perl code; especially _utf8_{on,off}. Use the functions
in Encode:: instead. Note also that from_to gives you a non-character
string as output: if you want to manipulate the characters from Perl,
you should use decode, and then encode to your desired output encoding
when you've done.
> > #!/usr/bin/perl
> > use strict;
> > use utf8;
> > use Unicode::Lite;
use Encode qw/encode decode/;
> > # string in cp1250 codepage
> > my $wintxt="\xec\x9a\xe8\xf8\x9e\xfd\xe1\xed\xe9";
> >
> > # convert to utf8
> > my $utftxt=convert('CP1250','UTF8',$wintxt);
my $txt = decode CP1250 => $wintxt;
> > print "<br>Win: $wintxt, ",uc($wintxt),"<br>utf8:$utftxt, ",uc($utftxt),"\n";
You can't 'uc' $wintxt: it is a binary string, not a character string,
so the operation is fairly meaningless (the fact perl will actually do
something fairly sensible is not a reason to rely on that). If you
*really* want mixed CP1250/UTF8 output, you need to do something like
my $uctxt = uc $txt;
printf '<br>Win: %s, %s<br>utf8: %s, %s\n',
encode(CP1250 => $txt),
encode(CP1250 => $uctxt),
encode(utf8 => $txt),
encode(CP1250 => $uctxt);
but more likely you want to pick one encoding and stick to it. In that
case you can get perl to do the encoding for you with and :encoding
PerlIO layer (see PerlIO::encoding).
Ben
------------------------------
Date: Tue, 26 Feb 2008 14:50:26 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: uc() and utf8
Message-Id: <fq15jp$172d$3@ns.felk.cvut.cz>
Ben Morrow wrote:
> Quoth Alex <check.sig@for.email.invalid>:
>>
>>> use strict;
>>> use utf8;
>>> use Unicode::Lite;
>
> use Encode qw/encode decode/;
>
>>> # string in cp1250 codepage
>>> my $wintxt="\xec\x9a\xe8\xf8\x9e\xfd\xe1\xed\xe9";
>>>
>>> # convert to utf8
>>> my $utftxt=convert('CP1250','UTF8',$wintxt);
>
> my $txt = decode CP1250 => $wintxt;
>
>>> print "<br>Win: $wintxt, ",uc($wintxt),"<br>utf8:$utftxt,
>>> ",uc($utftxt),"\n";
>
> You can't 'uc' $wintxt: it is a binary string, not a character string,
> so the operation is fairly meaningless (the fact perl will actually do
> something fairly sensible is not a reason to rely on that). If you
> *really* want mixed CP1250/UTF8 output, you need to do something like
>
Thank you for response.
My data source is in cp1250 so I *really* need to use this codepage. I want to
read data (in cp1250), convert it *as is* to utf8 and now use uc() or lc().
Mean you this code will work properly?
use strict;
use utf8;
use Encode qw/encode decode/;
# string in cp1250 codepage
my $wintxt="\xec\x9a\xe8\xf8\x9e\xfd\xe1\xed\xe9";
# convert to utf8
my $utftxt = Encode::decode( 'CP1250', $wintxt );
print "<br>utf8:$utftxt, " uppercase utf8: ", uc($utftxt), "\n";
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
------------------------------
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 1311
***************************************