[19120] in Perl-Users-Digest
Perl-Users Digest, Issue: 1315 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 17 06:06:07 2001
Date: Tue, 17 Jul 2001 03:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <995364310-v10-i1315@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 17 Jul 2001 Volume: 10 Number: 1315
Today's topics:
about image::Magick quality. <shijialee@yahoo.com>
Re: about image::Magick quality. <ubl@schaffhausen.de>
Re: Advice REQ for newbie <pne-news-20010717@newton.digitalspace.net>
ANNOUNCE: POE 0.15 (Rocco Caputo)
Re: Array Sorting-Looping-Number Formatting <goldbb2@earthlink.net>
Re: big versions problem from a newbie <hafner-usenet@ze.tu-muenchen.de>
Re: Checking for changed or missing links in perl (Eric Bohlman)
Re: Colored quotes in Html (Eric Bohlman)
Re: Compress::Zlib install problem (J.H.M. Dassen (Ray))
FAQ: How can I use curses with Perl? <faq@denver.pm.org>
Re: Format problems <pne-news-20010717@newton.digitalspace.net>
help : Graph.pm <james@alphyra.ie>
Re: HELP WITH PERLDAP!!!!!!!!! (Eric Bohlman)
Re: How to run Perl on MS-DOS <bryce_anderson@yahoo.com>
Re: Looking for the right direction <npeles@bigpond.net.au>
Obtaining remote users ip <cmicallef@playground.net>
Re: Obtaining remote users ip <ron@savage.net.au>
Re: Obtaining remote users ip <hafner-usenet@ze.tu-muenchen.de>
Pull ng posts behind firewall (BUCK NAKED1)
Re: Pull ng posts behind firewall <pne-news-20010717@newton.digitalspace.net>
Re: sortlen -- filter to sort text by line length <goldbb2@earthlink.net>
Re: warn() does not use a localized STDERR filehandle, (Villy Kruse)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 17 Jul 2001 07:31:08 GMT
From: "James" <shijialee@yahoo.com>
Subject: about image::Magick quality.
Message-Id: <0RR47.198498$Mf5.54623396@news3.rdc1.on.home.com>
Hi, all
i am trying to resize image and lower the quality in order to make a
thumbnail.i am expecially dealing with JPEG file now.My problem is the
quality of the image seems not to be effected no matter what number i set
for the quality. Such as i have a JPEG file 555x740 93.3k. after resizing,
size to be 6.84k no matter what quality i set. Why?
code is like this:
_______________________________________________
use Image::Magick;
$width=70;
$height =100;
$image = Image::Magick->new;
$image->Read('1012.jpg');
$test = $image->Clone();
my ($w1,$h1) = $test->Get('width','height');
my($w2,$h2) = &getNewSize($w1,$h1);
$test->Resize(width=>$w2,height=>$h2);
$test->Write(quality=>'50',filename=>'copy.jpg');
-----------------------------------------------
i am new to perl , please give me any thought you may have, thanks!
James
------------------------------
Date: Tue, 17 Jul 2001 11:14:06 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: about image::Magick quality.
Message-Id: <3B540FEF.2A923C54@schaffhausen.de>
James schrieb:
> i am trying to resize image and lower the quality in order to make a
> thumbnail.i am expecially dealing with JPEG file now.My problem is the
> quality of the image seems not to be effected no matter what number i set
> for the quality. Such as i have a JPEG file 555x740 93.3k. after resizing,
> size to be 6.84k no matter what quality i set. Why?
> code is like this:
> $test->Write(quality=>'50',filename=>'copy.jpg');
Just by quickly looking at the docs, quality seems to be a paramater
you give to the method "Set" not "Write". Subs using the named parameters
via hash scheme will usually silently ignore params which they dont expect.
Love it or hate it.
->malte
------------------------------
Date: Tue, 17 Jul 2001 08:46:29 +0200
From: Philip Newton <pne-news-20010717@newton.digitalspace.net>
Subject: Re: Advice REQ for newbie
Message-Id: <j9m7ltkb60mo08bcr9on3gb1378pdc1t14@4ax.com>
On Mon, 16 Jul 2001 19:49:02 +0100, "Pete" <bloke6789@hotmail.com>
wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrn9l5uqe.5ld.tadmc@tadmc26.august.net...
> >
> > [ Please do not send stealth Cc's. It makes people angry. ]
> >
> As for stealth, I wouldn't know it if it crept up on me!
He means, basically, "don't send a message as a newsgroup article and as
an email message at the same time (reply to group and to author) without
mentioning that this takes place, for example, by inserting a short
sentence to that effect at the beginning of the message".
Otherwise many people assume that email messages are sent only by email.
Possibly consequences are (a) people feeling that the sender is imposing
on them by choosing *them* to answer a question, rather than posting to
the newsgroup where many people have the opportunity to do so, and
readers can self-select on the basis of (for example) available time and
perceived skills, and (b) people answering a question in detail by
return email and then finding out later that the question also appeared
on a newsgroup and the answer could have benefitted other readers or
later archive-divers.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 15 Jul 2001 21:54:04 GMT
From: troc@netrus.net (Rocco Caputo)
Subject: ANNOUNCE: POE 0.15
Message-Id: <tl7ek1od93db6d@corp.supernews.com>
Good morning. It's my pleasure to announce that POE 0.15 has been
uploaded to the PAUSE. It will arrive at your favorite CPAN mirror
after the customary propagation delay.
It's available from two web sites right now, if you'd rather not wait
for it to reach the CPAN site of your choice:
POE's main web site: http://poe.perl.org/
SourceForge : http://sf.net/projects/poe/
It's been some 80 days and four development releases since 0.14.
Thanks to everyone who sent in feedback and patches.
If you would like to receive announcements of POE's development
releases, please send a message to <poe-help@perl.org>. You will
receive instructions for subscribing to POE's mailing list.
Change highlights since 0.14:
* Added a TODO file to the distribution. This is part changes roadmap
and mostly a feature wishlist.
* A second alarms interface. It's a little more complex than the
original one, but it gives programs more control over timers.
* XyzState parameters in wheels have been renamed to XyzEvent. This
doesn't break existing code yet, but it is expected to in September.
See the TODO file for exact breakage dates.
* Documentation and installation fixes. POE won't clobber
Devel::Trace anymore.
* Removed use of features specific to perl 5.6.1. POE should once
again be compatible with perl 5.004_05 and possibly older.
* Better memory leak checking, and a leak fix in the signals code.
* Better dependency checking and more graceful failure in the face of
adversity.
* Better Win32 support. Instructions for installing POE with
ActiveState's PPM.
You can read more about this, historical, and future releases on the
web:
The full CHANGES file: http://poe.perl.org/poedown/CHANGES
The full README file : http://poe.perl.org/poedown/README
The full TODO file : http://poe.perl.org/poedown/TODO
Thanks for reading!
-- Rocco Caputo / troc@netrus.net / poe.perl.org / poe.sourceforge.net
------------------------------
Date: Tue, 17 Jul 2001 00:58:37 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Array Sorting-Looping-Number Formatting
Message-Id: <3B53C5FD.C1B99216@earthlink.net>
Eric wrote:
>
> Regarding the following data file parsing and writing to a new file
> script (partial code):
>
> <snip> #Routine stuff
> my $line;
> while ( defined( $line = <INFILE> ) )
>
> {
> next unless $line =~ /--.*STATUS AVAILABLE/;
Does this expression always identify the start of your records?
If so, then try code like the following:
foreach my $record ( do { local $/;
split /(?=--.*STATUS AVAILABLE)/, <INFILE> } ) {
Each $record should be an entire record.
my @lines = split /\n/, $record;
my ($status) = unpack 'x42 A10', shift @lines;
my %record = map /^\s*(.*?):(.*)/, @lines;
my ($addr, $price) = # assuming it was " LOCATION:"
unpack 'A25 x33 A11', $record{"LOCATION"};
my ($bd,$sf) = # assuming it was " ZIP:"
unpack 'x46 A3 x14 A4', $record{"ZIP"};
This eliminates any dependency on order, and uses the strings which
prefix the fields as keys. The presence or absence of "NEW FIN" should
now have no effect whatsoever. You'll have to change your unpack
templates, though.
[snip]
> $index = $price/$sf; # calculate the Index per sf value
> writedatafile( $status, $addr, $price, $bd, $sf, $ba, $ag, $lot,
> $index );
> }
> ### SUBROUTINE
> sub writedatafile
> {
> my ($status, $addr, $price, $bd, $sf, $ba, $ag, $lot, $index ) = @_;
> open (FILE ,">>$datafile"); #open output file for append
Always, yes, always, check the return value of open.
Also, there's no need to open for append for each and every read, you
should only need to open the file once.
> print FILE "$R,$status,\"$addr\",$price,$sf,$bd,$ba,$lot,$ag,$index\n";
I would do this as:
my ( $file, $counter );
END { $file && (close($file) or die "Couldn't close $datafile: $!\n") }
sub writetofile {
$file or open ($file ,">>", $datafile)
or die "Couldn't open $datafile for append: $!\n";
$_[1] = qq{"$_[1]"};
++$counter;
print $file join(",", $counter, @_[0..2,4,3,5,7,6,8]), "\n";
}
> print to file
> $R++; #increment record counter
> close (FILE); #close output file
Again, opening and closing the file for each record is innefficient.
> }
> ------------
> Question #1:
>
> On some of the data file records, an unwanted Line #3 sometimes
> appears, which then shifts all the other lines down & messes up the
> rest of the parsing (the ZIP line becomes Line #4, etc.) Example:
>
> Input Data File Line #3: NEW FIN:blahblah #THIS LINE IS ONLY INCLUDED
> ON SOME RECORDS
> Input Data File Line #4: ZIP:blahblah #THIS IS THE ONLY DESIRED LINE
> BEFORE PROCEEDING
>
> In trying to loop past the unwanted line, I tried: next unless $line
> =~ /^ ZIP/; Yes...there is a leading space before ZIP... but
> everything is still whacked into die mode. I axed out the die line
> and at least I know that doesn't work either. Will something?
Answered... use the prefixes as field names, and ignore the actual order
of the fields.
> Question #2:
>
> $index = $price/$sf yields a number, but I need to have a non-decimal
> place number rounded up (or down) and to print on the same .csv record
> line. I just can't figure out how to combine the printf function in
> the same line with the print FILE above, or is that just not possible
> or the right way to approach it?
Use printf to put the formatted string in the file, or sprintf to create
a formated string and return it, so you can put it in the file yourself.
> Question #3:
>
> I've read about the foreach & keys array functions, but am lost here
> out how to integrate things to get the parsed records into an
> appropriate array so that I can then sort and print them to a file by
> (1st Field = $status, Alphabetic, in Ascending order) and then (2nd
> Field = $index, in Descending/Reverse Numeric order). Having a blank
> line print to separate the different $status entries is most
> desirable. Is this possible or must I still do this part manually
> after importing the .csv file into Excel?
It's possible, but you have to store the intermediate results in an
array, not send them straight to the file.
So:
my @records;
foreach my $record ( do { local $/;
split /(?=--.*STATUS AVAILABLE)/, <INFILE> } )
{
my @lines = split /\n/, $record;
my ($status) = unpack 'x42 A10', shift @lines;
my %in_record = map /^\s*(.*?):(.*)/, @lines;
my %out_record;
@out_record{addr,price} =
unpack 'A25 x33 A11', $in_record{"LOCATION"};
@out_record{bd,sf} =
unpack 'x46 A3 x14 A4', $in_record{"ZIP"};
...
$out_record{index} = $out_record{price} / $out_record{sv};
push @records, \%out_record;
}
@records = sort {
$a->{status} cmp $b->{status} || #status, ascending alpha
$b->{index} <=> $a->{index} #index, descending numeric.
} @records;
open (FILE ,">>", $datafile) or die "Couldn't open $datafile: $!\n";
my @fields = qw(status addr price sf bd ba lot ag index);
for my $r (0 .. $#records) {
my $record = $records[$r];
$$record{addr} = qq{"$$record{addr}"};
$$record{index} = sprintf "%.2f", $$record{index};
print FILE join(",", $r, @$record{@fields}), "\n";
}
close FILE or die "Couldn't close $datafile: $!\n";
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: 17 Jul 2001 09:08:11 +0200
From: Walter Hafner <hafner-usenet@ze.tu-muenchen.de>
Subject: Re: big versions problem from a newbie
Message-Id: <srjbsmkm3s4.fsf@w3proj1.ze.tu-muenchen.de>
kanem@ic.edu (Matt) writes:
> Okay I have perl version 4 running on a Linux 1.2.8 machine. I want to
> put a messageboard on the server, but it requires version 5. So how do
> I go about upgrading to version 5? I've read that I can download the
> source code for free, but where do I go from there? I understand that
> there may be a lot of steps, but I would appreciate any help that I
> could possibly receive.
You don't want to upgrade Perl. You really, really, really want to
upgrade your Linux system!
BTW: Every Linux compilation ships with Perl 5 for more than 2 years
now.
-Walter
------------------------------
Date: 17 Jul 2001 07:29:14 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Checking for changed or missing links in perl
Message-Id: <9j0pga$3j7$1@bob.news.rcn.net>
Tore Aursand <tore@extend.no> wrote:
> In article <e2c00ae.0107160927.2354c378@posting.google.com>,
> usted@cyberspace.org says...
>> Your question almost seems to imply that you want to
>> know if the webpage has *changed* in some way so that
>> you no longer want to link to it. This may require
>> human intelligence.
> Sure thing. I got an idea, however; What if you create an
> md5sum of the page _without_ the HTML codes? That would make
> more sense, as there is a bigger chance the the HTML code is
> dynamic, than the content. Right?
That will help, but it will still trigger on things like a change only in
the navigation (which tends to be a lot more volatile than the actual
content) or the correction of a typo.
If you had some way to extract a couple "key" phrases from the document
when you first linked to it, then you could simply check to see if they
still exist the next time you fetch it. Presumably they'd be phrases
related to the subject of whatever section of your page is doing the
linking. Ideally they'd be stored in your page itself; if HTML in general
allowed processing instructions, that would be an ideal place to put them,
but more likely you'd need to come up with some kludge involving
pseudo-directives stored in comments.
------------------------------
Date: 17 Jul 2001 07:39:41 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Colored quotes in Html
Message-Id: <9j0q3t$3j7$2@bob.news.rcn.net>
* Tong * <sun_tong@users.sourceforge.net> wrote:
> Can you give me some suggestion on how to produce the colored mail
> quotations in Html pages, just like what the google news is doing?
There's a CPAN module called HTML::Highlight intended for doing just that.
------------------------------
Date: Tue, 17 Jul 2001 09:17:43 +0000 (UTC)
From: jdassen@cistron.nl (J.H.M. Dassen (Ray))
Subject: Re: Compress::Zlib install problem
Message-Id: <slrn9l80lm.i2m.jdassen@odin.cistron-office.nl>
Kelton Joyner <kelton@isle-escape.com> wrote:
> I am trying to install Compress::Zlib in an HPUX 10.20 systen using gcc.
> /usr/bin/gcc -c -I/usr/local/include -D_HPUX_SOURCE
> -L/lib/pa1.1 -DUINT32_MAX_BROKEN -fno-strict-al
> iasing -I/usr/local/include -O -DVERSION=\"1.13\"
> -DXS_VERSION=\"1.13\" -fpic -I/opt/perl5/lib/5
OK, so Position Independent Code is requested.
> ld: DP relative code in file /usr/local/lib/libz.a(gzio.o) - shared
> library must be position
> independent. Use +z or +Z to recompile.
But the resulting code apparently isn't position independent.
Quoting gcc's documentation:
"`-fpic'
Generate position-independent code (PIC) suitable for use in a
shared library, if supported for the target machine.
[...]
The GNU assembler does not fully support PIC. Currently, you must
use some other assembler in order for PIC to work."
Thus, you may want to try a newer version of gcc and/or binutils, or attempt
a build using the native toolset.
It's been a few years since I worked on an HP-UX system, and back then its
native toolset was rather awkward and while there were GNU utils available,
the HP-UX support in the regular GNU distribution was rather
limited/outdated compared to versions available from some HP-UX centric
sites.
Your best bet is to ask for advice in a HP-UX specific newsgroup or mailing
list.
HTH,
Ray
--
NATUURLIJK krijg je er geen signaal doorheen - het is *dark* fibre.
jtv
------------------------------
Date: Tue, 17 Jul 2001 06:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I use curses with Perl?
Message-Id: <xLQ47.222$T3.215939584@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How can I use curses with Perl?
The Curses module from CPAN provides a dynamically loadable object
module interface to a curses library. A small demo can be found at the
directory http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/rep;
this program repeats a command and updates the screen as needed,
rendering rep ps axu similar to top.
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
03.12
--
This space intentionally left blank
------------------------------
Date: Tue, 17 Jul 2001 08:46:30 +0200
From: Philip Newton <pne-news-20010717@newton.digitalspace.net>
Subject: Re: Format problems
Message-Id: <ehm7lto6aqsakngbjf5utbpopg13nbeifd@4ax.com>
On 16 Jul 2001 06:04:51 -0700, orenB@CogniTens.com (oren blum) wrote:
> 2 when i try to use this command "write (TOP1);" - its not working
> instead i write "local $~="TOP1";
> write; - this work.
> why the firt syntax not working ?
Because it's not supposed to. write() takes a filehandle as an argument
(or an expression evaluating to the name of a filehandle) and uses the
format associated with that filehandle. You can't directly specify a
format that write should use; instead, associate the format with the
desired filehandle and then write to that filehandle.
Associating a format with a filehandle is either by naming the format
the same as the filehandle, or by selecting the filehandle if it isn't
already and modifying the $~ variable, as you found out.
perldoc -f write
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Tue, 17 Jul 2001 10:51:57 +0100
From: James Heneghan <james@alphyra.ie>
Subject: help : Graph.pm
Message-Id: <3B540ABD.8CB685D6@alphyra.ie>
Hi All,
I downloaded Graph.pm and tried to run the example.
Here was my output ...
./example.pl
Setting title to Daily Web Site Hits
Setting subtitle to Content pages only
Setting keys_label to Day of the Week
Setting values_label to Hits
Setting value_min to 0
Setting value_max to 35000
Setting value_labels to 10000,20000,30000
Setting background_image to bg.gif
Minimum Data value: 10712
Maximum Data value: 29976
Minimum Y value set to 0
Maximum Y value set to 35000
Image Created: 928 x 367
Colors Allocated
Can't locate object method "newFromGif" via package "GD::Image" at
/usr/lib/perl5/site_perl/5.6.0/i386-linux/Graph.pm line 761.
I've tried to locate this method too but its not there!
Anyone know the solution?
Thanks,
James
------------------------------
Date: 17 Jul 2001 07:43:51 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: HELP WITH PERLDAP!!!!!!!!!
Message-Id: <9j0qbn$3j7$3@bob.news.rcn.net>
In comp.lang.perl.misc David Busby <dbusby3@slb.com> wrote:
> I am trying to run perldap on Solaris 2.8 with perl version 5.00404.
> Here is the simple code I have:
> #!/usr/bin/perl
> push(@INC,"/usr/lib/perl5/site_perl/5.005/sun4-solaris");
This takes place at run time.
> print("@INC\n");
> use Mozilla::LDAP::Conn(\%ld);
> use Mozilla::LDAP::Utils;
Whereas this takes place at compile time.
Change your push to
use lib "/usr/lib/perl5/site_perl/5.005/sun4-solaris";
which takes place at compile time.
------------------------------
Date: Mon, 16 Jul 2001 23:52:13 -0600
From: Bryce <bryce_anderson@yahoo.com>
Subject: Re: How to run Perl on MS-DOS
Message-Id: <3B53D28D.5030703@yahoo.com>
sam wrote:
> I have installed ActivePerl 5.6.1.628 MSI on Windows 98 from
> http://aspn.activestate.com . After I opened MS-DOS and type in cd
> C:\Perl.in. , it says invalid directory. Can anyone kindly help me on this?
>
> Thanks
The ActiveState port installs to C:\Perl by default, unless you've
changed it. If you actually typed in "cd C:\Perl.in." instead of "cd
C:\Perl", that could be your problem. Otherwise, go to the Start
Button, go to "Find" and do a search for perl.exe.
Hope this helps.
Posted from NetWORLD Connections, Inc.
------------------------------
Date: Tue, 17 Jul 2001 06:27:33 GMT
From: "Ruth" <npeles@bigpond.net.au>
Subject: Re: Looking for the right direction
Message-Id: <pVQ47.10123$Xr6.83211@news-server.bigpond.net.au>
> The best place to get help on Perl/Tk matters is in comp.lang.perl.tk.
Oh I did try there, but I havent heard anything yet, and I thought someone
here might be able to help?
> Take a look at the Perl/Tk FAQ:
>
> http://w4.lns.cornell.edu/~pvhp/ptk/ptkTOC.html
Thats great, thank you very much, answers a lot of my questions I felt too
stupid to ask!
> Finally, a trip to your local bookstore may be in order as well. Look
> for "Learning Perl/Tk" by Nancy Walsh (O'Reilly).
Yes, I bought that before I started, but I feel like there is a lot of
things _not_ covered by her book, and while it is a good intro, it is hard
to find answers to more difficult or specific questions. It would be nice to
have a equivalent to Programming Perl, but with Tk - anyone out there want
to write it? I can promise you I would buy it!
Thanks again for your help,
Ruth
------------------------------
Date: Tue, 17 Jul 2001 00:37:03 -0400
From: Chris Micallef <cmicallef@playground.net>
Subject: Obtaining remote users ip
Message-Id: <3B53C0EE.1889AB18@playground.net>
I am a newbie (1 week) using perl to write cgi scripts for a web page.
I have succeeded in obtaining a users ip using code I stole and reduced:
$RemoteHost = (gethostbyaddr(pack('C4',$1,$2,$3,$4),2))[0] ||
$ENV{'REMOTE_ADDR'};
I do not, however, understand how it works. I understand pack( ) but
where does it get the $1,$2,$3,$4 values and why do they contain null if
I try to print them?
The perl documentation gives:
gethostbyaddr ADDR,ADDRTYPE
($name,$aliases,$addrtype,$length,@addrs) = gethost*
Based on my code, I assume pack ( ) is the ADDR and 2 is the ADDRTYPE.
What are the options for ADDRTYPE?
I still don't understand where the data comes from for the pack
statement.
What does the [0] do? It looks like an element number for an array but
if I put in 1, 2, or 3 I still get the ip.
Why will the code not work if I eliminate "|| $ENV{'REMOTE_ADDR'}"
Too many questions!
If some one could just tell me how gethostbyaddr works I would be
happier than a mosquito in a nudist camp.
C
------------------------------
Date: Tue, 17 Jul 2001 16:04:15 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Obtaining remote users ip
Message-Id: <vCQ47.92880$Rr4.319980@ozemail.com.au>
Chris
See below.
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
Chris Micallef <cmicallef@playground.net> wrote in message news:3B53C0EE.1889AB18@playground.net...
> I am a newbie (1 week) using perl to write cgi scripts for a web page.
> I have succeeded in obtaining a users ip using code I stole and reduced:
>
> $RemoteHost = (gethostbyaddr(pack('C4',$1,$2,$3,$4),2))[0] ||
> $ENV{'REMOTE_ADDR'};
This code is meaningless out of context,as well as badly written (eg the hard-coded '2'). Try (tested code):
-----><8-----
#!/usr/bin/perl -T
#
# Name:
# ip.cgi.
use strict;
use warnings;
use CGI;
use Socket;
# -----------------------------------------------------------------------
delete @ENV{'BASH_ENV', 'CDPATH', 'ENV', 'IFS', 'PATH'}; # Zap for safety.
my($q) = CGI -> new();
my($remote_host) = 'undefined';
if ($ENV{'REMOTE_ADDR'} =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)
{
$remote_host = (gethostbyaddr(pack('C4', $1, $2, $3, $4), AF_INET) )[0];
}
print $q -> header(),
$q -> start_html(),
$q -> center($q -> h1('Get remote host') ),
$q -> center($q -> h3('Using AF_INET from Socket') ),
$q -> center("Host name: $remote_host"),
$q -> end_html();
-----><8-----
In future, please post complete, working examples, even though their output is wrong.
------------------------------
Date: 17 Jul 2001 09:23:33 +0200
From: Walter Hafner <hafner-usenet@ze.tu-muenchen.de>
Subject: Re: Obtaining remote users ip
Message-Id: <srj66csm32i.fsf@w3proj1.ze.tu-muenchen.de>
"Ron Savage" <ron@savage.net.au> writes:
> -----><8-----
> #!/usr/bin/perl -T
> #
> # Name:
> # ip.cgi.
>
> use strict;
> use warnings;
>
> use CGI;
> use Socket;
>
> # -----------------------------------------------------------------------
>
> delete @ENV{'BASH_ENV', 'CDPATH', 'ENV', 'IFS', 'PATH'}; # Zap for safety.
>
> my($q) = CGI -> new();
> my($remote_host) = 'undefined';
>
> if ($ENV{'REMOTE_ADDR'} =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)
> {
> $remote_host = (gethostbyaddr(pack('C4', $1, $2, $3, $4), AF_INET) )[0];
> }
>
> print $q -> header(),
> $q -> start_html(),
> $q -> center($q -> h1('Get remote host') ),
> $q -> center($q -> h3('Using AF_INET from Socket') ),
> $q -> center("Host name: $remote_host"),
> $q -> end_html();
> -----><8-----
Hiho!
Remember, that most Proxies rewrite the IP address and send the original
address in an X-Forwarded-For header. I use (for logging purposes in a
Apache mod_perl authentification handler):
...
# insert usual -w, -T, strict and diagnostics advisories
use Apache ();
...
my $ip = $ENV{'HTTP_X_FORWARDED_FOR'};
if ((!$ip) || ($ip !~ /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/)) {
$ip = $ENV{'REMOTE_ADDR'};
}
if ((!$ip) || ($ip !~ /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/)) {
$ip = $r->connection->remote_ip;
}
where $r is an apache request object.
If the request comes over a proxy, X-Forwarded-For is usually set. If
the proxy is set to "information hiding" or it's a direct request, I
take Remote_Addr, and if that's not set, I get the address from the
Apache object (usually the same as in Remote_Addr).
-Walter
------------------------------
Date: Tue, 17 Jul 2001 01:36:58 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Pull ng posts behind firewall
Message-Id: <26858-3B53DD0A-4@storefull-245.iap.bryant.webtv.net>
Is there a way in Perl to download newsgroup posts behind a firewall, if
the firewall is my own ISP? For example, I want to write a perl
newsreader that will get all of the posts from alt.discuss.computer
(which is a webtv only discussion group).
Will the NNTP module do this?
Thanks,
--Dennis
------------------------------
Date: Tue, 17 Jul 2001 09:12:42 +0200
From: Philip Newton <pne-news-20010717@newton.digitalspace.net>
Subject: Re: Pull ng posts behind firewall
Message-Id: <e5p7lt4h45d9gsib6gpm1oqqlfhvbjvk1q@4ax.com>
On Tue, 17 Jul 2001 01:36:58 -0500 (CDT), dennis100@webtv.net (BUCK
NAKED1) wrote:
> Is there a way in Perl to download newsgroup posts behind a firewall, if
> the firewall is my own ISP?
That depends on the nature of the firewall and how it is configured (for
example, does it allow traffic to the NNTP port to pass).
> For example, I want to write a perl newsreader that will get all of the
> posts from alt.discuss.computer (which is a webtv only discussion group).
>
> Will the NNTP module do this?
I think your question is "can I use the Net::NNTP module on a machine
that's connected to the net to access the webtv-only newsgroup
alt.discuss.computer?".
You need to find a news server that carries that newsgroup and that
allows you to read. If you have such a server, and can connect to it
with Net::NNTP, then you can use it.
If, say, only news.webtv.net (or whatever) carries that group, and it
restricts access by IP address to WebTV devices, then Net::NNTP from a
non-WebTV device would not be able to access it. If acess is granted by
username/password, you could use Net::NNTP and authenticate with your
Net::NNTP username/password combination.
More knowledge of your setup is required before we can give a useful
answer.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Tue, 17 Jul 2001 01:35:43 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: sortlen -- filter to sort text by line length
Message-Id: <3B53CEAF.52417836@earthlink.net>
Ren Maddox wrote:
>
> On Fri, 13 Jul 2001, gbacon@HiWAAY.net wrote:
>
> [snipped sorting by length with ST or GRT]
>
> > A scalar already knows its length, so all the time and space used
> > in constructing, accessing, and stripping the augmented list is
> > wasted.
>
> Ack! I thought that perhaps the GRT advantage of the built-in
> comparison would overcome this, but some quick benchmarking has not
> revealed that to be true.
The basic sort (using the custom sort routine, doing a numeric
comparison on lengths) only compares a small, fixed, number of bytes
(depending on the size of a double), whereas the grt sort has to compare
(at least) 4 bytes, plus it continues on to look at the string contents
if the lengths are equal. So if you grt sort 100_000 strings all of
length 50, it will do many many 54-byte comparisons. If you do the
basic/custom sort, it will do many many 8-byte comparisons (assuming
doubles are 8 bytes).
If strings are especially long, and many strings are all the same
length, you may get a significant benefit by adding a "stabilizer":
my $stabilizer = 0;
print map { substr $_, 8 } sort map {
pack 'NNa*', length, $stabilizer++, $_ } <>;
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: 17 Jul 2001 09:29:41 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: warn() does not use a localized STDERR filehandle, how come?
Message-Id: <slrn9l81c5.6fu.vek@pharmnl.ohout.pharmapartners.nl>
On 16 Jul 2001 14:49:14 -0500,
Ren Maddox <ren@tivoli.com> wrote:
>
>FWIW, it also worked fine for me with Perl 5.6.0 on Linux.
>
Wasn't that one of the things that was fixed in version 5.6 of perl?
Villy
------------------------------
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.
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 1315
***************************************