[29502] in Perl-Users-Digest
Perl-Users Digest, Issue: 746 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 11 18:09:40 2007
Date: Sat, 11 Aug 2007 15:09:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 11 Aug 2007 Volume: 11 Number: 746
Today's topics:
commandline replace and running out of quotes <to.eric.smith@gmail.com>
Re: form script question <rvtol+news@isolution.nl>
Re: Help: Newbie Question <tzz@lifelogs.com>
Re: how to tranpose a huge text file <tzz@lifelogs.com>
Re: how to tranpose a huge text file <tzz@lifelogs.com>
Re: I am giving up perl because of assholes on clpm -- <rvtol+news@isolution.nl>
Re: I am giving up perl because of assholes on clpm -- <rvtol+news@isolution.nl>
Re: I am giving up perl because of assholes on clpm -- <rvtol+news@isolution.nl>
Re: match and group across 2 lines <rvtol+news@isolution.nl>
Re: Objects/Structures in Perl <rvtol+news@isolution.nl>
Re: Out of memory in vec <tzz@lifelogs.com>
Re: Out of memory in vec <rvtol+news@isolution.nl>
Re: Out of memory in vec <rvtol+news@isolution.nl>
Re: Out of memory in vec <spamtrap@dot-app.org>
Pagination webmaster@valleywebnet.com
Re: Pagination <sigzero@gmail.com>
Re: pass by reference <savagebeaste@yahoo.com>
Re: pass by reference <savagebeaste@yahoo.com>
Re: Replacing a line <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 11 Aug 2007 21:47:06 -0000
From: John Bagins <to.eric.smith@gmail.com>
Subject: commandline replace and running out of quotes
Message-Id: <1186868826.514758.182590@22g2000hsm.googlegroups.com>
I am using the inplace edit of commandline perl in a per script.
How do I insert those doublequotes in the RHS?
system qq|perl -pi -e "s/(?=#FILE_MARKER)/" $var "/| file_name;
^ ^
Thanls
Eric Smith
------------------------------
Date: Sat, 11 Aug 2007 17:34:01 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: form script question
Message-Id: <f9ks7j.1ko.1@news.isolution.nl>
Dr.Ruud schreef:
> David Pyles:
>> $homedir || $vdeck->fatal_error("Can't determine home directory");
>
> That line seems to have to be moved up about 8 lines.
Correction:
> my $homedir = '';
> $ENV{DOCUMENT_ROOT} =~ m|(/home/[\w\-]+)| and $homedir = $1;
>
> # print "Content-type: text/plain\n\n--$homedir--"; exit(0);
>
> my $vdeck = vDeckPublic->new({ -db =>
> "DBI:CSV:f_dir=$homedir/.panel/data/;csv_eol=\n;",
> -user => '',
> -pass => '' });
>
> $homedir || $vdeck->fatal_error("Can't determine home directory");
I now read it as that the error is postponed on a purpose, until $vdeck
defined.
(So maybe there should be a die() added for when the new() fails.)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 11 Aug 2007 11:04:02 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Help: Newbie Question
Message-Id: <m24pj66ost.fsf@lifelogs.com>
On Sat, 11 Aug 2007 15:33:57 +0800 Amy Lee <openlinuxsource@gmail.com> wrote:
AL> On Fri, 10 Aug 2007 11:03:14 -0500, Ted Zlatanov wrote:
>> I think this was fairly rude (not that it's unusual on c.l.p.m in the
>> last few years). At least point the OP in the right direction. I'll
>> follow up to her question separately.
AL> Thanks your patience. I suppose that I have no brilliant in coding. So if
AL> I post some "stupid" questions, please do not angry.
I was saying the reply to your e-mail was fairly rude, I wasn't angry
with your original post (you're the OP, "original poster"). Your
question was not stupid, it simply showed nothing you have tried
already, and that's what Josef was talking about.
Did you look in the perlinto and perlretut documentation pages? They
will get you started on this task and on your Perl knowledge.
Ted
------------------------------
Date: Sat, 11 Aug 2007 10:41:48 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: how to tranpose a huge text file
Message-Id: <m2d4xu6ptv.fsf@lifelogs.com>
On Sat, 11 Aug 2007 03:51:27 +0000 (UTC) Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
IZ> Words words words. You can't do *all the things* efficiently.
IZ> Databases are optimized for some particular access patterns. I doubt
IZ> that even "good databases" are optimized for *this particular* access
IZ> pattern.
You mean "SELECT column FROM table" (which is what you need in order to
write each line of the transposed file)? I think that's a pretty common
access pattern, and would perform well in most databases.
Ted
------------------------------
Date: Sat, 11 Aug 2007 11:00:06 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: how to tranpose a huge text file
Message-Id: <m28x8i6ozd.fsf@lifelogs.com>
On 11 Aug 2007 01:17:08 GMT xhoster@gmail.com wrote:
x> Ted Zlatanov <tzz@lifelogs.com> wrote:
>> Look, databases are optimized to store large amounts of data
>> efficiently.
x> For some not very general meanings of "efficiently", sure.
Actually, it's the general meaning that I had in mind. For specific
efficiency and optimization, databases are not always the right tool.
For instance, a database will never perform as quickly as a fixed-offset
file for individual seeks to retrieve a record. Based on the OP's data,
I think a database is the right solution.
x> One of the major gene-chip companies was very proud that in one of
x> their upgrades, they started using a database instead of plain files
x> for storing the data. And then their customers were very pleased
x> when in a following upgrade they abandoned that, and went back to
x> using plain files for the bulk data and using the database just for
x> the small DoE metadata.
I can give you many examples where databases improved a business; I've
worked with large sets of data to do data analysis and storing it in a
database was ridiculously better than the equivalent work on a flat-file
database. For the OP's data set, I think database storage is a
reasonable, cost-efficient, and maintainable solution.
>> You can always create a hand-tuned program that will do
>> one task (e.g. transposing a huge text file) well, but you're missing
>> the big picture: future uses of the data. I really doubt the only thing
>> anyone will ever want with that data is to transpose it.
x> And I really doubt that any single database design is going to support
x> everything that anyone may ever want to do with the data, either.
My point is that the single-task program to transpose a file will be
much less useful than the database setup for general use. You're taking
the argument to an absurd extreme ("everything that anyone may ever
want").
x> I think you are missing the big picture. Once you make a seekable
x> file format, that probably does away with the need to transpose the
x> data in the first place--whatever operation you wanted to do with the
x> transposition can be probably be done on the seekable file instead.
Usually the rewrite is for another program that wants that data as
input, so no, you can't do "whatever" operation on the seekable file
without rewriting the consumer program's input routine.
Ted
------------------------------
Date: Sat, 11 Aug 2007 17:37:36 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: I am giving up perl because of assholes on clpm -- switching to Python
Message-Id: <f9ks7k.1ko.1@news.isolution.nl>
Paul Boddie schreef:
> let us
> avoid comp.lang.python becoming some kind of linux-kernel ego trip
> where anyone who has stuck around has an interest in perpetuating a
> hostile atmosphere.
"When did you stop beating your wife?"
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 11 Aug 2007 17:54:59 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: I am giving up perl because of assholes on clpm -- switching to Python
Message-Id: <f9ktdc.1ho.1@news.isolution.nl>
grocery_stocker schreef:
> In the beginning there was Mathematics
> And all was good
> Then one day God said "Let there be the Lambda Calculus"
> And hence the Lambda Calculus was born.
> However, God felt the the Lambda Calculus needed a mate
> So god said "Let there be Lisp"
> And thus, Lisp was born.
>
> As the years went on, god became depressed by how impure the Lisp had
> become.
> For from the Lisp, came Emacs Lisp, Java, Perl, Ruby, and Python.
http://xkcd.com/224/
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 11 Aug 2007 17:53:11 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: I am giving up perl because of assholes on clpm -- switching to Python
Message-Id: <f9kt3u.1d8.1@news.isolution.nl>
RedGrittyBrick schreef:
> treasure the saints, tolerate the irritable and
> ignore the whiners.
*You are what you read.* What is "irritating" to some, is "to the point"
to others.
That should say enough, but some people just can not stand short
replies, they can not hold themselves back from reading all negative
kinds of things into them. Too little attention maybe? (I am just making
the same mistake to show how it works.)
Only rarely someone mistakes the "to the point" for the "irritating",
without acknowledging their mistake in the first or second next reply.
Newbies with the wrong focus, under pressure, probably suffering lack of
sleep? (I am just making things worse.)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 11 Aug 2007 18:10:46 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: match and group across 2 lines
Message-Id: <f9ku9l.1bk.1@news.isolution.nl>
ktlind@gmail.com schreef:
> I would like to group six numbers separated by commas into $1 thru $6.
> The problem is that four of the numbers are on the first line and two
> of the numbers are on the second line. Here is an example of those 2
> lines:
>
> SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 $
> ,-49.320486,347.560579
>
> The $ on the end of the first line is a continuation symbol for the
> next line.
>
>
> I can group the first four numbers with:
>
> ^SLN\d\d\d = LINE\/(.*),(.*),(.*),(.*) \$$
>
> How can I reach down one more line and get the other two numbers?
>
>
> Thanks for your help.
Why require usage of $1 to $6?
#!/usr/bin/perl
use strict;
use warnings;
my $t = <<'EOT';
SLN499 = LINE/994.455930,-49.320125,347.561019,994.456333 $
,-49.320486,347.560579
EOT
my @numbers = $t =~ /[\d.-]+/g;
print "$_\n" for @numbers[ 1 .. $#numbers ];
__END__
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 11 Aug 2007 18:50:46 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Objects/Structures in Perl
Message-Id: <f9l0gt.1j8.1@news.isolution.nl>
A. Sinan Unur schreef:
> When programming Perl, I always look at the documentation first. Perl
> has great documentation.
>
> Python does not. Ruby does not. PHP does not. At least, what is
> available is not suitable for me and I have avoided those languages.
PHP is just a tiny language and a lot of functions, so after a short
while, one "just" needs the functions reference, like:
http://www.php.net/manual/en/ref.strings.php
The TOC of the manual is here: http://www.php.net/manual/en/
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 11 Aug 2007 11:09:50 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Out of memory in vec
Message-Id: <m2zm0y59yp.fsf@lifelogs.com>
On Sat, 11 Aug 2007 01:12:41 -0500 "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net> wrote:
MW> Alright, I admit I cheated :-)
MW> Five bits were needed, so I used five bits. No, I didn't hack the
MW> vec() function in the Perl core. I just used two buffers:
...
MW> This works on Jie's submitted data, and it takes less than two minutes
MW> to run and requires only 10MB of memory. I'm happy about that, but I
MW> suspect it may encounter problems when dealing with over a gigabyte of
MW> input data.
Cool solution. I thought about using a separate list to store the "--"
instances, so the storage would be 4 bits per pair plus a sorted list of
offsets (or hash of offsets, for faster lookups). I think your solution
is better, though.
Ted
------------------------------
Date: Sat, 11 Aug 2007 18:54:27 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Out of memory in vec
Message-Id: <f9l0qb.t8.1@news.isolution.nl>
Mumia W. schreef:
> I have 512mb RAM and 800mb swap,
Yeah, millibits won't get you far.
;-)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 11 Aug 2007 19:13:17 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Out of memory in vec
Message-Id: <f9l1vu.160.1@news.isolution.nl>
Mumia W. schreef:
> my %bases = (
> 0,'AA',1,'AC',2,'AG',3,'AT',4,'A-',5,'CA',6,'CC',
> 7,'CG',8,'CT',9,'C-',10,'GA',11,'GC',12,'GG',13,'GT',
> 14,'G-',15,'TA',16,'TC',17,'TG',18,'TT',19,'T-',
> 20,'-A',21,'-C',22,'-G',23,'-T',24,'--',
> );
> my %rbases = reverse %bases;
Maybe a base-5 approach will give somebody some ideas:
0 => 00 => --
1 => 01 => -A
2 => 02 => -C
3 => 03 => -G
4 => 04 => -T
5 => 10 => A-
6 => 11 => AA
7 => 12 => AC
8 => 13 => AG
9 => 14 => AT
A => 20 => B-
B => 21 => BA
C => 22 => BC
D => 23 => BG
E => 24 => BT
F => 30 => G-
G => 31 => GA
H => 32 => GC
I => 33 => GG
J => 34 => GT
K => 40 => T-
L => 41 => TA
M => 42 => TC
N => 43 => TG
O => 44 => TT
Maybe a combination of a sparse array, index being the result of
t/-ACGT/01234/, is faster than a hash lookup?
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sat, 11 Aug 2007 15:29:22 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Out of memory in vec
Message-Id: <m23aypc1kd.fsf@dot-app.org>
"Dr.Ruud" <rvtol+news@isolution.nl> writes:
> Mumia W. schreef:
>
>> I have 512mb RAM and 800mb swap,
>
>
> Yeah, millibits won't get you far.
> ;-)
Every little bit helps... :-)
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Sat, 11 Aug 2007 11:40:12 -0700
From: webmaster@valleywebnet.com
Subject: Pagination
Message-Id: <1186857612.698731.36300@q75g2000hsh.googlegroups.com>
I have a DB with ~1100 entries that I have made searchable. However,
the results can be VERY long. So, I want a way of paginating the
output.
I have seen oodles of these types of scripts for PHP, but nothing for
PERL, and my PERL skills are rusty.
Anyone seen somethng like this for PERL, or have an example lying
around?
Thanks!
Jim
------------------------------
Date: Sat, 11 Aug 2007 21:03:13 -0000
From: Robert Hicks <sigzero@gmail.com>
Subject: Re: Pagination
Message-Id: <1186866193.941020.43860@22g2000hsm.googlegroups.com>
On Aug 11, 2:40 pm, webmas...@valleywebnet.com wrote:
> I have a DB with ~1100 entries that I have made searchable. However,
> the results can be VERY long. So, I want a way of paginating the
> output.
>
> I have seen oodles of these types of scripts for PHP, but nothing for
> PERL, and my PERL skills are rusty.
>
> Anyone seen somethng like this for PERL, or have an example lying
> around?
>
> Thanks!
> Jim
HTML::Pager
Data::Pager
Data::Pageset
Try one of those...
HTH
Robert
------------------------------
Date: Sat, 11 Aug 2007 14:50:14 -0700
From: "Clenna Lumina" <savagebeaste@yahoo.com>
Subject: Re: pass by reference
Message-Id: <5i6p9dF3ndod1U1@mid.individual.net>
Michele Dondi wrote:
> On Thu, 09 Aug 2007 11:28:07 -0700, Jim Gibson
> <jgibson@mail.arc.nasa.gov> wrote:
>
>> $_ is a name, just not a pronounceable one!
>
> In English, it's "it".
Yes, in the context of for loops*, map, and such, from what I understand
that's exactly what "it" is :)
* Though it doesn't seem to be the came of a while loop onless you're
reading a handle (file, pipe, socket, etc) using the <HANDLE> systax
that sets the line to $_ each time around.
--
CL
------------------------------
Date: Sat, 11 Aug 2007 15:08:36 -0700
From: "Clenna Lumina" <savagebeaste@yahoo.com>
Subject: Re: pass by reference
Message-Id: <5i6qbsF3iu64bU1@mid.individual.net>
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
Or do ya one better for a variable amount of arguments and
simultaneously increasing it's usefulness:
sub square_me { wantarray ? map { $_*$_ } @_ : $_[0]*$_[0]; }
my $sq = square_me 5;
print $sq, "\n";
my @squares = square_me 3, 7, 12;
print join(', ', @squares);
Output:
25
9, 49, 144
This allows it to be used in both scalar and list context, and of course
can be expanded for more useful algorithms of course.
:-)
--
CL
------------------------------
Date: Sat, 11 Aug 2007 16:41:33 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Replacing a line
Message-Id: <slrnfbrp9l.deq.tadmc@tadmc30.sbcglobal.net>
Ved <vedpsingh@gmail.com> wrote:
> On Aug 9, 5:38 am, Tad McClellan <ta...@seesig.invalid> wrote:
>> Ved <vedpsi...@gmail.com> wrote:
>>
>> [ Please learn to compose followups properly.
>> Quoting 100 lines to add 2 lines will make you go invisible...
>> ]
[ Please learn to compose followups properly.
Please do this very soon.
]
>> You should attempt to write a short and complete program that we
>> can run that illustrates your problem.
You should attempt to write a short and complete program that we
can run that illustrates your problem.
> Tad I will be more adherant to the guidelines in future.
Now is the future!
> #use strict;
You lose all of the benfits of the strict pragma when you comment it out.
> chop $cpp_file;
You should still use chomp() instead of chop() for removing newlines.
> our $module_name = "$cpp_file";
^^^
^^^
Why did you put that there?
Why are you still quoting that lone variable?
Are you reading the followups?
Is there anybody in there? Just nod if you can hear me.
> if( m{^//#define ${module_name}FileLoadInput 1$} )
> { print "true $module_name \n"
> s{^//}{}; # Is something wrong here ?
> }
> else
> { print "false $module_name \n"}
As I also told you before, there is no need to test the match
before doing the substitution, so you should not test the
match before doing the substitution.
if ( s{^//(#define ${module_name}FileLoadInput 1)}{$1} ) {
print "true $module_name\n"
}
else {
print "false $module_name\n"
}
> PROBLEM (1)
> Now when I use "strict" I am getting following error:
> Global symbol "$module_name" requires explicit package name at
> rx_top_script.pl line 30.
"Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
and
perldoc strict
and
perldoc my
> PROBLEM(2)
> I thought to ignore STRICT for the time being and try to achieve what
> I desire.
That is not a good thought. Abandon it.
Instead learn how to control the scope of variables in Perl.
> Do I need to rectify the STRICT issue(problem)
Yes. Unless you _like_ spending time finding bugs that a program
could have found for you.
> to get rid of
> PROBLEM(2) ?
but not for that reason.
Rather for the reason that using strict will automatically find
bugs in your programs for you, so you don't have to find them yourself.
> If yes :
> Is this the best link to solve PROBLEM(1) ?
> http://www.perl.com/pub/a/2002/04/23/mod_perl.html
No, since that is about mod_perl, and you are not using mod_perl (or are you?).
> Or is there something even better?
You should always prefer lexical (my) variables over package (our)
variables, except when you can't.
I see nothing in what you are trying to do that indicates that
you can't, so you should be using lexical (my) variables.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
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 746
**************************************