[29819] in Perl-Users-Digest
Perl-Users Digest, Issue: 1062 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 25 16:09:43 2007
Date: Sun, 25 Nov 2007 13:09:07 -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 Sun, 25 Nov 2007 Volume: 11 Number: 1062
Today's topics:
Re: Get my IP address? <krahnj@telus.net>
Re: Get my IP address? <No_4@dsl.pipex.com>
How to set a global on the command line? <socyl@987jk.com.invalid>
Re: How to set a global on the command line? <No_4@dsl.pipex.com>
opendir mydir/??/??/?? <avilella@gmail.com>
Re: opendir mydir/??/??/?? <s.denaxas@gmail.com>
Re: regex instead of a new lover. . . <noreply@gunnar.cc>
Re: regex instead of a new lover. . . <uri@stemsystems.com>
Re: Script to disconnect Linksys WRT54G wireless router <hjp-usenet2@hjp.at>
Re: Script to disconnect Linksys WRT54G wireless router <hjp-usenet2@hjp.at>
Re: Script to disconnect Linksys WRT54G wireless router <hjp-usenet2@hjp.at>
Re: Script to disconnect Linksys WRT54G wireless router <hjp-usenet2@hjp.at>
web crawling for books <alexxx.magni@gmail.com>
Re: web crawling for books <spamtrap@dot-app.org>
Re: web crawling for books <s.denaxas@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 25 Nov 2007 08:38:10 GMT
From: "John W. Krahn" <krahnj@telus.net>
Subject: Re: Get my IP address?
Message-Id: <4749345E.C1E9FC0@telus.net>
Ben Morrow wrote:
>
> Sorry, scratch my last response.
OK, scratched.
> I (and you, I think) was completely
> misunderstanding how SIOCGIFADDR is supposed to be called.
Correct on this end.
> Quoth "John W. Krahn" <krahnj@telus.net>:
> >
> > $ perl -le'
> > use Socket qw/PF_INET SOCK_DGRAM/;
> > require "linux/ioctl.ph";
> > my $proto = getprotobyname "ip";
> > socket SOCKET, PF_INET, SOCK_DGRAM, $proto or die "socket: $!";
> > defined( ioctl SOCKET, SIOCGIFADDR, my $address ) or die "ioctl: $!";
> > '
> > ioctl: No such device at -e line 6.
>
> You're calling it wrong :). SIOCGIFADDR takes a pointer to a struct
> ifreq, which starts with an interface name. If you pass it an empty
> string (which has an implicit "\0" at the end) then it's looking for an
> interface with an empty name. Unsurprisingly, it can't find one :).
>
> Under FreeBSD, with 5.8.8 or 5.6.0, this script
>
> #!/usr/bin/perl -l
>
> use Socket qw/PF_INET SOCK_DGRAM inet_ntoa sockaddr_in/;
>
> # h2ph gets SIOCGIFADDR wrong on my system.
> # Modern systems have complicated ioctl definitions that encode the
> # sizes of the types used, and h2ph can't cope.
> # h2ph is evil anyway. Use h2xs instead. ;)
I just looked the numbers up in the header file.
> my $SIOCGIFADDR = 3223349537;
That seems like a rather large number, on my Linux system its 0x8915.
(Although I would probably use SIOCGIFDSTADDR instead.)
> # This is slightly daft... ip is protocol 0 by definition, and 0
> # means 'default protocol for this socket type', so you'll actually
> # get an ordinary UDP socket. IPPROTO_IP only really applies to
> # SOCK_RAW sockets.
>
> my $proto = getprotobyname 'ip';
>
> socket SOCKET, PF_INET, SOCK_DGRAM, $proto
> or die "socket: $!";
>
> # struct ifreq is 16 bytes of name, null-padded, followed by 16
> # bytes of answer. In the case of SIOCGIFADDR, that answer is a
> # packed address.
>
> my $ifreq = pack 'a32', 'xl0';
I found that this:
my $ifreq = 'eth0';
works fine for me (I don't have an 'x10' interface.) Perl will expand
the string to the required size.
> ioctl SOCKET, $SIOCGIFADDR, $ifreq
> or die "ioctl: $!";
>
> my ($if, $sin) = unpack 'a16 a16', $ifreq;
> my ($port, $addr) = sockaddr_in $sin;
> my $ip = inet_ntoa $addr;
>
> print "addr: $ip";
>
> __END__
>
> prints my ip address. You will of course need to change the value of
> $SIOCGIFADDR (write a trivial bit of C to tell you what it should be)
> and the interface name, and perhaps look up Linux' struct ifreq and
> change the unpack format (it's probably the same though).
Thanks a lot Ben. Now if I could figure out SIOCGIFCONF to get the list
of interfaces! :-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 25 Nov 2007 14:53:51 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Get my IP address?
Message-Id: <zPidnSSPQeYdEdTaRVnyhgA@pipex.net>
John W. Krahn wrote:
> Is this just broken on 5.6.0 or does it work anywhere? :-)
The basic principle works. I have perl code which quickly answers the
question "is the given IP address one my my interface addresses", and it
works in roughly the same way (exact details unsure - it's at work..)
Just remember that "my IP address" is not a generally valid query, since it
is perfectly possible to have > 1 (indeed, since you will always have the
localhost interface as well you *always* have more than one).
However, for the common case you can get a UDP socket to an arbitrary
address and ask for for sockaddr() of that socket. Since you haven't
actually sent anything, or even connected to it (it's UDP) there is no
actual network traffic involved.
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Sun, 25 Nov 2007 14:51:11 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: How to set a global on the command line?
Message-Id: <fic24v$935$1@reader1.panix.com>
I often use Johan Vromans' handy script mp3cat, which I downloaded
from CPAN. I invoke it like this, for example:
% mp3cat --output=all.mp3 /some/dir/*.mp3
mp3cat works great most of the time, but lately it has been giving
me problems. I've traced these problems to the value of a certain
global variable, $MPEG::Audio::Frame::free_bitrate. This variable
is undef by default, and mp3cat leaves it unchanged. I discovered
(by running mp3cat in the debugger) that the problems I mentioned
would disappear if I set this variable to the correct bitrate (which
I know).
The only problem now is that mp3cat offers no way to specify a
value for this variable. I could hack mp3cat to add this functionality,
but I wondered, is there was a less "invasive" way to specify the
value of a global variable, e.g. on the command line?
TIA!
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: Sun, 25 Nov 2007 14:57:43 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: How to set a global on the command line?
Message-Id: <zPidnSePQeb6ENTaRVnyhgA@pipex.net>
kj wrote:
...
> The only problem now is that mp3cat offers no way to specify a
> value for this variable. I could hack mp3cat to add this functionality,
> but I wondered, is there was a less "invasive" way to specify the
> value of a global variable, e.g. on the command line?
Write your own init.pm module which sets it, then run
perl -Minit /path/to/mp3cat --output=all.mp3 /some/dir/*.mp3
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Sun, 25 Nov 2007 12:11:06 -0800 (PST)
From: "avilella@gmail.com" <avilella@gmail.com>
Subject: opendir mydir/??/??/??
Message-Id: <1737c7a7-60a8-41ba-b3a2-453895a80502@s19g2000prg.googlegroups.com>
Hi all,
I have a group of dirs and subdirs that look like mydir/00/00/00,
mydir/00/00/01 ... mydir 11/55/99.
In the same way I can do an "ls mydir/??/??/??/*.ext", is there a way
that I can do an opendir like:
opendir(DIR, "mydir/??/??/??")
Cheers,
Albert.
------------------------------
Date: Sun, 25 Nov 2007 12:18:17 -0800 (PST)
From: Spiros Denaxas <s.denaxas@gmail.com>
Subject: Re: opendir mydir/??/??/??
Message-Id: <d28dccfb-a9c3-4d61-bdde-b1c47d2d6154@s19g2000prg.googlegroups.com>
On Nov 25, 8:11 pm, "avile...@gmail.com" <avile...@gmail.com> wrote:
> Hi all,
>
> I have a group of dirs and subdirs that look like mydir/00/00/00,
> mydir/00/00/01 ... mydir 11/55/99.
>
> In the same way I can do an "ls mydir/??/??/??/*.ext", is there a way
> that I can do an opendir like:
>
> opendir(DIR, "mydir/??/??/??")
>
> Cheers,
>
> Albert.
Hi Albert,
use the File::Find module. I think it will give you the flexibility to
do what you want.
http://search.cpan.org/~nwclark/perl-5.8.8/lib/File/Find.pm
Good luck,
Spiros
------------------------------
Date: Sun, 25 Nov 2007 10:11:13 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regex instead of a new lover. . .
Message-Id: <5qsshoF11khhhU1@mid.individual.net>
aardvarkman wrote:
> What I am looking for is a regex that finds anything one line at a
> time separated by ===. In other words, all my config options are on a
> single line like: key === value.
my %config;
while (<$fh>) {
if ( /(.+) === (.+)/ ) {
$config{ $1 } = $2;
}
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 25 Nov 2007 09:25:22 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: regex instead of a new lover. . .
Message-Id: <x7k5o6fzi5.fsf@mail.sysarch.com>
>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
GH> aardvarkman wrote:
>> What I am looking for is a regex that finds anything one line at a
>> time separated by ===. In other words, all my config options are on a
>> single line like: key === value.
GH> my %config;
GH> while (<$fh>) {
GH> if ( /(.+) === (.+)/ ) {
GH> $config{ $1 } = $2;
GH> }
GH> }
a 2 liner that also does the i/o (untested):
(assuming the config come from a file)
use File::Slurp ;
my %config = read_file( 'config' ) =~ /^([^=]+)===(.*)$/mg ;
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 25 Nov 2007 09:48:30 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Script to disconnect Linksys WRT54G wireless router on Windows
Message-Id: <slrnfkidn0.bk6.hjp-usenet2@zeno.hjp.at>
["Followup-To:" header set to comp.lang.perl.misc.]
On 2007-11-24 06:31, Wilson <davewilson69@sbcglobal.net> wrote:
> On Fri, 23 Nov 2007 16:54:36 -0500, Sherman Pendley wrote:
>> In a generic sense, there are literally hundreds of examples of Perl doing what
>> you claim it can't do - just google for "WWW::Mechanize" or "perl web scraping"
>> to see them. There is absolutely no question that Perl is capable of logging
>> into an https web server and performing the moral equivalent of a button click.
>
> Even web pages which seem to require "javascript" in order to view the
> buttons?
In the general case, no: You need a JavaScript interpreter for that.
In most realistic cases, yes: The JavaScript code on the page is always
the same, so you just need to find out what it does and reimplement it
in Perl.
hp
--
_ | Peter J. Holzer | It took a genius to create [TeX],
|_|_) | Sysadmin WSR | and it takes a genius to maintain it.
| | | hjp@hjp.at | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex
------------------------------
Date: Sun, 25 Nov 2007 10:04:36 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Script to disconnect Linksys WRT54G wireless router on Windows
Message-Id: <slrnfkiel4.bk6.hjp-usenet2@zeno.hjp.at>
["Followup-To:" header set to comp.lang.perl.misc.]
On 2007-11-24 18:56, Bit Twister <BitTwister@mouse-potato.com> wrote:
> On Sat, 24 Nov 2007 18:13:08 GMT, Wilson wrote:
>> It's just that I really hate it when I have to do anything manual and,
>> despite the fact I'm not a programmer-type person, I always try to cut down
>> on the number of button clicks I do, even if it's only three or five clicks
>> when I do it a lot. I find that makes me much more efficient even if there
>> is a lot of up-front work to get the job done.
So Wilson does have a programmer's mind after all.
>> So, I _will_ automate the task of disconnecting and reconnecting from the
>> ISP - I just don't know how yet. I have just a few more things to try
>> (although I said that days ago) and I'll get the damn thing working.
>
> I do not do windows, I run Mandriva Linux.
I didn't realize Wilson is using Windows. If he does he should be able
to use WWW::Mechanize::IE, which lets him use IE's JavaScript
interpreter.
hp
--
_ | Peter J. Holzer | It took a genius to create [TeX],
|_|_) | Sysadmin WSR | and it takes a genius to maintain it.
| | | hjp@hjp.at | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex
------------------------------
Date: Sun, 25 Nov 2007 10:23:55 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Script to disconnect Linksys WRT54G wireless router on Windows
Message-Id: <slrnfkifpb.bk6.hjp-usenet2@zeno.hjp.at>
["Followup-To:" header set to comp.lang.perl.misc.]
On 2007-11-24 18:06, Wilson <davewilson69@sbcglobal.net> wrote:
> You have always been the one useful voice of reason. The rest were voices
> of reason, but not useful (like the ones who lambasted my lack of
> programming experience or those who claimed it could be done w/o any
> evidence).
The proof is rather simple.
1) Perl is a turing-complete programming language which provides the
means to communicate over TCP. Therefore any task which can be
described by an algorithm and which only requires communication over
TCP can be implemented in Perl.
2) The task at hand can be done by a human using a standard web browser.
3) The part done by the browser can of course be implemented by a
program since a browser is a program.
4) So the part done by the human remains: Can this be described by an
algorithm? Yes: It requires only a series of simple, precicely
defined steps.
Therefore the whole task can be implemented in Perl.
Of course that proof is not very useful. Writing a whole web-browser in
Perl just to automate such a simple task would be a bit over the top.
But it shows that it can be done in principle, and once you know one way
to do it you can search for simpler ways.
hp
--
_ | Peter J. Holzer | It took a genius to create [TeX],
|_|_) | Sysadmin WSR | and it takes a genius to maintain it.
| | | hjp@hjp.at | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex
------------------------------
Date: Sun, 25 Nov 2007 10:27:41 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Script to disconnect Linksys WRT54G wireless router on Windows
Message-Id: <slrnfkig0k.bk6.hjp-usenet2@zeno.hjp.at>
On 2007-11-25 08:48, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> ["Followup-To:" header set to comp.lang.perl.misc.]
> On 2007-11-24 06:31, Wilson <davewilson69@sbcglobal.net> wrote:
>> On Fri, 23 Nov 2007 16:54:36 -0500, Sherman Pendley wrote:
>>> In a generic sense, there are literally hundreds of examples of Perl doing what
>>> you claim it can't do - just google for "WWW::Mechanize" or "perl web scraping"
>>> to see them. There is absolutely no question that Perl is capable of logging
>>> into an https web server and performing the moral equivalent of a button click.
>>
>> Even web pages which seem to require "javascript" in order to view the
>> buttons?
>
> In the general case, no: You need a JavaScript interpreter for that.
Let me qualify that: It is of course possible to write a JavaScript
interpreter in Perl, so Perl is certainly capable of doing it, it would
just be much more work than you are probably willing to do.
On some platforms there may already be a JavaScript interpreter you can
use from Perl, so you don't have to implement it yourself.
hp
--
_ | Peter J. Holzer | It took a genius to create [TeX],
|_|_) | Sysadmin WSR | and it takes a genius to maintain it.
| | | hjp@hjp.at | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex
------------------------------
Date: Sun, 25 Nov 2007 01:58:25 -0800 (PST)
From: "alexxx.magni@gmail.com" <alexxx.magni@gmail.com>
Subject: web crawling for books
Message-Id: <4f8930cd-55fe-4619-8a53-9292b735beab@i12g2000prf.googlegroups.com>
I have a large list of my library's books,
and I would like to setup a Perl spider, going on the web for each
author/title information, and returning useful info I didnt put into
the records (editor, year, topic, isbn, ...).
I already wrote down the basic spider's structure, but I'm not sure
which site is more apt to such a search (considering also that its
robots.txt should allow me access).
Which site would you suggest for such a task?
Thank you!
Alessandro Magni
------------------------------
Date: Sun, 25 Nov 2007 08:56:47 -0500
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: web crawling for books
Message-Id: <m1myt2l97k.fsf@dot-app.org>
"alexxx.magni@gmail.com" <alexxx.magni@gmail.com> writes:
> I have a large list of my library's books,
> and I would like to setup a Perl spider, going on the web for each
> author/title information, and returning useful info I didnt put into
> the records (editor, year, topic, isbn, ...).
> I already wrote down the basic spider's structure, but I'm not sure
> which site is more apt to such a search (considering also that its
> robots.txt should allow me access).
> Which site would you suggest for such a task?
I'd suggest using Amazon's Web Services API for that. It'll give you back
structured data, which will be far easier to deal with than spidering sites
and scraping HTML.
Have a look at the Net::Amazon module on CPAN.
sherm--
--
WV News, Blogging, and Discussion: http://wv-www.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Sun, 25 Nov 2007 05:59:41 -0800 (PST)
From: Spiros Denaxas <s.denaxas@gmail.com>
Subject: Re: web crawling for books
Message-Id: <03434f6b-4620-4d53-8cd6-b7db43cb1c74@y5g2000hsf.googlegroups.com>
On Nov 25, 9:58 am, "alexxx.ma...@gmail.com" <alexxx.ma...@gmail.com>
wrote:
> I have a large list of my library's books,
> and I would like to setup a Perl spider, going on the web for each
> author/title information, and returning useful info I didnt put into
> the records (editor, year, topic, isbn, ...).
> I already wrote down the basic spider's structure, but I'm not sure
> which site is more apt to such a search (considering also that its
> robots.txt should allow me access).
> Which site would you suggest for such a task?
>
> Thank you!
>
> Alessandro Magni
Hi,
speaking from experience, I think you will be able to obtain higher
quality results which are more relevant using API's instead of just
scraping sites. For example, check out the Amazon Web Services API at
http://www.amazon.com/AWS-home-page-Money/b?ie=UTF8&node=3435361
You could also potentially use http://books.google.com/.
Spiros
------------------------------
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 1062
***************************************