[31922] in Perl-Users-Digest
Perl-Users Digest, Issue: 3185 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 21 06:09:33 2010
Date: Thu, 21 Oct 2010 03:09:15 -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, 21 Oct 2010 Volume: 11 Number: 3185
Today's topics:
Re: fetching webpage and extracting contents <alfonso.baldaserra@gmail.com>
Re: fetching webpage and extracting contents <peter@makholm.net>
Re: fetching webpage and extracting contents <alfonso.baldaserra@gmail.com>
Formatting to delete leading zeroes junior@iam.invalid
Re: Formatting to delete leading zeroes <uri@StemSystems.com>
Re: Formatting to delete leading zeroes <glennj@ncf.ca>
Re: Formatting to delete leading zeroes <uri@StemSystems.com>
Re: Formatting to delete leading zeroes junior@iam.invalid
Re: modifying a PDF using PDF::API2? <cawqzny8@gmail.com>
Re: modifying a PDF using PDF::API2? <bugbear@trim_papermule.co.uk_trim>
PAMELA ANDERSON New SEX Video ( Very EROTIC ) <using4personal@gmail.com>
Re: perl curl get data from website <emailsrvr-groups@yahoo.com>
Re: PERL environment for EMACS... <tzz@lifelogs.com>
Re: Perl OO - combined static & instance method. (Randal L. Schwartz)
Re: Perl OO - combined static & instance method. <RedGrittyBrick@spamweary.invalid>
Re: Perl OO - combined static & instance method. <willem@turtle.stack.nl>
Re: Perl OO - combined static & instance method. (Randal L. Schwartz)
Re: useful modules to install <john@example.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 21 Oct 2010 00:25:29 -0700 (PDT)
From: alfonsobaldaserra <alfonso.baldaserra@gmail.com>
Subject: Re: fetching webpage and extracting contents
Message-Id: <0fa17728-a197-4f7b-b4dd-4dafe7a94e7c@x17g2000yqn.googlegroups.com>
> Huh?
>
> http://www.perlmonks.org/?node_id=280461http://search.cpan.org/perldoc?HTML::TreeBuilderhttp://groups.google.com/group/comp.lang.perl.misc/msg/372b363f0e9be360
>
> //Makholm
thank you guys :)
i finally utilised perlmonks link, read a little at cpan at here i am
#!/usr/bin/perl
use strict;
use warnings;
use HTML::Tree;
use LWP::Simple;
my $uri = "http://www.bbc.co.uk/radio1/chart/singles";
my $html = get($uri);
my $tree = HTML::Tree->new();
$tree->parse($html);
my @artist = $tree->look_down('_tag' , 'span', 'class', 'artist');
my @track = $tree->look_down('_tag' , 'span', 'class', 'track');
foreach my $i (0..$#artist) {
print $artist[$i]->as_text, " - ", $track[$i]->as_text, "\n";
}
again i am wondering if there is a better way to group these two
arrays together instead of the way i did
foreach my $i (0..$#artist) {
print $artist[$i]->as_text, " - ", $track[$i]->as_text, "\n";
}
thank you
------------------------------
Date: Thu, 21 Oct 2010 09:52:23 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: fetching webpage and extracting contents
Message-Id: <871v7kugnc.fsf@vps1.hacking.dk>
alfonsobaldaserra <alfonso.baldaserra@gmail.com> writes:
> my @artist = $tree->look_down('_tag' , 'span', 'class', 'artist');
> my @track = $tree->look_down('_tag' , 'span', 'class', 'track');
>
> foreach my $i (0..$#artist) {
> print $artist[$i]->as_text, " - ", $track[$i]->as_text, "\n";
> }
>
> again i am wondering if there is a better way to group these two
> arrays together instead of the way i did
It all depends on the HTML. But looking at the URL you posted it looks
like you're looke for a structure looking like this:
<a class="artist-link" href="/music/artists/ba7d2626-38ce-4859-8495-bdb5732715c4" id="link-13">
<span class="artist">Taio Cruz</span>
<span class="track">Dynamite</span>
</a>
What you could do was to iterate over all the <a class="artist-link>
nodes and then look for the artist and track below this
node. Untested, but something like this:
for my $link ( $tree->look_down(_tag => 'a', class => 'artist-link') ) {
my $artist = $link->look_down(class => 'artist')->as_text;
my $track = $link->look_down(class => 'track' )->as_text;
print "$artist - $track\n";
}
//Makholm
------------------------------
Date: Thu, 21 Oct 2010 02:10:48 -0700 (PDT)
From: alfonsobaldaserra <alfonso.baldaserra@gmail.com>
Subject: Re: fetching webpage and extracting contents
Message-Id: <2b52885f-75b1-4a9b-b698-636ab0cf1c23@j2g2000yqf.googlegroups.com>
> for my $link ( $tree->look_down(_tag =3D> 'a', class =3D> 'artist-link') =
) {
> =A0 =A0 my $artist =3D $link->look_down(class =3D> 'artist')->as_text;
> =A0 =A0 my $track =A0=3D $link->look_down(class =3D> 'track' )->as_text;
>
> =A0 =A0 print "$artist - $track\n";
>
> }
>
> //Makholm
thank you again makholm, your code worked sexily without any
modification :)
------------------------------
Date: Wed, 20 Oct 2010 13:38:17 -0700
From: junior@iam.invalid
Subject: Formatting to delete leading zeroes
Message-Id: <mgkub6p8vjppaq8cu5vouk3tqpiggma5s0@4ax.com>
How do I use sprintf() to delete a leading zero before the decimal point?
E.g., $num = 0.25 and I want $num = .25. I don't want to delete any
posiive integers, only the zero if there's no positive integer, i.e., 9.54
shows as 9.54, but 0.54 shows as .54.
Thanks,
--
JR
------------------------------
Date: Wed, 20 Oct 2010 16:56:50 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Formatting to delete leading zeroes
Message-Id: <87pqv4lh0t.fsf@quad.sysarch.com>
>>>>> "j" == junior <junior@iam.invalid> writes:
j> How do I use sprintf() to delete a leading zero before the decimal point?
j> E.g., $num = 0.25 and I want $num = .25. I don't want to delete any
j> posiive integers, only the zero if there's no positive integer, i.e., 9.54
j> shows as 9.54, but 0.54 shows as .54.
why use sprintf for trimming? just use a simple regex after you sprintf
it:
$number =~ s/^0+// ;
that will delete all leading zeros. use the right tool for the job.
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: 20 Oct 2010 21:00:18 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Formatting to delete leading zeroes
Message-Id: <slrnibum34.n91.glennj@smeagol.ncf.ca>
At 2010-10-20 04:38PM, "junior@iam.invalid" wrote:
> How do I use sprintf() to delete a leading zero before the decimal point?
>
> E.g., $num = 0.25 and I want $num = .25. I don't want to delete any
> posiive integers, only the zero if there's no positive integer, i.e., 9.54
> shows as 9.54, but 0.54 shows as .54.
What you asked for
$num =~ s/^0\././;
or simply remove all leading zeroes
$num =~ s/^0+//;
If you do any arithmetic with that number, you'll see that leading zero
again, so remove it just before you want to print it.
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Wed, 20 Oct 2010 17:26:15 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Formatting to delete leading zeroes
Message-Id: <871v7klfns.fsf@quad.sysarch.com>
>>>>> "GJ" == Glenn Jackman <glennj@ncf.ca> writes:
GJ> At 2010-10-20 04:38PM, "junior@iam.invalid" wrote:
>> How do I use sprintf() to delete a leading zero before the decimal point?
>>
>> E.g., $num = 0.25 and I want $num = .25. I don't want to delete any
>> posiive integers, only the zero if there's no positive integer, i.e., 9.54
>> shows as 9.54, but 0.54 shows as .54.
GJ> What you asked for
GJ> $num =~ s/^0\././;
why replace the . with a .?
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: Wed, 20 Oct 2010 14:33:34 -0700
From: junior@iam.invalid
Subject: Re: Formatting to delete leading zeroes
Message-Id: <a0oub6l76chtr6d03jcg968qkp7lkaqcb4@4ax.com>
Uri Guttman wrote:
>>>>>> "GJ" == Glenn Jackman <glennj@ncf.ca> writes:
>
> GJ> At 2010-10-20 04:38PM, "junior@iam.invalid" wrote:
> >> How do I use sprintf() to delete a leading zero before the decimal point?
> >>
> >> E.g., $num = 0.25 and I want $num = .25. I don't want to delete any
> >> posiive integers, only the zero if there's no positive integer, i.e., 9.54
> >> shows as 9.54, but 0.54 shows as .54.
>
> GJ> What you asked for
> GJ> $num =~ s/^0\././;
>
>why replace the . with a .?
>
Thank you Uri and Glenn.
--
JR
------------------------------
Date: Wed, 20 Oct 2010 10:17:30 -0700 (PDT)
From: pdftk <cawqzny8@gmail.com>
Subject: Re: modifying a PDF using PDF::API2?
Message-Id: <4fc8f436-1f0c-48d0-8ae5-366ac5b8110c@z20g2000pra.googlegroups.com>
On Oct 13, 6:56=A0am, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> I'm trying to add a watermark to an existing page; the watermark
> is in a separate pre-prepared PDF.
>
> ...
>
> sidebar
> =A0 =A0 anyone know a good PDF checker that gives detailed fault reports?
>
> ...
Hello-
I use pdfinfo, available as part of the xpdf project, to test PDF
files. It can also report all kinds of useful things.
For applying watermarks to PDFs, consider the command-line pdftk. The
command would look like:
pdftk in.pdf background water.pdf output out.pdf
You can also output to stdout:
pdftk in.pdf background water.pdf output -
This operation will preserve the input PDF's metadata.
Regards-
Sid Steward
Pdftk Author
------------------------------
Date: Thu, 21 Oct 2010 09:35:58 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: modifying a PDF using PDF::API2?
Message-Id: <3omdnQyWjYnzZiLRnZ2dnUVZ8vudnZ2d@brightview.co.uk>
pdftk wrote:
> On Oct 13, 6:56 am, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
>> I'm trying to add a watermark to an existing page; the watermark
>> is in a separate pre-prepared PDF.
>>
>> ...
>>
>> sidebar
>> anyone know a good PDF checker that gives detailed fault reports?
>>
>> ...
>
> Hello-
>
> I use pdfinfo, available as part of the xpdf project, to test PDF
> files. It can also report all kinds of useful things.
Yes - it's good at extracting data, but it's not giving me good diagnostics
on "bad" PDFs (e.g. PDFs with duff xrefs, missing/typo's dict keys etc)
BugBear
------------------------------
Date: Wed, 20 Oct 2010 10:46:11 -0700 (PDT)
From: group <using4personal@gmail.com>
Subject: PAMELA ANDERSON New SEX Video ( Very EROTIC )
Message-Id: <df888ba5-3ad6-4c79-9353-c40306ba2e4e@l17g2000yqe.googlegroups.com>
Due to some Premises I have Hidden the videos....... CLICK on the
IMAGE below the SEARCH BOX for videos http://actressvideos.us.tt
------------------------------
Date: Wed, 20 Oct 2010 07:53:08 -0700 (PDT)
From: SVCitian <emailsrvr-groups@yahoo.com>
Subject: Re: perl curl get data from website
Message-Id: <11f92bb9-3550-4cff-bddf-0124d0e0ee54@s12g2000prs.googlegroups.com>
On Oct 20, 10:47=A0am, s...@netherlands.com wrote:
> On Tue, 19 Oct 2010 20:10:42 -0700, s...@netherlands.com wrote:
> >On Tue, 19 Oct 2010 07:17:14 -0700 (PDT),SVCitian<emailsrvr-gro...@yahoo=
.com> wrote:
>
> >>On Oct 19, 2:26=A0am, s...@netherlands.com wrote:
> >>> On Mon, 18 Oct 2010 05:58:42 -0700 (PDT),SVCitian<emailsrvr-gro...@ya=
hoo.com> wrote:
> >>> >On Oct 17, 10:21=A0pm, Tad McClellan <ta...@seesig.invalid> wrote:
> >>> >>SVCitian<emailsrvr-gro...@yahoo.com> wrote:
> >>> >> > I even tried to user "tamper data" firefox add to get behind the
> >>> >> > scenes of GET, POST, etc... but I can't proceed any further than=
the
> >>> >> > URLs given above.
>
> >>I have no clue of how to make heads or tails of the result.
>
> >>If you could post the result in a more helpful format.. I would
> >>appreciate it.
>
> >>Thanks.
>
> >This may be better, my first afternoon with LWP.
>
> >-sln
>
> >----------------------
> >use strict;
> >use warnings;
>
> >use HTML::TableExtract;
> >use HTTP::Cookies;
> >use HTTP::Request::Common qw(POST GET);
> >use LWP::UserAgent;
>
> >my $show_content =3D 0;
> >my ($content1, $content2);
>
> [snip code]
>
> ># Create asecond request: "get search table"
> ># ---------
>
> > $request =3D HTTP::Request->new('GET' =3D>
> > =A0join '', qw{
> >http://www.bangkokflightservices.com/TrackTrace/search_awb.php?m_pref...
> >n=3D75064953&h_prefix=3DHWB&h_sn=3D&ch=3D } );
>
> ## Or, to create a variable AWB lookup
> # =A0my $WBNprefix =3D '176';
> # =A0my $WBN =A0 =A0 =A0 =3D '75064953';
> # =A0 $request =3D HTTP::Request->new('GET' =3D>
> # =A0"http://www.bangkokflightservices.com/TrackTrace/search_awb.php?m_pr=
efix=3D" .
> # =A0 $WBNprefix. "&m_sn=3D" . $WBN . "&h_prefix=3DHWB&h_sn=3D&ch=3D ");
>
> -sln
Thank you for your efforts... I will try out the perl code tomorrow.
By the way, I am not on a linux machine.. I am on Windows XP using
cygwin / perl.
So, I don't know if the proxy and all the rest of it could work. Any
way I will try if I ever get successful.
Any other helpful pointers for Windows / Cygwin / Perl... will be
appreciated too.
Thanks.
------------------------------
Date: Wed, 20 Oct 2010 13:02:54 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: PERL environment for EMACS...
Message-Id: <87k4lcvj1t.fsf@lifelogs.com>
On Tue, 19 Oct 2010 13:36:22 -0700 (PDT) fortunatus <daniel.eliason@excite.com> wrote:
f> Does everyone use PDE?
f> I'm using it now (first day) and I like it so far. But anyone have
f> any other suggestions?
It really depends on how familiar you are with Emacs itself. I
personally find cperl-mode fits my Emacs usage best.
Ted
------------------------------
Date: Wed, 20 Oct 2010 06:05:23 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl OO - combined static & instance method.
Message-Id: <86lj5tui98.fsf@red.stonehenge.com>
>>>>> "RedGrittyBrick" == RedGrittyBrick <RedGrittyBrick@spamweary.invalid> writes:
RedGrittyBrick> The background is that I have a handful of programs, the
RedGrittyBrick> earlier ones have some subroutines in common so these
RedGrittyBrick> were moved into a common procedural module. A set of
RedGrittyBrick> programs written later use an OO version of the
RedGrittyBrick> module. I wanted to merge the OO and procedural modules
RedGrittyBrick> whilst delaying the refactoring of the earlier programs.
You should have said this first. The solution is simple:
Use a global substitution on the older programs to replace
"Your::Module" with "Your::Module::Legacy". Then create a subroutine in
that package that invokes the correct method in "Your::Module".
Simple.
Most people work too hard. :)
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.posterous.com/ for Smalltalk discussion
------------------------------
Date: Wed, 20 Oct 2010 14:47:07 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: Perl OO - combined static & instance method.
Message-Id: <4cbef2dc$0$2540$da0feed9@news.zen.co.uk>
On 20/10/2010 14:05, Randal L. Schwartz wrote:
>>>>>> "RedGrittyBrick" == RedGrittyBrick<RedGrittyBrick@spamweary.invalid> writes:
>
> RedGrittyBrick> The background is that I have a handful of programs, the
> RedGrittyBrick> earlier ones have some subroutines in common so these
> RedGrittyBrick> were moved into a common procedural module. A set of
> RedGrittyBrick> programs written later use an OO version of the
> RedGrittyBrick> module. I wanted to merge the OO and procedural modules
> RedGrittyBrick> whilst delaying the refactoring of the earlier programs.
>
> You should have said this first.
I should. The trouble was I half remembered something of the sort that
Sherm helpfully pointed out. Plus I hadn't thought through the implications.
> The solution is simple:
>
> Use a global substitution on the older programs to replace
> "Your::Module" with "Your::Module::Legacy". Then create a subroutine in
> that package that invokes the correct method in "Your::Module".
>
> Simple.
My thoughts had turned to writing wrappers, thanks for the additional
organisational hints.
> Most people work too hard. :)
I obviously still have to work on increasing my laziness, impatience and
hubris†.
--
RGB
† http://en.wikipedia.org/wiki/Larry_Wall#Virtues_of_a_programmer
(for anyone who started to learn Perl in the last 5 seconds).
------------------------------
Date: Wed, 20 Oct 2010 16:05:09 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: Perl OO - combined static & instance method.
Message-Id: <slrnibu4pl.1aoh.willem@turtle.stack.nl>
Randal L. Schwartz wrote:
)>>>>> "RedGrittyBrick" == RedGrittyBrick <RedGrittyBrick@spamweary.invalid> writes:
)
)RedGrittyBrick> The background is that I have a handful of programs, the
)RedGrittyBrick> earlier ones have some subroutines in common so these
)RedGrittyBrick> were moved into a common procedural module. A set of
)RedGrittyBrick> programs written later use an OO version of the
)RedGrittyBrick> module. I wanted to merge the OO and procedural modules
)RedGrittyBrick> whilst delaying the refactoring of the earlier programs.
)
) You should have said this first. The solution is simple:
)
) Use a global substitution on the older programs to replace
) "Your::Module" with "Your::Module::Legacy". Then create a subroutine in
) that package that invokes the correct method in "Your::Module".
Why not use a global substitution to replace
"Your::Module::(\w+)" with "Your::Module->$1" ?
This should work as long as there are no module variables in use, no ?
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Wed, 20 Oct 2010 15:25:23 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl OO - combined static & instance method.
Message-Id: <86aam8tsbw.fsf@red.stonehenge.com>
>>>>> "Willem" == Willem <willem@turtle.stack.nl> writes:
Willem> Why not use a global substitution to replace
Willem> "Your::Module::(\w+)" with "Your::Module->$1" ?
Might miss imports. Mine'll work either way.
--
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.posterous.com/ for Smalltalk discussion
------------------------------
Date: Thu, 21 Oct 2010 01:40:05 -0600
From: John Smith <john@example.invalid>
Subject: Re: useful modules to install
Message-Id: <97adnVU2gdbIcyLRnZ2dnUVZ5gCdnZ2d@giganews.com>
[unfortunate mispost corrected]
[not waiting]
$ sudo apt-get install acl
[sudo] password for ron:
Reading package lists... Done
Building dependency tree
Reading state information... Done
acl is already the newest version.
The following packages were automatically installed and are no longer
required:
linux-headers-2.6.28-11 linux-headers-2.6.28-11-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
$
------------------------------
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 3185
***************************************