[31620] in Perl-Users-Digest
Perl-Users Digest, Issue: 2879 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 18 18:09:25 2010
Date: Thu, 18 Mar 2010 15:09: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 Thu, 18 Mar 2010 Volume: 11 Number: 2879
Today's topics:
altering PDF file security settings (David Griffith)
Re: altering PDF file security settings (David Griffith)
Re: Asynchronous TCP Socket Connect <Steve.Roscio@hp.com>
Re: Fast way to fill memory <tzz@lifelogs.com>
Re: Fast way to fill memory <cartercc@gmail.com>
Re: to RG - Lisp lunacy and Perl psychosis <xahlee@gmail.com>
Re: to RG - Lisp lunacy and Perl psychosis <hjp-usenet2@hjp.at>
Re: Writing to the end of a record <jruffino@gailborden.info>
Re: Writing to the end of a record <uri@StemSystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 18 Mar 2010 20:13:10 +0000 (UTC)
From: davidmylastname@acm.org (David Griffith)
Subject: altering PDF file security settings
Message-Id: <hnu1gm$ecc$1@frotz.eternal-september.org>
I'm trying to come up with a way to alter the security settings on PDF
files. For example: I frequently rebuild PDF forms. Manually running
these through Adobe Acrobat Pro is extremely tedious. If I can come up
with a Perl script to strip the security settings, that would speed
things up a great deal. So... How can I, with Perl, alter these
security settings?
--
David Griffith
davidmylastname@acm.org <--- Put my last name where it belongs
------------------------------
Date: Thu, 18 Mar 2010 21:57:48 +0000 (UTC)
From: davidmylastname@acm.org (David Griffith)
Subject: Re: altering PDF file security settings
Message-Id: <hnu7ks$skv$1@frotz.eternal-september.org>
David Griffith <davidmylastname@acm.org> wrote:
> I'm trying to come up with a way to alter the security settings on PDF
> files. For example: I frequently rebuild PDF forms. Manually running
> these through Adobe Acrobat Pro is extremely tedious. If I can come up
> with a Perl script to strip the security settings, that would speed
> things up a great deal. So... How can I, with Perl, alter these
> security settings?
To answer any suggestions for using CAM::PDF, I tried that. The
following command yielded a corrupted file. Different combinations of
permissions didn't seem to help.
rewritepdf.pl -P 0 0 0 0 foo.pdf bar.pdf
--
David Griffith
davidmylastname@acm.org <--- Put my last name where it belongs
------------------------------
Date: Thu, 18 Mar 2010 13:36:45 -0600
From: Steve Roscio <Steve.Roscio@hp.com>
Subject: Re: Asynchronous TCP Socket Connect
Message-Id: <hntv5a$kqp$1@usenet01.boi.hp.com>
Thanx Uri - You mention the one thing I missed, that should do the trick:
> you can tell when a socket is
> connected by checking if it can be written
Duh! I missed the obvious. I've got the Stevens book too, somewhere, so
I'll pull that out as a refresher. Thanx all!
- Steve
Uri Guttman, on 03/12/2010 at 04:05 PM:
>>>>>> "JG" == Jim Gibson <jimsgibson@gmail.com> writes:
>
> JG> In article <cedq67-cj6.ln1@news.rtij.nl>, Martijn Lievaart
> JG> <m@rtij.nl.invlalid> wrote:
>
> >> On Fri, 12 Mar 2010 10:10:25 -0700, Steve Roscio wrote:
> >>
> >> > Howdy -
> >> >
> >> > Is there a way to do an asynchronous connection of a TCP socket, without
> >> > threads or forking? Something like a two-step method, where I start the
> >> > connect, then later check to see if it's done and if it worked?
> >> >
> >> > So basically I want to turn this:
> >> >
> >> > my $s = IO::Socket::INET->new(
> >> > Proto => $proto,
> >> > PeerAddr => $addr,
> >> > PeerPort => $port,
> >> > # Blocking => 0,
> >> > Timeout => $timeout,
> >> > );
> >> >
> >> > into a two-step call:
> >> > my $s = start_connection (...);
> >> >
> >> > # later...
> >> > if ($s->connected() || $s->error()) ... #(whatever)
> >>
> >> This is not a Perl question, You are looking for non-blocking sockets.
> >> Whole volumes have been written about this, but best is Stevens "Unix
> >> Network Programming".
>
> JG> But asking how to do it in Perl _is_ a Perl question. Alas, I do not
> JG> know the answer. :(
>
> JG> The documentation to IO::Socket::INET indicates that setting 'Blocking
> JG> => 0' in the arguments to IO::Socket::INET make the connect call
> JG> non-blocking. The documentation to IO::Socket describes the connected()
> JG> method that returns undef if the socket is not in a connected state.
> JG> Perhaps those two together, with suitable waiting intervals and
> JG> retries, provide the needed functionality.
>
> even better is to use an event loop and you can tell when a socket is
> connected by checking if it can be written. this is how event loops do
> async socket connections while also handling other events. you do need
> to set the socket to non-blocking before the connect call. and this will
> not affect the block nature of the i/o so if you want async i/o too you
> need to set non-blocking AFTER the connect happens.
>
> uri
>
------------------------------
Date: Wed, 17 Mar 2010 13:47:22 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Fast way to fill memory
Message-Id: <871vfieqf9.fsf@lifelogs.com>
On Wed, 17 Mar 2010 07:00:13 -0700 (PDT) ccc31807 <cartercc@gmail.com> wrote:
c> On Mar 15, 5:22 am, Oliver 'ojo' Bedford <news...@web.de> wrote:
>> For testing purposes I would like to fill chunks of memory (say 20M) with
>> arbitrary data (say bytes with values 1,2,...255,1,...).
>>
>> What would be the fastest method?
c> Use the recursive Fibonacci function, not tail recursive. It calls
c> itself twice on each iteration, so clogs up memory even for small
c> values.
Out of curiousity, did you come up with this method for filling memory
on your own? I haven't seen it in the literature. It could be
patentable.
Ted
------------------------------
Date: Wed, 17 Mar 2010 13:29:11 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Fast way to fill memory
Message-Id: <88786d3a-1446-4137-8681-5e428f278f8b@g4g2000yqa.googlegroups.com>
On Mar 17, 2:47=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
> Out of curiousity, did you come up with this method for filling memory
> on your own? =A0I haven't seen it in the literature. =A0It could be
> patentable.
>
> Ted
This is the standard recursive definition of Fibonacci, and I can't
take the credit for it.
In Joe Armstrong's book on Erlang, he gives a multi threaded way of
filling memory using threads, which is very easy and interesting.
CC.
------------------------------
Date: Wed, 17 Mar 2010 12:17:28 -0700 (PDT)
From: Xah Lee <xahlee@gmail.com>
Subject: Re: to RG - Lisp lunacy and Perl psychosis
Message-Id: <6ede3156-9e9c-45ed-a532-89f5825646ea@p3g2000pra.googlegroups.com>
2010-03-17
On Mar 10, 9:17=C2=A0am, Ben Morrow <b...@morrow.me.uk> wrote:
> Also, flamebait language-comparison xposts involving Lisp are one
> of Xah Lee's trademarks. You might want to look into not imitating
> him/her/it.
being a professional programer today, typically you know more than
just one language. Practical questions, discussions, involving more
than one language is natural, and in fact happens more and more often
in online forums over the past 15 years i've seen. Partly due to, of
course, the tremendous birth of languages in the past decade.
In the 1980s or 1990s, you don't typically use more than one lang in a
project. Today, probably majority of projects requires you to use more
than one well known general purpose language. In those times,
discussion of more than one language is usually academic comparison.
Today, honest post as =E2=80=9Ci know this in X but how you do in Y=E2=80=
=9D is a
common need.
The reason they become flame wars is mostly not about the message
content. More about tech geeker's sensitivity, with the carried over
old school netiquette that any person mentioning lang x in group y
must be of no good intentions.
If you look at online forums today, in fact most comp lang forums have
no problem in mentioning or discussion different languages in context.
The problem occur more frequently in free-for-all type of forums where
the know-it-all tech geekers reside (the in-group argot is =E2=80=9Chacker=
=E2=80=9D),
each thinking they are justice kings and queens, take opportunities to
ridicule, flame, any post that mention other lang or any thing that
doesn't seem to be protective of their lang. This is comp.lang.*
newsgroups, with good as well as mostly bad aspects. Of course, the
free-for-all nature is precisely the reason most tech geekers stay in
newsgroups. A good percentage of them, if not majority, are old
timers.
Most newsgroup tech geekers consider cross-posting wrong. I consider
such taboo in this convention being a major contribution to the
redundant creation of new languages, flaws, and foster the hostile
faction nature of programing language groups we see.
It is sad to say, comp.lang.lisp today is 90% machine generated spam.
You see that each time this is brought up in the past 3 years, the
regulars are too busy boasting about how they've set up some tech geek
system so that spam don't reach their eyes, and sternly sputter about
web browser using idiots, with, profuse suggestions from their
infinite knowledge about what newsgroup reading software people should
be using.
To the comp.lang.python people, i think perhaps it is fruitful now to
think about de-coupling the newsgroup from the mailing list... am not
very involved in the comp.lang.python or python community in recent
years, but my thought is that, i got the feeling that most practical
posts happen in the mailing list and the newsgroup ones tend to be
more free flow of thoughts... so perhaps de-couple them is good,
because python is main stream now and mailing list is sustainable
large, is good for more practical, concrete questions and answers, and
philosophical free thoughts still have a place to go, in newsgroups.
further readings:
=E2=80=A2 Proliferation of Computing Languages
xahlee.org/UnixResource_dir/writ/new_langs.html
=E2=80=A2 Tech Geekers vs Spammers
xahlee.org/UnixResource_dir/writ/tech_geekers_vs_spammers.html
=E2=80=A2 Cross-posting & Language Factions
xahlee.org/Netiquette_dir/cross-post.html
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
------------------------------
Date: Thu, 18 Mar 2010 10:10:19 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: to RG - Lisp lunacy and Perl psychosis
Message-Id: <slrnhq3rft.e4b.hjp-usenet2@hrunkner.hjp.at>
On 2010-03-17 13:08, Nick Keighley <nick_keighley_nospam@hotmail.com> wrote:
> On 15 Mar, 23:23, RG <rNOSPA...@flownet.com> wrote:
>> But FWIW, there are sound theoretical reasons to believe that Lisp
>> programs are easier to debug than Perl programs, mainly because Lisp has
>> a REPL and Perl (normally) does not.
>
> why would the presence of a REPL theoretically make debugging
> something easier? Whose theory? Ive debugged small Perl and Scheme
> programs.
I don't know about the theory, but in practice a REPL makes debugging
easier because you can interactively test your code. This is especially
powerful if it is combined with a debugger. The Perl debugger is a
primitive REPL (well, only a REL, you have to P yourself), so you may
already have used some of its features (like invoking functions or
evaluating arbitrarily complex expressions) and take them for granted,
but if you've ever used a debugger which didn't have the ability or had
to work without any debugger you'll appreciate it (of course you can
always write test programs which do the same thing, but that takes more
time).
hp
------------------------------
Date: Thu, 18 Mar 2010 10:58:25 -0700 (PDT)
From: Joe <jruffino@gailborden.info>
Subject: Re: Writing to the end of a record
Message-Id: <f7e9177e-561b-473d-ace2-8260a703e223@t41g2000yqt.googlegroups.com>
On Mar 12, 8:40=A0am, Permostat <pshend...@gmail.com> wrote:
> On Mar 11, 12:36=A0pm, Joe <jruff...@gailborden.info> wrote:
>
> > Hi,
>
> > I am trying to write to the end of a record once I find the data
> > needed, but everything I have tried and the Internet is no real help.
>
> > I open my data file by using 'open (LOCATE +<$filename') and the data
> > is processed correctly when a match is found. =A0It is when I try to
> > write to the end is when I have trouble.
>
> > I have tried, using 'print LOCATE ($_ . ", done")', but when I run the
> > program the data is never written to the file
>
> > =A0If someone could tell me what i am doing wrong, I would really
> > appreciate it.
>
> Blast it with piss.
>
> Herm=3D
<code>
Here is the ccde i am using:
open (MAIN, $file);
while (<MAIN>)
{
chomp;
$count_rec++;
if ($key eq "yes") {
open (LOCAT, $csv);
$tble_loc =3D $_;
while (<LOCAT>) {
chomp;
($loc,$chkout,$renwal,$total) =3D split(/,/);
if ($loc eq $tble_loc) {
$total_first =3D $total;
print LOCAT ($_ . ",done\n");
$count2++;
}
}
close (LOCAT);
}
}
close (MAIN);
</code>
What happens above is I open a file then while i loop through it, I
open another file, compare the codes in each file, and when I find it
the total from the record i the second file is added to an
accumulator. This is repeated for every code in the first file.
I hope this explains better what I am trying to do.
------------------------------
Date: Thu, 18 Mar 2010 14:18:25 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Writing to the end of a record
Message-Id: <87634tpk7i.fsf@quad.sysarch.com>
>>>>> "J" == Joe <jruffino@gailborden.info> writes:
use strict and warnings. always ask perl to help you. this will save you
many hours of debug time later on.
J> open (MAIN, $file);
that is a very bad way to open a file. use lexical handles, 3 arg open
and check for failure and handle it.
open( my $main, '<', $file ) or die "can't open $file $!" ;
J> while (<MAIN>)
while ( my $line = <$main> ) {
is much better. no need to assign $_ later on.
J> {
J> chomp;
J> $count_rec++;
no need for that. the perl var $. is the record number. see perldoc perlvar.
J> if ($key eq "yes") {
J> open (LOCAT, $csv);
same thing. do a better open. what if it fails? you won't know, your
program continues to run or even just exit without any info.
J> $tble_loc = $_;
J> while (<LOCAT>) {
J> chomp;
see, you just clobbered your $_ (though you saved it). use lexical loop
variables and this will never be a worry
J> ($loc,$chkout,$renwal,$total) = split(/,/);
J> if ($loc eq $tble_loc) {
J> $total_first = $total;
J> print LOCAT ($_ . ",done\n");
you can't print to a file opened for only reading. and even if you did
open it for read/write, you usually can't print to it without a seek
call to reverse the i/o flow. and even IF you could do this, it would
clobber the next line you will read in (or even more if the write is
long). this is against all current designs of file systems (other than
some odd ones like vms which actually do true line oriented records).
the proper way is to read in this file line by line and write out a new
one printing the old lines and appending the new stuff as needed.
J> $count2++;
J> }
J> }
J> close (LOCAT);
if you did lexical handles, then that line isn't needed. the file will
be closed when the handle leaves scope.
J> }
J> }
J> close (MAIN);
J> </code>
J> What happens above is I open a file then while i loop through it, I
J> open another file, compare the codes in each file, and when I find it
J> the total from the record i the second file is added to an
J> accumulator. This is repeated for every code in the first file.
what you want is simple enough. your method will never work as
coded. you have to copy and modify the file on the fly. it can't be done
in place as lines are nothing more than newlines in the text
stream. think about what i said and you will see the error of your
design.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
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 2879
***************************************