[29506] in Perl-Users-Digest
Perl-Users Digest, Issue: 750 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 13 14:09:52 2007
Date: Mon, 13 Aug 2007 11:09:07 -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 Mon, 13 Aug 2007 Volume: 11 Number: 750
Today's topics:
Air conditioners for free!??!?!!! <povkra@gmail.com>
conditional regular expressions <morfysster@gmail.com>
Re: conditional regular expressions <wahab@chemie.uni-halle.de>
Re: conditional regular expressions xhoster@gmail.com
Re: File::Find problem? <dale.schmitz@offutt.af.mil>
Re: how to tranpose a huge text file <bugbear@trim_papermule.co.uk_trim>
limiting the amount of resources used by perl <nospam@home.com>
Re: limiting the amount of resources used by perl xhoster@gmail.com
Re: Pagination <webmaster@valleywebnet.com>
Parsing Huge File <manjunatha.nayak@gmail.com>
Re: Parsing Huge File <thepoet_nospam@arcor.de>
Re: Parsing Huge File <scobloke2@infotop.co.uk>
Re: Parsing Huge File xhoster@gmail.com
Re: Pass by reference question anno4000@radom.zrz.tu-berlin.de
Re: Pass by reference question <josef.moellers@fujitsu-siemens.com>
Re: Pass by reference question (Jens Thoms Toerring)
Re: Pass by reference question anno4000@radom.zrz.tu-berlin.de
Re: Pass by reference question xhoster@gmail.com
Re: Pass by reference question xhoster@gmail.com
Re: pass by reference <bpatton@ti.com>
perl DBI OO <jtbutler78@comcast.net>
Re: perl DBI OO (Jens Thoms Toerring)
Re: perl DBI OO <jtbutler78@comcast.net>
Re: perl DBI OO xhoster@gmail.com
redirecting output from find emannion@gmail.com
Re: redirecting output from find <bik.mido@tiscalinet.it>
Regular Expression: Perl and vi <pinaki_m77@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 13 Aug 2007 10:55:29 -0000
From: fritz <povkra@gmail.com>
Subject: Air conditioners for free!??!?!!!
Message-Id: <1187002529.270520.26960@o61g2000hsh.googlegroups.com>
http://airconlinks.blogspot.com/
------------------------------
Date: Mon, 13 Aug 2007 12:37:59 -0000
From: Morfys <morfysster@gmail.com>
Subject: conditional regular expressions
Message-Id: <1187008679.148719.35370@d55g2000hsg.googlegroups.com>
hi,
I was having trouble understanding how regular conditional expressions
work. In particular, in this piece of code:
$str = "ttt, 2";
if(($result) = $str =~ /\w\w\w(?(?=, )(\d))/){
print "$result\n";
}
I don't understand why there is empty output versus "2".
The desired effect is that $result contain the digit following ", " if
it exists in the string.
I've tried almost every variation of the regular expression but I'm
missing something. Thanks in advance for any help.
------------------------------
Date: Mon, 13 Aug 2007 14:54:50 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: conditional regular expressions
Message-Id: <f9pkaq$1vu5$1@nserver.hrz.tu-freiberg.de>
Morfys wrote:
> $str = "ttt, 2";
> if(($result) = $str =~ /\w\w\w(?(?=, )(\d))/){
> print "$result\n";
> }
> I don't understand why there is empty output versus "2".
> The desired effect is that $result contain the digit following ", " if
> it exists in the string.
The regular expression is stepped through from
left to right. Therefore there is an implicit
"the more right pattern matches only if the more
left pattern already matched", which leads to the
trivial solution 1.:
my $str = 'ttt, 2';
my $result;
# trivial solution w/capturing
($result) = $str=~/\w{3}, (\d)/ and print "1. $result\n";
If you want to do some more fancy stuff, you
could 'ifify' the whole expression with
a "positive lookbehind", like:
# lookbehind (?<= ...), no capturing, /g in list context
($result) = $str=~/(?<=\w{3}, )\d/g and print "2. $result\n";
Regards
M.
------------------------------
Date: 13 Aug 2007 16:47:17 GMT
From: xhoster@gmail.com
Subject: Re: conditional regular expressions
Message-Id: <20070813124719.534$gN@newsreader.com>
Morfys <morfysster@gmail.com> wrote:
> hi,
>
> I was having trouble understanding how regular conditional expressions
> work. In particular, in this piece of code:
>
> $str = "ttt, 2";
>
> if(($result) = $str =~ /\w\w\w(?(?=, )(\d))/){
>
> print "$result\n";
>
> }
>
> I don't understand why there is empty output versus "2".
?= is zero-width, meaning that after the ', ' matches, the \d is left
to match starting at the same place, namely, at the ','. Since ',' is not
a \d, it can't match.
>
> The desired effect is that $result contain the digit following ", " if
> it exists in the string.
Isn't that just what the simple /\w\w\w, (\d)/ would do?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 13 Aug 2007 15:28:51 -0000
From: Monty <dale.schmitz@offutt.af.mil>
Subject: Re: File::Find problem?
Message-Id: <1187018931.580238.281680@x40g2000prg.googlegroups.com>
Ok, my apologies for not getting back to anyone over the weekend.
I've had a chance to look over the solutions and I've implemented some
additional troubleshooting steps, but the result is the same.
Henry Law: you pretty much have verbatim what I've coded.
John Krahn: I replaced $File::Find::name with $_ and got the same
results.
There are no spaces in any of the file names. I also verified there
were no trailing spaces by doing an ls -aF on all the files.
How about setting the depth of the find()? The documentation leads me
to believe that the depth is infinite (not really, but such as that
is) by default, but I wonder is that really the case? This find()
I've coded has to go two directories deep before it finds a matching
file.
Thanks
------------------------------
Date: Mon, 13 Aug 2007 13:51:28 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: how to tranpose a huge text file
Message-Id: <13c0kuh6q0rbt2d@corp.supernews.com>
RedGrittyBrick wrote:
> bugbear wrote:
>> Jie wrote:
>>> I have a huge text file with 1000 columns and about 1 million rows,
>>> and I need to transpose this text file so that row become column and
>>> column become row. (in case you are curious, this is a genotype file).
>>>
>>> Can someone recommend me an easy and efficient way to transpose such a
>>> large dataset, hopefully with Perl ?
>>
>> This is very analagous to the problems
>> of rotating a (much larger than memory) photograph.
>>
>
> Are you suggesting
> encode as GIF
> invoke Image::Magik rotate 90
> decode
> ?
>
> Feasible* but a little weird :-)
>
No, I'm suggesting some of the approaches
and concepts used when rotating images
might be applicable.
BugBear
------------------------------
Date: Mon, 13 Aug 2007 16:12:16 GMT
From: "Nospam" <nospam@home.com>
Subject: limiting the amount of resources used by perl
Message-Id: <Ap%vi.12578$Db6.6514@newsfe3-win.ntli.net>
Is there way to limit the amount of resources/ram/cpu used by a perl
script? so that the script still runs, but does not exceed certain limits?
------------------------------
Date: 13 Aug 2007 16:38:36 GMT
From: xhoster@gmail.com
Subject: Re: limiting the amount of resources used by perl
Message-Id: <20070813123837.903$nz@newsreader.com>
"Nospam" <nospam@home.com> wrote:
> Is there way to limit the amount of resources/ram/cpu used by a perl
> script?
Your OS should provide facilities for this. Perl may have facilities for
negotiating this with the OS, but they would depend on the OS.
> so that the script still runs, but does not exceed certain
> limits?
In the case of ram, what would you have it do? In very specific cases,
there are options. But in a general purpose language not designed for only
those specific cases, what exactly do you do when you ask for more memory
and are told you can't have any more?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 13 Aug 2007 11:34:03 -0000
From: JimJx <webmaster@valleywebnet.com>
Subject: Re: Pagination
Message-Id: <1187004843.407822.242490@g4g2000hsf.googlegroups.com>
On Aug 12, 3:02 pm, Sherm Pendley <spamt...@dot-app.org> wrote:
> webmas...@valleywebnet.com writes:
> > Unfortunately, I can't use any of those, my server doesn't have them
> > installed and getting them to install something new is like pulling
> > teeth from an alligator.
>
> > Anyone have any other suggestions?
>
> Install it yourself - you only need root access if you want to install a
> module into a directory to which only root can write, such as /usr/lib.
>
> In a nutshell, just download the module tarball, unpack it, and specify
> an install location to which you have access when you run Makefile.PL. For
> example:
>
> perl Makefile.PL PREFIX=/home/mylogin
>
> The above assumes you've already downloaded and unpacked the tarball, of
> course. You can also configure the CPAN shell to use a configuration step
> like this automatically.
>
> For details, see:
>
> perldoc perlmodinstall
> perldoc CPAN
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians:http://wv-www.net
> Cocoa programming in Perl:http://camelbones.sourceforge.net
Thanks Sherm!
Greatly appreciated.
Jim
------------------------------
Date: Mon, 13 Aug 2007 13:05:55 -0000
From: Majnu <manjunatha.nayak@gmail.com>
Subject: Parsing Huge File
Message-Id: <1187010355.270268.129540@d55g2000hsg.googlegroups.com>
Hello,
I have a strange problem. I have a flat file of about 6 million rows,
each row of 600 bytes. I read the file line by line after opening like
this:
open(IN, "cat $InputFile |") or die "Failed to open the File";
##This was changed from open(IN, "< $InputFile") because Perl
outrightly refused to open the file.
while(<IN>) {......
The problem is that, at times, Perl just stops after reading 3,334,601
records. No error message printed. And this is not a problem whih
occurs always. It just happens sporadically and hence difficult to
track because, if I re-process the file, it gets read completely.
Would someone please shed light on how this could be happening? Is
this something related with memory?
------------------------------
Date: Mon, 13 Aug 2007 16:20:16 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Parsing Huge File
Message-Id: <46c068a0$0$7693$9b4e6d93@newsspool2.arcor-online.net>
Majnu wrote:
> I have a strange problem. I have a flat file of about 6 million rows,
> each row of 600 bytes. I read the file line by line after opening like
> this:
>
> open(IN, "cat $InputFile |") or die "Failed to open the File";
> ##This was changed from open(IN, "< $InputFile") because Perl
> outrightly refused to open the file.
With which error message did Perl refuse to open the file?
Normally this shouldn't happen. If your numbers are correct,
even a Perl compiled without uselargefiles=define should be
able to open a file of under 2GB on any halfway recent platform.
> while(<IN>) {......
>
> The problem is that, at times, Perl just stops after reading 3,334,601
> records. No error message printed.
That's really strange. Giving no error message at all shouldn't
happen. Does your script still react to Ctrl+C then, or is the
whole Perl process hung up? If yes, is there nothing in the OS kernel's
log that gives a hint?
> And this is not a problem whih
> occurs always. It just happens sporadically and hence difficult to
> track because, if I re-process the file, it gets read completely.
And you're sure that the error _always_ occurs after exactly 3,334,601
records?
> Would someone please shed light on how this could be happening? Is
> this something related with memory?
This really sounds strange to me. Does the file reside on a local
disk (otherwise it could be some network fs issue)? Does it also
happen with a copy of the file in a different directory / partition
/ disk?
What platform (OS, Filesystems) are you running your script on, and
which Perl version are you using (output from "perl -V")?
-Chris
------------------------------
Date: Mon, 13 Aug 2007 16:14:41 +0100
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Parsing Huge File
Message-Id: <46c07565$0$24757$da0feed9@news.zen.co.uk>
Majnu wrote:
> Hello,
>
> I have a strange problem. I have a flat file of about 6 million rows,
> each row of 600 bytes. I read the file line by line after opening like
> this:
>
> open(IN, "cat $InputFile |") or die "Failed to open the File";
> ##This was changed from open(IN, "< $InputFile") because Perl
> outrightly refused to open the file.
I'd write that as
open my $in, '<', $InputFile
or die "Failed to open '$InputFile' because $!";
Your `cat` doesn't seem to be doing anything useful.
I always print information about the cause of the error ($!).
I'd get Perl to say exactly *why* it "refused to open the file" before
introducing further complications like `cat`.
> while(<IN>) {......
while(<$in>) { ...
>
> The problem is that, at times, Perl just stops after reading 3,334,601
> records. No error message printed. And this is not a problem whih
> occurs always. It just happens sporadically and hence difficult to
> track because, if I re-process the file, it gets read completely.
>
> Would someone please shed light on how this could be happening? Is
> this something related with memory?
>
I guess that would depend on what sort of processing you are doing.
Perhaps a side effect of your script changes the run-time environment
for the re-run. e.g. it creates a log-file that didn't exist and that
your script expects to be present. Maybe there's resource conflicts with
other running processes. Still it is unusual to get no messages, have
you been assiduous in checking for errors in all statements that can
potentially report run-time errors?
------------------------------
Date: 13 Aug 2007 16:53:16 GMT
From: xhoster@gmail.com
Subject: Re: Parsing Huge File
Message-Id: <20070813125317.957$bS@newsreader.com>
Majnu <manjunatha.nayak@gmail.com> wrote:
> Hello,
>
> I have a strange problem. I have a flat file of about 6 million rows,
> each row of 600 bytes. I read the file line by line after opening like
> this:
>
> open(IN, "cat $InputFile |") or die "Failed to open the File";
> ##This was changed from open(IN, "< $InputFile") because Perl
> outrightly refused to open the file.
Instead of just silly things to circumvent the problem, perhaps you
should figure out why Perl refused to open the file. That is what $! is
for. If you put electrical tape over the "oil pressure" light on your
dashboard, instead of fixing the problem, you shouldn't be surprised when
your car stops working.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 13 Aug 2007 11:44:46 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Pass by reference question
Message-Id: <5iauheF3od4m7U1@mid.dfncis.de>
grocery_stocker <cdalten@gmail.com> wrote in comp.lang.perl.misc:
> If perl can pass stuff by reference, then why do you have to deference
> it. Like for example
>
> @tailings = popmany ( \@a, \@b, \@c, \@d );
>
>
> sub popmany {
> my $aref;
> my @retlist = ();
> foreach $aref ( @_ ) {
> push @retlist, pop @$aref;
> }
> return @retlist;
> }
>
>
> Wouldn't it be more accurate to say that perl passes the reference by
> value? I just find this sort of odd because in both Java (withc uses
> pass the reference by value) and C++ (which supports pass by
> reference), I never recall having to dereference a reference like what
> I have to in perl.
The perceived problem here is mostly due to ambiguous terminology.
There is the common distinction of parameter passing "by value" vs "by
reference". The first one means that all a subroutine ever gets to see
is a copy of the parameter value whereas the second means the subroutine
has access to the variable as it exists in the caller's context and can,
for instance, change the value so that the change is visible to the
caller.
Perl subs implement "pass by reference" in this sense, since assigning
to elements of @_ changes the value for the caller. This description
went into the Perl documentation, and when Perl was young (before Perl
5) this caused no problems because the term "reference" didn't have
a Perl-specific meaning back then.
That changed when Perl 5 introduced its own references (what you get
by prefixing a variable with a backslash). These references are *not*
what Perl uses to implement its "pass by reference", but an entirely
distinct notion. In Perl terms, what is commonly called "pass by
reference" might be called "pass by alias(ing)", but that term is not
in general use and wouldn't be readily understood. So the documentation
continues to use the commonly recognized term even after it has become
ambiguous.
Anno
------------------------------
Date: Mon, 13 Aug 2007 13:50:31 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Pass by reference question
Message-Id: <f9pgic$u7q$1@nntp.fujitsu-siemens.com>
grocery_stocker wrote:
> If perl can pass stuff by reference, then why do you have to deference
> it. Like for example
>=20
> @tailings =3D popmany ( \@a, \@b, \@c, \@d );
>=20
>=20
> sub popmany {
> my $aref;
> my @retlist =3D ();
> foreach $aref ( @_ ) {
> push @retlist, pop @$aref;
> }
> return @retlist;
> }
>=20
>=20
> Wouldn't it be more accurate to say that perl passes the reference by
> value? I just find this sort of odd because in both Java (withc uses
> pass the reference by value) and C++ (which supports pass by
> reference), I never recall having to dereference a reference like what
> I have to in perl.
>=20
Perl passes variables by reference and dereferences them automagically.=20
If you explicitly pass a reference ('\@a'), you'll have to dereference=20
it explicitly.
I.e. in your example, popmany is passed four references to references to =
arrays.
Josef
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: 13 Aug 2007 12:07:16 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Pass by reference question
Message-Id: <5iavrkF3nsladU1@mid.uni-berlin.de>
Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
> Jens Thoms Toerring wrote:
> > grocery_stocker <cdalten@gmail.com> wrote:
> >
> >>If perl can pass stuff by reference, then why do you have to deference
> >>it.
> >
> > No, you can't. Perl only allows to pass scalars to functions and
> > those are passed by value.
> Why, then, does the following script print "Bar"?
> sub f($) {
> $_[0] = 'Bar';
> }
> my $v = 'Foo';
> f($v);
> print "$v\n";
> And what does this script's error message tell us?
> sub f($) {
> $_[0] = 'Bar';
> }
> f('Foo');
It tells me that I obviously I was writing BS, at least when I
didn't mention that using prototypes changes the picture.
Ok, to the OP: you could write your function e.g. as
sub popmany(\@;\@;\@;\@) {
return map { pop @$_ } @_;
}
and then call it as
@tailings = popmany @a, @b, @c, @d;
using the possibility to "pass by reference" when using prototypes.
But please note that this only will work with up to four arrays,
so the function would be better named pop_up_to_four() or something
like that.
But my personal preference is to avoid prototypes except for the
very purpose they were introduced for, mimiking the behaviour of
built-in functions like push or pop. You still have to use the
dereference syntax for arrays and hashes within the subroutine
since what arrives within the subroutine are still scalars. And
be wary of modifying elements of @_ unless you understand fully
what to expect (I find it a bit weird). And, finally, prototypes
don't influence method calls, only "normal" functions.
At least don't assume that prototypes play a similar role to
those in other languages like C, C++, Java etc., they don't.
They aren't meant for compile time type checking.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: 13 Aug 2007 13:26:48 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Pass by reference question
Message-Id: <5ib4goF3olcncU1@mid.dfncis.de>
grocery_stocker <cdalten@gmail.com> wrote in comp.lang.perl.misc:
> If perl can pass stuff by reference, then why do you have to deference
> it. Like for example
>
> @tailings = popmany ( \@a, \@b, \@c, \@d );
>
>
> sub popmany {
> my $aref;
> my @retlist = ();
> foreach $aref ( @_ ) {
> push @retlist, pop @$aref;
> }
> return @retlist;
> }
On an unrelated note (unrelated to the question, that is), popmany()
can be written more compact as
sub popmany { map pop @$_, @_ }
Anno
------------------------------
Date: 13 Aug 2007 16:59:10 GMT
From: xhoster@gmail.com
Subject: Re: Pass by reference question
Message-Id: <20070813125911.964$FM@newsreader.com>
grocery_stocker <cdalten@gmail.com> wrote:
> If perl can pass stuff by reference, then why do you have to deference
> it. Like for example
>
> @tailings = popmany ( \@a, \@b, \@c, \@d );
You are sticking the backwhacks in front of those arrays, not Perl.
(If you are using prototypes, then perl will in effect add the backwhacks
for you, but that is a different matter).
Since you took the reference, not Perl, then you have to do the
dereference.
>
> sub popmany {
> my $aref;
> my @retlist = ();
> foreach $aref ( @_ ) {
> push @retlist, pop @$aref;
> }
> return @retlist;
> }
>
> Wouldn't it be more accurate to say that perl passes the reference by
> value? I just find this sort of odd because in both Java (withc uses
> pass the reference by value) and C++ (which supports pass by
> reference), I never recall having to dereference a reference like what
> I have to in perl.
Perl does "pass the thingamabob by alias". That that thingamabob which was
passed by alias is a reference is due to your particulars and Perl's
generals.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 13 Aug 2007 17:08:19 GMT
From: xhoster@gmail.com
Subject: Re: Pass by reference question
Message-Id: <20070813130821.242$Fg@newsreader.com>
grocery_stocker <cdalten@gmail.com> wrote:
> If perl can pass stuff by reference, then why do you have to deference
> it. Like for example
>
> @tailings = popmany ( \@a, \@b, \@c, \@d );
You are sticking the backwhacks in front of those arrays, not Perl.
(If you are using prototypes, then perl will in effect add the backwhacks
for you, but that is a different matter).
Since you took the reference, not Perl, then you have to do the
dereference.
>
> sub popmany {
> my $aref;
> my @retlist = ();
> foreach $aref ( @_ ) {
> push @retlist, pop @$aref;
> }
> return @retlist;
> }
>
> Wouldn't it be more accurate to say that perl passes the reference by
> value? I just find this sort of odd because in both Java (withc uses
> pass the reference by value) and C++ (which supports pass by
> reference), I never recall having to dereference a reference like what
> I have to in perl.
Perl does "pass the thingamabob by alias". That that thingamabob which was
passed by alias is a reference is due to your particulars and not Perl's
generals.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 13 Aug 2007 08:08:09 -0500
From: Billy Patton <bpatton@ti.com>
To: Clenna Lumina <savagebeaste@yahoo.com>
Subject: Re: pass by reference
Message-Id: <46C057B9.3010007@ti.com>
Clenna Lumina wrote:
> Billy Patton wrote:
>> anno4000@radom.zrz.tu-berlin.de wrote:
>>> Billy Patton <bpatton@ti.com> wrote in comp.lang.perl.misc:
>>>> Larry wrote:
>>>>> The following code snippet shows how I do "pass by reference" in
>>>>> Perl. It works fine, but I'm wondering... is there a less verbose
>>>>> way to do this?
>>> [...]
>>>
>>>> Do you really want side effects ?
>>>> Passing by reference does this.
>>>> Guess this is too simple to make that decision.
>>>>
>>>> sub squareMe($) {
>>>> my ($arg) = @_;
>>>> $arg *= $arg;
>>>> }
>>>>
>>>> my $n=7;
>>>> $n = squareMe $n; # no side effects
>>>> I hate it when my variables get changed somewhere else and I have to
>>>> track it down for debugging!
>>> That raises the question why you are using the mutator "*=" at all.
>>> It doesn't do anything useful.
>>>
>>> sub square_me {
>>> my $arg = shift;
>>> $arg*$arg;
>>> }
>>>
>>> would be exactly equivalent, as would be
>>>
>>> sub square_me { $_[0]*$_[0] }
>>>
>>> Anno
>> The beauty of perl "Always more than one way to skin a cat" :)
>
> Just how many ways do you need to skin a cat :-P yeeesh
>
> (Seriously though, it's one the things I really love about Perl)
>
>
Depends on the cat and your skinning tool :)
------------------------------
Date: Mon, 13 Aug 2007 07:35:01 -0700
From: "jtbutler78@comcast.net" <jtbutler78@comcast.net>
Subject: perl DBI OO
Message-Id: <1187015701.377762.127150@22g2000hsm.googlegroups.com>
I have a module that I instantiate a DBI connection from. My question
is - I am doing the right way? It works but I dont know know I am
making a connection to the DB each time I call getResults or am I only
using the first connection I make. I call getResults inside loops or
make several calls to it within my application and its a waste to make
connections with each call.
sub new {
my ($pkg, $db_host, $db, $uid, $pwd) = @_;
my $app = {};
$app->{DB} = DBI->connect("DBI:mysql:$db:$db_host", "$uid",
"$pwd");
bless $app, $pkg;
return $app;
} #end new
sub getDB { return $_[0]->{DB} };
sub getResults {
my ($pkg, $query) = @_;
my $sth = $pkg->getDB()->prepare($query);
$sth->execute or die "Can't execute statement: $DBI::errstr";
return $sth->fetchall_arrayref();
} #getResults
------------------------------
Date: 13 Aug 2007 15:27:08 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: perl DBI OO
Message-Id: <5ibbicF3oeh91U1@mid.uni-berlin.de>
jtbutler78@comcast.net <jtbutler78@comcast.net> wrote:
> I have a module that I instantiate a DBI connection from. My question
> is - I am doing the right way? It works but I dont know know I am
> making a connection to the DB each time I call getResults or am I only
> using the first connection I make. I call getResults inside loops or
> make several calls to it within my application and its a waste to make
> connections with each call.
> sub new {
> my ($pkg, $db_host, $db, $uid, $pwd) = @_;
> my $app = {};
> $app->{DB} = DBI->connect("DBI:mysql:$db:$db_host", "$uid",
> "$pwd");
> bless $app, $pkg;
> return $app;
> } #end new
> sub getDB { return $_[0]->{DB} };
> sub getResults {
> my ($pkg, $query) = @_;
> my $sth = $pkg->getDB()->prepare($query);
I guess it's about this line. No, you don't create a new connection
every time since the getDB method returns a value you stored after
you called connect(). You call connect() only each time you create
a new object.
> $sth->execute or die "Can't execute statement: $DBI::errstr";
> return $sth->fetchall_arrayref();
> } #getResults
What I would think about is why you writw your own class when
there are existing ones like e.g. DBIx::Class etc. - you don't
even have to write SQL anymore which makes writing programs a
lot simpler and less tedious.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: Mon, 13 Aug 2007 08:34:00 -0700
From: "jtbutler78@comcast.net" <jtbutler78@comcast.net>
Subject: Re: perl DBI OO
Message-Id: <1187019240.268348.288800@o61g2000hsh.googlegroups.com>
On Aug 13, 11:27 am, j...@toerring.de (Jens Thoms Toerring) wrote:
> jtbutle...@comcast.net <jtbutle...@comcast.net> wrote:
> > I have a module that I instantiate a DBI connection from. My question
> > is - I am doing the right way? It works but I dont know know I am
> > making a connection to the DB each time I call getResults or am I only
> > using the first connection I make. I call getResults inside loops or
> > make several calls to it within my application and its a waste to make
> > connections with each call.
> > sub new {
> > my ($pkg, $db_host, $db, $uid, $pwd) = @_;
> > my $app = {};
> > $app->{DB} = DBI->connect("DBI:mysql:$db:$db_host", "$uid",
> > "$pwd");
> > bless $app, $pkg;
> > return $app;
> > } #end new
> > sub getDB { return $_[0]->{DB} };
> > sub getResults {
> > my ($pkg, $query) = @_;
> > my $sth = $pkg->getDB()->prepare($query);
>
> I guess it's about this line. No, you don't create a new connection
> every time since the getDB method returns a value you stored after
> you called connect(). You call connect() only each time you create
> a new object.
>
> > $sth->execute or die "Can't execute statement: $DBI::errstr";
> > return $sth->fetchall_arrayref();
> > } #getResults
>
> What I would think about is why you writw your own class when
> there are existing ones like e.g. DBIx::Class etc. - you don't
> even have to write SQL anymore which makes writing programs a
> lot simpler and less tedious.
> Regards, Jens
> --
> \ Jens Thoms Toerring ___ j...@toerring.de
> \__________________________ http://toerring.de
I will look into it - I didnt know about that module. I basically
want to have one place where I make/modify my connections.
------------------------------
Date: 13 Aug 2007 17:06:44 GMT
From: xhoster@gmail.com
Subject: Re: perl DBI OO
Message-Id: <20070813130645.866$uF@newsreader.com>
"jtbutler78@comcast.net" <jtbutler78@comcast.net> wrote:
> I have a module that I instantiate a DBI connection from. My question
> is - I am doing the right way? It works but I dont know know I am
> making a connection to the DB each time I call getResults or am I only
> using the first connection I make. I call getResults inside loops or
> make several calls to it within my application and its a waste to make
> connections with each call.
You are making a new connection each time you call "new", and just re-use
that connection each time you call getResults on a given object obtained
by new. So if your class is only instantiated once per program, then
you only make one connection. But from the bigger picture, I'd have to
wonder what the point is. It looks like you just made a simple wrapper
around DBI which adds no new functionality but takes away a lot of existing
functionality.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 13 Aug 2007 13:43:30 -0000
From: emannion@gmail.com
Subject: redirecting output from find
Message-Id: <1187012610.381813.254920@d55g2000hsg.googlegroups.com>
Hi,
I have a script that finds files like this:
find(\&finds, $dir);
sub finds {
return unless -f;
if ( $_ =~ /^core./ ){
@ls = `ls -l $File::Find::name`;
fail("Core file $_ found in: $File::Find::dir ", "MEDIUM");
print PX_HEALTH_REPORT "@ls \n";
$flag = 1;
}
}
This works fine but the error output from find gets printed to the
screen like this:
Can't cd to (/var/spool/) mqueue : The file access permissions do not
allow the specified action.
Can't cd to (/var/spool/cron/) crontabs : The file access permissions
do not allow the specified action.
Can't cd to (/var/spool/cron/) atjobs : The file access permissions do
not allow the specified action.
Can't cd to (/var/adm/) SRC : The file access permissions do not allow
the specified action.
Can't cd to (/var/adm/) cron : The file access permissions do not
allow the specified action.
Can someone tell me how to redirect this output somewhere else. I
still want some output to be printed to the screen so a change in the
code for this function would be helpful.
All help appreciated
Enda
------------------------------
Date: Mon, 13 Aug 2007 16:01:07 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: redirecting output from find
Message-Id: <mlo0c3lbn4juj6mmkve0lai6q2ca45g352@4ax.com>
On Mon, 13 Aug 2007 13:43:30 -0000, emannion@gmail.com wrote:
> if ( $_ =~ /^core./ ){
This is just as if you had stepped on my thumb. Use
if ( /^core./ ) { ... }
# or
if ( $var =~ /^core./ ) { ... }
BTW: how strange a regex
> @ls = `ls -l $File::Find::name`;
This is more as if you had stabbed me in the back.
Well, a quick way to gather and display some info, but since you cd in
the browsed directory, it should *not* do what you mean.
>This works fine but the error output from find gets printed to the
>screen like this:
>
>
>Can't cd to (/var/spool/) mqueue : The file access permissions do not
>allow the specified action.
[snip]
Then it *can't* "work fine". There are some directories you're not
accessing. If you don't want to anyway, then you'd better check for
yourself and prune.
Or see if the no_chdir find() param helps.
>Can someone tell me how to redirect this output somewhere else. I
>still want some output to be printed to the screen so a change in the
>code for this function would be helpful.
Well, supposedly those are errors printed to STDERR. From your shell
redirect it to some place where it doesn't annoy you. Most probably,
with 2>/dev/null
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Mon, 13 Aug 2007 17:58:49 -0000
From: googler <pinaki_m77@yahoo.com>
Subject: Regular Expression: Perl and vi
Message-Id: <1187027929.706461.35810@m37g2000prh.googlegroups.com>
I am trying to create a list of the differences in regular expression
for Perl and vi. I have been using both Perl and vi, and get confused
by this sometimes. There are a few that I already know of.
1. In Perl, characters like (, { etc when used as metacharacter can be
used by themselves (without using a \). In vi, they should be escaped
with a \. (Question: what is the full list of the metacharacters where
we see this difference?)
2. In Perl, non-greedy search can be done by using a ? character
(like .*?). In vi, this is done as .\{-}
3. In Perl, zero or one match can be achieved by putting a ? character
after the pattern. In vi, this is done by \=
4. In Perl, the RE for matching only a particular word is \bword\b .
In vi, it is \<word\> (Question: does \<word\> work for Perl?)
Please add to the list if you know of any difference that I missed.
Thanks.
------------------------------
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 750
**************************************