[23025] in Perl-Users-Digest
Perl-Users Digest, Issue: 5245 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 20 18:05:50 2003
Date: Sun, 20 Jul 2003 15:05:11 -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 Sun, 20 Jul 2003 Volume: 10 Number: 5245
Today's topics:
Re: "use" remote modules? <bik.mido@tiscalinet.it>
Re: Basic "IO::Select" problem <jwillmore@cyberia.com>
Re: Basic "IO::Select" problem <jwillmore@cyberia.com>
Re: Code to put today's date into MM-DD-YY format <devdas@users.sourceforge.net>
Re: Code to put today's date into MM-DD-YY format <tony_curtis32@yahoo.com>
Re: compiling Perl code <mrwbp@comcast.net>
Re: generalizing cgi handling <pinyaj@rpi.edu>
Re: generalizing cgi handling <me@home.com>
Re: IP Conversion..Sending to Subroutine.. (David Efflandt)
Re: Matching URls <usenet@expires082003.tinita.de>
Re: Matching URls <pinyaj@rpi.edu>
Re: Matching URls (JR)
Re: Matching URls <bwalton@rochester.rr.com>
Re: Matching URls <bwalton@rochester.rr.com>
Re: Matching URls <sheukels=cuthere=@yahoo.co.uk>
Re: Matching URls (Patrick LeBoutillier)
Re: Matching URls <sheukels=cuthere=@yahoo.co.uk>
Perl variable "leading white spaces" Please help <ducott@hotmail.com>
Re: Perl variable "leading white spaces" Please help <pinyaj@rpi.edu>
Re: Read/Write IO on socket file descriptor (Patrick LeBoutillier)
restricting number of access to cgi <perseus_medusa@hotmail.com>
Re: restricting number of access to cgi <bwalton@rochester.rr.com>
retrieve wishlist from Amazon <Patrick_member@newsguy.com>
Re: Secure module version <noreply@gunnar.cc>
Re: Write a loop <devdas@users.sourceforge.net>
Re: Write a loop <jaspax@u.washington.edu>
Re: Write a loop <jurgenex@hotmail.com>
Re: Write a loop <krahnj@acm.org>
Re: XML attributes and values (Tad McClellan)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 20 Jul 2003 19:53:48 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: "use" remote modules?
Message-Id: <nuklhvsi8i3rag947961c2kdh99uqoimss@4ax.com>
On Fri, 18 Jul 2003 18:36:33 -0400, Benjamin Goldberg
<ben.goldberg@hotpop.com> wrote:
>Perl 5.6.1 and latter allow you to put a coderef into @INC.
>
>When you use or require a file, that coderef will be called with two
>arguments -- the first one being the coderef itself, the second being
^^^^^^^^^^^^^^
What is the possible use of that? I guess there must have been a good
reason why it has been implemented that way, but I cannot see what it
may be...
[snip]
> open(my ($fh), "<:scalar", \$doc) or die horribly;
^^^^^^
Browsing through the docs I finally ('perldoc PerlIOl') understood the
meaning of that layer, but it seems that it wouldn't have been
necessary while opening \$doc anyway, so I ask you if there's any
advantage specifying it explicitly or if it "just" for a matter of
clarity (always an important issue, IMHO).
Also, as I said, it was not exactly straightforward to get to the
pertinent piece of documentation. How is one supposed to learn "this
kind of things", apart being so fortunate as to decide to read by
chance such a precious post as this one?
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: Sun, 20 Jul 2003 16:49:10 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Basic "IO::Select" problem
Message-Id: <20030720124734.7bdf8690.jwillmore@cyberia.com>
> use IO::File;
> use IO::Select;
>
> my $H = IO::File->new("multi-client16.pl |");
> $H->blocking(0);
> $s = IO::Select->new();
> $s->add($H);
>
>
> my @readable = $s->can_read(0);
> if (@readable) {
> # We never get here? Why?
> $H->sysread($ARG, 10);
> print $ARG;
> }
I made a few changes to the code and got something back. Since I
don't have a real understanding of what multi-client16.pl is suppose
to output, I used the Unix 'ls' command for a test. I added comments
to the new code below to point out what I did. I anyone sees an error
in what I did, please let me know. It works, but it may have some
pitfalls that are unknown to me.
#!/usr/bin/perl -w
#I always use strict
use strict;
use IO::File;
use IO::Select;
#used the 'ls' command for testing
my $H = IO::File->new("ls |");
$H->blocking(0);
my $s = IO::Select->new();
$s->add($H);
#set the timeout to 90 seconds - you may want to set it to something
i#else
#when run with 0 as the timeout, nothing returned
#this may be because you're not waiting for the command to
#finish before doing something with the output
my @readable = $s->can_read(90);
if (@readable) {
# We never get here? Why?
#Don't know why the original had $ARG - maybe you wanted
#$ARGV[0] or @ARGV
#In any event, I'm thinking @ARGV holds the command line
#arguments passed to this script, not the output from the
#command being read earlier (in my case, 'ls'.
$H->sysread(@readable, 1000000);
print @readable;
}
HTH
Jim
------------------------------
Date: Sun, 20 Jul 2003 18:26:59 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Basic "IO::Select" problem
Message-Id: <20030720142749.498f30cc.jwillmore@cyberia.com>
> use IO::File;
> use IO::Select;
>
> my $H = IO::File->new("multi-client16.pl |");
> $H->blocking(0);
> $s = IO::Select->new();
> $s->add($H);
>
>
> my @readable = $s->can_read(0);
> if (@readable) {
> # We never get here? Why?
> $H->sysread($ARG, 10);
> print $ARG;
> }
I made a few changes to the code and got something back. Since I
don't have a real understanding of what multi-client16.pl is suppose
to output, I used the Unix 'ls' command for a test. I added comments
to the new code below to point out what I did. I anyone sees an error
in what I did, please let me know. It works, but it may have some
pitfalls that are unknown to me.
#!/usr/bin/perl -w
#I always use strict
use strict;
use IO::File;
use IO::Select;
#used the 'ls' command for testing
my $H = IO::File->new("ls |");
$H->blocking(0);
my $s = IO::Select->new();
$s->add($H);
#set the timeout to 90 seconds - you may want to set it to something
i#else
#when run with 0 as the timeout, nothing returned
#this may be because you're not waiting for the command to
#finish before doing something with the output
my @readable = $s->can_read(90);
if (@readable) {
# We never get here? Why?
#Don't know why the original had $ARG - maybe you wanted
#$ARGV[0] or @ARGV
#In any event, I'm thinking @ARGV holds the command line
#arguments passed to this script, not the output from the
#command being read earlier (in my case, 'ls'.
$H->sysread(@readable, 1000000);
print @readable;
}
HTH
Jim
------------------------------
Date: 20 Jul 2003 15:57:21 GMT
From: Devdas Bhagat <devdas@users.sourceforge.net>
Subject: Re: Code to put today's date into MM-DD-YY format
Message-Id: <slrnbhlets.3m5.devdas@evita.devdas.geek>
On Sun, 20 Jul 2003 13:48:32 GMT, Ron <his_ron@yahoo.com> poured into the
usenet group comp.lang.perl.misc:
> Thanks Matija,
>
> That works great. Just one more little problem (My Fault) I need the year
> in YYYY format?
>
> How would I change this to get MM-DD-YYYY Day?
>
> my($dd,$mm,$yy,$day) = (localtime)[3,4,5,6];
> my $today = join '-', map sprintf("%02d", $_), ($mm+1,$dd,$yy%100);
my $today = join '-', map sprintf("%02d", $_), ($mm+1, $dd, $yy+1900);
I would recommend
my $today = sprintf("%02d-%02d-%d", $mm+1, $dd, $yy+1900);
Much easier to follow and it should be faster.
Devdas Bhagat
------------------------------
Date: Sun, 20 Jul 2003 11:00:37 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Code to put today's date into MM-DD-YY format
Message-Id: <87oezp9oii.fsf@limey.hpcc.uh.edu>
>> On 20 Jul 2003 15:57:21 GMT,
>> Devdas Bhagat <devdas@users.sourceforge.net> said:
> On Sun, 20 Jul 2003 13:48:32 GMT, Ron
> <his_ron@yahoo.com> poured into the usenet group
> comp.lang.perl.misc:
>> Thanks Matija,
>>
>> That works great. Just one more little problem (My
>> Fault) I need the year in YYYY format?
>>
>> How would I change this to get MM-DD-YYYY Day?
>>
>> my($dd,$mm,$yy,$day) = (localtime)[3,4,5,6]; my $today
>> = join '-', map sprintf("%02d", $_),
>> ($mm+1,$dd,$yy%100);
> my $today = join '-', map sprintf("%02d", $_), ($mm+1,
> $dd, $yy+1900);
> I would recommend my $today = sprintf("%02d-%02d-%d",
> $mm+1, $dd, $yy+1900); Much easier to follow and it
> should be faster.
use POSIX qw(strftime);
my $today = strftime('%m-%d-%Y', localtime);
Let the module take the strain.
------------------------------
Date: Sun, 20 Jul 2003 17:04:55 GMT
From: "William Peckham" <mrwbp@comcast.net>
Subject: Re: compiling Perl code
Message-Id: <XYzSa.93309$GL4.26292@rwcrnsc53>
"Joe Smith" <inwap@inwap.com> wrote in message
news:2MSPa.351$603.19125@iad-read.news.verio.net...
> In article <1b0363da.0307110844.7bcabe0d@posting.google.com>,
> -bill <i_ching@yahoo.com> wrote:
> >Bart Lateur <bart.lateur@pandora.be> wrote in message
> >news:<o9bsgvs37gk4995jrevsn456badns7252g@4ax.com>...
> >
> >hey Bart,
> >thanx for the info. Not sure if I get it....in a simple explanation ,
>
> The answer was correct, but not appropriate to what you want.
>
> >can PDB's be created where I can use the symbols files to help me
> >debug a program?
>
> 1) Perl code is interpreted, not compiled.
> 2) Perl has a very powerful built-in debugger.
>
> C:\Work> perl -d program.pl arg1 arg2
>
> -Joe
> --
> See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
Joe,
There are actually a couple of ways that PERL code can be said to be
'compiled' rather than interpreted.
1. The distribution kits generally contain the C translater/compiler (it
converst to C and calls GCC to compile) can sometimes be made to work. It
is very experimental, and I have had problems with it forever.
2. The perl2exe compiler form IndigoStar at
<http://www.indigostar.com/perl2exe.htm> has a good reputation is some
circles. I have not tried it myself.
-bill
While his detail was questionable, Joe makes a good point. Have you
verified your PERL source using interpreted execution prior to attempting to
compile? Were there any errors or warnings either running interpreted or
when you compiled?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.500 / Virus Database: 298 - Release Date: 2003-07-10
------------------------------
Date: Sun, 20 Jul 2003 11:58:57 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: generalizing cgi handling
Message-Id: <Pine.SGI.3.96.1030720114742.3749A-100000@vcmr-64.server.rpi.edu>
On Sun, 20 Jul 2003, Steve in NY wrote:
>On Sat, 19 Jul 2003 19:59:18 -0500, "Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote:
>
>>If you really really want to do that (and hey, this is just a learning
>>excercise so what the heck), you have to do something like the following.
>>
>> # at start of cgi_handling function
>> my $caller_package = caller;
>>
>> # later, at the point where you currently assign $a{$key}
>> {
>> no strict 'refs';
>> *{$caller_package . '::' . $key) = \$value;
>> }
>
>This is what I was thinking of, but it is over my head right now.
>I need to read up on references and passing varibles as
>objects.
This here is an example of a symbolic reference. You'll notice Eric
turned off "strict 'refs'" before doing it? That's because "strict
'refs'" doesn't allow symbolic references, only hard ("real") references.
What he's doing is creating a variable's NAME, and then working with the
variable with that name. Here's a brief example, although I still urge
you NOT to use symrefs until you truly understand them (and then, many
experts will tell you, you'll know why you SHOULDN'T use them):
# notice these are NOT my()d variables
# symrefs only work with package variables
$red = 'FF0000';
$green = '00FF00';
$blue = '0000FF';
for my $color ('red', 'green', 'blue') {
print "$color is represented as $$color\n";
}
You'll notice the double $-sign in $$color. That can also be written as
${ $color }
which might help you see more clearly what it's doing. It's taking
$color's VALUE (which might be "green"), and then using THAT as the name
of a scalar.
This example, however, should scream "use a hash" to you. In fact, all of
Perl's variables are stored in hashes. This might be a bit too internal-y
for you, but the variable $red in the package Foo can be accessed as
$Foo::red, but also as ${ $Foo::{red} }. %Foo:: is a (special) hash that
holds the symbols (variable names) in the Foo:: package. $Foo::{red} is
just a hash access; it returns a special symbol that can be dereferenced
into a scalar, an array, a hash, etc. -- it's called a glob. $Foo::{red}
is pretty much the same as *Foo::red, so ${ *Foo::red }, ${ $Foo::{red} },
and $Foo::red are all the same value.
Granted, Eric's example is a bit more complex -- he's using a glob and a
reference, and you probably don't need to know the deep inner workings
right now. If you're interested in knowing, though, I wrote an article
for perlmonth.com a while back that might help you:
http://www.pobox.com/~japhy/articles/pm/2000-03.html
There's also the standard perl docs; these four have information about
typeglobs:
perldata
perlref
perlsub
perlmod
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Sun, 20 Jul 2003 17:41:25 -0700
From: Steve in NY <me@home.com>
Subject: Re: generalizing cgi handling
Message-Id: <hfdmhv87vhq9f9ajuscpcl8gbic6g123ht@4ax.com>
Hi Jeff,
Thank you for the reply and the pointers. To tell you the truth, the material about
symbolic references is going to take awhile to sink in. I am glad to be aware of
it....but it confuses the heck out of me at this point ;-)
Hey, but I did a web search on articles you wrote and found this:
http://www.devarticles.com/art/1/293
which seems to me to be exactly what I was trying to do.
------------------------------
Date: Sun, 20 Jul 2003 15:51:12 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: IP Conversion..Sending to Subroutine..
Message-Id: <slrnbhlejf.t85.efflandt@typhoon.xnet.com>
On Sun, 20 Jul 2003 09:45:24 GMT, Joe <joecool118@nospam.hotmail.com> wrote:
>> On Sat, 19 Jul 2003, Joe Henderson wrote:
>>
>> >Or does ne1 have a better way...
>>
>> I don't really know what you're doing, or why you're doing it.
>
>
> Normally this is a whole array of sorting ip's in a file..
> .While reading a file of ip's i want to sort then by lowest
> to highest then print.. However.. when i do not split them
> the values are not correctly push to the sub's.. So.. I tried
> to use "big::int" but that did not work.. Any Ideas?
This is an example of a script that can sort a file list of full or
partial IPs, or insert (optional) single IP from the commandline into the
sorted list.
Simply sorting a unique list of packed IPs and then unpacking them did
not work for partial IPs because either 192.168. or 192.168.0. became
192.168.0.0 which would not work for intended purpose. So I put the IPs
into a hash with a packed value, and sort on the value string (cmp). Not
sure if this is optimized, but it works.
The partial IPs (ending with dot) are for class A, B, or C subnets (dot is
appended if needed). I did not get into more specific subnet masking yet
(more complicated). This demo does not check if IPs are valid and would
need added code for multi-user access of same IP list (flock, etc.).
#!/usr/bin/perl -w
# banip 5/30/2003 by David Efflandt efflandt@xnet.com
# Inserts (optional) single full or partial IP from commandline
# into file list. List is sorted and duplicates removed.
#
# set $file to point to your IP list file
my $file = "$ENV{HOME}/banlist.txt";
my $newip = shift or 0;
$newip =~ s/^[^\d\.]+$// if $newip;
my ($iplist,%hash);
if ($_ = $newip) {
$newip .= '.' unless (/\.$/ || /\d+\.\d+\.\d+\.\d+/);
$hash{$newip} = pack('C4',split(/\./,$newip));
print "using: $file\n";
} else {
warn "usage: $0 ip_addr\n$file is just being sorted\n";
}
if (open (IN,"$file")) {
while (<IN>) {
chomp;
$_ .= '.' unless (/\.$/ || /\d+\.\d+\.\d+\.\d+/);
$hash{$_} = pack('C4',split(/\./,$_));
}
close IN;
} elsif (!$newip) {
die "nothing to do!\n";
} else {
die "can't read $file: $!\n";
}
@iplist = sort { $hash{$a} cmp $hash{$b} } keys %hash;
open (OUT,"> $file") || die "Can't write $file: $!";
foreach (@iplist) {
print OUT "$_\n";
}
close OUT;
--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: 20 Jul 2003 15:50:22 GMT
From: Tina Mueller <usenet@expires082003.tinita.de>
Subject: Re: Matching URls
Message-Id: <bfednu$dqpfa$2@ID-24002.news.uni-berlin.de>
Seansan wrote:
> Does anyone know of a link to or an example of a decent regexp that wil
> recognize internet URLs? (It needs to match urls starting with http:// and
> www.)
perldoc URI::Find
and
perldoc URI::Find::Schemeless
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
- my mail address expires end of august 2003 -
------------------------------
Date: Sun, 20 Jul 2003 12:11:25 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Matching URls
Message-Id: <Pine.SGI.3.96.1030720121107.3948A-100000@vcmr-64.server.rpi.edu>
On 20 Jul 2003, Tina Mueller wrote:
>Seansan wrote:
>
>> Does anyone know of a link to or an example of a decent regexp that wil
>> recognize internet URLs? (It needs to match urls starting with http:// and
>> www.)
>
>perldoc URI::Find
>and
>perldoc URI::Find::Schemeless
Damn those URIs and their zany schemes.
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: 20 Jul 2003 10:40:16 -0700
From: jrolandumuc@yahoo.com (JR)
Subject: Re: Matching URls
Message-Id: <b386d54b.0307200940.b8ef6b9@posting.google.com>
"Seansan" <sheukels=cuthere=@yahoo.co.uk> wrote in message news:<3f1aa893$0$61643$e4fe514c@dreader3.news.xs4all.nl>...
> Hi,
>
> Does anyone know of a link to or an example of a decent regexp that wil
> recognize internet URLs? (It needs to match urls starting with http:// and
> www.)
>
> I am trying to replace a string like
> "My Homepage is @ http://www.homepage.nl"
> with
> "My Homepage is @ <A HREF =
> 'http://www.homepage.nl'>http://www.homepage.nl</A>"
>
> Thx, Seansan
## I think this is what you want. Good luck.
## JR
#!/perl
use strict;
use diagnostics;
use warnings;
while(<DATA>) {
s/(http:\/\/www.*)\b/<a href='$1'>$1<\/a>/g;
print $_, "\n";
}
__DATA__
My homepage is @ http://www.homepage.nl
My favorite site is @ http://www.espn.com
My second most favorite site is @ http://www.whatever.org
=pod
## OUTPUT
My homepage is @ <a href='http://www.homepage.nl'>http://www.homepage.nl</a>
My favorite site is @ <a
href='http://www.espn.com'>http://www.espn.com</a>
My second most favorite site is @ <a
href='http://www.whatever.org'>http://www.whatever.org</a>
=cut
------------------------------
Date: Sun, 20 Jul 2003 18:11:38 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Matching URls
Message-Id: <3F1ADB2D.9010306@rochester.rr.com>
Seansan wrote:
...
> Does anyone know of a link to or an example of a decent regexp that wil
> recognize internet URLs? (It needs to match urls starting with http:// and
> www.)
...
> Thx, Seansan
You could:
use Regexp::Common::URI;
--
Bob Walton
------------------------------
Date: Sun, 20 Jul 2003 18:13:16 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Matching URls
Message-Id: <3F1ADB8F.1090905@rochester.rr.com>
Bob Walton wrote:
...
> You could:
>
> use Regexp::Common::URI;
>
Make that:
use Regexp::Common qw(URI);
--
Bob Walton
------------------------------
Date: Sun, 20 Jul 2003 20:55:48 +0200
From: "Seansan" <sheukels=cuthere=@yahoo.co.uk>
Subject: Re: Matching URls
Message-Id: <3f1ae5b0$0$61642$e4fe514c@dreader3.news.xs4all.nl>
Thx JR (and others),
I tried it, and it works. But I only have 1 problem:
*) It matches all the text after the url as well."My String: "Homepage is @
http://www.homepage.nl, yep thats it" becomes
"Homepage is @ <A HREF=http://www.homepage.nl yep thats
it>http://www.homepage.nl yep thats it</A>"
Any ideas on how to solve this? I played witht he regexp a while, but I cant
figure it out.
ps. How would I alter the regexp to match www. also? Like this?
s/([http:\/\/www|www].*)\b/<a href='$1'>$1<\/a>/g;
Seansan
"JR" <jrolandumuc@yahoo.com> wrote in message
news:b386d54b.0307200940.b8ef6b9@posting.google.com...
> "Seansan" <sheukels=cuthere=@yahoo.co.uk> wrote in message
news:<3f1aa893$0$61643$e4fe514c@dreader3.news.xs4all.nl>...
> > Hi,
> >
> > Does anyone know of a link to or an example of a decent regexp that wil
> > recognize internet URLs? (It needs to match urls starting with http://
and
> > www.)
> >
> > I am trying to replace a string like
> > "My Homepage is @ http://www.homepage.nl"
> > with
> > "My Homepage is @ <A HREF =
> > 'http://www.homepage.nl'>http://www.homepage.nl</A>"
> >
> > Thx, Seansan
>
> ## I think this is what you want. Good luck.
> ## JR
>
> #!/perl
> use strict;
> use diagnostics;
> use warnings;
>
> while(<DATA>) {
> s/(http:\/\/www.*)\b/<a href='$1'>$1<\/a>/g;
> print $_, "\n";
> }
>
> __DATA__
> My homepage is @ http://www.homepage.nl
> My favorite site is @ http://www.espn.com
> My second most favorite site is @ http://www.whatever.org
>
> =pod
> ## OUTPUT
>
> My homepage is @ <a
href='http://www.homepage.nl'>http://www.homepage.nl</a>
> My favorite site is @ <a
> href='http://www.espn.com'>http://www.espn.com</a>
> My second most favorite site is @ <a
> href='http://www.whatever.org'>http://www.whatever.org</a>
>
> =cut
------------------------------
Date: 20 Jul 2003 12:29:02 -0700
From: patrick_leboutillier@hotmail.com (Patrick LeBoutillier)
Subject: Re: Matching URls
Message-Id: <154121e6.0307201129.e841247@posting.google.com>
"Seansan" <sheukels=cuthere=@yahoo.co.uk> wrote in message news:<3f1aa893$0$61643$e4fe514c@dreader3.news.xs4all.nl>...
> Hi,
>
> Does anyone know of a link to or an example of a decent regexp that wil
> recognize internet URLs? (It needs to match urls starting with http:// and
> www.)
Check out the Regexp::Common module. I think it has what you are looking for.
>
> I am trying to replace a string like
> "My Homepage is @ http://www.homepage.nl"
> with
> "My Homepage is @ <A HREF =
> 'http://www.homepage.nl'>http://www.homepage.nl</A>"
>
> Thx, Seansan
------------------------------
Date: Sun, 20 Jul 2003 21:34:37 +0200
From: "Seansan" <sheukels=cuthere=@yahoo.co.uk>
Subject: Re: Matching URls
Message-Id: <3f1aeec6$0$136$e4fe514c@dreader9.news.xs4all.nl>
<update>
I found:
sub CHECK4URLS ($) { my $t=shift; $$t =~ s|([a-z]*://[\w:\./\~\?-]*)|<A
HREF="$1" target=_blank>$1</A>|gi; }
Now I only need to match URLs starting with www. Do you think I can
incorporate this in the same regexp?
Sean
"JR" <jrolandumuc@yahoo.com> wrote in message
news:b386d54b.0307200940.b8ef6b9@posting.google.com...
> "Seansan" <sheukels=cuthere=@yahoo.co.uk> wrote in message
news:<3f1aa893$0$61643$e4fe514c@dreader3.news.xs4all.nl>...
> > Hi,
> >
> > Does anyone know of a link to or an example of a decent regexp that wil
> > recognize internet URLs? (It needs to match urls starting with http://
and
> > www.)
> >
> > I am trying to replace a string like
> > "My Homepage is @ http://www.homepage.nl"
> > with
> > "My Homepage is @ <A HREF =
> > 'http://www.homepage.nl'>http://www.homepage.nl</A>"
> >
> > Thx, Seansan
>
> ## I think this is what you want. Good luck.
> ## JR
>
> #!/perl
> use strict;
> use diagnostics;
> use warnings;
>
> while(<DATA>) {
> s/(http:\/\/www.*)\b/<a href='$1'>$1<\/a>/g;
> print $_, "\n";
> }
>
> __DATA__
> My homepage is @ http://www.homepage.nl
> My favorite site is @ http://www.espn.com
> My second most favorite site is @ http://www.whatever.org
>
> =pod
> ## OUTPUT
>
> My homepage is @ <a
href='http://www.homepage.nl'>http://www.homepage.nl</a>
> My favorite site is @ <a
> href='http://www.espn.com'>http://www.espn.com</a>
> My second most favorite site is @ <a
> href='http://www.whatever.org'>http://www.whatever.org</a>
>
> =cut
------------------------------
Date: Sun, 20 Jul 2003 17:03:41 GMT
From: "\"Dandy\" Randy" <ducott@hotmail.com>
Subject: Perl variable "leading white spaces" Please help
Message-Id: <NXzSa.468952$ro6.11261570@news2.calgary.shaw.ca>
Hello everyone. I have been following misc posts, as well as reading several
FAQ's on this issue, unfortunatley I cannot locate a solution. I am hoping
that someone will be able to provide me with the simple answer. My problem
has to do with the leading white spaces after the first line when calling
data using the @ variable. Here is my code:
open (PREVIEW, "<preview.txt") or &error("Unable to open the data file for
reading");
flock PREVIEW, 2;
@previewcontent=<PREVIEW>;
close(PREVIEW);
Later down the script there is this code:
print "Content-type: text/html \n\n";
print <<PRINTHTML;
<html><head><title>My Script></title></head>
<body>
<textarea rows="5" name="headerdata" cols="50">@previewcontent</textarea>
</body>
</html>
PRINTHTML
exit;
On most FAQ's and other support pages, this issue is usually caused by
adding "" 's to the variable when assigning it's value ... in my case, i'm
just opening a text file, and assigning all data to the @previewcontent
variable ... no "" 's present. When I run the script, the open file command
works correctly and shows the data in the textarea box, but on every line
except the first, all lines lead off with a white space like below:
This is the first line data
This is the second line data
This is the third line data
This is the forth line data ... and so on.
This is a big problem because below the textarea box there is a button to
save the data back to the text file ... and it saves these whitespaces with
it. Everytime the script loads, an additional white space is added without
end. Please help me! I wouldnt have posted this topic unless I has searched
everywhere I could first. Thank you to all who read and/or respond with a
solution! Hoping to deliver a solution to my boss soon.
TIA Randy
------------------------------
Date: Sun, 20 Jul 2003 13:13:20 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: "\"Dandy\" Randy" <ducott@hotmail.com>
Subject: Re: Perl variable "leading white spaces" Please help
Message-Id: <Pine.SGI.3.96.1030720131001.5139A-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Sun, 20 Jul 2003, "Dandy" Randy wrote:
>Hello everyone. I have been following misc posts, as well as reading several
>FAQ's on this issue, unfortunatley I cannot locate a solution. I am hoping
>that someone will be able to provide me with the simple answer. My problem
>has to do with the leading white spaces after the first line when calling
>data using the @ variable. Here is my code:
I suggest you look in the FAQ:
perldoc -q spaces
yields the following:
=======================================================================
=head1 Found in /usr/lib/perl5/5.00503/pod/perlfaq5.pod
=head2 Why do I get weird spaces when I print an array of lines?
Saying
print "@lines\n";
joins together the elements of C<@lines> with a space between them.
If C<@lines> were C<("little", "fluffy", "clouds")> then the above
statement would print:
little fluffy clouds
but if each element of C<@lines> was a line of text, ending a newline
character C<("little\n", "fluffy\n", "clouds\n")> then it would print:
little
fluffy
clouds
If your array contains lines, just print them:
print @lines;
=======================================================================
There are a couple ways you can fix this problem:
1. join the elements of the array together into a scalar beforehand, and
print the scalar
$text = join "", @array;
2. set the $" variable to "" (locally); this means that when you print an
array in double quotes, it will insert "" (nothing) in between the
elements, instead of the default which is " " (a space)
{
local $" = "";
print "... @lines ...";
}
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: 20 Jul 2003 11:33:52 -0700
From: patrick_leboutillier@hotmail.com (Patrick LeBoutillier)
Subject: Re: Read/Write IO on socket file descriptor
Message-Id: <154121e6.0307201033.d84d303@posting.google.com>
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message news:<Xns93BE6A3368CD7asu1cornelledu@132.236.56.8>...
> patrick_leboutillier@hotmail.com (Patrick LeBoutillier) wrote in
> news:154121e6.0307200548.415e0d21@posting.google.com:
>
> > Hi all,
> >
> > I'm trying to perform read and write I/O on a socket file descriptor
> > received for another process via a Unix Domain Socket. In trying to
> > understand all this I came up with a small test script that is not
> > working for me:
>
> I am no expert so please take what I say with a grain of salt.
>
> > use strict ;
> > use IO::Socket::INET ;
> >
> > my $socket = new IO::Socket::INET(
> > PeerAddr => 'www.perl.com',
> > PeerPort => 80,
> > Proto => 'tcp',
> > ) ;
> >
> > my $rfd = fileno($socket) ;
> > my $rfh = new IO::Handle->fdopen($rfd, "r") ;
> > my $wfd = fileno($socket) ;
> > my $wfh = new IO::Handle->fdopen($wfd, "w") ;
>
> $wfh->autoflush(1);
Doh! I think that was my problem.... I can't beleive
I missed that! Thanks!
>
> > print "$rfd $rfh $wfd $wfh\n" ;
> > print $wfh "GET / HTTP/1.0\n\n" ;
> > print "Sent GET...\n" ;
> > my $line = <$rfh> ;
> > print $line ;
>
>
> Also, I am not sure why you are creating $rfh and $wfh. $socket can be read
> from and written to using regular Perl syntax:
>
Yes, I know. But this script is only a simplification of my real
appplication
in which the socket file descriptor is received by a UNIX Domain.
Therefore
in my real app the $socket object is in another process, only the file
descriptor is passed.
> #! C:/Perl/bin/perl.exe
>
> use strict;
> use warnings;
>
> use IO::Socket::INET;
>
> my $socket = new IO::Socket::INET(
> PeerAddr => 'www.perl.com',
> PeerPort => 80,
> Proto => 'tcp');
>
> die "Cannot open connection: $!\n" unless $socket;
>
> print $socket "GET / HTTP/1.0\n\n";
> print "Sent GET...\n";
> my $line = <$socket>;
> close $socket;
>
> print $line, "\n";
>
> __END__
>
> Sinan.
------------------------------
Date: Mon, 21 Jul 2003 01:57:15 +0800
From: "j" <perseus_medusa@hotmail.com>
Subject: restricting number of access to cgi
Message-Id: <3f1ad699$1@newsgate.hknet.com>
Hi all ,
I have a cgi but I'd like to limit the number concurrent user for this
cgi. I am now using `ps -ef | grep -v | grep mycgi | wc -l` and get the
number and limit it to a number. But I found that this take quite some
seconds. Is there faster way and safer ways to limit that if database is not
allowed ?
I am thinking of using variable written in a file to record the process
with some locking mechanism. If the cgi is triggered, the variable inside
the file is added by one and reduced when the cgi exit. But I am worrying if
the cgi failed in the middle for whatever reason in the middle, the number
will be not correctly reflecting the number of process.
Can some one suggest a way to provide a more appropriate way or solve
the above problem ?
Thanks.
Perseus
------------------------------
Date: Sun, 20 Jul 2003 19:09:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: restricting number of access to cgi
Message-Id: <3F1AE8D7.4020309@rochester.rr.com>
j wrote:
...
> I have a cgi but I'd like to limit the number concurrent user for this
> cgi. I am now using `ps -ef | grep -v | grep mycgi | wc -l` and get the
> number and limit it to a number. But I found that this take quite some
> seconds. Is there faster way and safer ways to limit that if database is not
> allowed ?
>
> I am thinking of using variable written in a file to record the process
> with some locking mechanism. If the cgi is triggered, the variable inside
> the file is added by one and reduced when the cgi exit. But I am worrying if
> the cgi failed in the middle for whatever reason in the middle, the number
> will be not correctly reflecting the number of process.
>
> Can some one suggest a way to provide a more appropriate way or solve
> the above problem ?
...
There should be a configuration parameter in your web server which will
let you limit the number of simultaneous connections. Your CGI scripts
shouldn't have to deal with this problem. See the docs for your web
server, or if you have trouble, ask in a newsgroup where they discuss
configuration of your particular web server.
> Perseus
--
Bob Walton
------------------------------
Date: 20 Jul 2003 13:44:39 -0700
From: Patrick Flaherty <Patrick_member@newsguy.com>
Subject: retrieve wishlist from Amazon
Message-Id: <bfeuvn01q1s@drn.newsguy.com>
Hi,
Would like to use Perl to retrive my wishlist periodically from Amazon.
Checked CPAN and there's actually a module to do this: WWW::Amazon::Wishlist
Written by someone in the UK so I had to modify it slightly. Did so and tried
but then realized that it wasn't logging into my account (maybe this didn't
exist in 2001 when the script was first written).
So either I'm overlooking something in the code (I don't think so) or some https
stuff needs to be added.
Explaining further, here's the text of what I mailed the author. No repsonse so
I'm posting it here which is probably what I should have done in the first
place:
> Hello Simon,
>
> How are things? My name's pat flaherty - I'm a programmer
> in CA. Relatively little experience with either perl or Web
> programming.
>
> I'd like to transfer my Amazon wishlist (which has grown
> quite large) to my Palm. Installed your module
> WWW::Amazon::Wishlist.
>
> Modified it to look as follows for the US and for my
> Amazon account (id):
>
> use WWW::Amazon::Wishlist qw(get_list);
>
> my @wishlist;
> my $my_amazon_com_id = "002-1656974-7132841";
>
> @wishlist = get_list ($my_amazon_com_id);# gets it from amazon.com
>
> # the elements of @wishlist are hashrefs that contain ...
> foreach my $book (@wishlist)
> {
> print $book->{title}, # the, err, title
> $book->{author}, # and the author(s)
> $book->{asin}, # the asin number, its unique id on Amazon
> $book->{price},# how much it will set you back
> $book->{type}; # Hardcover/Paperback/CD/DVD etc
>
> }
>
> This runs and tries to do what it's supposed to do but the
> http connection reports an error.
>
> Investigated some. I think the problem is that I need to
> login to my Amazon account (which is not built into your
> code). Was it the case when you wrote this (2001) that,
> amazon.co.uk, did not require a user login to see the
> wishlist?
>
> Downloaded WWW::Authenticate. But at least at first sight
> this seems to require rather more baggage than I want to
> deal with at the moment.
>
> Hope you might be of some help.
>
> pat
------------------------------
Date: Sun, 20 Jul 2003 20:47:04 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Secure module version
Message-Id: <bfeo9m$d3ufk$1@ID-184292.news.uni-berlin.de>
Benjamin Goldberg wrote:
> Gunnar Hjalmarsson wrote:
>> I want to ensure that at least a certain version of a core module
>> is used in a portable CGI script. Accordingly, a copy of that
>> version is included in the distribution of my program, but if a
>> later version is installed on the server, I would like that
>> version to be used instead.
>>
>> This is my first attempt to a resolution:
>>
>> my %tempinc = %INC;
>> require Module;
>> unless (eval { Module->VERSION(2.5) }) {
>> %INC = %tempinc;
>> unshift @INC, 'mylib';
>> require Module;
>> }
>
> The problem with this is that if/when we reach the second
> require(), the older Module is still loaded into perl... there are
> a number of potential problems with this, the least of which would
> be lots of 'subroutine redefined' warnings.
Hmm.. I don't get any such warnings. What other potential problems do
you have in mind?
It's CGI::Carp I'm playing with. The other options I can see are
either to simply enforce 'my' version, or to say in the installation
instructions that 'my' version is not installed in the program
specific modules library if there already is a sufficient version
available on the server.
>> It should work as long as the script is run as a plain CGI
>> script, but scarcely when the program is run under mod_perl.
I have made some further tests, and it seems to work under mod_perl as
well. Not sure what problems I thought of...
>> Anybody who knows about a better way to accomplish the load of at
>> least version X of a module, and that works also under mod_perl?
>
> Does only.pm work under mod_perl?
I had no idea that such a module existed. Thanks for the tip! Will
check it out.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 20 Jul 2003 16:02:15 GMT
From: Devdas Bhagat <devdas@users.sourceforge.net>
Subject: Re: Write a loop
Message-Id: <slrnbhlf72.3m5.devdas@evita.devdas.geek>
On Sun, 20 Jul 2003 14:28:18 GMT, Ron <his_ron@yahoo.com> poured into the
usenet group comp.lang.perl.misc:
> Thanks Jürgen,
>
> Tried this code but I get a server 500 error. Can I use zero for my
> @size_file = 0 ?
@size_file = ();
Devdas Bhagat
------------------------------
Date: Sun, 20 Jul 2003 09:18:51 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: Write a loop
Message-Id: <Pine.A41.4.55.0307200909420.84180@dante16.u.washington.edu>
Ron sikyal:
> Thanks J=FCrgen,
>
> Tried this code but I get a server 500 error. Can I use zero for my
> @size_file =3D 0 ?
Um, the perl statemenet @size_file =3D 0 makes very little sense. Do you
understand what an array is, and how you should assign to it?
> my @size_file =3D <<<Filled with whatever you want>>>;
> > for (1..9) {
> > if ($size_file[$_] >1) {$Num_Files =3D $_;}
This code is missing a trailing '}'. Try:
my @size_file =3D ( <<<< list of file sizes >>>> );
my $num_files =3D 0;
for (1 .. 9) {
if ($size_file[$_] > 1) {
$num_files++;
}
}
Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
------------------------------
Date: Sun, 20 Jul 2003 17:23:01 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Write a loop
Message-Id: <VdASa.39373$EZ2.15858@nwrddc01.gnilink.net>
[Please do not top-post; rearranged into chronological order]
[Please reduce the quoted text to a reasonable amount]
Ron wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:daxSa.47091$kI5.34330@nwrddc02.gnilink.net...
>> Ron wrote:
>>> Would you show me how I can write this as a loop?
>>>
>>> #Get the number of files uploaded
>>> my $Num_Files = 0;
>>> if ($size_file > 1) {
>>> $Num_Files = 1;
>>> }
>>> if ($size_file2 > 1) {
>>> $Num_Files = 2;
>>> }
>>> if ($size_file3 > 1) {
>>> $Num_Files = 3;
[...]
>> Use a more suitable datastructe.
>> If you enumerate scalars like this then you should really use an
>> array instead (the other option would have been a hash).
>>
>> Untested, just to give you an idea:
>>
>> my @size_file = <<<Filled with whatever you want>>>;
>> for (1..9) {
>> if ($size_file[$_] >1) {$Num_Files = $_;}
> Tried this code but I get a server 500 error.
That is not a perl error message. Please see 'perldoc -q 500' about what to
do.
> Can I use zero for my
> @size_file = 0 ?
Well, it as poor style to assign a scalar to an array.
This is better written as
@size_file = (0);
because then it is clear that you are assigning a one-element list to the
array.
But why do you want to assign only one value to the array when in your
original code you had 9 values?
jue
------------------------------
Date: Sun, 20 Jul 2003 19:18:06 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Write a loop
Message-Id: <3F1AEB2E.3BF040A@acm.org>
Ron wrote:
>
> Would you show me how I can write this as a loop?
>
> #Get the number of files uploaded
> my $Num_Files = 0;
> if ($size_file > 1) {
> $Num_Files = 1;
> }
> if ($size_file2 > 1) {
> $Num_Files = 2;
> }
> if ($size_file3 > 1) {
> $Num_Files = 3;
> }
> if ($size_file4 > 1) {
> $Num_Files = 4;
> }
> if ($size_file5 > 1) {
> $Num_Files = 5;
> }
> if ($size_file6 > 1) {
> $Num_Files = 6;
> }
> if ($size_file7 > 1) {
> $Num_Files = 7;
> }
> if ($size_file8 > 1) {
> $Num_Files = 8;
> }
> if ($size_file9 > 1) {
> $Num_Files = 9;
> }
Sure, no problem.
my @files = ( $size_file9, $size_file8, $size_file7,
$size_file6, $size_file5, $size_file4,
$size_file3, $size_file2, $size_file );
my $Num_Files = @files;
for ( @files ) {
last if $_ > 1;
$Num_Files--;
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 20 Jul 2003 15:51:33 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: XML attributes and values
Message-Id: <slrnbhm06l.ala.tadmc@magna.augustmail.com>
Saya <vahu@novonordisk.com> wrote:
><data>
><tuple name="Abb">ARG</tuple>
><tuple name="Reg">EU</tuple>
></data>
>
> assuming a XML document as above with alot of data tags containing
> tuple tags.
What you describe is not possible in XML.
Tags cannot contain tags.
Elements can contain elements though, so that must be what you meant...?
See the XML FAQ:
http://www.ucc.ie:8080/cocoon/xmlfaq#makeup
then use the proper terminology.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5245
***************************************