[31475] in Perl-Users-Digest
Perl-Users Digest, Issue: 2727 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 17 06:09:38 2009
Date: Thu, 17 Dec 2009 03:09:05 -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, 17 Dec 2009 Volume: 11 Number: 2727
Today's topics:
Re: Closing a DBI instance <zaimoni@zaimoni.com>
Re: Closing a DBI instance <tim@johnsons-web.com>
cpan errors <ruben@mrbrklyn.com>
Re: Curious benchmark results with Inline::C <xhoster@gmail.com>
Opening a file with case-insensitive name <jwcarlton@gmail.com>
Re: Opening a file with case-insensitive name <goodcall1@hotmail.com>
Re: Opening a file with case-insensitive name <john@castleamber.com>
Re: Opening a file with case-insensitive name <jurgenex@hotmail.com>
Re: Opening a file with case-insensitive name <jwcarlton@gmail.com>
Re: Opening a file with case-insensitive name <user@example.net>
Re: Opening a file with case-insensitive name <m@rtij.nl.invlalid>
Re: Opening a file with case-insensitive name <someone@example.com>
Re: Opening a file with case-insensitive name <no@email.com>
Re: push integers from strings <user@example.net>
Re: push integers from strings <uri@StemSystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 16 Dec 2009 18:50:44 -0800 (PST)
From: "Kenneth 'Bessarion' Boyd" <zaimoni@zaimoni.com>
Subject: Re: Closing a DBI instance
Message-Id: <7541e6b3-2e82-47e8-bba8-440a3d3cf086@j24g2000yqa.googlegroups.com>
On Dec 16, 7:13=A0pm, Tim Johnson <t...@johnsons-web.com> wrote:
> Platform: Red Hat Linux server, perl 5.8.8, mysql ver 5.0.45
>
> FYI: I am an experienced programmer but _not_ a perl programmer.
>
> I am trouble-shooting a problem on this server where mysql connections
> do not seem to be closed by cron jobs
>
> ....
>
> To properly disconnect, should I not see something like the following:
> $dbh->disconnect
> somewhere in this script?
Ideally it should just disconnect-and-commit when going out of scope.
I was running out of DB connection handles this way, though.
I ended up using an END block in the central file require'd to call
the functions that wrapped opening the DB in a moderately secure way.
Assuming $dbh is a global, something like this:
END {
$dbh->disconnect() if $dbh;
$dbh =3D undef;
}
I have no reason to believe this is foolproof, but this did
practically eliminate running out of DB connection handles for the
Perl application I work on.
------------------------------
Date: Thu, 17 Dec 2009 00:13:25 -0600
From: Tim Johnson <tim@johnsons-web.com>
Subject: Re: Closing a DBI instance
Message-Id: <slrnhijgud.hbs.tim@bart.johnson.com>
On 2009-12-17, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth tim@johnsons-web.com:
>> Platform: Red Hat Linux server, perl 5.8.8, mysql ver 5.0.45
>>
>> FYI: I am an experienced programmer but _not_ a perl programmer.
>
> What language(s) do you know? It is useful when explaining things to
> know which analogies will be useful and which confusing.
Server-side:
Currently - Python, rebol, (10 years) newlisp .
Previously, 11 yrs. in C/C++.
<..>
>> Consider the following perl code snippet in a stand-alone script with
>> executable privileges that is called by cron:
>>
>> my $data_Source = "DBI:mysql:".$DATABASE .":".$HOSTNAME;
>> my $dbh = DBI->connect($data_Source,$USERNAME,$PASSWORD)
>> or die "$DBI::errstr\n";
>>
>> To properly disconnect, should I not see something like the following:
>> $dbh->disconnect
>> somewhere in this script?
>
> Not necessarily. $dbh is a DBI::dbh object, and has a DESTROY method
> (like a C++ destructor) that will call ->disconnect when the object goes
> out of scope. At that point any transactions in prgress will be rolled
> back, so you *should* see a ->commit in the appropriate place (assuming
> you are using transactions).
Thanks for that Ben. Can you think of any syntax or system factors
that might prevent the destructor from being triggered?
--
Tim
tim@johnsons-web.com
http://www.akwebsoft.com
------------------------------
Date: Thu, 17 Dec 2009 03:03:18 +0000 (UTC)
From: Ruben Safir <ruben@mrbrklyn.com>
Subject: cpan errors
Message-Id: <hgc71m$4n5$2@reader1.panix.com>
I have a new distro of openSuse and cpan seems to be not working.
I'm getting weird errors like this
CPAN: Storable loaded ok (v2.18)
CPAN: LWP::UserAgent loaded ok (v5.829)
CPAN: Time::HiRes loaded ok (v1.9711)
I would like to connect to one of the following sites to get
'authors/01mailrc.txt.gz':
http://www.perl.org/CPAN/
ftp://ftp.perl.org/pub/CPAN/
Is it OK to try to connect to the Internet? [yes] yes
Fetching with LWP:
http://www.perl.org/CPAN/authors/01mailrc.txt.gz
Going to read /root/.cpan/sources/authors/01mailrc.txt.gz
............................................................................DONE
Fetching with LWP:
http://www.perl.org/CPAN/modules/02packages.details.txt.gz
Use of uninitialized value $file_length in numeric lt (<) at /usr/lib/
perl5/vendor_perl/5.10.0/LWP/UserAgent.pm line 845.
Use of uninitialized value $file_length in concatenation (.) or string
at /usr/lib/perl5/vendor_perl/5.10.0/LWP/UserAgent.pm line 847.
Catching error: 'Transfer truncated: only out of 845183 bytes received
' at /usr/lib/perl5/5.10.0/CPAN.pm line 281
CPAN::shell() called at /usr/bin/cpan line 198
Going to read /root/.cpan/sources/authors/01mailrc.txt.gz
............................................................................DONE
Fetching with LWP:
http://www.perl.org/CPAN/modules/02packages.details.txt.gz
Use of uninitialized value $file_length in numeric lt (<) at /usr/lib/
perl5/vendor_perl/5.10.0/LWP/UserAgent.pm line 845.
Use of uninitialized value $file_length in concatenation (.) or string
at /usr/lib/perl5/vendor_perl/5.10.0/LWP/UserAgent.pm line 847.
Lockfile removed.
Transfer truncated: only out of 845183 bytes received
??
------------------------------
Date: Wed, 16 Dec 2009 21:53:55 -0800
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Curious benchmark results with Inline::C
Message-Id: <4b29c80c$0$7850$ed362ca5@nr5-q3a.newsreader.com>
jl_post@hotmail.com wrote:
> Hi,
>
> I've recently been toying around with Inline::C, benchmarking
> certain variations of C and Perl and examining the results.
>
> I was curious about the performance penalty of calling an extra
> function, so I created three different (but similar C functions). All
> of them use the Pythagorean theorem to calculate the average distance
> from the origin for all points with integer coordinates from 1 to
> 100. However, one function calls distance() to compute the distance,
> another is the same except that it calls an inlined function, and the
> other doesn't use a distance() function -- it just uses the "unrolled"
> code, calling the distance logic in place of the function.
>
...
>
> When I ran this code with the following command:
>
> perl extra_function_c.pl 100_000
>
> I got the following as output:
>
> Rate C with inline C unrolled C with
> function
> C with inline 11090/s -- -0%
> -11%
> C unrolled 11130/s 0% --
> -10%
> C with function 12422/s 12% 12%
> --
I get very similar results, only a factor of 10 slower (Asus EeePC
Netbook with Linux)
...
>
> Still curious, I created an all-C file that contained the C code in
> my Perl script (on the same platform). When I compiled, ran, and
> timed it, I saw that the C code without the function call was the
> fastest (while the C code that used the inline function was the
> slowest). This is in contrast to the Perl Benchmark findings, which
> say that the function with the non-inlined function call was the
> fastest.
What were the actual timings? If they all got faster when going to pure
C, just at different rates, that would probably mean something rather
different than if just one of them got faster upon conversion.
Anyway, if I were really serious about figuring this out, I'd compile
the Inline::C code with NoClean, then go look in the build directory log
to see what options were passed to cc or gcc, and then try your pure C
code with those same options.
Also, I would compile with the -S flag so that it saves the assembly
code to see if that reveals anything. Doing that, I notice that the
with_inline and the unrolled yield identical assembly. Unfortunately I
don't know assembly well enough to figure anything else out. It looks
like the with_function code might be have fewer "align" operations.
Xho
------------------------------
Date: Wed, 16 Dec 2009 19:15:11 -0800 (PST)
From: Jason Carlton <jwcarlton@gmail.com>
Subject: Opening a file with case-insensitive name
Message-Id: <6ad9f15b-775f-4da3-b7b6-661712f6f9b0@k19g2000yqc.googlegroups.com>
Let's say that I have a script that allows the user to manually type
in the file name that they want to open. It would go something like
this:
$filename = param('filename');
open FILENAME "/home/mydomain/$filename" or die;
<do whatever...>
close FILENAME;
(Please overlook any typos above; it's just an example for the sake of
clarity, and not important.)
The question is, what if the file name is "MyFile.txt", but they type
"myfile.txt", "MYFILE.TXT", "mYfILE.txt", or something similar. Is
there a way to open the file and ignore the case of the file name?
Ideally, all of the files would have been saved in lower case, then I
could just lc($filename) and be done with it. But I'm inheriting this,
and what's done is done. I could probably change all of the filenames,
but I'm hoping there's a coding option that would make it unnecessary.
------------------------------
Date: Thu, 17 Dec 2009 03:41:40 GMT
From: "Jack" <goodcall1@hotmail.com>
Subject: Re: Opening a file with case-insensitive name
Message-Id: <ULhWm.57875$PH1.28741@edtnps82>
"Jason Carlton" <jwcarlton@gmail.com> wrote in message
news:6ad9f15b-775f-4da3-b7b6-661712f6f9b0@k19g2000yqc.googlegroups.com...
> Let's say that I have a script that allows the user to manually type
> in the file name that they want to open. It would go something like
> this:
>
> $filename = param('filename');
>
> open FILENAME "/home/mydomain/$filename" or die;
> <do whatever...>
> close FILENAME;
>
>
> (Please overlook any typos above; it's just an example for the sake of
> clarity, and not important.)
>
> The question is, what if the file name is "MyFile.txt", but they type
> "myfile.txt", "MYFILE.TXT", "mYfILE.txt", or something similar. Is
> there a way to open the file and ignore the case of the file name?
>
> Ideally, all of the files would have been saved in lower case, then I
> could just lc($filename) and be done with it. But I'm inheriting this,
> and what's done is done. I could probably change all of the filenames,
> but I'm hoping there's a coding option that would make it unnecessary.
1. Get a listing of your directory contents (i.e. filenames) and store them
in an array (or hash).
2. Do a case insensitive comparison on the variable to see if it matches any
filename.
3. Open the file using the proper filename.
The easier way is to change your input to a controlled environment using a
listbox selection or a drop-down entry where "you" control the file names.
Jack D.
------------------------------
Date: Wed, 16 Dec 2009 22:02:51 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: Opening a file with case-insensitive name
Message-Id: <87fx7a6ydw.fsf@castleamber.com>
Jason Carlton <jwcarlton@gmail.com> writes:
> Let's say that I have a script that allows the user to manually type
> in the file name that they want to open. It would go something like
> this:
>
> $filename = param('filename');
>
> open FILENAME "/home/mydomain/$filename" or die;
> <do whatever...>
> close FILENAME;
>
>
> (Please overlook any typos above; it's just an example for the sake of
> clarity, and not important.)
>
> The question is, what if the file name is "MyFile.txt", but they type
> "myfile.txt", "MYFILE.TXT", "mYfILE.txt", or something similar. Is
> there a way to open the file and ignore the case of the file name?
>
> Ideally, all of the files would have been saved in lower case, then I
> could just lc($filename) and be done with it. But I'm inheriting this,
> and what's done is done. I could probably change all of the filenames,
> but I'm hoping there's a coding option that would make it unnecessary.
I would suggest to read all files in /home/mydomain/, lowercase all
entries, and match it with the lowercase version of $filename.
see perldoc -f opendir
PS. I really hope that the above code you gave doesn't come close to the
actual code.
--
John Bokma
Read my blog: http://johnbokma.com/
Hire me (Perl/Python): http://castleamber.com/
------------------------------
Date: Wed, 16 Dec 2009 20:16:50 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Opening a file with case-insensitive name
Message-Id: <qpbji55ggdfp277mm49be2d0tovnk53oof@4ax.com>
Jason Carlton <jwcarlton@gmail.com> wrote:
>open FILENAME "/home/mydomain/$filename" or die;
> <do whatever...>
>close FILENAME;
>
>The question is, what if the file name is "MyFile.txt", but they type
>"myfile.txt", "MYFILE.TXT", "mYfILE.txt", or something similar. Is
>there a way to open the file and ignore the case of the file name?
That depends upon your operating/file system. All (newer) Windows file
systems are case-preserving, but still case-insensitive, i.e. "it would
just work". Your sample file names with the ending txt (in different
capitalization) seem to indicate that you are using some sort of
Windows.
>Ideally, all of the files would have been saved in lower case, then I
>could just lc($filename) and be done with it. But I'm inheriting this,
>and what's done is done. I could probably change all of the filenames,
>but I'm hoping there's a coding option that would make it unnecessary.
If you are on a file/operating system that is case-sensitive you could
read the directory and create a hash from it, using the normalized form
of the file name as the key and the original form as the value.
Then you could simply say
open FILE, $dirhash{normalize($userstring)} ......
jue
------------------------------
Date: Wed, 16 Dec 2009 20:27:24 -0800 (PST)
From: Jason Carlton <jwcarlton@gmail.com>
Subject: Re: Opening a file with case-insensitive name
Message-Id: <370660c6-f717-4755-9805-5c662be74872@m3g2000yqf.googlegroups.com>
> That depends upon your operating/file system. All (newer) Windows file
> systems are case-preserving, but still case-insensitive, i.e. "it would
> just work". Your sample file names with the ending txt (in different
> capitalization) seem to indicate that you are using some sort of
> Windows.
Sorry, that was my mistake. I'm running it on Linux, and didn't think
about the extension meaning anything.
> If you are on a file/operating system that is case-sensitive you could
> read the directory and create a hash from it, using the normalized form
> of the file name as the key and the original form as the value.
> Then you could simply say
>
> =A0 =A0 =A0 =A0 open FILE, $dirhash{normalize($userstring)} ......
OK, that'll work. It's not perfect, since there are about 60,000 files
to consider (which is why I don't put them in a drop menu, as Jack
suggested), but it should hold over for now. Eventually I'll set up an
Ajax system to cope with it.
Thanks, all,
Jason
------------------------------
Date: Thu, 17 Dec 2009 00:02:13 -0500
From: monkeys paw <user@example.net>
Subject: Re: Opening a file with case-insensitive name
Message-Id: <w6Kdnb7i48jMJrTWnZ2dnUVZ_uJi4p2d@insightbb.com>
Jason Carlton wrote:
> Let's say that I have a script that allows the user to manually type
> in the file name that they want to open. It would go something like
> this:
>
> $filename = param('filename');
>
> open FILENAME "/home/mydomain/$filename" or die;
> <do whatever...>
> close FILENAME;
>
>
> (Please overlook any typos above; it's just an example for the sake of
> clarity, and not important.)
>
> The question is, what if the file name is "MyFile.txt", but they type
> "myfile.txt", "MYFILE.TXT", "mYfILE.txt", or something similar. Is
> there a way to open the file and ignore the case of the file name?
>
> Ideally, all of the files would have been saved in lower case, then I
> could just lc($filename) and be done with it. But I'm inheriting this,
> and what's done is done. I could probably change all of the filenames,
> but I'm hoping there's a coding option that would make it unnecessary.
Copy the file to a temp file with a lc($filename) setting. Do your
necessary business, and save to the original file name which you will
have saved.
my $filename = 'FiLe.Txt';
my $temp = lc ($filename);
open TMP, $temp;
# Copy file to TMP
#Operate on TMP
# Copy $temp back to $filename
------------------------------
Date: Thu, 17 Dec 2009 07:39:04 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Opening a file with case-insensitive name
Message-Id: <890pv6-5l8.ln1@news.rtij.nl>
On Wed, 16 Dec 2009 19:15:11 -0800, Jason Carlton wrote:
> Let's say that I have a script that allows the user to manually type in
> the file name that they want to open. It would go something like this:
>
> $filename = param('filename');
>
> open FILENAME "/home/mydomain/$filename" or die;
> <do whatever...>
> close FILENAME;
>
>
> (Please overlook any typos above; it's just an example for the sake of
> clarity, and not important.)
>
> The question is, what if the file name is "MyFile.txt", but they type
> "myfile.txt", "MYFILE.TXT", "mYfILE.txt", or something similar. Is there
> a way to open the file and ignore the case of the file name?
>
> Ideally, all of the files would have been saved in lower case, then I
> could just lc($filename) and be done with it. But I'm inheriting this,
> and what's done is done. I could probably change all of the filenames,
> but I'm hoping there's a coding option that would make it unnecessary.
untested:
my $realfilename = grep { lc($filename) eq lc($_) }
glob('/home/mydomain/*');
HTH,
M4
------------------------------
Date: Wed, 16 Dec 2009 23:36:06 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: Opening a file with case-insensitive name
Message-Id: <QblWm.96675$Wf2.18948@newsfe23.iad>
Martijn Lievaart wrote:
> On Wed, 16 Dec 2009 19:15:11 -0800, Jason Carlton wrote:
>
>> Let's say that I have a script that allows the user to manually type in
>> the file name that they want to open. It would go something like this:
>>
>> $filename = param('filename');
>>
>> open FILENAME "/home/mydomain/$filename" or die;
>> <do whatever...>
>> close FILENAME;
>>
>>
>> (Please overlook any typos above; it's just an example for the sake of
>> clarity, and not important.)
>>
>> The question is, what if the file name is "MyFile.txt", but they type
>> "myfile.txt", "MYFILE.TXT", "mYfILE.txt", or something similar. Is there
>> a way to open the file and ignore the case of the file name?
>>
>> Ideally, all of the files would have been saved in lower case, then I
>> could just lc($filename) and be done with it. But I'm inheriting this,
>> and what's done is done. I could probably change all of the filenames,
>> but I'm hoping there's a coding option that would make it unnecessary.
>
> untested:
>
> my $realfilename = grep { lc($filename) eq lc($_) }
> glob('/home/mydomain/*');
That won't work as glob() returns the complete path, and grep returns
the number of matches in scalar context, not the file name(s). Should
work as:
my @realfilenames = grep lc eq lc "/home/mydomain/$filename", glob
'/home/mydomain/*';
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
------------------------------
Date: Thu, 17 Dec 2009 08:39:59 +0000
From: Brian Wakem <no@email.com>
Subject: Re: Opening a file with case-insensitive name
Message-Id: <7ou931F3rq0ehU1@mid.individual.net>
John Bokma wrote:
>
> I would suggest to read all files in /home/mydomain/, lowercase all
> entries, and match it with the lowercase version of $filename.
One potential gotcha here is that lowercasing all the files in the dir could
leave you with more than 1 file with the same name. What is the OP going
to do then I wonder?
--
Brian Wakem
------------------------------
Date: Wed, 16 Dec 2009 23:57:42 -0500
From: monkeys paw <user@example.net>
Subject: Re: push integers from strings
Message-Id: <w6Kdnb_i48jfJ7TWnZ2dnUVZ_uJi4p2d@insightbb.com>
sln@netherlands.com wrote:
> On Wed, 16 Dec 2009 13:53:40 -0800, sln@netherlands.com wrote:
>
>> On Wed, 16 Dec 2009 00:54:09 -0500, monkeys paw <user@example.net> wrote:
>>
>> my @allnums = (eval $input);
> ^^
> Note that eval's can execute code, so user input can cause harm:
> my $input = 'print "shit happens\n";30-32,34,50,54-56';
> my @allnums = (eval $input);
>
> *> shit happens
>
> -sln
Thats funny and a good point.
i found several ways that work, and as uri
points out, perl interprets numbers and strings for you,
even if an array element has quotes, as long
as it is numerical it will be interpreted correctly.
@a = (
35,
'35',
);
Either element is a valid int.
------------------------------
Date: Thu, 17 Dec 2009 00:12:03 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: push integers from strings
Message-Id: <87ocly9obg.fsf@quad.sysarch.com>
>>>>> "mp" == monkeys paw <user@example.net> writes:
mp> i found several ways that work, and as uri
mp> points out, perl interprets numbers and strings for you,
mp> even if an array element has quotes, as long
mp> as it is numerical it will be interpreted correctly.
array elements don't have quotes. dumper showed quotes as you had left
those values as strings. please learn to explain things correctly.
mp> @a = (
mp> 35,
mp> '35',
mp> );
mp> Either element is a valid int.
only after you use them as numbers.
and one more time, use a module for this. you still haven't said
anything about the module that does this for you. why not?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
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 2727
***************************************