[32926] in Perl-Users-Digest
Perl-Users Digest, Issue: 4204 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 1 00:09:32 2014
Date: Wed, 30 Apr 2014 21:09:05 -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 Wed, 30 Apr 2014 Volume: 11 Number: 4204
Today's topics:
How do I get the text that is found by a regular expres scottcabit@gmail.com
Re: How do I get the text that is found by a regular ex <rweikusat@mobileactivedefense.com>
Re: How do I get the text that is found by a regular ex <jimsgibson@gmail.com>
Re: How do I get the text that is found by a regular ex scottcabit@gmail.com
Re: How do I get the text that is found by a regular ex <rweikusat@mobileactivedefense.com>
IO::Socket client <gravitalsun@hotmail.foo>
Re: IO::Socket client <rweikusat@mobileactivedefense.com>
Re: IO::Socket client <gravitalsun@hotmail.foo>
Re: IO::Socket client <rweikusat@mobileactivedefense.com>
Re: IO::Socket client <news@todbe.com>
Re: IO::Socket client <xhoster@gmail.com>
Re: IO::Socket client <gravitalsun@hotmail.foo>
Re: IO::Socket client <gravitalsun@hotmail.foo>
Re: IO::Socket client <news@todbe.com>
Re: IO::Socket client <news@todbe.com>
Re: IO::Socket client <gravitalsun@hotmail.foo>
Re: IO::Socket client <news@todbe.com>
More general programming than perl... <justin.1401@purestblue.com>
Re: More general programming than perl... <rweikusat@mobileactivedefense.com>
Re: More general programming than perl... <rweikusat@mobileactivedefense.com>
Re: More general programming than perl... <gamo@telecable.es>
Re: More general programming than perl... <gravitalsun@hotmail.foo>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 30 Apr 2014 09:58:23 -0700 (PDT)
From: scottcabit@gmail.com
Subject: How do I get the text that is found by a regular expression?
Message-Id: <823795eb-0fa2-473a-b6c1-27fe2479611e@googlegroups.com>
Hi,
I am using a perl program I wrote to search MS Word .doc files for regular expressions using pattern matching. But after 3 days of googling, I cannot find any example where someone actually retrieves the text that is found by the pattern matching!
Here is part of my code:
# The following pattern finds all document numbers
$find->{Text} = m/\d{3}-\d{4}-\d{3}/;
if ($find->Execute()) {
print "The search text was found in $File::Find::name\n";
printf TextFile ("%s\n", $File::Find::name);
# my $output = $find->Found;
# printf TextFile ("%s\n",$find->{Text});
printf TextFile ($1."\n");
} else {
print ".";
}
The line printf TextFile ("%s\n",$find->{Text});
will display the text if it is assigned as a string, not with regular expressions. With regular expressions, it only shows me 1 or 0.
The line printf TextFile ($1."\n");
gives me a warning when run saying: Use of uninitialized value $1 in concatenation (.) or string
So what is the syntax for actually printing the text that was found by the search for a regular expression?
Thanks!
------------------------------
Date: Wed, 30 Apr 2014 19:17:48 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: How do I get the text that is found by a regular expression?
Message-Id: <87vbtq65rn.fsf@sable.mobileactivedefense.com>
scottcabit@gmail.com writes:
> I am using a perl program I wrote to search MS Word .doc files for
> regular expressions using pattern matching. But after 3 days of
> googling, I cannot find any example where someone actually retrieves
> the text that is found by the pattern matching!
>
> Here is part of my code:
>
> # The following pattern finds all document numbers
> $find->{Text} = m/\d{3}-\d{4}-\d{3}/;
NB: This is a general answer which might be totally useless for you
because you didn't explain what $find is.
This matches against the current value of $_ and assigns the result of
the match to $find->{Text}. This results is either 1 (matched) or undef
(not matched). The matched text itself could be assigned via
($find->{Text}) = m/(\d{3}-\d{4}-\d{3})/;
The () inside the pattern capture the matched text. The patterns around
$find->{Text} mean 'this is a list assignment' which cause the first bit
of 'captured text' to be assigned to the first variable in the list and
so on, eg
perl -ne '($a,$b) = /(.)(.)/; print("$a\t$b\n");'
captures the first two characters if each input line, assigning the
first to $a and the second to $b.
In case the match was successful, the captured text will also be
available via $1 ($2, $3 and so on in case of more than one bracketed
expression in the pattern), so this first could also be written as
m/(\d{3}-\d{4}-\d{3})/ and $find->{TexT} = $1;
------------------------------
Date: Wed, 30 Apr 2014 11:29:07 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: How do I get the text that is found by a regular expression?
Message-Id: <300420141129079429%jimsgibson@gmail.com>
In article <823795eb-0fa2-473a-b6c1-27fe2479611e@googlegroups.com>,
<scottcabit@gmail.com> wrote:
> Hi,
>
> I am using a perl program I wrote to search MS Word .doc files for regular
> expressions using pattern matching. But after 3 days of googling, I cannot
> find any example where someone actually retrieves the text that is found by
> the pattern matching!
> Here is part of my code:
>
> # The following pattern finds all document numbers
> $find->{Text} = m/\d{3}-\d{4}-\d{3}/;
You want to use the binding operator =~, not simple assignment. You are
assigning the result of a regular expression match with the default
variable $_, not the string in $find->{Text}.
> The line printf TextFile ("%s\n",$find->{Text});
>
> will display the text if it is assigned as a string, not with regular
> expressions. With regular expressions, it only shows me 1 or 0.
You are assigning the result of the binding operation, not the string
matched. The result of the binding operation in a scalar context is
true if the pattern matched and false if it did not.
>
> The line printf TextFile ($1."\n");
>
> gives me a warning when run saying: Use of uninitialized value $1 in
> concatenation (.) or string
>
> So what is the syntax for actually printing the text that was found by the search for a regular expression?
You want to enclose the parts of the regular expression to be captured
in parentheses:
$find->{Text} =~ m/(\d{3}-\d{4}-\d{3})/;
If the string matches, then following this line, $1 will contain the
document number.
You should check to see if the string matched before trying to use the
results:
if( $find->{Text} =~ m/(\d{3}-\d{4}-\d{3})/ ) {
print "The document number is $1\n";
}
See 'perldoc perlre' for details and 'perldoc perlop', searching the
latter for "Regexp Quote-Like Operators".
--
Jim Gibson
------------------------------
Date: Wed, 30 Apr 2014 11:51:35 -0700 (PDT)
From: scottcabit@gmail.com
Subject: Re: How do I get the text that is found by a regular expression?
Message-Id: <55ab6637-2234-4bbe-b126-0711f0805dd2@googlegroups.com>
Jim wrote:=20
You want to enclose the parts of the regular expression to be captured=20
in parentheses:=20
$find->{Text} =3D~ m/(\d{3}-\d{4}-\d{3})/;=20
Yes, that helps. My code now finds the search text regular expression and=
puts it in $1, most of the time! There is still an occasion when it perfor=
ms a find execute and thinks it found the text, only to give me the error: =
Use of uninitialized value $1 in concatenation (.) or string, even though t=
here are instances of my regular expression in the document it was searchin=
g.
Now I need to iterate through my document and find all instances of my =
regular expression match and print them.
Here is the subroutine I am calling each time the File::Find finds a word=
document for me to check:
sub rTxt {
# We only want .doc files (no links...)
return unless /\.doc$/ && -f && ! -l;
# Open document
my $doc =3D $MSWord->Documents->Open({FileName=3D>$File::Find::name});
# Exit nicely if we couldn't open doc
return unless $doc;
my $content=3D$doc->Content;
my $find=3D$content->Find;
# The following pattern finds all document numbers
$find->{Text} =3D m/(\d{3}-\d{4}-\d{3})/;
if ($find->Execute()) {
print "The search text was found in $File::Find::name\n";
printf TextFile ("%s\n", $File::Find::name);
printf TextFile ($1."\n");
} else { =20
print ".";
}
# Close document
$doc->Close();
}
Is there any easy way to search the whole document for every occurrence t=
hat matches my pattern? Do I have to copy the whole document text first and=
then search it?
Thanks
------------------------------
Date: Wed, 30 Apr 2014 21:39:17 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: How do I get the text that is found by a regular expression?
Message-Id: <87iopq5z7u.fsf@sable.mobileactivedefense.com>
scottcabit@gmail.com writes:
> Yes, that helps. My code now finds the search text regular
> expression and puts it in $1, most of the time! There is still an
> occasion when it performs a find execute and thinks it found the
> text, only to give me the error: Use of uninitialized value $1 in
> concatenation (.) or string, even though there are instances of my
> regular expression in the document it was searching.
The code you've quoted below absolutely, certainly doesn't do that as
$_ is matched against this regex and the result is assigned to
$find->{Text}, whatever the purpose of that may be.
[...]
> sub rTxt {
>
> # We only want .doc files (no links...)
> return unless /\.doc$/ && -f && ! -l;
>
> # Open document
> my $doc = $MSWord->Documents->Open({FileName=>$File::Find::name});
>
> # Exit nicely if we couldn't open doc
> return unless $doc;
>
> my $content=$doc->Content;
> my $find=$content->Find;
>
> # The following pattern finds all document numbers
> $find->{Text} = m/(\d{3}-\d{4}-\d{3})/;
[...]
------------------------------
Date: Mon, 28 Apr 2014 17:42:59 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: IO::Socket client
Message-Id: <ljlpce$1nsl$1@news.ntua.gr>
I have a small problem receiving data using the IO::Socket
if the message is bigger than the buffer (512) I loose data with the
simple statement
$socket->recv($_, 512)
if I do this
while (1)
{
$socket->recv($_, 512);
s/[\r\n]*$//;
last if length $_ == 0;
$msg .= $_;
}
it reads the big messages but is blocked for messages smaller than 512.
Any idea ?
------------------------------
Date: Mon, 28 Apr 2014 16:07:45 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: IO::Socket client
Message-Id: <87mwf5v6f2.fsf@sable.mobileactivedefense.com>
George Mpouras <gravitalsun@hotmail.foo> writes:
> if the message is bigger than the buffer (512) I loose data with the
> simple statement
>
> $socket->recv($_, 512)
>
> if I do this
>
> while (1)
> {
> $socket->recv($_, 512);
> s/[\r\n]*$//;
> last if length $_ == 0;
> $msg .= $_;
> }
>
> it reads the big messages but is blocked for messages smaller than
> 512. Any idea ?
If you're using a record protocol layered above a bytestream transport,
you'll need to ;'frame' your records/ messages with sufficient metadata
so that the application can detect message boundaries.
------------------------------
Date: Mon, 28 Apr 2014 18:25:49 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: IO::Socket client
Message-Id: <ljlrsp$1t8c$1@news.ntua.gr>
Στις 28/4/2014 18:07, ο/η Rainer Weikusat έγραψε:
> George Mpouras <gravitalsun@hotmail.foo> writes:
>> if the message is bigger than the buffer (512) I loose data with the
>> simple statement
>>
>> $socket->recv($_, 512)
>>
>> if I do this
>>
>> while (1)
>> {
>> $socket->recv($_, 512);
>> s/[\r\n]*$//;
>> last if length $_ == 0;
>> $msg .= $_;
>> }
>>
>> it reads the big messages but is blocked for messages smaller than
>> 512. Any idea ?
>
> If you're using a record protocol layered above a bytestream transport,
> you'll need to ;'frame' your records/ messages with sufficient metadata
> so that the application can detect message boundaries.
>
yes I know this, I was hoping for an "easier" answer !
------------------------------
Date: Mon, 28 Apr 2014 16:34:32 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: IO::Socket client
Message-Id: <87eh0hv56f.fsf@sable.mobileactivedefense.com>
George Mpouras <gravitalsun@hotmail.foo> writes:
> Στις 28/4/2014 18:07, ο/η Rainer Weikusat έγραψε:
>> George Mpouras <gravitalsun@hotmail.foo> writes:
>>> if the message is bigger than the buffer (512) I loose data with the
>>> simple statement
>>>
>>> $socket->recv($_, 512)
>>>
>>> if I do this
>>>
>>> while (1)
>>> {
>>> $socket->recv($_, 512);
>>> s/[\r\n]*$//;
>>> last if length $_ == 0;
>>> $msg .= $_;
>>> }
>>>
>>> it reads the big messages but is blocked for messages smaller than
>>> 512. Any idea ?
>>
>> If you're using a record protocol layered above a bytestream transport,
>> you'll need to ;'frame' your records/ messages with sufficient metadata
>> so that the application can detect message boundaries.
>>
>
> yes I know this, I was hoping for an "easier" answer !
Easier method which works (but is inefficient): Do it "HTTP/1.0-style",
open a new connection for each request/reply exchange. Whoever is
currently sending a message can then do a 'write shutdown' afterwards
and the receiver sees this as 'EOF indicator' but it can still reply.
Easier method which doesn't work (but you might get away with it until
someone runs half of your code in a nuclear reactor close to your home
and the other in a remote-control station located in Anarctica to have a
good chance to be unaffected by 'funny networking issues'): Use a
receive timeout (setsockopt/ SO_RCVTIMEO or via select) you believe to
be 'large enough'.
------------------------------
Date: Mon, 28 Apr 2014 18:40:59 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: IO::Socket client
Message-Id: <ljmvv6$lk1$1@dont-email.me>
On 4/28/2014 07:42, George Mpouras wrote:
> I have a small problem receiving data using the IO::Socket
>
>
> if the message is bigger than the buffer (512) I loose data with the simple statement
>
> $socket->recv($_, 512)
>
> if I do this
>
> while (1)
> {
> $socket->recv($_, 512);
> s/[\r\n]*$//;
> last if length $_ == 0;
> $msg .= $_;
> }
>
> it reads the big messages but is blocked for messages smaller than 512. Any idea ?
Are you on NIX or Doze ? Are you using UDP/TCP/UNIX sockets ?
Have you tried using sysread instead of recv ?
If that doesn't help, you could try setting the socket to
non-blocking OR use FIONBIO ioctl to set non-blocking and
test for EWOULDBLOCK return OR test the amount of data
avail using FIONREAD ioctl before reading (I'd try the
latter which gives you the info you really need).
It's harder on Doze to get any of these to work properly
than it is on NIX.
------------------------------
Date: Mon, 28 Apr 2014 18:42:40 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: IO::Socket client
Message-Id: <ljn2jc$2te$2@dont-email.me>
On 04/28/14 08:25, George Mpouras wrote:
> Στις 28/4/2014 18:07, ο/η Rainer Weikusat έγραψε:
>> George Mpouras <gravitalsun@hotmail.foo> writes:
>>> if the message is bigger than the buffer (512) I loose data with the
>>> simple statement
>>>
>>> $socket->recv($_, 512)
>>>
>>> if I do this
>>>
>>> while (1)
>>> {
>>> $socket->recv($_, 512);
>>> s/[\r\n]*$//;
>>> last if length $_ == 0;
>>> $msg .= $_;
>>> }
>>>
>>> it reads the big messages but is blocked for messages smaller than
>>> 512. Any idea ?
>>
>> If you're using a record protocol layered above a bytestream transport,
>> you'll need to ;'frame' your records/ messages with sufficient metadata
>> so that the application can detect message boundaries.
>>
>
>
> yes I know this, I was hoping for an "easier" answer !
Consult a psychic.
It is easy, every time.
Xho
------------------------------
Date: Tue, 29 Apr 2014 13:53:42 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: IO::Socket client
Message-Id: <ljo0ah$1216$1@news.ntua.gr>
>
> Consult a psychic.
>
> It is easy, every time.
>
> Xho
>
are you one ?
------------------------------
Date: Tue, 29 Apr 2014 14:01:27 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: IO::Socket client
Message-Id: <ljo0p2$138o$1@news.ntua.gr>
Στις 28/4/2014 18:07, ο/η Rainer Weikusat έγραψε:
> George Mpouras <gravitalsun@hotmail.foo> writes:
>> if the message is bigger than the buffer (512) I loose data with the
>> simple statement
>>
>> $socket->recv($_, 512)
>>
>> if I do this
>>
>> while (1)
>> {
>> $socket->recv($_, 512);
>> s/[\r\n]*$//;
>> last if length $_ == 0;
>> $msg .= $_;
>> }
>>
>> it reads the big messages but is blocked for messages smaller than
>> 512. Any idea ?
>
> If you're using a record protocol layered above a bytestream transport,
> you'll need to ;'frame' your records/ messages with sufficient metadata
> so that the application can detect message boundaries.
>
after many tests I think that there is no easy workaround, so I will
implement a simple protocol, thanks
------------------------------
Date: Tue, 29 Apr 2014 19:33:00 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: IO::Socket client
Message-Id: <ljpnd8$5sh$1@dont-email.me>
On 4/29/2014 04:01, George Mpouras wrote:
>
> after many tests I think that there is no easy workaround, so I will implement a simple protocol, thanks
What have you tried? I gave you several suggestions - at least
one of them should work for you depending somewhat on platform.
------------------------------
Date: Tue, 29 Apr 2014 23:52:53 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: IO::Socket client
Message-Id: <ljq6k4$g88$1@dont-email.me>
On 4/29/2014 19:33, $Bill wrote:
> On 4/29/2014 04:01, George Mpouras wrote:
>>
>> after many tests I think that there is no easy workaround, so I will implement a simple protocol, thanks
>
> What have you tried? I gave you several suggestions - at least
> one of them should work for you depending somewhat on platform.
A really small test script showing the problem would probably get
you a more usable solution by those of us that have the time to
test/try it.
------------------------------
Date: Wed, 30 Apr 2014 12:38:33 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: IO::Socket client
Message-Id: <ljqg9k$1l6e$1@news.ntua.gr>
Στις 30/4/2014 09:52, ο/η $Bill έγραψε:
> On 4/29/2014 19:33, $Bill wrote:
>> On 4/29/2014 04:01, George Mpouras wrote:
>>>
>>> after many tests I think that there is no easy workaround, so I will
>>> implement a simple protocol, thanks
>>
>> What have you tried? I gave you several suggestions - at least
>> one of them should work for you depending somewhat on platform.
>
> A really small test script showing the problem would probably get
> you a more usable solution by those of us that have the time to
> test/try it.
>
I test everything you mention Bill. Actually it was not really a
problem but an understanding that you can not get away using simple approach
while ($socket) ... or ... $socket->recv($var, 1024) ...
when you want complex things like.
-- hey client, I am going to send you a file so big
++ ok server
-- now lets exchange some small control messages
++ ok server
-- now get a big serialized data structure
++ not everything is defined
-- ops client I did not like your answer, wait for three messages for me
Thanks
------------------------------
Date: Wed, 30 Apr 2014 21:01:31 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: IO::Socket client
Message-Id: <ljsgur$4d1$1@dont-email.me>
On 4/30/2014 02:38, George Mpouras wrote:
>
> I test everything you mention Bill. Actually it was not really a problem but an understanding that you can not get away using simple approach
> while ($socket) ... or ... $socket->recv($var, 1024) ...
>
> when you want complex things like.
>
> -- hey client, I am going to send you a file so big
> ++ ok server
You should be able to just send the file with a proper header saying what it is.
> -- now lets exchange some small control messages
> ++ ok server
Again, you don't have to tell the server what you're going to do,
just prepend a header saying what it is.
> -- now get a big serialized data structure
> ++ not everything is defined
Asking for something back - that needs a request. You have to be prepared
to then receive the data back.
> -- ops client I did not like your answer, wait for three messages for me
That's not something I would do. Normally, you would just re-request the
data, but you can implement whatever you need obviously.
Obviously you have to have a control structure of some kind if you're doing
more than one thing in the server, but the code to read the socket can still
be simple before farming the record off to the proper sub to handle it.
I've done similar logic for a PTP app where two or more users can share a
directory on their disk with others. Basically I implemented logic to connect
to a master server to find other sharers; logic to connect to a share server
and get a list of files being shared; logic to register with the master server;
logic to retrieve a file from the sharer; a GUI to show sharers directories
and active xfers, etc. in basically two tasks (a client and a server).
I wrote a layer on top of TCP/IP Sockets in my case to create a record structure
to pass between them with a common record header structure. I used select
and sysread/syswrite for my I/O on Doze (harder than UNIX).
Good luck doing what you're doing - feel free to ask for any further assistance.
------------------------------
Date: Wed, 30 Apr 2014 12:29:47 +0100
From: Justin C <justin.1401@purestblue.com>
Subject: More general programming than perl...
Message-Id: <be373b-kaa.ln1@zem.masonsmusic.co.uk>
I will be coding this in perl, but I can't yet get my head
around how I'm going to achieve what I want, maybe people
here can offer suggestions on how I might proceed -
obviously in broad terms, code is a way off at the moment
I think.
I need to prepare a "Latest Products" document, the
contents are coming from a database, I've got to fill the
document with the latest and stop when the document is 24
pages, however, the document runs chronologically from
oldest to newest. I'm trying to work out how I can decide
which item/date to put at the start of the document, so I
don't run out of data before 24 pages, or over-run 24
pages.
Information is broken up into date sections (listing new
products for that day), there are varying amounts of data
for each date, from a few lines to more than a page. There
is a section heading which is larger than a line of data,
and there is a vertical space between sections, so how
many lines I can fit on a page depends on how many
sections there will be.
Every page starts with a section/date heading regardless
of whether it's a continuation of the section on the
previous page or not.
Any suggestions one how I might, programatically, decide
where I should begin my document?
Justin.
--
Justin C, by the sea.
------------------------------
Date: Wed, 30 Apr 2014 13:11:59 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: More general programming than perl...
Message-Id: <87d2fzm2y8.fsf@sable.mobileactivedefense.com>
Justin C <justin.1401@purestblue.com> writes:
[...]
> I need to prepare a "Latest Products" document, the
> contents are coming from a database, I've got to fill the
> document with the latest and stop when the document is 24
> pages, however, the document runs chronologically from
> oldest to newest. I'm trying to work out how I can decide
> which item/date to put at the start of the document, so I
> don't run out of data before 24 pages, or over-run 24
> pages.
[formatting details]
> Any suggestions one how I might, programatically, decide
> where I should begin my document?
Start with the last entry supposed to appear on the last page, ie, the
most recent one, and work backwards from that until you either run out
of data or have produced 24 pages.
------------------------------
Date: Wed, 30 Apr 2014 14:23:02 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: More general programming than perl...
Message-Id: <87k3a76jex.fsf@sable.mobileactivedefense.com>
Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
> Justin C <justin.1401@purestblue.com> writes:
>
> [...]
>
>> I need to prepare a "Latest Products" document, the
>> contents are coming from a database, I've got to fill the
>> document with the latest and stop when the document is 24
>> pages, however, the document runs chronologically from
>> oldest to newest. I'm trying to work out how I can decide
>> which item/date to put at the start of the document, so I
>> don't run out of data before 24 pages, or over-run 24
>> pages.
>
> [formatting details]
>
>> Any suggestions one how I might, programatically, decide
>> where I should begin my document?
>
> Start with the last entry supposed to appear on the last page, ie, the
> most recent one, and work backwards from that until you either run out
> of data or have produced 24 pages.
This is not sufficient on its own in case there is less than 24 pages
worth of data, assuming that a partially filled page may appear at the
end and must not appear at the beginning. This can be solved with a
2-pass algorithm: First, move backward through the data (recording the
space needed for each entry and meta-entry, ie, section header) until 24
pages have been accumulated or there's no more data. Then, move forward
through the entries in order to produce actual pages. This step can be
avoided if there are 24 pages but that's probably not worth the effort.
Possible gotcha: A situation where a lone 'date section heading' appears
at the bottom of a page, followed by the first entry for that day should
probably be avoided.
------------------------------
Date: Wed, 30 Apr 2014 15:58:57 +0200
From: gamo <gamo@telecable.es>
Subject: Re: More general programming than perl...
Message-Id: <ljqvj0$d4b$1@speranza.aioe.org>
El 30/04/14 13:29, Justin C escribi:
> I will be coding this in perl, but I can't yet get my head
> around how I'm going to achieve what I want, maybe people
> here can offer suggestions on how I might proceed -
> obviously in broad terms, code is a way off at the moment
> I think.
>
> I need to prepare a "Latest Products" document, the
> contents are coming from a database, I've got to fill the
> document with the latest and stop when the document is 24
> pages, however, the document runs chronologically from
> oldest to newest. I'm trying to work out how I can decide
> which item/date to put at the start of the document, so I
> don't run out of data before 24 pages, or over-run 24
> pages.
>
> Information is broken up into date sections (listing new
> products for that day), there are varying amounts of data
> for each date, from a few lines to more than a page. There
> is a section heading which is larger than a line of data,
> and there is a vertical space between sections, so how
> many lines I can fit on a page depends on how many
> sections there will be.
>
> Every page starts with a section/date heading regardless
> of whether it's a continuation of the section on the
> previous page or not.
>
> Any suggestions one how I might, programatically, decide
> where I should begin my document?
>
>
>
> Justin.
>
I assume you can produce 100 pages.
Just produce 25 pages and then do 'intelligent' cuts, like
based on section length, recentness, etc. until it fits in
24 pages.
--
http://www.telecable.es/personales/gamo/
------------------------------
Date: Wed, 30 Apr 2014 17:17:23 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: More general programming than perl...
Message-Id: <ljr0kf$2qco$1@news.ntua.gr>
it does not look very difficult task.
You need some sql queries through DBI and create the documents using e.g
the html template .
------------------------------
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 4204
***************************************