[29133] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 377 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 24 21:09:59 2007

Date: Tue, 24 Apr 2007 18:09:11 -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           Tue, 24 Apr 2007     Volume: 11 Number: 377

Today's topics:
        Cant open a file with just a relative path <nikos1337@gmail.com>
    Re: Compiling Perl with ICC vs GCC - Benchmarks <sam@email-scan.com>
        How to execute a SQL select???? (successfully that is!) (none)
    Re: How to execute a SQL select???? (successfully that  <glex_no-spam@qwest-spam-no.invalid>
        How to retrieve the Perl script returned value in C pro <needpassion@gmail.com>
    Re: How to retrieve the Perl script returned value in C <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: How to trigger garbage collection <rvtol+news@isolution.nl>
    Re: How to trigger garbage collection <ignoramus2319@NOSPAM.2319.invalid>
    Re: How to trigger garbage collection <ignoramus2319@NOSPAM.2319.invalid>
    Re: How to trigger garbage collection xhoster@gmail.com
    Re: How to trigger garbage collection <ignoramus2319@NOSPAM.2319.invalid>
    Re: How to trigger garbage collection xhoster@gmail.com
    Re: How to trigger garbage collection <ignoramus2319@NOSPAM.2319.invalid>
        Management of Enterprise Computing iguanodon@guano.com
    Re: Re-inventing the wheel, same hash, three scripts <someone@example.com>
    Re: Re-inventing the wheel, same hash, three scripts <justin.0704@purestblue.com>
    Re: Re-inventing the wheel, same hash, three scripts <justin.0704@purestblue.com>
    Re: Re-inventing the wheel, same hash, three scripts <justin.0704@purestblue.com>
    Re: Reading a ctime formatted date <glex_no-spam@qwest-spam-no.invalid>
    Re: Reading a ctime formatted date <lambik@kieffer.nl>
    Re: Reading a ctime formatted date <purlgurl@purlgurl.net>
    Re: regular expression for wc <wahab-mail@gmx.de>
    Re: regular expression for wc <nospam-abuse@ilyaz.org>
    Re: Relative path wont work when opening a file for wri <glex_no-spam@qwest-spam-no.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 24 Apr 2007 13:04:31 -0700
From: skieros <nikos1337@gmail.com>
Subject: Cant open a file with just a relative path
Message-Id: <1177445071.441150.81140@o40g2000prh.googlegroups.com>

open(FILE, ">>/somefolder/somesubfolder/digest.passwd") or die $!;
     print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
$pass") . "\n";
close(FILE);

Wehn i try to use this relative path instead of d:\www\blabla which is
absolute apache tells me it cant find the file.

Why i dotn sue an absolute path then? Because the same script will run
both on localhost and remote server and the paths are not the same, so
i need a relative path in order to work.

I could use the $ENV{'SERVER_NAME'} to determine in which host the
script runs and then set an appropriate path variable but i wan to
avoid that by using a relatiev path.



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

Date: Tue, 24 Apr 2007 17:39:11 -0500
From: Sam <sam@email-scan.com>
Subject: Re: Compiling Perl with ICC vs GCC - Benchmarks
Message-Id: <cone.1177454351.134807.19019.500@commodore.email-scan.com>

This is a MIME GnuPG-signed message.  If you see this text, it means that
your E-mail or Usenet software does not support MIME signed messages.
The Internet standard for MIME PGP messages, RFC 2015, was published in 1996.
To open this message correctly you will need to install E-mail or Usenet
software that supports modern Internet standards.

--=_mimegpg-commodore.email-scan.com-19019-1177454351-0002
Content-Type: text/plain; format=flowed; charset="US-ASCII"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

UsenetBinaries.com writes:

> http://www.usenetbinaries.com/doc/gcc_vs_icc_benchmarks_perl.html
> 
> I was wondering if anyone else had any experience with running an icc -O3 
> compiler Perl executable
> under Linux?
> 
> Seems to be a lot more efficient even on AMD platform.
> 
> Sorry if this is a dupe I posted yesterday and it didnt show up.

You are a far better chance of getting an informative and meaningful 
response to this question on one of the CPAN or Perl-specific mailing lists, 
then here.


--=_mimegpg-commodore.email-scan.com-19019-1177454351-0002
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBGLocPx9p3GYHlUOIRAtqsAJ9AgD2yVRAgYCql1wQcTlUkxi8JLwCdHnp8
jiRtUznFG6JcUMkH6m5koPY=
=Ammk
-----END PGP SIGNATURE-----

--=_mimegpg-commodore.email-scan.com-19019-1177454351-0002--


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

Date: Tue, 24 Apr 2007 22:11:34 +0100
From: "Richard" <(none)>
Subject: How to execute a SQL select???? (successfully that is!)
Message-Id: <462e7973@newsgate.x-privat.org>

I have been following a "worked example" of how to retrieve a row from an 
SQL table in Perl and use a returned column from that row in my Perl script.

Unfortunately, as soon as I get to the statement:-
         $execute = $connect->query($myquery);
I just get an error 500 from the website.

I know it's failing on that $execute statement because the error occurs only 
when that statement is present. Comment it out, and the error disappears.

So QUESTIONS :-))) .....

1. How can I find out EXACTLY what error (ie. SQL status and return codes) 
are resulting from the failed operation?

2. Why would this fail anyway?  The code I have used does the following 
before the failing statement  (I've replaced identifying info with x's):-

# MYSQL CONFIG VARIABLES
use Mysql;
$host = "localhost";
$database = "xxxxxxxx";
$tablename = "pages";
$user = "xxxxxxxx";
$pw = "xxxxxxx";

# PERL MYSQL CONNECT()
$connect = Mysql->connect($host, $database, $user, $pw);
# SELECT DB
$connect->selectdb($database);

         #Try to get the page Id from the database
         # DEFINE A MySQL QUERY
         $myquery = "SELECT title FROM $tablename where PageID = $PageID 
order by ID desc";
         # EXECUTE THE QUERY FUNCTION
         $execute = $connect->query($myquery);


I've also tried the simpler
         $myquery = "SELECT * FROM $tablename";
         # EXECUTE THE QUERY FUNCTION
         $execute = $connect->query($myquery);

But in either case the last statement results in an error, and I can't even 
see what that error is (beyond HTML error 500).

FYI, my web server tells me I have Perl version 5.8.7 installed.





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

Date: Tue, 24 Apr 2007 17:12:49 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: How to execute a SQL select???? (successfully that is!)
Message-Id: <462e80e1$0$10309$815e3792@news.qwest.net>

Richard wrote:
> I have been following a "worked example" of how to retrieve a row from an 
> SQL table in Perl and use a returned column from that row in my Perl script.
> 
> Unfortunately, as soon as I get to the statement:-
>          $execute = $connect->query($myquery);
> I just get an error 500 from the website.
> 
> I know it's failing on that $execute statement because the error occurs only 
> when that statement is present. Comment it out, and the error disappears.
> 
> So QUESTIONS :-))) .....
> 
> 1. How can I find out EXACTLY what error (ie. SQL status and return codes) 
> are resulting from the failed operation?

perldoc Mysql

Look at $dbh->errmsg
> 
> 2. Why would this fail anyway?  The code I have used does the following 
> before the failing statement  (I've replaced identifying info with x's):-
> 
> # MYSQL CONFIG VARIABLES
> use Mysql;

> 
> # PERL MYSQL CONNECT()
> $connect = Mysql->connect($host, $database, $user, $pw);
 > # SELECT DB
 > $connect->selectdb($database);

Check if your method calls, like connect(), were successful.

> But in either case the last statement results in an error, and I can't even 
> see what that error is (beyond HTML error 500).

Look in the Web server's error logs or print the error.

Does it run via command line?  I don't see the HTTP header information
being printed.

Ya might want to migrate to using DBI and DBD::mysql.  From the perldoc
for Mysql module:
"As of March 1998, the Msql and Mysql modules are obsoleted by the DBI
drivers DBD::mSQL and DBD::mysql, respectively."


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

Date: 24 Apr 2007 12:39:56 -0700
From: mike <needpassion@gmail.com>
Subject: How to retrieve the Perl script returned value in C program? Many thanks
Message-Id: <1177443596.226126.36850@s33g2000prh.googlegroups.com>

Hi Guys:

I have an Email application that was made of C(no source code). Only I
know is that it can call a program with a parameter(email file name)
and check the return value. If returns 0, go ahead and work with the
next one; return 1, drop it, and work with next one.

I intend to use Perl script to check the email's FROM field. Once it
comes from a specific domain, then return 1; otherwise, return 0.

Here comes the question: How can I return 0 or 1 from Perl script to
the C program? I made a C test program, and called the Perl script
this way:

int ret_val = system("perl_script email_file_name");

When I call exit(0) in the Perl script, the ret_val in the C test
program is 0; but when I call exit(1) in the Perl script, the ret_val
in the C test program is 256,

How come it happens this way? Any suggestion would be appreciated.

Mike



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

Date: Wed, 25 Apr 2007 00:14:36 GMT
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: How to retrieve the Perl script returned value in C program? Many thanks
Message-Id: <M3xXh.4823$j63.696@newsread2.news.pas.earthlink.net>

On 04/24/2007 02:39 PM, mike wrote:
> [...]
> When I call exit(0) in the Perl script, the ret_val in the C test
> program is 0; but when I call exit(1) in the Perl script, the ret_val
> in the C test program is 256,
> 
> How come it happens this way? Any suggestion would be appreciated.
> 
> Mike
> 

Shift the return value right by eight bits.



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

Date: Tue, 24 Apr 2007 21:22:00 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: How to trigger garbage collection
Message-Id: <f0lsig.1ho.1@news.isolution.nl>

Ignoramus2319 schreef:

> I do use one global hash that maps integers to integers, which I
> estimate to be about 20,000 integers. (not much) I also have a second
> hash with not much more.

Are these integers -327678 <= $i <= 32767 ?
Or 0 <= $i <= 65535 ?
Then you could pack each in 2 bytes.

You can store those packed integers in an AoA, sort that, and use a
binary search.

20_000 * 4 * 2 = 160 kB, not 600 MB.
That requires storing the data in a string.
Maybe use a Vector module?

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Tue, 24 Apr 2007 15:03:29 -0500
From: Ignoramus2319 <ignoramus2319@NOSPAM.2319.invalid>
Subject: Re: How to trigger garbage collection
Message-Id: <2e6dncrWftYM_7PbnZ2dnUVZ_r_inZ2d@giganews.com>

On Tue, 24 Apr 2007 21:22:00 +0200, Dr.Ruud <rvtol+news@isolution.nl> wrote:
> Ignoramus2319 schreef:
>
>> I do use one global hash that maps integers to integers, which I
>> estimate to be about 20,000 integers. (not much) I also have a second
>> hash with not much more.
>
> Are these integers -327678 <= $i <= 32767 ?
> Or 0 <= $i <= 65535 ?
> Then you could pack each in 2 bytes.

They are not, they are from 0 to a few tens of billions.

> You can store those packed integers in an AoA, sort that, and use a
> binary search.
>
> 20_000 * 4 * 2 = 160 kB, not 600 MB.
> That requires storing the data in a string.
> Maybe use a Vector module?
>

Those hashes are not the issue. Something else is. 

i


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

Date: Tue, 24 Apr 2007 15:05:10 -0500
From: Ignoramus2319 <ignoramus2319@NOSPAM.2319.invalid>
Subject: Re: How to trigger garbage collection
Message-Id: <2e6dncXWftZr_7PbnZ2dnUVZ_r_inZ2d@giganews.com>

On Tue, 24 Apr 2007 19:48:20 +0200, Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr> wrote:
> Ignoramus2319 wrote:
>> I have a script that runs 10 hours or so, using XML::Simple,
>> HTML::TreeBuilder, DBI, etc. I do properly use 'my' variables, so that
>> they get deleted when they get out of scope, and for HTML::TreeBuilder
>> trees, I do use delete method to trigger garbage collection. I also
>> 'use strict' to let me know if I am making any scoping mistakes.
>> 
>> I do use one global hash that maps integers to integers, which I
>> estimate to be about 20,000 integers. (not much) I also have a second
>> hash with not much more. 
>> 
>> Despite that, my script grows to large sizes in memory, which screws
>> things up. (600+ MB)
>> 
>> What I would like to know is whether I can trigger some sort of
>> garbage collection that deletes circular structures and everything
>> else that perl can find, besides just doing reference count based
>> deletion. I would then do that periodically, say every 100
>> iterations. 
>> 
>
> You may want to check out weak references. Have a look at Scalar::Util.
>
> http://search.cpan.org/~gbarr/Scalar-List-Utils-1.19/lib/Scalar/Util.pm#weaken

My problem is, I know that I already remove those things that I need
to remove (by using scoping, use strict and 'my' statements). 

There is no reason to make them weak, it is not going to help.

There are some deeply linked things somewhere (and I suspect
XML::Simple, though it could be something else) and I would like to
remove them properly. 


i


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

Date: 24 Apr 2007 21:02:23 GMT
From: xhoster@gmail.com
Subject: Re: How to trigger garbage collection
Message-Id: <20070424170226.313$pi@newsreader.com>

Ignoramus2319 <ignoramus2319@NOSPAM.2319.invalid> wrote:
> On Tue, 24 Apr 2007 19:48:20 +0200, Mark Clements
> <mark.clementsREMOVETHIS@wanadoo.fr> wrote:
> > Ignoramus2319 wrote:
> >> I have a script that runs 10 hours or so, using XML::Simple,
> >> HTML::TreeBuilder, DBI, etc. I do properly use 'my' variables, so that
> >> they get deleted when they get out of scope, and for HTML::TreeBuilder
> >> trees, I do use delete method to trigger garbage collection. I also
> >> 'use strict' to let me know if I am making any scoping mistakes.
> >>
> >> I do use one global hash that maps integers to integers, which I
> >> estimate to be about 20,000 integers. (not much) I also have a second
> >> hash with not much more.
> >>
> >> Despite that, my script grows to large sizes in memory, which screws
> >> things up. (600+ MB)
> >>
> >> What I would like to know is whether I can trigger some sort of
> >> garbage collection that deletes circular structures and everything
> >> else that perl can find, besides just doing reference count based
> >> deletion. I would then do that periodically, say every 100
> >> iterations.
> >>
> >
> > You may want to check out weak references. Have a look at Scalar::Util.
> >
> > http://search.cpan.org/~gbarr/Scalar-List-Utils-1.19/lib/Scalar/Util.pm
> > #weaken
>
> My problem is, I know that I already remove those things that I need
> to remove (by using scoping, use strict and 'my' statements).
>
> There is no reason to make them weak, it is not going to help.

If you have circular references, then weaken will help.  If you don't have
circular references, then I don't see that your post makes much sense.

> There are some deeply linked things somewhere (and I suspect
> XML::Simple, though it could be something else) and I would like to
> remove them properly.

If they aren't being properly removed now, then it sounds like a bug.  I
don't think there is any generic advice to give you, other than Figure out
where the bug is and fix it.  What makes you think it is in XML::Simple
rather than somewhere else?  How simple can you make your program and still
exhibit this behavior?


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 24 Apr 2007 16:14:43 -0500
From: Ignoramus2319 <ignoramus2319@NOSPAM.2319.invalid>
Subject: Re: How to trigger garbage collection
Message-Id: <q-GdnTdE8IPe7rPbnZ2dnUVZ_oLinZ2d@giganews.com>

On 24 Apr 2007 21:02:23 GMT, xhoster@gmail.com <xhoster@gmail.com> wrote:
> Ignoramus2319 <ignoramus2319@NOSPAM.2319.invalid> wrote:
>> On Tue, 24 Apr 2007 19:48:20 +0200, Mark Clements
>> <mark.clementsREMOVETHIS@wanadoo.fr> wrote:
>> > Ignoramus2319 wrote:
>> >> I have a script that runs 10 hours or so, using XML::Simple,
>> >> HTML::TreeBuilder, DBI, etc. I do properly use 'my' variables, so that
>> >> they get deleted when they get out of scope, and for HTML::TreeBuilder
>> >> trees, I do use delete method to trigger garbage collection. I also
>> >> 'use strict' to let me know if I am making any scoping mistakes.
>> >>
>> >> I do use one global hash that maps integers to integers, which I
>> >> estimate to be about 20,000 integers. (not much) I also have a second
>> >> hash with not much more.
>> >>
>> >> Despite that, my script grows to large sizes in memory, which screws
>> >> things up. (600+ MB)
>> >>
>> >> What I would like to know is whether I can trigger some sort of
>> >> garbage collection that deletes circular structures and everything
>> >> else that perl can find, besides just doing reference count based
>> >> deletion. I would then do that periodically, say every 100
>> >> iterations.
>> >>
>> >
>> > You may want to check out weak references. Have a look at Scalar::Util.
>> >
>> > http://search.cpan.org/~gbarr/Scalar-List-Utils-1.19/lib/Scalar/Util.pm
>> > #weaken
>>
>> My problem is, I know that I already remove those things that I need
>> to remove (by using scoping, use strict and 'my' statements).
>>
>> There is no reason to make them weak, it is not going to help.
>
> If you have circular references, then weaken will help.  If you don't have
> circular references, then I don't see that your post makes much sense.

I do, I just do not know where they are.

>> There are some deeply linked things somewhere (and I suspect
>> XML::Simple, though it could be something else) and I would like to
>> remove them properly.
>
> If they aren't being properly removed now, then it sounds like a bug.  I
> don't think there is any generic advice to give you, other than Figure out
> where the bug is and fix it.  What makes you think it is in XML::Simple
> rather than somewhere else?  How simple can you make your program and still
> exhibit this behavior?

What would be very interesting is to be able to print contents of the
perl memory to see what variables are out there.

HTML::Tree does say in the manual that I should explicitly 'delete'
it, and I do that. XML::Simple does not say anything of the sort, so I
do not do it. 

All other stuff is either 'my' variable, or relatively small hashes. 

i


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

Date: 24 Apr 2007 21:42:07 GMT
From: xhoster@gmail.com
Subject: Re: How to trigger garbage collection
Message-Id: <20070424174210.004$DU@newsreader.com>

Ignoramus2319 <ignoramus2319@NOSPAM.2319.invalid> wrote:
> >>
> >> There is no reason to make them weak, it is not going to help.
> >
> > If you have circular references, then weaken will help.  If you don't
> > have circular references, then I don't see that your post makes much
> > sense.
>
> I do, I just do not know where they are.
>
> >> There are some deeply linked things somewhere (and I suspect
> >> XML::Simple, though it could be something else) and I would like to
> >> remove them properly.
> >
> > If they aren't being properly removed now, then it sounds like a bug.
> > I don't think there is any generic advice to give you, other than
> > Figure out where the bug is and fix it.  What makes you think it is in
> > XML::Simple rather than somewhere else?  How simple can you make your
> > program and still exhibit this behavior?
>
> What would be very interesting is to be able to print contents of the
> perl memory to see what variables are out there.
>
> HTML::Tree does say in the manual that I should explicitly 'delete'
> it, and I do that. XML::Simple does not say anything of the sort, so I
> do not do it.

Then I strongly suspect the problem is with the way you are using
HTML::Tree rather than with XML::Simple.  Maybe Object::Destroyer could
help, but, I think it would be easier to just figure out what you are doing
wrong rather than work around it.  Devel::Leak might help.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 24 Apr 2007 19:34:15 -0500
From: Ignoramus2319 <ignoramus2319@NOSPAM.2319.invalid>
Subject: Re: How to trigger garbage collection
Message-Id: <I8GdnTtaP9yaP7PbnZ2dnUVZ_jGdnZ2d@giganews.com>

On 24 Apr 2007 21:42:07 GMT, xhoster@gmail.com <xhoster@gmail.com> wrote:
> Ignoramus2319 <ignoramus2319@NOSPAM.2319.invalid> wrote:
>> >>
>> >> There is no reason to make them weak, it is not going to help.
>> >
>> > If you have circular references, then weaken will help.  If you don't
>> > have circular references, then I don't see that your post makes much
>> > sense.
>>
>> I do, I just do not know where they are.
>>
>> >> There are some deeply linked things somewhere (and I suspect
>> >> XML::Simple, though it could be something else) and I would like to
>> >> remove them properly.
>> >
>> > If they aren't being properly removed now, then it sounds like a bug.
>> > I don't think there is any generic advice to give you, other than
>> > Figure out where the bug is and fix it.  What makes you think it is in
>> > XML::Simple rather than somewhere else?  How simple can you make your
>> > program and still exhibit this behavior?
>>
>> What would be very interesting is to be able to print contents of the
>> perl memory to see what variables are out there.
>>
>> HTML::Tree does say in the manual that I should explicitly 'delete'
>> it, and I do that. XML::Simple does not say anything of the sort, so I
>> do not do it.
>
> Then I strongly suspect the problem is with the way you are using
> HTML::Tree rather than with XML::Simple.  Maybe Object::Destroyer could
> help, but, I think it would be easier to just figure out what you are doing
> wrong rather than work around it.  Devel::Leak might help.


Here's my entire usage of HTML::Tree:

    my $tree = HTML::TreeBuilder->new; 
    $tree->parse( $html ); 
    my $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 9978 ); 
    my $text = $formatter->format($tree); 

    # Deleting tree to conserve memory. 
    $tree = $tree->delete; 

I will look into Devel::Leak. 

i


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

Date: Tue, 24 Apr 2007 15:47:10 -0500
From: iguanodon@guano.com
Subject: Management of Enterprise Computing
Message-Id: <apWdnVmtVcxT8bPbnZ2dnUVZ_vHinZ2d@giganews.com>

I have been tasked to create a system for managing enterprise
computing in our company. This would involve managing hundreds of
computers running our proprietary software, keeping an eye for
trouble, starting/restarting things, performing remote actions
conditionally based on success of other actions, etc.

All should be configurable and accept human input, etc.

We are going to use 'perl' for this and I would like to know what
relevant perl modules could you recommend, for managing a lot of
computers at once, watching for stuff, etc.

The enterprise is a mixture of mostly XP and Linux.

iguanodon


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

Date: Tue, 24 Apr 2007 22:22:14 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Re-inventing the wheel, same hash, three scripts
Message-Id: <qqvXh.7$_G.4@edtnps89>

Justin C wrote:
> I've been re-inventing the wheel, and it's costing me time. I have a
> hash that is used in three scripts, and it's in all three scripts. Each
> time there is a change to it I have to update all three scripts. I know
> I'm wasting my time.
> 
> I'd like to store this hash in an external file and reference the
> contents from each script. The scripts are only going to need to look up
> one or two elements (out of about 100) each time they are run.
> 
> It has been suggested to me that I use one of the Config:: modules, I'd
> rather, if possible, do this without modules (these may end up running
> somewhere I can't request modules be installed).
> 
> I'm happy to read the documentation, I just don't know which
> documentation I should read. Opening a file, reading all the contents
> into a hash seems, though easy, a waste of time.

perldoc -f dbmopen
perldoc -f dbmclose



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Tue, 24 Apr 2007 22:30:40 -0000
From: Justin C <justin.0704@purestblue.com>
Subject: Re: Re-inventing the wheel, same hash, three scripts
Message-Id: <slrnf2t18i.66g.justin.0704@justin-catteralls-computer.local>

In article <20070424110709.877$KD@newsreader.com>, xhoster@gmail.com wrote:
> justin.news@purestblue.com wrote:
>> I've been re-inventing the wheel, and it's costing me time. I have a
>> hash that is used in three scripts, and it's in all three scripts. Each
>> time there is a change to it I have to update all three scripts. I know
>> I'm wasting my time.
>>
>> I'd like to store this hash in an external file and reference the
>> contents from each script. The scripts are only going to need to look up
>> one or two elements (out of about 100) each time they are run.
> 
> If the scripts are only going to look up 1 or 2, then why are there 100
> in the first place?

What I meant was that though they'll only look up 1 or 2 values each
time, they're likely to be different keys/values each time.


>> It has been suggested to me that I use one of the Config:: modules, I'd
>> rather, if possible, do this without modules (these may end up running
>> somewhere I can't request modules be installed).
> 
> A module is nothing more than an external file containing a certain kind
> of valid perl code.  If you can't install modules, you can't install an
> external file to contain the hash's info, either.

I understand. What I mean, then, is that I'd rather manage this task
with a standard Perl install.


>> I'm happy to read the documentation, I just don't know which
>> documentation I should read. Opening a file, reading all the contents
>> into a hash seems, though easy, a waste of time.
> 
> How precious is your computer's time relative to your own?  If it is very
> precious, perhaps you should choose a different language to code in in the
> first place.

Yes, but I'm not starting from "in the first place" am I? I already have
these scripts written, and my time is valuable enough that I don't want
to write them again in something else.

Thank you for your comments.

	Justin.

-- 
Justin C, by the sea.


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

Date: Tue, 24 Apr 2007 22:35:45 -0000
From: Justin C <justin.0704@purestblue.com>
Subject: Re: Re-inventing the wheel, same hash, three scripts
Message-Id: <slrnf2t1i2.66g.justin.0704@justin-catteralls-computer.local>

In article <240420071017079484%jgibson@mail.arc.nasa.gov>, Jim Gibson wrote:
> In article <slrnf2s4vc.fja.justin.0704@stigmata.purestblue.com>, Justin
> C <justin.0704@purestblue.com> wrote:
> 
>> I've been re-inventing the wheel, and it's costing me time. I have a
>> hash that is used in three scripts, and it's in all three scripts. Each
>> time there is a change to it I have to update all three scripts. I know
>> I'm wasting my time.
>> 
>> I'd like to store this hash in an external file and reference the
>> contents from each script. The scripts are only going to need to look up
>> one or two elements (out of about 100) each time they are run.
>> 
>> It has been suggested to me that I use one of the Config:: modules, I'd
>> rather, if possible, do this without modules (these may end up running
>> somewhere I can't request modules be installed).
>> 
>> I'm happy to read the documentation, I just don't know which
>> documentation I should read. Opening a file, reading all the contents
>> into a hash seems, though easy, a waste of time.
> 
> Here is one way:
> 
> main.pl:
> 
> require 'hash.pl';
> if( $hash{$key} ) {
> ...
> 
> 
> hash.pl:
> 
> %hash = ( ... );

OK, that looks fairly straight forward. I'll have a read up on 'require'
and see where that leads me. I'm not sure, at this stage how we get from
"require 'fname' ;" to "$hash{$key}" ... does it just 'import' those?
I'd have to be careful not to re-use those variable names.


> You can improve this scheme by using 'package', 'my', or 'our' in
> various combinations (left as an exercise or another poster).

Thanks, that's more to read up on, I know 'my' (learnt that very early!)
not come across 'package', or 'our' before, so that's going to confuse
the grey matter... still, I need something to keep me occupied at work.

Thanks again for the help.

	Justin.

-- 
Justin C, by the sea.


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

Date: Tue, 24 Apr 2007 22:53:26 -0000
From: Justin C <justin.0704@purestblue.com>
Subject: Re: Re-inventing the wheel, same hash, three scripts
Message-Id: <slrnf2t2j8.66g.justin.0704@justin-catteralls-computer.local>

In article <qqvXh.7$_G.4@edtnps89>, John W. Krahn wrote:
> Justin C wrote:
>> I've been re-inventing the wheel, and it's costing me time. I have a
>> hash that is used in three scripts, and it's in all three scripts. Each
>> time there is a change to it I have to update all three scripts. I know
>> I'm wasting my time.
>> 
>> I'd like to store this hash in an external file and reference the
>> contents from each script. The scripts are only going to need to look up
>> one or two elements (out of about 100) each time they are run.
>> 
>> It has been suggested to me that I use one of the Config:: modules, I'd
>> rather, if possible, do this without modules (these may end up running
>> somewhere I can't request modules be installed).
>> 
>> I'm happy to read the documentation, I just don't know which
>> documentation I should read. Opening a file, reading all the contents
>> into a hash seems, though easy, a waste of time.
> 
> perldoc -f dbmopen
> perldoc -f dbmclose

Thank you, I shall read those.

	Justin.

-- 
Justin C, by the sea.


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

Date: Tue, 24 Apr 2007 15:14:49 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Reading a ctime formatted date
Message-Id: <462e6539$0$494$815e3792@news.qwest.net>

ivan@0x4849.net wrote:
> Hi,
> 
> Given a date string of this format:
> 
> Fri Apr 13 23:46:01 2007
> 
> Whats the simplest perl script that can convert the string into an epoch
> number?

Probably one that uses Date::Manip, or one that splits the date and uses 
Time::Local.


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

Date: Tue, 24 Apr 2007 22:35:03 +0200
From: "Lambik" <lambik@kieffer.nl>
Subject: Re: Reading a ctime formatted date
Message-Id: <462e69fe$0$726$5fc3050@dreader2.news.tiscali.nl>

<ivan@0x4849.net> wrote in message
news:20070424134637.163$nW@newsreader.com...
> Hi,
>
> Given a date string of this format:
>
> Fri Apr 13 23:46:01 2007
>
> Whats the simplest perl script that can convert the string into an epoch
> number?

use Date::Manip;
$ENV{TZ}= "GMT"; # see
http://search.cpan.org/~sbeck/DateManip-5.44/Manip.pod#TIMEZONES
print &UnixDate('Fri Apr 13 23:46:01 2007',"%s");




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

Date: Tue, 24 Apr 2007 15:40:37 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Reading a ctime formatted date
Message-Id: <Mb6dneEkN8b-GrPbnZ2dnUVZ_vmqnZ2d@giganews.com>

ivan wrote:

> Given a date string of this format:

> Fri Apr 13 23:46:01 2007

> Whats the simplest perl script that can convert the string into an epoch number?

There are literally hundreds of examples of how to do this
available to you on the web. You should search via Google.
Chances are there as many examples found in archives for
this discussion group.

#!perl

use Time::Local;

@Months = qw (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);

$date = "Fri Apr 13 23:46:01 2007";

$date = substr ($date, 4);
$date =~ tr/ /:/;

$count = 0;

for (@Months)
  {
   if (index ($date, $_) == 0)
    {substr ($date, 0, 3, $count); last;}
   $count++;
  }

($month, $day, $hour, $minute, $second, $year) = split (/:/, $date);

$epoch_seconds = timelocal($second, $minute, $hour, $day, $month, $year);

print "$epoch_seconds\n";

print scalar localtime($epoch_seconds);


PRINTED RESULTS:

1176533161
Fri Apr 13 23:46:01 2007


Purl Gurl


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

Date: Tue, 24 Apr 2007 20:08:50 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: regular expression for wc
Message-Id: <f0lhek$l3d$1@mlucom4.urz.uni-halle.de>

Ilya Zakharevich wrote:
> <anno4000@radom.zrz.tu-berlin.de>], who wrote in article <5962p7F2ilslcU1@mid.dfncis.de>:
>> I don't understand why it finds four /\b/ for each word, but that's
>> apparently what happens.
> 
> It finds two \b per word.  It also FAILS to match \b at each boundary
> - but due to bugs in the REx above, even failing attempts run += code
> (there is no "undoing" for failing attempts).

What's meant with 'bugs in the REx'?

Can you help out w/explanation why the
following prints the "pseudo correct"
word boundaries:

    ...

    my $chars ='Ilya Zakharevich';

    my $re = qr/   \b
                 | \b (?{ print '\b:'.pos().',' })
             /x;

    () = $chars =~ /$re/g;

    ...

Hmmm ...

Thanks & Regards

Mirco


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

Date: Tue, 24 Apr 2007 20:03:48 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: regular expression for wc
Message-Id: <f0lnr4$u04$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Mirco Wahab 
<wahab-mail@gmx.de>], who wrote in article <f0lhek$l3d$1@mlucom4.urz.uni-halle.de>:
> Ilya Zakharevich wrote:
> > <anno4000@radom.zrz.tu-berlin.de>], who wrote in article <5962p7F2ilslcU1@mid.dfncis.de>:
> >> I don't understand why it finds four /\b/ for each word, but that's
> >> apparently what happens.
> > 
> > It finds two \b per word.  It also FAILS to match \b at each boundary
> > - but due to bugs in the REx above, even failing attempts run += code
> > (there is no "undoing" for failing attempts).
> 
> What's meant with 'bugs in the REx'?

As I said: there is no "undoing" for failing attempts.  It does +=
even in the cases when the match will fail immediately after this.

> Can you help out w/explanation why the
> following prints the "pseudo correct"
> word boundaries:
> 
>     ...
> 
>     my $chars ='Ilya Zakharevich';
> 
>     my $re = qr/   \b
>                  | \b (?{ print '\b:'.pos().',' })
>              /x;

Did you try

    use re 'debugcolor';

?

Yours,
Ilya


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

Date: Tue, 24 Apr 2007 15:11:13 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Relative path wont work when opening a file for writing
Message-Id: <462e6461$0$494$815e3792@news.qwest.net>

Mark Clements wrote:
> skieros wrote:
>> open(FILE, ">>/some_folder/some_sub_folder/digest.passwd") or die $!;
>>      print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
>> $pass") . "\n";
>> close(FILE);
>>
>> Hello i have the above code that i have changed from absolute hdd path
>> to a relative to a web server path, but after the change the file
>> cannot be opened.

Why not?  What's the error?

>>
>> Problem is that cause of the script runnign both in localhost and
>> remote server
>> i cant specify the same absolute path so i need some relativity here.
>>
>> I could use a varibale after determiantion of *where* the scrpt is
>> running, that is which host, but i want to accomplish it with a
>> relative path. Is this possible?!
>>
> 
> It'll depend on your webserver, but something like
> 
> use strict;
> use warnings;
> 
> my %paths = (
>     relative => q(some_folder/asdf.txt),
>     absolute => q(/other_path/some_folder/asdf.txt),
> );
> my $filepath;
> 
> if($ENV{SERVER_NAME} eq 'localhost'){
>         $filepath = $paths{relative};
> }else{
>         $filepath = $paths{absolute};
> }
> 
> open my $file,">>",$filepath or die $!;

That's fine as long as the path exists and is writable by the user
running the process.


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

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 377
**************************************


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