[31034] in Perl-Users-Digest
Perl-Users Digest, Issue: 2279 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 17 03:09:46 2009
Date: Tue, 17 Mar 2009 00:09:08 -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 Tue, 17 Mar 2009 Volume: 11 Number: 2279
Today's topics:
Re: Debian MySQL Perl DBI - connection terminates unex <xhoster@gmail.com>
Re: FAQ posts <ben@morrow.me.uk>
Re: FAQ posts (Randal L. Schwartz)
Re: How to set the message displayed when a Perl Script <xhoster@gmail.com>
Re: Most efficient way to do set-comparison sln@netherlands.com
new CPAN modules on Tue Mar 17 2009 (Randal Schwartz)
perl/postscript csv->labels HERE-PROGRAM <mijoryx@yahoo.com>
Re: perl/postscript csv->labels HERE-PROGRAM <tadmc@seesig.invalid>
Re: perl/postscript csv->labels HERE-PROGRAM <nospam-abuse@ilyaz.org>
Re: perl/postscript csv->labels HERE-PROGRAM <mijoryx@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 16 Mar 2009 18:59:31 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: Debian MySQL Perl DBI - connection terminates unexpectedly after 100 secs.
Message-Id: <49bf08ca$0$9725$ed362ca5@nr5-q3a.newsreader.com>
John wrote:
> Hi
>
> I'm updating a MySQL table with about 2 million records. After about 100
> seconds the program ends with no error message.
Are you sure? If there were an error message, do you know where it
would go and do you know you could find it?
> If I use LIMIT 800000,50000
> the part where it stopped is OK so the UPDATE part is OK.
>
> Is there a time out parameter?
I don't think there is one in DBD::mysql. The program that calls your
perl script could have a time out, or your MySQL server might have a
time out, but neither of those are Perl issues
> Or am I running out of memory. Can the
> memory be increased?
Unlike a select, there is no reason that large update should consume
much memory in the Perl client. And I don't use Debian specifically,
but on other linux systems running out of memory does produce an error
somewhere, but not always in the first place one might think to look.
Xho
------------------------------
Date: Mon, 16 Mar 2009 23:11:38 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ posts
Message-Id: <au2396-eno2.ln1@osiris.mauzo.dyndns.org>
Quoth "darkon" <darkon.tdo@gmail.com>:
>
> "brian d foy" <brian.d.foy@gmail.com> wrote in message
> news:140320090235236820%brian.d.foy@gmail.com...
> > In article <xdadnfJ_d-_cCSfUnZ2dnUVZ_jWWnZ2d@supernews.com>, darkon
> > <darkon.tdo@gmail.com> wrote:
> >
> >> Out of simple curiousity, what algorithm is used to decide which FAQ is
> >> posted when? I noticed that the FAQs are posted roughly in sequence, but
> >> not strictly in sequence. For example, FAQs from section 5 began to be
> >> posted before all the FAQs from section 4 had been posted.
> >
> > The script that does it all is in the perlfaq repository:
> >
> > http://github.com/briandfoy/perlfaq/tree/master
> >
> > Roughly, there's a script that splits up the faq into individual
> > questions, then the posting faq selects the one with the oldest mtime.
> > Some of the answers have the same mtime so it's slightly out of order.
>
> Ah, I see now. But there is one part of the code that confuses me. In
> get_files() you do a Swchartzian transform with a grep in the middle of it:
>
> my $time = 0;
> my @files =
> map { $_->[0] }
> grep { $time ||= $_->[1]; $_->[1] == $time }
> sort { $b->[1] <=> $a->[1] }
> map { [ $_, -A $_ ] }
> glob( File::Spec->catfile( $config->FAQ_DIR, "perlfaq*.txt" ) );
>
> If I understand the grep correctly, @files ends up with only one filename in
> it: the oldest file. But later, in select_faq(), you say
>
> my @files = get_files( $config );
> my $file = $files[rand @files];
>
> I see no reason for the call to rand() unless it's just left over from an
> earlier version. Maybe I'm missing something.
Yes: some of the files have the *same* -A time. In the case that there
are several oldest files that are equally old, one is picked at random.
Ben
------------------------------
Date: Mon, 16 Mar 2009 16:26:04 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: "darkon" <darkon.tdo@gmail.com>
Subject: Re: FAQ posts
Message-Id: <863addvylv.fsf@blue.stonehenge.com>
>>>>> "darkon" == darkon <darkon.tdo@gmail.com> writes:
darkon> my $time = 0;
darkon> my @files =
darkon> map { $_->[0] }
darkon> grep { $time ||= $_->[1]; $_->[1] == $time }
darkon> sort { $b->[1] <=> $a->[1] }
darkon> map { [ $_, -A $_ ] }
darkon> glob( File::Spec->catfile( $config->FAQ_DIR, "perlfaq*.txt" ) );
darkon> If I understand the grep correctly, @files ends up with only one filename in
darkon> it: the oldest file.
Nope. It ends up with all files that have the same mtime as the
oldest file.
darkon> But later, in select_faq(), you say
darkon> my @files = get_files( $config );
darkon> my $file = $files[rand @files];
darkon> I see no reason for the call to rand() unless it's just left over from an
darkon> earlier version. Maybe I'm missing something.
And then random-draws one of them.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Mon, 16 Mar 2009 19:11:12 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: How to set the message displayed when a Perl Script fails compilation?
Message-Id: <49bf08cc$0$9725$ed362ca5@nr5-q3a.newsreader.com>
Gunnar Hjalmarsson wrote:
> Krishna Chaitanya wrote:
>> Hi, I don't know if this is going to help you....but read up on
>> fatalsToBrowser ...
>
> That feature
>
> 1) might reveal sensitive information,
What kind? The only sensitive information I've seen it reveal is "Hey,
this programmer is clueless." No one, other than a clueless
programmer, would think this info hard to obtain by means other than
fatalsToBrowser.
>
> 2) does typically not display "a friendly page" to a visitor, and
Right. And the user unfriendly message it typically displays might very
well be the very message the OP is currently seeing. So he might want
to read up on it.
>
> 3) does not alert the script author if the error happens when a visitor
> uses the script.
It can be made to.
Xho
------------------------------
Date: Tue, 17 Mar 2009 02:01:48 GMT
From: sln@netherlands.com
Subject: Re: Most efficient way to do set-comparison
Message-Id: <33str4pbo4s9uuubbjg7lv6hcav2gvgti7@4ax.com>
On Mon, 16 Mar 2009 07:05:54 -0700 (PDT), Krishna Chaitanya <schaitan@gmail.com> wrote:
>Thanks, sln. I'd started to think about this problem in relation to a
>larger one...namely that of how to design a constructor in the best
>way in general for .pm that I write. Some of the common tasks in
>constructor would involve:
>
>1. creating hash-ref and blessing it with package name
>2. populating keys and values in hash-ref with what the user supplied
>(this is where this set-comparison comes of use)
>3. doing other "validations" on the values of those user-supplied keys
>..
>..finally returning the blessed referent.
>
>A major discussion here at my work place is - is it good to put strict
>checks in new() and bail out the program if user didn't give any
>options to it or gave bad options. I'm of this idea. But several
>others feel the new() should be benign and when you call other
>methods, it should report problem and bail out.
>
>What would all of you say about this? Is there a general best-practice
>for designing constructors?
>
>Also, is there a cool way to create the get-set methods for the
>numerous instance-attributes in my classes? Any ready-made CPAN
>tricks or something??
To me, it all depends on what your module does.
If its a busy module, usually the majority of instance data is module generated
to a defualt state with helper member subs that can change the state during the
course of operations after initialization. So that file-scoped global arrays and
scalars hold some kind of general static data tha is used by the module to generate
and track dynamic instance data to be stuffed into the "$self" blessed hash reference.
Users may pass in arguments (that they can add/change) to new() but ideally, it should
not be a requirement at construction time. So the module should have the default parameters
in $self if none are provided. So in constructors, the module should set up a default state
then any args passed in to the constructor should be passed to another method, along with
the instance reference, that add/change values to the hash. Then that method can be called
later by users to change state at a time past instantiation.
So as a general rule, you want to set up methods both public and private, that change state,
during runtime. It is possible that over the course of usage, the $self hash gets used quite
frequently and it state sometimes needs to be reset before other operations take place.
Beyond state that persists between method calls, most of the argument (parameter) checking
is done within user called methods. Most of the parameters are consumed as local to the method,
however with complex data, processing sometimes permutes to sub calls to private helper methods
and area's of $self are sometimes used for scratch instead of passing around the data again.
It all depends on how you design it. Its based on your needs. If its a big item, you may want
to build a reporting truss within it that can be called by methods. There may be different levels
of errors from fatal to misdemeaner. A good logging system is always recommended.
I would always recommend ways to work around just die'ing if you can avoid it, report the
error and continue. You never know, your module may be used in automation. But if you have
to croak, do it for a good reason, otherwise report an error and return from sub with some
indication of error, but without dying.
For setting/getting $self values, unless its something very distinct, usually the way its done
is to have a setVal() kind of method that accepts a hash. Processing and validation is
done via something like: while (my ($name, $val) = splice (@args, 0, 2))
But there a many many ways to do this, it depends on your needs. You can absolutely force
compliance any way you want.
Good luck.
-sln
------------------------------
Date: Tue, 17 Mar 2009 04:42:27 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Tue Mar 17 2009
Message-Id: <KGMvqr.CnM@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
AnyEvent-XMPP-0.5
http://search.cpan.org/~elmex/AnyEvent-XMPP-0.5/
An implementation of the XMPP Protocol
----
App-DualLivedDiff-1.06
http://search.cpan.org/~smueller/App-DualLivedDiff-1.06/
Diff between the perl core and dual-lived modules' CPAN distributions
----
Astro-FITS-Header-3.01
http://search.cpan.org/~tjenness/Astro-FITS-Header-3.01/
Object Orientated interface to FITS HDUs
----
Business-CardInfo-0.02
http://search.cpan.org/~wreis/Business-CardInfo-0.02/
Get/Validate data from credit & debit cards
----
Catalyst-Controller-Validation-DFV-0.0.5
http://search.cpan.org/~chisel/Catalyst-Controller-Validation-DFV-0.0.5/
check form data
----
Class-Data-Remote-0.001
http://search.cpan.org/~johnd/Class-Data-Remote-0.001/
Object-oriented interface to remote data sources.
----
Class-Data-Remote-0.002
http://search.cpan.org/~johnd/Class-Data-Remote-0.002/
Object-oriented interface to remote data sources.
----
Class-Data-Remote-0.003
http://search.cpan.org/~johnd/Class-Data-Remote-0.003/
Object-oriented interface to remote data sources.
----
Class-Data-Remote-0.004
http://search.cpan.org/~johnd/Class-Data-Remote-0.004/
Object-oriented interface to remote data sources.
----
Convert-Binary-C-0.73
http://search.cpan.org/~mhx/Convert-Binary-C-0.73/
Binary Data Conversion using C Types
----
Coro-5.131
http://search.cpan.org/~mlehmann/Coro-5.131/
the only real threads in perl
----
DBIx-DataModel-1.11
http://search.cpan.org/~dami/DBIx-DataModel-1.11/
Classes and UML-style Associations on top of DBI
----
DOCSIS-ConfigFile-0.55
http://search.cpan.org/~jhthorsen/DOCSIS-ConfigFile-0.55/
Decodes and encodes DOCSIS config-files
----
DateTime-TimeZone-0.85
http://search.cpan.org/~drolsky/DateTime-TimeZone-0.85/
Time zone object base class and factory
----
Devel-DLMProf-0.05
http://search.cpan.org/~kitano/Devel-DLMProf-0.05/
dynamid loaded modules detector
----
File-Download-0.1
http://search.cpan.org/~byrne/File-Download-0.1/
Fetch large files from the web
----
File-Download-0.2
http://search.cpan.org/~byrne/File-Download-0.2/
Fetch large files from the web
----
File-Download-0.3
http://search.cpan.org/~byrne/File-Download-0.3/
Fetch large files from the web
----
FlatFile-DataStore-0.02
http://search.cpan.org/~bbaxter/FlatFile-DataStore-0.02/
Perl module that implements a flat file data store.
----
FlatFile-DataStore-0.03
http://search.cpan.org/~bbaxter/FlatFile-DataStore-0.03/
Perl module that implements a flat file data store.
----
GitStore-0.04
http://search.cpan.org/~fayland/GitStore-0.04/
Git as versioned data store in Perl
----
GitStore-0.05
http://search.cpan.org/~fayland/GitStore-0.05/
Git as versioned data store in Perl
----
Hessian-Client-0.1.6
http://search.cpan.org/~heytrav/Hessian-Client-0.1.6/
RPC via Hessian with a remote server.
----
IO-Moose-0.1002
http://search.cpan.org/~dexter/IO-Moose-0.1002/
Reimplementation of IO::* with improvements
----
IPC-Capture-0.06
http://search.cpan.org/~doom/IPC-Capture-0.06/
portably run external apps and capture the output
----
JavaScript-Packer-0.01_02
http://search.cpan.org/~nevesenin/JavaScript-Packer-0.01_02/
Perl version of Dean Edwards' Packer.js
----
Marpa-0.001_004
http://search.cpan.org/~jkegl/Marpa-0.001_004/
General BNF Parsing (Experimental version)
----
MediaWiki-Bot-2.2.1
http://search.cpan.org/~dcollins/MediaWiki-Bot-2.2.1/
a Wikipedia bot framework written in Perl
----
Module-Pluggable-3.9
http://search.cpan.org/~simonw/Module-Pluggable-3.9/
automatically give your module the ability to have plugins
----
MooseX-Iterator-0.10
http://search.cpan.org/~rlb/MooseX-Iterator-0.10/
Iterate over collections
----
MooseX-Role-Restricted-1.01
http://search.cpan.org/~gbarr/MooseX-Role-Restricted-1.01/
Restrict which sub are exported by a role
----
Net-DHCP-Info-0.10
http://search.cpan.org/~jhthorsen/Net-DHCP-Info-0.10/
Fast dhcpd.leases and dhcpd.conf parser
----
Net-FireEagle-1.3
http://search.cpan.org/~simonw/Net-FireEagle-1.3/
access Yahoo's new FireEagle location service
----
Net-OAuth-Simple-0.7
http://search.cpan.org/~simonw/Net-OAuth-Simple-0.7/
a simple wrapper round the OAuth protocol
----
Net-OAuth-Simple-0.8
http://search.cpan.org/~simonw/Net-OAuth-Simple-0.8/
a simple wrapper round the OAuth protocol
----
News-Pictures-0.03
http://search.cpan.org/~cguine/News-Pictures-0.03/
The great new News::Pictures!
----
Object-Event-1.0
http://search.cpan.org/~elmex/Object-Event-1.0/
A class that provides an event callback interface
----
Object-LocalVars-0.19
http://search.cpan.org/~dagolden/Object-LocalVars-0.19/
Outside-in objects with local aliasing of $self and object variables
----
POE-Component-SmokeBox-0.20
http://search.cpan.org/~bingos/POE-Component-SmokeBox-0.20/
POE enabled CPAN smoke testing with added value.
----
POE-Component-TFTPd-0.02
http://search.cpan.org/~jhthorsen/POE-Component-TFTPd-0.02/
A tftp-server, implemented through POE
----
POE-Declare-0.19
http://search.cpan.org/~adamk/POE-Declare-0.19/
A POE abstraction layer for conciseness and simplicity
----
POE-Filter-Hessian-0.1.0
http://search.cpan.org/~heytrav/POE-Filter-Hessian-0.1.0/
Translate datastructures to and from Hessian for transmission via a POE ReadWrite wheel.
----
Parse-Dia-SQL-0.05
http://search.cpan.org/~aff/Parse-Dia-SQL-0.05/
Convert Dia class diagrams into SQL.
----
Parse-Method-Signatures-1.003003
http://search.cpan.org/~ash/Parse-Method-Signatures-1.003003/
Perl6 like method signature parser
----
Parse-RPN-2.45
http://search.cpan.org/~fdulau/Parse-RPN-2.45/
----
Perl6-Say-0.13
http://search.cpan.org/~jkeenan/Perl6-Say-0.13/
print -- but no newline needed
----
Perl6-Say-0.14
http://search.cpan.org/~jkeenan/Perl6-Say-0.14/
print(), but no newline needed
----
Pod-Usage-CommandLine-0.03
http://search.cpan.org/~ctilmes/Pod-Usage-CommandLine-0.03/
Add some common command line options from Pod::Usage
----
RDF-Query-2.100_01
http://search.cpan.org/~gwilliams/RDF-Query-2.100_01/
An RDF query implementation of SPARQL/RDQL in Perl for use with RDF::Redland and RDF::Core.
----
SNMP-Effective-1.06
http://search.cpan.org/~jhthorsen/SNMP-Effective-1.06/
An effective SNMP-information-gathering module
----
Set-Intersection-0.01
http://search.cpan.org/~turugina/Set-Intersection-0.01/
provides an API to get intersection (of set theory) of ARRAYs.
----
Set-Intersection-0.02
http://search.cpan.org/~turugina/Set-Intersection-0.02/
provides an API to get intersection (of set theory) of ARRAYs.
----
Simo-0.1007
http://search.cpan.org/~kimoto/Simo-0.1007/
Very simple framework for Object Oriented Perl.
----
Statistics-ANOVA-0.061
http://search.cpan.org/~rgarton/Statistics-ANOVA-0.061/
Perform oneway analyses of variance
----
Statistics-FisherPitman-0.031
http://search.cpan.org/~rgarton/Statistics-FisherPitman-0.031/
Randomization-based alternative to one-way independent groups ANOVA; unequal variances okay
----
Storable-AMF-0.55
http://search.cpan.org/~grian/Storable-AMF-0.55/
Perl extension for serialize/deserialize AMF0/AMF3 data
----
Sys-Info-Driver-Unknown-0.69_08
http://search.cpan.org/~burak/Sys-Info-Driver-Unknown-0.69_08/
Compatibility layer for Sys::Info
----
Test-Sys-Info-0.13
http://search.cpan.org/~burak/Test-Sys-Info-0.13/
Centralized test suite for Sys::Info.
----
Test-WWW-Mechanize-Catalyst-0.51
http://search.cpan.org/~ash/Test-WWW-Mechanize-Catalyst-0.51/
Test::WWW::Mechanize for Catalyst
----
TryCatch-1.000002
http://search.cpan.org/~ash/TryCatch-1.000002/
first class try catch semantics for Perl, without source filters.
----
URI-Find-20090316
http://search.cpan.org/~mschwern/URI-Find-20090316/
Find URIs in arbitrary text
----
Var-State-0.04
http://search.cpan.org/~jhthorsen/Var-State-0.04/
state variable in perl 5.8
----
XML-Bare-0.42
http://search.cpan.org/~codechild/XML-Bare-0.42/
Minimal XML parser implemented via a C state engine
----
YAML-Object-0.04
http://search.cpan.org/~jhthorsen/YAML-Object-0.04/
Use OO to point to a yaml-node
----
httpi-1.6.1
http://search.cpan.org/~ckaiser/httpi-1.6.1/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Mon, 16 Mar 2009 17:26:52 -0700 (PDT)
From: luser-ex-troll <mijoryx@yahoo.com>
Subject: perl/postscript csv->labels HERE-PROGRAM
Message-Id: <27b50efb-dcb2-4780-8e1c-f4b46e653515@v15g2000yqn.googlegroups.com>
Mommy likes it!
Double-clicking a shortcut is ultimately easier
than any Wizard M$Word can concoct.
Wait till I show her how to edit the file with
a text-editor instead of Excel!
Version 0.2beta:
#!/usr/bin/perl
# labels.pl reads csv records in the form:
# "Name","123 Street","Apt","City, ST ZIP"
# from files named on the command line or
# "addr.csv", if none are specified, and
# produces a postscript program on stdout
# containing records in the form:
# [(Name)(123 Street)(Apt)(City, ST ZIP)]
# suitable for piping into ps2pdf or distiller.
# eg.$ labels|ps2pdf - out.pdf
# CAVEATS:
# coded for Avery 5160 2.5935" x 1"
# letter-sheet labels 3 x 10 / page
if ($#ARGV == -1) { $ARGV[0] = "addr.csv"; } #default argument
print <<PROLOG;
%!
% persuade acrobat reader to obey the numbers
[ {Catalog} << /ViewerPreferences << /PrintScaling /None >> >> /PUT
pdfmark
/in{72 mul}def % tom thumb's shoe size
% measurements
/H 1 in def % how big
/W 2.5935 in def % they are
/Palatino-Roman 16 selectfont % set text 16/
/LEAD H 4 div def % 18
/LM 0.1875 10 add def % edge + padding
/TM 11 in 0.5 in sub LEAD sub def % top - margin - line
% control
/count 0 def
/perLINE 3 def
/perPAGE perLINE 10 mul def
{ %make array as executable to avoid stackoverflow
PROLOG
$\ = $/;
while(<>) {
chop;
s/^"/\{\(/;
s/","/\)\(/g;
s/"$/\)\}/;
print;
}
print <<PSPROGRAM;
} cvlit
{ % each record
cvlit LM TM moveto
{ % each address line
dup () eq { pop } { % skip empties
%dup currentpoint exch = = = % diagnostic
show % paint the string
LM currentpoint exch pop LEAD sub moveto % reposition
} ifelse
} forall
/LM LM W add store % move over
/count count 1 add store
count perLINE mod 0 eq { % back to left after each 3
/LM 10 store
/TM TM H sub store
} if
count perPAGE mod 0 eq { % print a page when it's full
showpage
/LM 10 store
/TM 11 in LEAD sub store
} if
} forall
count perPAGE mod 0 ne { showpage } if
%the end
PSPROGRAM
#eof labels
sample input (addr.csv):
"M. Joshua Ryan","1234 Streetname","","City, ST 12345"
"M. Joshua Ryan","4567 Streetname","","City, ST 23456"
"M. Joshua Ryan","7890 Streetname","","City, ST 34567"
"M. Joshua Ryan","1234 Streetname","","City, ST 45678"
"M. Joshua Ryan","4567 Streetname","","City, ST 56789"
"M. Joshua Ryan","7890 Streetname","","City, ST 67890"
"M. Joshua Ryan","7890 Streetname","","City, ST 67890"
"","","",""
sample output:
%!
% persuade acrobat reader to obey the numbers
[ {Catalog} << /ViewerPreferences << /PrintScaling /None >> >> /PUT
pdfmark
/in{72 mul}def % tom thumb's shoe size
% measurements
/H 1 in def % how big
/W 2.5935 in def % they are
/Palatino-Roman 16 selectfont % set text 16/
/LEAD H 4 div def % 18
/LM 0.1875 10 add def % edge + padding
/TM 11 in 0.5 in sub LEAD sub def % top - margin - line
% control
/count 0 def
/perLINE 3 def
/perPAGE perLINE 10 mul def
{ %make array as executable to avoid stackoverflow
{(M. Joshua Ryan)(1234 Streetname)()(City, ST 12345)}
{(M. Joshua Ryan)(4567 Streetname)()(City, ST 23456)}
{(M. Joshua Ryan)(7890 Streetname)()(City, ST 34567)}
{(M. Joshua Ryan)(1234 Streetname)()(City, ST 45678)}
{(M. Joshua Ryan)(4567 Streetname)()(City, ST 56789)}
{(M. Joshua Ryan)(7890 Streetname)()(City, ST 67890)}
{(M. Joshua Ryan)(7890 Streetname)()(City, ST 67890)}
{()()()()}
} cvlit
{ % each record
cvlit LM TM moveto
{ % each address line
dup () eq { pop } { % skip empties
%dup currentpoint exch = = = % diagnostic
show % paint the string
LM currentpoint exch pop LEAD sub moveto % reposition
} ifelse
} forall
/LM LM W add store % move over
/count count 1 add store
count perLINE mod 0 eq { % back to left after each 3
/LM 10 store
/TM TM H sub store
} if
count perPAGE mod 0 eq { % print a page when it's full
showpage
/LM 10 store
/TM 11 in LEAD sub store
} if
} forall
count perPAGE mod 0 ne { showpage } if
%the end
lxt
(yes, that's my real name, mostly)
------------------------------
Date: Mon, 16 Mar 2009 21:35:59 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: perl/postscript csv->labels HERE-PROGRAM
Message-Id: <slrngru34f.eqh.tadmc@tadmc30.sbcglobal.net>
["Followup-To:" header set to comp.lang.perl.misc.]
luser-ex-troll <mijoryx@yahoo.com> wrote:
> #!/usr/bin/perl
Ask for all the help you can get:
use strict;
use warnings;
> if ($#ARGV == -1) { $ARGV[0] = "addr.csv"; } #default argument
$ARGV[0] = "addr.csv" unless defined $ARGV[0]; # default argument
> while(<>) {
> chop;
chop() was how we removed newlines in the mid-90s.
chomp() is how we remove newlines nowadays.
> s/^"/\{\(/;
> s/","/\)\(/g;
> s/"$/\)\}/;
The replacement part of s/PATTERN/REPLACEMENT/ is a string.
None of those backslashed characters are special in strings,
so none of those backslashes are needed.
s/^"/{(/;
s/","/)(/g;
s/"$/)}/;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 17 Mar 2009 06:00:00 GMT
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: perl/postscript csv->labels HERE-PROGRAM
Message-Id: <slrngruf30.5s6.nospam-abuse@chorin.math.berkeley.edu>
On 2009-03-17, Tad J McClellan <tadmc@seesig.invalid> wrote:
>> #!/usr/bin/perl
>
> Ask for all the help you can get:
>
> use strict;
> use warnings;
Or, better, add -w ot the #!-line...
>> if ($#ARGV == -1) { $ARGV[0] = "addr.csv"; } #default argument
> $ARGV[0] = "addr.csv" unless defined $ARGV[0]; # default argument
I would write
@ARGV = "addr.csv" unless @ARGV;
[ Unfortunately, the most logical @ARGV ||= "addr.csv" does not
compile... If it would, the scalar/list context determination
might get in the way, too... ]
>> s/^"/\{\(/;
>> s/","/\)\(/g;
>> s/"$/\)\}/;
> The replacement part of s/PATTERN/REPLACEMENT/ is a string.
Still, one should keep in mind that backslashes may help with "less
capable" editors... ;-)
Ilya
------------------------------
Date: Mon, 16 Mar 2009 23:03:29 -0700 (PDT)
From: luser-ex-troll <mijoryx@yahoo.com>
Subject: Re: perl/postscript csv->labels HERE-PROGRAM
Message-Id: <6f00b0c2-47c2-40c6-b6a4-d0893b46841b@v15g2000yqn.googlegroups.com>
On Mar 16, 9:35=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> ["Followup-To:" header set to comp.lang.perl.misc.]
>
> luser-ex-troll <mijo...@yahoo.com> wrote:
> > #!/usr/bin/perl
>
> Ask for all the help you can get:
>
> =A0 =A0 use strict;
> =A0 =A0 use warnings;
>
> > if ($#ARGV =3D=3D -1) { $ARGV[0] =3D "addr.csv"; } #default argument
>
> =A0 =A0 $ARGV[0] =3D "addr.csv" unless defined $ARGV[0]; # default argume=
nt
>
> > while(<>) {
> > =A0 =A0 chop;
>
> chop() was how we removed newlines in the mid-90s.
>
> chomp() is how we remove newlines nowadays.
>
> > =A0 =A0 s/^"/\{\(/;
> > =A0 =A0 s/","/\)\(/g;
> > =A0 =A0 s/"$/\)\}/;
>
> The replacement part of s/PATTERN/REPLACEMENT/ is a string.
>
> None of those backslashed characters are special in strings,
> so none of those backslashes are needed.
>
> =A0 =A0 s/^"/{(/;
> =A0 =A0 s/","/)(/g;
> =A0 =A0 s/"$/)}/;
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
Excellent. Thank you.
I was transcribing my memory of vi substitutions
while simultaneously relearning perl. It went though
some very ugly stages.
lxt
------------------------------
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 2279
***************************************