[26256] in Perl-Users-Digest
Perl-Users Digest, Issue: 8440 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 21 14:05:28 2005
Date: Wed, 21 Sep 2005 11:05:04 -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, 21 Sep 2005 Volume: 10 Number: 8440
Today's topics:
https with LWP::UserAgent <newsAT@screenlightDOT.com>
newbie, what is the best way to include common settings <info2005@remove-this-including-dot.bigbunker.com>
Re: newbie, what is the best way to include common sett <info2005@remove-this-including-dot.bigbunker.com>
Re: newbie, what is the best way to include common sett <djames@thehub.com.au>
Re: newbie, what is the best way to include common sett <josef.moellers@fujitsu-siemens.com>
Re: newbie, what is the best way to include common sett <nobull@mail.com>
Package to calculate time diff <sun_tong@users.sourceforge.net>
Re: Package to calculate time diff <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 21 Sep 2005 17:47:09 GMT
From: one man army <newsAT@screenlightDOT.com>
Subject: https with LWP::UserAgent
Message-Id: <newsAT-29564C.10490721092005@newsclstr02.news.prodigy.com>
Hi All-
I am an infrequent user of Perl, but have succeeded in a few endeavors.
I have a script that reads data from a series of web pages. But now I
want to modify it to handle an HTTPS page.
I looked briefly in UserAgent.pm, most of the code is beyond my skill
level. I found the lines:
use Carp ();
if ($ENV{PERL_LWP_USE_HTTP_10}) {
require LWP::Protocol::http10;
LWP::Protocol::implementor('http', 'LWP::Protocol::http10');
eval {
require LWP::Protocol::https10;
LWP::Protocol::implementor('https', 'LWP::Protocol::https10');
};
}
And there is an option described, $ua->protocols_allowed(). So I added
the following line after init'ing my $ua
$ua->protocols_allowed( [ 'http', 'https'] ); # to set
Alas, still an error connecting to the page. The very same urls pasted
in to Firefox result in no error.
What to do?
thanks much
------------------------------
Date: Wed, 21 Sep 2005 10:32:31 GMT
From: "Pritchie" <info2005@remove-this-including-dot.bigbunker.com>
Subject: newbie, what is the best way to include common settings.conf values
Message-Id: <3FaYe.10292$st1.5292@newsfe3-gui.ntli.net>
Hi
What is the best way to include common settings/values into a perl script?
in shell script you can have a file called "common-vars.sh" with
sMyVar="My string"
and call it from "MyProgram.sh" by
. ./common-vars.sh
echo ${sMyVar}
so when you run ./MyProgram.sh you get echoed back
My String
How can I do this in Perl? I want a common settings file for my database
details (database name, username, password etc)
eg.
my sDatabaseName="LoadsOfData";
my sDbUserName="LoadsOfData_User";
my sDbPassword="*****";
I then want too include this into a number of different perl scripts...
at the moment I am using a common shell file to hold these values as
environmental variable (see shell example above), which is called before
the
perl scripts. I then use ENV to import them into perl.
my $sDbSrv=$ENV{'sDbSrv'};
my $sDbName=$ENV{'sDbName'};
my $sDbUser=$ENV{'sDbUser'};
my $sDbUserPw=$ENV{'sDbUserPw'};
I am sure there's got to be a better way.
Thanks
Pritchie
------------------------------
Date: Wed, 21 Sep 2005 11:54:49 GMT
From: "Pritchie" <info2005@remove-this-including-dot.bigbunker.com>
Subject: Re: newbie, what is the best way to include common settings.conf values
Message-Id: <dSbYe.29711$Aa1.2508@newsfe5-gui.ntli.net>
ok so I now have 2 files in the same folder
==> START myvar.pm<==
print "my var: $sVar\n";
$sVar="Hello World";
==> END <==
and
==> START myperl.pl <==
#!/usr/bin/perl
my $sVar = "help";
require myvar;
print "sVar[".$sVar."]\n";
==> END <==
When I run myperl.pl I get the following
bash-3.00# perl ./myperl.pl
my var:
sVar[help]
I was hoping to get
my var:help
sVar[Hello World]
Am I missing something or can you not pass variables values for some
reason
using "use" or "require"?
Thanks
Pritchie
"Josef Moellers" <josef.moellers@fujitsu-siemens.com> wrote in message
news:dgrd88$1g5$1@nntp.fujitsu-siemens.com...
Pritchie wrote:
> Hi
> What is the best way to include common settings/values into a perl
script?
>
> in shell script you can have a file called "common-vars.sh" with
> sMyVar="My string"
>
> and call it from "MyProgram.sh" by
> . ./common-vars.sh
> echo ${sMyVar}
>
> so when you run ./MyProgram.sh you get echoed back
> My String
>
>
> How can I do this in Perl? I want a common settings file for my
database
> details (database name, username, password etc)
> eg.
> my sDatabaseName="LoadsOfData";
> my sDbUserName="LoadsOfData_User";
> my sDbPassword="*****";
>
> I then want too include this into a number of different perl scripts...
>
> at the moment I am using a common shell file to hold these values as
> environmental variable (see shell example above), which is called before
> the
> perl scripts. I then use ENV to import them into perl.
> my $sDbSrv=$ENV{'sDbSrv'};
> my $sDbName=$ENV{'sDbName'};
> my $sDbUser=$ENV{'sDbUser'};
> my $sDbUserPw=$ENV{'sDbUserPw'};
>
> I am sure there's got to be a better way.
>
> Thanks
> Pritchie
Take a look at "use", "require" and friends.
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Wed, 21 Sep 2005 12:25:21 GMT
From: Damian James <djames@thehub.com.au>
Subject: Re: newbie, what is the best way to include common settings.conf values
Message-Id: <slrndj2j5f.76d.djames@puli.home>
On Wed, 21 Sep 2005 10:32:31 GMT, Pritchie said:
> What is the best way to include common settings/values into a perl script?
You may wish to look at the various modules listed under:
http://search.cpan.org/search?query=config
> in shell script you can have a file called "common-vars.sh" with
> sMyVar="My string"
> ...
> How can I do this in Perl? I want a common settings file for my database
> details (database name, username, password etc)
> eg.
> my sDatabaseName="LoadsOfData";
> my sDbUserName="LoadsOfData_User";
> my sDbPassword="*****";
>
> I then want too include this into a number of different perl scripts...
What I usually do is make a simple module that returns a hashref
containing config information. So for instance [example only and
untested]:
==== MyConf.pm
package MyConf;
return {
dsn => 'dbi:driver:database',
user => 'user',
passwd => 'passwd'
}
===== script
use DBI;
my $conf = require MyConf;
my $dbh = DBI->connect(
$conf->{dsn}, $conf->{user}, $conf->{passwd}
) or die $DBI::errstr;
etc.
You'd need to read perlmod, and the perlfunc entries for use() and
require().
> at the moment I am using a common shell file to hold these values as
> environmental variable (see shell example above), which is called before
> the
> perl scripts. I then use ENV to import them into perl.
> my $sDbSrv=$ENV{'sDbSrv'};
> my $sDbName=$ENV{'sDbName'};
> my $sDbUser=$ENV{'sDbUser'};
> my $sDbUserPw=$ENV{'sDbUserPw'};
>
> I am sure there's got to be a better way.
Yeah, anytime you find you're making lots of scalar vars with
a common element to their name, you probably wanteded a hash.
my %sDbVars = map $ENV{$_}, qw/sDbSrv sDbName sDbUser sDbUserPw/;
print $sDbVars{sDbSrv};
--Damian
------------------------------
Date: Wed, 21 Sep 2005 12:42:33 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: newbie, what is the best way to include common settings.conf values
Message-Id: <dgrd88$1g5$1@nntp.fujitsu-siemens.com>
Pritchie wrote:
> Hi
> What is the best way to include common settings/values into a perl scri=
pt?
>=20
> in shell script you can have a file called "common-vars.sh" with
> sMyVar=3D"My string"
>=20
> and call it from "MyProgram.sh" by
> . ./common-vars.sh
> echo ${sMyVar}
>=20
> so when you run ./MyProgram.sh you get echoed back
> My String
>=20
>=20
> How can I do this in Perl? I want a common settings file for my databa=
se
> details (database name, username, password etc)
> eg.
> my sDatabaseName=3D"LoadsOfData";
> my sDbUserName=3D"LoadsOfData_User";
> my sDbPassword=3D"*****";
>=20
> I then want too include this into a number of different perl scripts...=
>=20
> at the moment I am using a common shell file to hold these values as
> environmental variable (see shell example above), which is called befor=
e
> the
> perl scripts. I then use ENV to import them into perl.
> my $sDbSrv=3D$ENV{'sDbSrv'};
> my $sDbName=3D$ENV{'sDbName'};
> my $sDbUser=3D$ENV{'sDbUser'};
> my $sDbUserPw=3D$ENV{'sDbUserPw'};
>=20
> I am sure there's got to be a better way.
>=20
> Thanks
> Pritchie
Take a look at "use", "require" and friends.
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Wed, 21 Sep 2005 13:05:48 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: newbie, what is the best way to include common settings.conf values
Message-Id: <dgrias$ahj$1@redhat2.bham.ac.uk>
Pritchie wrote TOFU:
[ Please don't do that, it is rude. TOFU corrected ]
> "Josef Moellers" <josef.moellers@fujitsu-siemens.com> wrote
> > Pritchie wrote:
> > >What is the best way to include common settings/values into a perl
> > >script?
> >
> > Take a look at "use", "require" and friends.
>
> ok so I now have 2 files in the same folder
>
> ==> START myvar.pm<==
> print "my var: $sVar\n";
> $sVar="Hello World";
> ==> END <==
>
> and
> ==> START myperl.pl <==
> #!/usr/bin/perl
> my $sVar = "help";
> require myvar;
> print "sVar[".$sVar."]\n";
> ==> END <==
>
>
> When I run myperl.pl I get the following
>
> bash-3.00# perl ./myperl.pl
> my var:
> sVar[help]
>
> I was hoping to get
>
> my var:help
> sVar[Hello World]
>
> Am I missing something or can you not pass variables values for some
> reason using "use" or "require"?
Separate source files do not share lexically scoped variables because
each file is a separate lexical scope.
You need to use package scoped variables. Or possibly a single packaged
scoped hash.
Consider also using a proper Exporter module[1] or use fully qualified
names as the quick-and-dirty
Perl4-library-masquerading-as-a-Perl5-module approach will break down
quite quickly.
[1] The variables are declared in the module's own namespace then
aliases are exported into other namespaces when they use() the module.
Example without Exporter - just using fully qualified names.
==> START myvar.pm<==
package myvar;
use strict;
use warnings;
our $sVar="Hello World";
1;
==> END <==
==> START myperl.pl <==
#!/usr/bin/perl
use strict;
use warnings;
require myvar;
print "sVar[".$myvar::sVar."]\n";
==> END <==
------------------------------
Date: Wed, 21 Sep 2005 10:03:11 -0400
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Package to calculate time diff
Message-Id: <pan.2005.09.21.13.59.48.902301@users.sourceforge.net>
Hi,
I'm wondering which package can do time diff calculation. I.e., something
that can do time_diff 0:40:33 0:28:50 and gives me 00:11:43.
I've tried Date::Simple, Date::Calc, Class::Date and DateTime, but none
of them can. Maybe I'm too blunt, so I'm not going to show my stupid
trials here.
Thanks for your help.
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: Wed, 21 Sep 2005 17:24:00 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Package to calculate time diff
Message-Id: <QGgYe.180741$wr.154369@clgrps12>
* Tong * wrote:
>
> I'm wondering which package can do time diff calculation. I.e., something
> that can do time_diff 0:40:33 0:28:50 and gives me 00:11:43.
>
> I've tried Date::Simple, Date::Calc, Class::Date and DateTime, but none
> of them can. Maybe I'm too blunt, so I'm not going to show my stupid
> trials here.
$ perl -le'
use Time::Local;
my $end = q/0:40:33/;
my $start = q/0:28:50/;
sub time_diff { join q/:/, ( gmtime timegm( reverse 1, $_[1] =~ /\d+/g ) -
timegm( reverse 1, $_[0] =~ /\d+/g ) )[2,1,0] }
print "Start: $start End: $end Diff: ", time_diff $start, $end;
'
Start: 0:28:50 End: 0:40:33 Diff: 0:11:43
Or if you want to use sprintf to get leading zeros:
sub time_diff { sprintf q/%3$d:%2$02d:%1$02d/, gmtime timegm( reverse 1, $_[1]
=~ /\d+/g ) - timegm( reverse 1, $_[0] =~ /\d+/g ) }
John
--
use Perl;
program
fulfillment
------------------------------
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 V10 Issue 8440
***************************************