[31606] in Perl-Users-Digest
Perl-Users Digest, Issue: 2865 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 11 00:09:28 2010
Date: Wed, 10 Mar 2010 21:09:11 -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 Wed, 10 Mar 2010 Volume: 11 Number: 2865
Today's topics:
Re: convert BMP 256col to raw image data ? <dam-kat-jensen@gmail-kat-.com>
Data::Dumper output the results in single quote. <chunji08@gmail.com>
Re: Help on String to array ! <jismagic@gmail.com>
PDF::API2 (Creating PDF files) <helius@gmail.com>
Re: PDF::API2 (Creating PDF files) <ben@morrow.me.uk>
Re: PDF::API2 (Creating PDF files) <helius@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Mar 2010 21:20:03 GMT
From: Torben <dam-kat-jensen@gmail-kat-.com>
Subject: Re: convert BMP 256col to raw image data ?
Message-Id: <Xns9D37E325B9D9Dmyicqgmxnet@130.225.254.104>
Ben Morrow <ben@morrow.me.uk> wrote in
news:9fmh67-p2f.ln1@osiris.mauzo.dyndns.org:
> Yes (specifically unpack). You will also need
> http://msdn.microsoft.com/en-us/library/dd183391%28VS.85%29.aspx, and
> some understanding of C structures.
>
> An alternative would be to use one of the many image-handling
> libraries on CPAN, for example Imager, which will let you get the raw
> bits out in any format you like.
Thank you for the links.
Looked at Imager, but can't really an example of how to do.
Can you show an example ?
------------------------------
Date: Wed, 10 Mar 2010 20:57:54 -0800 (PST)
From: John <chunji08@gmail.com>
Subject: Data::Dumper output the results in single quote.
Message-Id: <17063714-d8e7-46ef-9412-21356e06b903@c34g2000pri.googlegroups.com>
Hi Follows,
That is first time that I am using this Data::Dumper module to create
an XML file. I don't know why that I am seeing single quote at the
beginning and the end of output file. such as:
"
'<?xml version="1.0"?>
<Properties>
<Edit></Edit>
<Priority>1</Priority>
<WhereUsed></WhereUsed>
</Properties>
'
"
And here is part of my code to output that XML file:
"
sub updateXML {
local $Data::Dumper::Terse = 1;
my $inData = $xml->XMLin("properties.xml");
$inData->{Priority} = 1;
my $outXml = new XML::Simple;
my $outData = $outXml->XMLout($inData, Rootname => "Properties",
noattr=> 1, xmldecl=> '<?xml version="1.0"?>');
my $file = "properties.xml";
open my $HR, ">", $file or die "can not open $file $!";
print Dumper($outData);
print $HR Dumper($outData);
close $HR;
" ,
And when I debug it, I don't see such single quote on that $outData
value, not sure why I have such things in the generated XML file ?
Does anyone know how to get rid of that ?
Chun
------------------------------
Date: Wed, 10 Mar 2010 21:02:19 -0800 (PST)
From: jis <jismagic@gmail.com>
Subject: Re: Help on String to array !
Message-Id: <beb236d2-6716-4d84-b325-f4cde463b273@x23g2000prd.googlegroups.com>
Even I want to beleive it should take very less time.
I post the scripts I used for testing.
1. #!/usr/bin/perl
use strict;
use warnings;
my $binary_file=3D"28247101.bin";
open FILE, $binary_file or die "Can't open $binary_file $!\n";
# binmode FILE to supress conversion of line endings
binmode FILE;
undef $/;
my $data =3D <FILE>;
close FILE;
# convert data to hex form
my $hex =3D unpack 'H*', $data;
my ($val, $offs, @arr) =3D ('',0);
#@arr =3D $hex =3D~ /[[:xdigit:]]{2}/g;
@arr =3D unpack("(C2)*",$hex);
print "bye";
print $arr[2]; ( this took 3minuts 25 sec)
if i uncommment regex protion and comment unpack it would take
1minute 25 sec
#!/usr/bin/perl
use strict;
use warnings;
my $binary_file=3D"28247101.bin";
open FILE, $binary_file or die "Can't open $binary_file $!\n";
# binmode FILE to supress conversion of line endings
binmode FILE;
undef $/;
my $data =3D <FILE>;
close FILE;
# convert data to hex form
my $hex =3D unpack 'H*', $data;
my $i=3D0;
my ($val, $offs, @arr) =3D ('',0);
while ($val=3Dsubstr( $hex, $offs, 2)){
push @arr, $val;
$offs+=3D2;
}
print "bye";
print $arr[2]; This would take only 9 seconds.
I have used a stopwatch to calculate time.
Appreciate your help in finding how it can be improved.
thanks,
jis
On Mar 10, 12:51=A0pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> >>>>> "j" =3D=3D jis =A0<jisma...@gmail.com> writes:
>
> =A0 j> As said regex and unpack took longer time than substr.
> =A0 j> I use Windows. The following are the time taken.
>
> =A0 j> 1. Regex : @arr =3D $hex =3D~ /[[:xdigit:]]{2}/g; =A0- To read =A0=
4Mb file
> =A0 j> into an array it took =A01min 7 seconds.
> =A0 j> 2. Unpack : @arr =3D unpack("(C2)*",$hex); =A0 =A0- To read =A04Mb=
file into
> =A0 j> an array it took =A03min 26seconds.
> =A0 j> 3. Substr: while ($val=3Dsubstr( $hex, $offs, 2))
> =A0 j> =A0 =A0 {
> =A0 j> =A0 =A0 =A0 =A0 push @arr, $val;
> =A0 j> =A0 =A0 =A0 =A0 $offs+=3D2;
> =A0 j> =A0 =A0 } - =A0To read =A04Mb file into an array it took =A011 sec=
onds.
>
> i am sorry, i can't believe it took on the order of minutes to read in a
> file and convert from hex to binary. this is not possible on anything
> but an abacus. given you haven't shown the complete script for each
> version i have to assume your code is broken in some way. also there is
> no way a substr loop would be faster than unpack or a regex. both of
> those would spend all their time in perl's guts while the substr version
> spends most of its time doing slow perl ops in a loop. i say this from
> plenty of experience benchmarking perl code. you can easily write an
> incorrect test of this so i must ask you to post complete working
> programs that exhibit the slowness you claim. i will wager large amounts
> of quatloos i can fix them so the substr will be outed as the slowest
> one.
>
> uri
>
> --
> Uri Guttman =A0------ =A0u...@stemsystems.com =A0-------- =A0http://www.s=
ysarch.com--
> ----- =A0Perl Code Review , Architecture, Development, Training, Support =
------
> --------- =A0Gourmet Hot Cocoa Mix =A0---- =A0http://bestfriendscocoa.com=
---------
------------------------------
Date: Wed, 10 Mar 2010 16:05:59 -0800 (PST)
From: Jasper2000 <helius@gmail.com>
Subject: PDF::API2 (Creating PDF files)
Message-Id: <c8f0d6b9-28bc-49ba-ac9b-77362b2af18a@t41g2000yqt.googlegroups.com>
Hi,
I'm creating PDF's on the fly, with Perl 5.8, using PDF::API2.
I have no problem with most of it, albeit there's a bit of a learning
curve with creating PDFs, but I can't figure out how to insert a URL
with anchor text.
i.e. It's easy enough to insert a URL as text, and the PDF will
recognize it as a URL and make it clickable when viewed in Acrobat.
However, I would like to be able to insert a URL, such as http://www.test.com
yet have the link text be something like "Test Site" (with the actual
URL not visible).
I know it's possible to do it with PDF::API2::Simple, but the rest of
my script is already done using PDF::API2, so I hope to keep it that
way if possible.
Any assistance would be greatly appreciated, since there seems to be a
bit of a lack of good documentation for this particular module.
Thanks!
------------------------------
Date: Thu, 11 Mar 2010 00:31:52 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: PDF::API2 (Creating PDF files)
Message-Id: <o8ql67-62a1.ln1@osiris.mauzo.dyndns.org>
Quoth Jasper2000 <helius@gmail.com>:
>
> I'm creating PDF's on the fly, with Perl 5.8, using PDF::API2.
>
> I have no problem with most of it, albeit there's a bit of a learning
> curve with creating PDFs, but I can't figure out how to insert a URL
> with anchor text.
>
> i.e. It's easy enough to insert a URL as text, and the PDF will
> recognize it as a URL and make it clickable when viewed in Acrobat.
> However, I would like to be able to insert a URL, such as http://www.test.com
> yet have the link text be something like "Test Site" (with the actual
> URL not visible).
>
> I know it's possible to do it with PDF::API2::Simple, but the rest of
> my script is already done using PDF::API2, so I hope to keep it that
> way if possible.
If you look at the source for PDF::API2::Simple, you will find that it
uses
@rect = $self->_render_text_at( $text_obj, $text, $x, $y, $align );
$annotation = $self->current_page->annotation;
$annotation->rect( @rect );
$annotation->url( $url );
where $self->current_page is the page currently being written and
$self->_render_text_at add a piece of text and returns its bounding box.
->annotation is documented in PDF::API2::Page, and the returned object
is a PDF::API2::Annotation.
Ben
------------------------------
Date: Wed, 10 Mar 2010 19:15:14 -0800 (PST)
From: Jasper2000 <helius@gmail.com>
Subject: Re: PDF::API2 (Creating PDF files)
Message-Id: <942c8f2f-22a2-411f-9ec7-a0f0e09ca709@g11g2000yqe.googlegroups.com>
> If you look at the source for PDF::API2::Simple, you will find that it
> uses
>
> @rect = $self->_render_text_at( $text_obj, $text, $x, $y, $align );
> $annotation = $self->current_page->annotation;
>
> $annotation->rect( @rect );
> $annotation->url( $url );
>
> where $self->current_page is the page currently being written and
> $self->_render_text_at add a piece of text and returns its bounding box.
> ->annotation is documented in PDF::API2::Page, and the returned object
> is a PDF::API2::Annotation.
>
> Ben
That's great ... thanks very much for your pointer.
------------------------------
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 2865
***************************************