[26131] in Perl-Users-Digest
Perl-Users Digest, Issue: 8324 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 15 18:05:44 2005
Date: Mon, 15 Aug 2005 15:05:06 -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, 15 Aug 2005 Volume: 10 Number: 8324
Today's topics:
ANNOUNCE: OpenOffice-OODoc for Open Document format <jean.marie.gouarne@online.fr>
Re: compare and merge (Anno Siegel)
Re: Very basic question on using references inside func xhoster@gmail.com
Re: what is the MVC all about (Robert Maas, see http://tinyurl.com/uh3t)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 15 Aug 2005 21:39:54 GMT
From: Jean-Marie Gouarné <jean.marie.gouarne@online.fr>
Subject: ANNOUNCE: OpenOffice-OODoc for Open Document format
Message-Id: <ILA9JA.oDM@zorch.sf-bay.org>
Version 2.003 of OpenOffice::OODoc has been uploaded today.
This new version has been reworked in order to support both the old
OpenOffice.org version 1 document format and the new OASIS Open Document
Format (ODF).
This Perl extension is an object oriented API for direct read/write queries
against OpenOffice.org (and now ODF) documents, without the help of any
office software API. It hides the details of file compression, encoding and
XML navigation. It provides some high level methods for content and layout
processing.
Please look at the project page for details
http://search.cpan.org/dist/OpenOffice-OODoc
Thanks for comments
------------------------------
Date: 15 Aug 2005 15:33:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: compare and merge
Message-Id: <ddqcjc$op3$1@mamenchi.zrz.TU-Berlin.DE>
Sharif Islam <mislam@spam.uiuc.edu> wrote in comp.lang.perl.misc:
> I am trying to read a text file and compare each line. The sorted
> records are separated by '|' and the first field is a number. If the
> numbers are same then I will merge the two lines. (I am yet to write the
> merge functions). But when I compare the numbers, I am getting '0' when
> I should get '-1'. What's wrong?
As for that, I'd go with Axel's suggestion and split on '|' instead of an
overly strict regex match. But your code has more problems than that, and
I don't mean the missing indentation, which is another one.
> #!/usr/bin/perl
>
> use strict;
> my @raw_data;
> while(<DATA>) {
> chomp;
> push @raw_data, $_; }
> my $a=$raw_data[0];
> my $b=$raw_data[1];
This doesn't do what you want. The first time through the loop,
$raw_data[1] will be undefined. After that, both $raw_data[0] and
$raw_data[1] are defined, but they won't change anymore. You'll
always compare the first two lines of your data. Also, you store the
whole file an an array when all you ever need is two lines at once.
You probably took care of sorting the input data with that in mind.
In cases like this, it is customary to use a "lag variable" to keep
the value of the previous line, like so (untested):
my $prev = <DATA>;
while ( <DATA> ) {
my $rv = compare2( $prev, $_);
# etc
$prev = $_;
}
Now, since you are going to merge consecutive records, the right
strategy may be a variant on the basic theme above. I am assuming
that merge() produces a line in a similar format as the originals.
In particular, I assume that compare2() can compare a merged line and
a data line. Even more untested:
my $merged = <DATA>;
while ( <DATA> ) {
if ( compare( $merged, $_) == 0 ) {
# same, merge on...
$merged = merge( $merged, $_);
} else {
# different
print $merged; # assuming final line feed
# start new merged line
$merged = $_;
}
}
print $merged if defined $merged;
The final line is typical for loops with a lag variable. It (the variable)
usually contains unfinished business that must be taken care of.
[rest of code snipped]
Incidentally, thanks for posting a runnable program including test data.
Well, I didn't run it, but it looks like one. It helps enormously in
diagnosing problems when what you see is the complete thing, not odds
and ends intermixed with prose.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: 15 Aug 2005 19:26:42 GMT
From: xhoster@gmail.com
Subject: Re: Very basic question on using references inside functions
Message-Id: <20050815152642.637$mm@newsreader.com>
Mark Seger <Mark.Seger@hp.com> wrote:
> I'd have thought this would have been answered in some of the
> documentation on using references but if it was I missed it.
>
> I understand that if I want to call a function and pass it a reference
> to a scalar I can then modify that scalar within the function as follows:
>
> sub foo {
> my $ref=shift;
> $$ref='new value';
> }
>
> and it works just fine. However, I want to use that scalar within the
> function many times and don't want to call it $$ref every time because
> it feels clumsy.
Tough it out. It stops feeling clumsy after a while.
> Is there some other way? I thought I could make a reference to that
> reference by something like $var=\$$ref and just access $var but that
> didn't work.
That is effectively the same thing as $var=$ref; It doesn't change the way
you dereference it.
> My REAL motive for asking is I have some code that passes
> parameters by value and I'd like to go back and pass them by reference
> without have to change all the other code that touches them.
If it currently passes parameters (effectively) by value, and it does the
right thing, then wouldn't changing it to pass them by reference cause it
to do the wrong thing unless you change all that other code anyway?
You could use typeglobs (or whatever it is I am supposed to call those
things). I don't particularly recommend it, but I have used it in a pinch.
use strict;
my $x='j' x 10;
print "$x\n";
foo3($x);
print "$x\n";
sub foo3 {
our $y;
*y = \$_[0];
$y =~ s/j/k/g;
};
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 15 Aug 2005 13:48:39 -0700
From: rem642b@Yahoo.Com (Robert Maas, see http://tinyurl.com/uh3t)
Subject: Re: what is the MVC all about
Message-Id: <REM-2005aug15-004@Yahoo.Com>
> Newsgroups: perl.beginners,misc.misc
> Message-ID: <Pine.OSX.4.58.0506141400170.16092@macgarnicle.local>
(I tried to post a followup several weeks ago, but my article never
appeared, so I'm re-posting from my backup copy:)
> From: cdevers@pobox.com (Chris Devers)
I like your fine article explaining how MVC is really a new name for
what we've been doing all along with multi-tiered software. I
respectfully disagree with one tiny point you made:
> And *that* is the big problem with tools like PHP, ASP, JSP, and
> Mason: all four of these co-mingle the View and the Controller, so
> that later on if you want to make changes to the view or to the
> controller, you run the risk of disrupting & introducing bugs to both
> of them.
That isn't quite true of JSPs. (I don't have enough experience with
PHP, and have never used ASP or Mason so I can't comment on any of
them.) WIth a JSP you can call any Java class/method directly from a
scriptlet, so if you want you can have the JSP simply call a master
routine that does all the logic and returns a code that tells the JSP
which of several reports to generate. This is assuming the JSP is
specified in the URL, so the JSP gets control first. (In such a case
it'd be silly for the JSP to immediately pass control to a Servlet and
never get control back, like why bother having the JSP first anyway,
just do this instead:) If a Servlet gets control first (specified by
the URL), then all the control logic can be there, typically some kind
of DispatcherServlet.java, and then the Servlet can simply pass control
to any one of several JSPs to prepare different kinds of reports, so
then you don't even need the hack of passing back a what-to-do-next
code. Using either design, all the JSP does is present data nicely
formatted, while the Servlet or other regular Java classes do all the
controller work. No need to co-mingle the View and the Controller at
all.
By the way, what I did for my one big Servlet application, on a laptop
that has only 39 megabytes of extended memory so J2EE ran horribly
slow, was to write an adapter that allowed me to run my servlet from
inside a test rig for all stages of debugging, and then switch to live
J2EE servlet container for final test run before uploading to
demonstrate on another system that was faster but not accessible from
my development location. The Servlet didn't generate HTML, but rather
generated a hierarchial record (object) structure that represented the
toplevel HTML sequence and the FORM within it and the controls within
the form and the attributes within the controls etc., then when the
adapter was passing control back from the Servlet to the test rig it'd
convert the hierarchial structure to HTML or swing or XML or
s-expression depending on the debug mode it was in, and convert to HTML
when in a live J2EE servlet-container session. So all the
HTML/whatever-specific presentation code was in that routine in the
adapter that converted from hierarchial structures to HTML. The
hierarchial structure was sufficiently abstract (not in the Java/C++
sense) that I could have written a command-line toplevel if I wanted.
> ?
Commands: Help SEtfield SHowfield LIstfields Whatneeded SUbmitform
> H
SE = SEtfield fieldname value [fieldname value]*
SH = SHowField fieldname [fieldname]*
L = Listfields
W = Whatneeded (which fields are not yet filed in)
SU = SUbmitform (POST)
> W
Have already filled: (nothing)
Need filled: FirstName MiddleName LastName PhoneNumber SSN
> SE LastName "Maas"
DONE
> SU
Error: You haven't yet filled in FirstName and 3 other fields.
> SE LastName "Murphy"
DONE (replaced "Maas")
> SE FirstName "George" MiddleName "W"
ALL DONE
My test rig also had a mode where it'd convert to HTML but simply
overwrite a file on /tmp/, whereupon I'd click over to lynx window or
Netscape window and refresh that view to see if I'd generated the right
form, allowing me to fully test generation of HTML without the pain of
very very slow J2EE server.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8324
***************************************