[27118] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8988 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 23 14:05:37 2006

Date: Thu, 23 Feb 2006 11:05:05 -0800 (PST)
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, 23 Feb 2006     Volume: 10 Number: 8988

Today's topics:
    Re: CAM::PDF and create image in document <1usa@llenroc.ude.invalid>
    Re: Reading Mac / Unix / DOS text files <dlking@cpan.org>
    Re: Reading Mac / Unix / DOS text files <dlking@cpan.org>
    Re: savely change permission and group on files <abaugher@esc.pike.il.us>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 23 Feb 2006 16:35:18 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: CAM::PDF and create image in document
Message-Id: <Xns977375FB295A3asu1cornelledu@127.0.0.1>

Greger <boss replace_this_with_@ gregerhaga.net> wrote in
news:dtkbq7$cem$1@phys-news4.kolumbus.fi: 

> I hope to find somebody with some experience using CAM::PDF module(s)
> I simply want to add an image ( png ) to a pre-existing pdf document,
> but can't seem to figure this one out. 
> Could somebody please advice as how to do this, thank you.

Don't multi-post. If you believe your question is relevant in a couple of 
groups, cross-post instead. See:

http://www.cs.tut.fi/~jkorpela/usenet/xpost.html

I was willing to wade through the documentation of a module I have not 
used before (despite the fact that you did not post code, you did not give 
us a starting point, and you did not identify how specifically you are not 
able to add an image to a PDF document), but I have changed my mind.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


------------------------------

Date: Thu, 23 Feb 2006 12:38:06 -0600
From: Donald King <dlking@cpan.org>
Subject: Re: Reading Mac / Unix / DOS text files
Message-Id: <iinLf.104317$4l5.81157@dukeread05>

January Weiner wrote:
> Hi, I'm sure this is a common problem:
> 
> I'd like my script to treat text files coming from various systems alike.
> More specifically, I'd like to recognize ends of line as one of: \r, \l,
> \r\l.  Is there a more elegant way than doing the obvious?:
> 
>   while(<IF>) {
>     s/\r?\l?$// ; # is this correct anyway? will an end of line be
>                   # recognized with a Mac file?
>     #...
>   }
> 
> I would expect that there is some weird variable out there (like the $/)
> that changes the behaviour of chomp to be more promiscous. 
> 
> The problem, of course, is, that this cannot be set platform- or
> scriptwide. One file might contain DOS eols, another one would come from
> Mac.
> 
> j.
> 

Short, short version:

binmode(IF);
my $whole_file = do { local $/; <IF> };
my @lines = split /(?:\r\n|\r|\n)/, $whole_file;
foreach(@lines) {
	...
}

Since regexps check alternatives from left to right, that splits as 
correctly as possible.  If something horrid has happened, like inserting 
the contents of a Mac file into a Unix file, you'll get some funny 
behavior near the seams, of course, but for a file that's all one line 
ending, it works great, and it even handles the common case of files 
that mix Unix LFs with Windows CRLFs.

However, if you want to cut back on memory consumption (important for 
files bigger than a few hundred KB or so) and your files have consistent 
line endings, you might probe the end-of-line by sysreading the first 
2KB or so, sysseek back to the start of the file, then locally set $/ to 
the exact line ending that you probed.

Something like this might work:

use Fcntl ':seek';
 ...
binmode(IF);
local $/ = "\n";
while(1) {
	last if sysread(IF, my $peek, 2048) == 0;
	$/ = $1, last if $peek =~ /(\r\n|\r|\n)/;
}
sysseek(IF, 0, SEEK_SET);
while(<IF>) {
	...
}

-- 
Donald King, a.k.a. Chronos Tachyon
http://chronos-tachyon.net/


------------------------------

Date: Thu, 23 Feb 2006 12:47:09 -0600
From: Donald King <dlking@cpan.org>
Subject: Re: Reading Mac / Unix / DOS text files
Message-Id: <NqnLf.104318$4l5.16978@dukeread05>

Donald King wrote:
> January Weiner wrote:
> 
>> Hi, I'm sure this is a common problem:
>>
>> I'd like my script to treat text files coming from various systems alike.
>> More specifically, I'd like to recognize ends of line as one of: \r, \l,
>> \r\l.  Is there a more elegant way than doing the obvious?:
>>
>>   while(<IF>) {
>>     s/\r?\l?$// ; # is this correct anyway? will an end of line be
>>                   # recognized with a Mac file?
>>     #...
>>   }
>>
>> I would expect that there is some weird variable out there (like the $/)
>> that changes the behaviour of chomp to be more promiscous.
>> The problem, of course, is, that this cannot be set platform- or
>> scriptwide. One file might contain DOS eols, another one would come from
>> Mac.
>>
>> j.
>>
> 
> Short, short version:
> 
> binmode(IF);
> my $whole_file = do { local $/; <IF> };
> my @lines = split /(?:\r\n|\r|\n)/, $whole_file;
> foreach(@lines) {
>     ...
> }
> 
> Since regexps check alternatives from left to right, that splits as 
> correctly as possible.  If something horrid has happened, like inserting 
> the contents of a Mac file into a Unix file, you'll get some funny 
> behavior near the seams, of course, but for a file that's all one line 
> ending, it works great, and it even handles the common case of files 
> that mix Unix LFs with Windows CRLFs.
> 
> However, if you want to cut back on memory consumption (important for 
> files bigger than a few hundred KB or so) and your files have consistent 
> line endings, you might probe the end-of-line by sysreading the first 
> 2KB or so, sysseek back to the start of the file, then locally set $/ to 
> the exact line ending that you probed.
> 
> Something like this might work:
> 
> use Fcntl ':seek';
> ...
> binmode(IF);
> local $/ = "\n";
> while(1) {
>     last if sysread(IF, my $peek, 2048) == 0;
>     $/ = $1, last if $peek =~ /(\r\n|\r|\n)/;
> }
> sysseek(IF, 0, SEEK_SET);
> while(<IF>) {
>     ...
> }
> 

Oh, and if your perl code is running or might run on any of a small 
handful of screwy systems (IIRC, EBCDIC systems and pre-OSX Macs are the 
main offenders), you might need to change \r => \x0D and \n => \x0A just 
to be specific.  (If you're on an EBCDIC system and handling an ASCII 
file, though, you've got bigger problems.)

-- 
Donald King, a.k.a. Chronos Tachyon
http://chronos-tachyon.net/


------------------------------

Date: Wed, 22 Feb 2006 16:19:11 -0600
From: Aaron Baugher <abaugher@esc.pike.il.us>
Subject: Re: savely change permission and group on files
Message-Id: <867j7n2g0w.fsf@cail.baugher.pike.il.us>

Lars Madsen <daleif@imf.au.dk> writes:

> Aaron Baugher wrote:
>> Not really a perl problem:
>> #!/bin/sh
>> if cd /wherever; then
>>   chgrp -R ourgroup .
>>   chmod -R g+rw .
>> fi
>>

> yes that's true, but real life is of cource not as simple as the
> case I described.

> One problem with this is that it allows users to create directories
> in /whatever (creating them in subdirectories are fine) which we
> don't want.

So add the line 'chmod g-w .' right before the 'fi' line to remove
group write permissions from the top directory.


-- 
Aaron -- aaron_baugher@yahoo.com
         http://360.yahoo.com/aaron_baugher


------------------------------

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 8988
***************************************


home help back first fref pref prev next nref lref last post