[19046] in Perl-Users-Digest
Perl-Users Digest, Issue: 1241 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 4 06:05:43 2001
Date: Wed, 4 Jul 2001 03:05:12 -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: <994241111-v10-i1241@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 4 Jul 2001 Volume: 10 Number: 1241
Today's topics:
auto installer <somewhere@in.paradise.net>
Re: auto installer <rlogsdon@io.com>
chicken and egg regexp problem <m.grimshaw@salford.ac.uk>
Re: chicken and egg regexp problem <pne-news-20010704@newton.digitalspace.net>
Re: chicken and egg regexp problem <bart.lateur@skynet.be>
Re: Chmod Problem (BUCK NAKED1)
Re: Chmod Problem <william-news-102374@scissor.com>
copy array of pointers, like malloc. (Alexvalara)
Re: copy array of pointers, like malloc. (Eric Bohlman)
Re: copy array of pointers, like malloc. (Logan Shaw)
does -B <FILE> work with upload FILE-Handles <patelnavin@icenet.net>
Re: does -B <FILE> work with upload FILE-Handles (Logan Shaw)
Re: FAQ 9.15: How do I decode a CGI form? newbie ?s <"goodrow"@opencity. com>
How to find pwd in Perl <Graham.T.Wood@oracle.com>
Re: Is REG_DATE a special type of mysql column? (Rafael Garcia-Suarez)
Newbie DBI question (^CooL^)
Parallel Execution <magilfix@us.ibm.com>
Re: Perl 6: -> vs . <pne-news-20010704@newton.digitalspace.net>
Perl server (Jens-Ole Frimann)
Re: readdir(..) function <magilfix@us.ibm.com>
regexp across lines <dommit@videotron.ca>
Re: regexp across lines <pne-news-20010704@newton.digitalspace.net>
Re: Retrieving Domain from URL line (Tony L. Svanstrom)
Re: Retrieving Domain from URL line <william-news-102374@scissor.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 4 Jul 2001 16:46:35 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: auto installer
Message-Id: <n_y07.19$e76.224320@news.interact.net.au>
I'm looking for ideas/suggestions on writing a auto installer Perl CGI
script.
My idea is to have an install script which a user puts on their server,
which when run, presents a form with various directory settings, defaults
etc. and then retrieves the required files from my website.
Obviously using the LWP modules would make life easier, but I know a lot of
sites don't have it installed, so I either need to wrap a portion of the
module into the script or use a very basic socket connection.
I assume this sort of function has been done many times before, so I'd just
like some feedback on the pitfalls or otherwise of doing this.
------------------------------
Date: Wed, 4 Jul 2001 03:15:34 -0500
From: Reuben Logsdon <rlogsdon@io.com>
Subject: Re: auto installer
Message-Id: <Pine.LNX.4.33.0107040242210.8117-100000@fnord.io.com>
Hi Tintin,
Many web hosting companies forbid sockets privileges for CGI scripts
(almost all free web hosting companies are like this) and so it might be
best to give your customers an install.pl and a data.tar file, with no
network dependencies, rather than risk putting sockets code into the
install.pl.
Also, for this to work, your customers will have to install at least one
script successfully (detect/set path to perl, detect/set extension,
upload in ascii, set permissions) and will then have to create an
extrator folder and set writable permissions on that. Many customers will
fail along the way. Also, many web sites run CGI Wrap by default which
will cause any script to fail if it's in a writable folder or if it's not
owned by the site owner, so you have to be extra careful about your
extraction process and instructions to the customer.
Most CGI vendors I have seen use a server-side FTP bot to perform installs
to other servers. Those bots can work around most user errors. There is
one at nickname.net that I helped write. It is limited in that some
customers don't trust it with username/pass and it can't see intranet
sites, but otherwise it is very helpful for inexperienced customers.
Regards,
Reuben
On Wed, 4 Jul 2001, Tintin wrote:
> I'm looking for ideas/suggestions on writing a auto installer Perl CGI
> script.
>
> My idea is to have an install script which a user puts on their server,
> which when run, presents a form with various directory settings, defaults
> etc. and then retrieves the required files from my website.
>
> Obviously using the LWP modules would make life easier, but I know a lot of
> sites don't have it installed, so I either need to wrap a portion of the
> module into the script or use a very basic socket connection.
>
> I assume this sort of function has been done many times before, so I'd just
> like some feedback on the pitfalls or otherwise of doing this.
>
>
>
--
Regards,
Reuben Logsdon
http://www.io.com/~rlogsdon/
------------------------------
Date: Wed, 04 Jul 2001 09:31:45 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: chicken and egg regexp problem
Message-Id: <3B42D471.E9FB5CC3@salford.ac.uk>
Hi all,
For a bulletin board I'm coding, I don't allow users to make use of <..>
HTML tags but require, for URLs, that they use something like:
[url]http://www.perl.com[/url]
which is then regexp'd into:
<A HREF="http://www.perl.com">www.perl.com</A>
# code for plain URLs
$message =~ s/(\[url\])(.*?)(\[\/url\])/<A HREF="$2">$2<\/A>/gi;
When a user edits the post, that section is translated back into the
[url]...[/url] type:
# code for plain URLs
$message =~ s/(<A
HREF=\")(.*?)(\">)(.*?<\/A>)/\[url\]$2\[\/url\]/gi;
(I know I'm probably using too many brackets but they make the code
readable for me......)
This all works fine for multiple instances per line of the message and
multiple instances per message. I now want to give the user the option
to use 'fancy' urls:
Something like:
[furl-http://www.perl.com]perl[/furl]
will become:
<A HREF="http://www.perl.com">perl</A>
# code for fancy urls
$message =~ s/\[furl-(.*?)\](.*?)\[\/furl\]/<A
HREF="$1">$2<\/A>/gi;
(I haven't tested the above yet.)
However, when I come to re-encode this for user editing of the post I
can see that I will run into a problem:
# code for fancy URLs
$message =~ s/(<A
HREF=\")(.*?)(\">)(.*?)<\/A>/\[furl-$2\]$4\[\/furl\]/gi;
# code for plain URLs
$message =~ s/(<A
HREF=\")(.*?)(\">)(.*?<\/A>)/\[url\]$2\[\/url\]/gi;
No matter what order I place these two statements in, the first will
take precedence and encode all HREF's as either a [furl] or [url] type
leaving nothing for the second to do and possibly incorrectly specifying
the HREF's as furls or urls.
I could put in a hidden character for the furls:
#encode:
# code for fancy urls
$message =~ s/\[furl-(.*?)\](.*?)\[\/furl\]/ \;<A
HREF="$1">$2<\/A>/gi;
#decode for editing:
# code for fancy URLs
$message =~ s/( \;<A
HREF=\")(.*?)(\">)(.*?)<\/A>/\[furl-$2\]$4\[\/furl\]/gi;
# code for plain URLs
$message =~ s/(<A
HREF=\")(.*?)(\">)(.*?<\/A>)/\[url\]$2\[\/url\]/gi;
but would rather not.
Any solutions?
------------------------------
Date: Wed, 04 Jul 2001 11:40:06 +0200
From: Philip Newton <pne-news-20010704@newton.digitalspace.net>
Subject: Re: chicken and egg regexp problem
Message-Id: <98n5ktc3e954mgehh8bsv972ebs06ba49e@4ax.com>
On Wed, 04 Jul 2001 09:31:45 +0100, Mark Grimshaw
<m.grimshaw@salford.ac.uk> wrote:
> However, when I come to re-encode this for user editing of the post I
> can see that I will run into a problem:
> # code for fancy URLs
> $message =~ s/(<A
> HREF=\")(.*?)(\">)(.*?)<\/A>/\[furl-$2\]$4\[\/furl\]/gi;
> # code for plain URLs
> $message =~ s/(<A
> HREF=\")(.*?)(\">)(.*?<\/A>)/\[url\]$2\[\/url\]/gi;
>
> No matter what order I place these two statements in, the first will
> take precedence and encode all HREF's as either a [furl] or [url] type
> leaving nothing for the second to do and possibly incorrectly specifying
> the HREF's as furls or urls.
Well, the difference appears to be that furls point have something else
for the link and the link text, so you could use one regexp and
distinguish between the two. Perhaps something like this (tested):
$message =~ s{
<A\ HREF=" # common beginning
([^"]+) # non-quote characters, captured to $1
# (this is the link)
"> # end of opening <A> tag
([^<]+) # >non-<> characters, captured to $2
# (this is the link text)
</A> # common ending
}{
$1 eq $2 ? '[url]' . $1 . '[/url]'
: "[furl-$1]" . $2 . '[/furl]'
}exig;
Note: this relies on [url]'s having the form <A
HREF="http://www.perl.com">http://www.perl.com</A> and not <A
HREF="http://www.perl.com">www.perl.com</A> as you gave in your example,
but it should be trivial to fix (for example, by replacing '$1 eq $2'
with something like '$1 eq "http://$2"').
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: Wed, 04 Jul 2001 09:43:57 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: chicken and egg regexp problem
Message-Id: <1ao5kt86jebdmtj6qvrcga46ahjn3376d7@4ax.com>
Mark Grimshaw wrote:
>For a bulletin board I'm coding, I don't allow users to make use of <..>
>HTML tags but require, for URLs, that they use something like:
>[url]http://www.perl.com[/url]
>which is then regexp'd into:
><A HREF="http://www.perl.com">www.perl.com</A>
>I now want to give the user the option
>to use 'fancy' urls:
>Something like:
>[furl-http://www.perl.com]perl[/furl]
>will become:
><A HREF="http://www.perl.com">perl</A>
>However, when I come to re-encode this for user editing of the post I
>can see that I will run into a problem:
>No matter what order I place these two statements in, the first will
>take precedence and encode all HREF's as either a [furl] or [url] type
>leaving nothing for the second to do and possibly incorrectly specifying
>the HREF's as furls or urls.
The distinction between [url] and [furl], is that for [url] the HREF and
the text between the tags is identical. Use that, make a regex that
matches either, checks equality of the HREF (with or without the
"http://" part)and the text, and makes the decision there and then.
$message =~ s{<A HREF="((?:http://)?(.*?))">(.*?)</A>}
{ $1 eq $3 || $2 eq $3 ? "[url]$2\[/url]" :
"[furl-$1]$3\[/furl]" }gei;
--
Bart.
------------------------------
Date: Wed, 4 Jul 2001 00:20:02 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Chmod Problem
Message-Id: <23117-3B42A782-411@storefull-244.iap.bryant.webtv.net>
Re: Chmod Problem
Group: comp.lang.perl.misc Date: Tue, Jul 3, 2001, 10:59pm (CDT+5) From:
mbudash@sonic.net (Michael=A0Budash)
In article <1425-3B422335-325@storefull-242.iap.bryant.webtv.net>,
dennis100@webtv.net (BUCK NAKED1) wrote:
Why isn't this code chmodding all my files and directories under $tmpdir
to 644?
# chmod all files to 644
find sub {-f or return;
if(my $new =3D $_)
{ chmod 0644, $_; rename $_, $new; } }, $tmpdir ;
gee, i don't know, but the system will tell you:
chmod (0644, $_) or die ("Can't chmod: $!"); rename ($_, $new) or die
("Can't rename: $!");
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
---------------------------------------------------------------
I mean, did I make a mistake in my coding below? Your code is totally
different. I used ...
# chmod all files to 644
use File::Find;
find sub {-f or return;
if(my $new =3D $_)
{ chmod 0644, $_; rename $_, $new; } }, $tmpdir ;
Regards,
Dennis
------------------------------
Date: Wed, 4 Jul 2001 00:12:42 -0700
From: William Pietri <william-news-102374@scissor.com>
Subject: Re: Chmod Problem
Message-Id: <tk5gfapa10ci93@corp.supernews.com>
BUCK NAKED1 wrote:
> > > Why isn't this code chmodding all my files and directories under
> > > $tmpdir to 644?
> > > { chmod 0644, $_; rename $_, $new; }
> >
> > gee, i don't know, but the system will tell you:
> > chmod (0644, $_) or die ("Can't chmod: $!");
>
> I mean, did I make a mistake in my coding below? Your code is totally
> different.
He is suggesting that chmod returns valuable error information which your
code does not check. If you want to know why chmod isn't working, you
should start by putting the "or die" stuff directly after your call to
chmod. This is good practice with all system calls.
Another valuable trick is to have your code print out what it's up to; the
results are often surprising. Thus, a line like this can help:
print STDERR "about to chmod '$_' to 0644\n";
And if this still doesn't do the trick, another valuable thing to do is to
check the thing you're trying to change before and after. You could do that
like this:
print STDERR "about to chmod '$file' from ",showmode($file),"\n";
chmod(0644,$file) || die "Can't chmod: $!";
print STDERR "'$file' now has mode ",showmode($file),"\n";
sub showmode {
my ($file) = @_;
my $mode = (stat($file))[2] & 0777;
return sprintf "%lo", $mode;
}
Good luck sorting this out.
By the way, it's traditional on usenet to use ">" to quote text from
previous posters; it's also traditional to trim out all unimportant stuff,
like headers, signatures, and whatnot. That makes it much easier for others
to read, which in turn makes it more likely that you'll get a useful answer.
William
------------------------------
Date: 04 Jul 2001 05:07:35 GMT
From: alexvalara@aol.com (Alexvalara)
Subject: copy array of pointers, like malloc.
Message-Id: <20010704010735.13923.00002167@ng-bk1.aol.com>
Hi everyone,
I would like to copy an array of pointers but i don's want to copy the
pointers!
i need to make a clone of an array but having pointers with diferrent
addresses...
any help...
Thank you in advance
Alexandros
------------------------------
Date: 4 Jul 2001 05:50:48 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: copy array of pointers, like malloc.
Message-Id: <9huaro$rvh$2@bob.news.rcn.net>
Alexvalara <alexvalara@aol.com> wrote:
> Hi everyone,
> I would like to copy an array of pointers but i don's want to copy the
> pointers!
> i need to make a clone of an array but having pointers with diferrent
> addresses...
A trip to search.cpan.org reveals a module called "Clone" described as a
"Perl extension for a recurrsive [sic] copy of nested objects."
Storable.pm also includes a "dclone" method for making deep clones of
complex data structures.
------------------------------
Date: 4 Jul 2001 01:01:10 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: copy array of pointers, like malloc.
Message-Id: <9hubf6$r0j$1@charity.cs.utexas.edu>
In article <20010704010735.13923.00002167@ng-bk1.aol.com>,
Alexvalara <alexvalara@aol.com> wrote:
>I would like to copy an array of pointers but i don's want to copy the
>pointers!
>i need to make a clone of an array but having pointers with diferrent
>addresses...
Sure, use a language that has pointers. Perl doesn't. :-)
But you probably mean references. Anyway, what you're
talking about is often called a "deep copy", and there
is no general method to do it. In other words, it
depends a lot on what the references are references to.
If the array is of references to arrays, you might use this:
@x = ();
foreach my $ref (@y)
{
push (@x, [ @$ref ]);
}
Or, the one-liner version:
@x = map ([ @$_ ], @y);
If you are copying an object, that object might have a
method you can use to have it copy itself. The Java way
of doing this is to have a method called clone(), so that
copying an array of such objects would look like this:
@x = ();
foreach my $ref (@y)
{
push (@y, $ref->clone());
}
The one-liner version:
@x = map ($_->clone(), @y);
Of course, there are other things that a reference can
be a reference to (including objects where cloning
doesn't make sense), so these examples don't cover
everything, but hopefully they'll give you an idea.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Wed, 4 Jul 2001 11:34:27 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: does -B <FILE> work with upload FILE-Handles
Message-Id: <9hubo2$g3eks$1@ID-93885.news.dfncis.de>
I know the following File testing modifiers.
-T File is an ASCII text file.
-B File is a "binary" file (opposite of -T)
Do they work correctly when you are trying to detect the File type when you
use the HANDLE returned by the upload function in the CGI library :
my $query = new CGI;
my $file_handle = $query->upload('upload_file'); #get glob to file handle...
if ( -B $file_handle )
#do binary stuff
}
------------------------------
Date: 4 Jul 2001 01:20:11 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: does -B <FILE> work with upload FILE-Handles
Message-Id: <9hucir$seh$1@charity.cs.utexas.edu>
In article <9hubo2$g3eks$1@ID-93885.news.dfncis.de>,
Aman Patel <patelnavin@icenet.net> wrote:
>I know the following File testing modifiers.
>
>-T File is an ASCII text file.
>-B File is a "binary" file (opposite of -T)
>
>Do they work correctly when you are trying to detect the File type when you
>use the HANDLE returned by the upload function in the CGI library :
Interesting question. "perldoc perlfunc" explains this somewhat:
The `-T' and `-B' switches work as follows. The
first block or so of the file is examined for odd
characters such as strange control codes or
characters with the high bit set. If too many
strange characters (>30%) are found, it's a `-B'
file, otherwise it's a `-T' file. Also, any file
containing null in the first block is considered a
binary file. If `-T' or `-B' is used on a
filehandle, the current stdio buffer is examined
rather than the first block. Both `-T' and `-B'
return true on a null file, or a file at EOF when
testing a filehandle. Because you have to read a
file to do the `-T' test, on most occasions you want
to use a `-f' against the file first, as in `next
unless -f $file && -T $file'.
So, it would appear that what you'd need to do is to read some of the
data before you attempt to use -T or -B. It's probably not a simple
task to figure out how much to read, how to read it, etc., so that the
desired data is in the buffer that those operators examine and so that
the data you've already read is somewhere where you can use it.
In fact, since -T and -B are just a heuristic and nothing particularly
magic, I think it would probably be more reliable to just ignore them
and implement the test that you're trying to do yourself.
Hope that helps.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Wed, 04 Jul 2001 03:12:21 -0400
From: Jason Goodrow <"goodrow"@opencity. com>
Subject: Re: FAQ 9.15: How do I decode a CGI form? newbie ?s
Message-Id: <9hufdi$dlg$1@news.panix.com>
If I was on a job I'd stick as close to CPAN as possible.
Thanks to all on the group - perl is pretty addictive.
goodrow@panix.com
------------------------------
Date: Wed, 04 Jul 2001 10:45:57 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: How to find pwd in Perl
Message-Id: <3B42E5D4.56A44D2@oracle.com>
This is a multi-part message in MIME format.
--------------992B0A91C3C4E590E919877C
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
I'm sure this is bleedin' obvious but I can't find it in the FAQ or
perlfunc or perlvar.
I want to find my current working directory without calling `pwd` on
Unix or `cd` on Windows and I can't find the native Perl method for
doing so.
Thanks in advance.
Graham Wood
--------------992B0A91C3C4E590E919877C
Content-Type: text/x-vcard; charset=UTF-8;
name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
filename="Graham.T.Wood.vcf"
begin:vcard
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.T.Wood@oracle.com
fn:Graham Wood
end:vcard
--------------992B0A91C3C4E590E919877C--
------------------------------
Date: 4 Jul 2001 06:43:44 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Is REG_DATE a special type of mysql column?
Message-Id: <slrn9k5eph.n9f.rgarciasuarez@rafael.kazibao.net>
Diane Strahl wrote in comp.lang.perl.misc:
> Can someone tell me if there's something special about using REG_DATE as
> a COLUMN name in a mysql database when updating the database from a perl
> script?
This is actually a MySQL question. Check the MySQL documentation. For
issues about using specifically Perl/DBI with MySQL, you should check
the DBD::mysql documentation; but it doesn't include a note about a
"REG_DATE" keyword.
> I have written a perl script that connects to a mysql database
> using the DBI module. When the cgi gets to the following lines,
>
> $SQL = "UPDATE REGINFO SET
> APPROVAL_CODE=\"$FORM{'approval_code'}\",CHARGE_AMOUNT=\"$FORM{'chargetotal'}\"
> WHERE ID=\"$reg_num\"";
>
> $sth = $dbh->prepare($SQL);
>
> $sth->execute || die "Could not execute SQL statement, maybe invalid?";
>
> it is also updating the REG_DATE column. The REG_DATE column is type
> TIMESTAMP.
We can't help you with so little code. The error seems to come from
another part of your script. However, here's an advice on using
correctly prepare() and execute() in CGI programs :
Don't embed directly external data in an SQL statement. What will happen
if someones provides to your script a value like '";DROP TABLE REGINFO;#'
for the variable 'approval_code' ? This is a security risk. The common
idiom, described in the DBI manpage, is :
$SQL = qq/UPDATE REGINFO SET APPROVAL_CODE=?, CHARGE_AMOUNT=? WHERE ID=?/;
$sth = $dbh->prepare($SQL);
$sth->execute($FORM{'approval_code'},$FORM{'chargetotal'},$reg_num)
|| die "Could not execute SQL statement; error: $DBI::errstr";
This ensures that the parameters to the SQL statement are properly
quoted to produce a valid SQL sentence. See the DBI documentation for
details.
HTH.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 4 Jul 2001 02:49:57 -0700
From: cool133@hotmail.com (^CooL^)
Subject: Newbie DBI question
Message-Id: <211c8e3f.0107040149.637156bb@posting.google.com>
Hi.
Is there a simple way of putting a single row from a DBI recordset
into a hash array? I need each field in the row to be stored as an
element in the hash array with the same name as the column name of
that row.
Cheers,
Clyde.
------------------------------
Date: Wed, 4 Jul 2001 03:46:58 -0500
From: Michael Gilfix <magilfix@us.ibm.com>
Subject: Parallel Execution
Message-Id: <9hul2t$g56$1@ausnews.austin.ibm.com>
If I wanted to write an application that uses parallel structure,
would it be reasonable to use perl threads at this point? This is by
no means mission critical software. More for amusement purposes. My
real question comes: Threading in Perl has been experimental for
a while now. Has the API pretty much gelled though so that my application
won't break *too* much in the future? Also, what does this mean to the users
of the software?
Otherwise, does anyone have any nice alternatives? forking with shared memory
or named sockets don't seem all that attractive...
Thanks,
-- Mike
--
Michael Gilfix
Extreme Blue Group - IBM (Austin)
magilfix@us.ibm.com
------------------------------
Date: Wed, 04 Jul 2001 10:05:31 +0200
From: Philip Newton <pne-news-20010704@newton.digitalspace.net>
Subject: Re: Perl 6: -> vs .
Message-Id: <ljh5kt4tngoucl0fgllmjfc7afsdubfld5@4ax.com>
On 3 Jul 2001 14:03:31 -0700, stupid@pobox.com (Michael G Schwern)
wrote:
> As for scripts, a few ideas are being tossed around. One idea is for
> Perl 6 to be sensitive to how its named. Say you've got
> /usr/bin/perl6 and its symlinked to /usr/bin/perl. If Perl 6 is
> called as "perl" it runs as Perl 5. If called as "perl6" it runs as
> Perl 6.
That would be ick IMO. Once Perl6 is really "there" (perhaps in five
years?), still having to type "perl6" all the time would be strange.
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: 4 Jul 2001 01:46:51 -0700
From: jens-ole.frimann@thomson.dk (Jens-Ole Frimann)
Subject: Perl server
Message-Id: <649cf897.0107040046.2e55fbc1@posting.google.com>
I have tried to use the following ( which I copied from an early posting )
It works Ok, but it won't stay up.
When it have had a couple of client connects it dies.
How can I have it running 'forever' ?
#!/usr/bin/perl -w
use strict;
use IO::Socket;
sub Slayer {
1 until ( -1 == waitpid(-1,0));
$SIG{CHLD} = \&Slayer;
}
$SIG{CHLD} = \&Slayer;
my $server = IO::Socket::INET->new(LocalPort => 8080,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10) or die "blah $@\n";
my $client ;
while ( $client = $server->accept())
{
next if my $pid = fork;
die "fork - $!\n" unless defined $pid;
my $headers;
while(<$client>)
{
last if /^\r\n$/;
$headers .= $_;
}
select $client;
$| = 1;
print $client "HTTP/1.0 200 OK\r\n";
print $client "Content-type: text/plain\r\n\r\n";
print $client $headers;
close($client);
exit;
}
continue
{
close($client);
}
------------------------------
Date: Wed, 4 Jul 2001 03:05:44 -0500
From: Michael Gilfix <magilfix@us.ibm.com>
Subject: Re: readdir(..) function
Message-Id: <9huili$2fru$2@ausnews.austin.ibm.com>
Hi. I think some people got part of your question but missed another. I think
you were looking for a way to filter out the '.' and '..' directory entires
when reading the directory. Code to do that would be:
@dir_items = grep!/^\.\.?$/, readdir (DIR);
Hope that helps.
-- Mike
On Saturday 30 June 2001 10:38%, news.talknet.de wrote:
> Hi all!
>
> can anyone tell me how to filter the directory entries when I read a
> directory with the readdir() function (or maybe another way)? I try to make
> a directory listing and the directory entries are mixed with the files in
> that directory.
>
> For eaxample, I use the following method:
>
> opendir (DIR, ".") || die "I was unable to open the directory";
> @dir_items = readdir(DIR);
> closedir (DIR);
>
> Thanks in advance
> Peter
--
Michael Gilfix
Extreme Blue Group - IBM (Austin)
magilfix@us.ibm.com
------------------------------
Date: 04 Jul 2001 04:49:09 -0400
From: Dominic Mitchell <dommit@videotron.ca>
Subject: regexp across lines
Message-Id: <m3elrx2i62.fsf@rlevesque.com>
Hi,
I have been trying all night to get this one working. I have a
file with entries like this:
\harvarditem[{\textsc{Alizadeh}}, {\textsc{Brandt}}, and
{\textsc{Diebold}}]{{\textsc{Alizadeh}}, {\textsc{Brandt}}, and
{\textsc{Diebold}}}{2001}{art106}
{\textsc{Alizadeh}}, Sassan, Michael~W. {\textsc{Brandt}}, and Francis~X.
{\textsc{Diebold}}, 2001, High- and low-frequency exchange rate volatility
dynamics: range-based estimation of stochastics volatility models, Working
{P}aper 8162 National Bureau of Economic Research Cambridge.
I want to capture the characters in between the [] if there are
comas in it.
I have play around this:
while (<>) {
if ($_ =~ m{^\\harvarditem\[(.*?)[,].*\]}xms ){
print $_;
print "\n\\harvarditem[$1 et al.]";
}
}
It captures does the job only if it is on one single line. I have
tried to use the /m /s modifiers but I must be missing something
because I can' t figure out what is wrong.
In the above example the regexp should capture
\harvarditem[{\textsc{Alizadeh}}, {\textsc{Brandt}}, and
{\textsc{Diebold}}]
Any help is really appreciated.
Thanks
Dominic Mitchell.
------------------------------
Date: Wed, 04 Jul 2001 11:43:14 +0200
From: Philip Newton <pne-news-20010704@newton.digitalspace.net>
Subject: Re: regexp across lines
Message-Id: <85p5ktok11ajbt4og3qft9fq5ku69koidp@4ax.com>
On 04 Jul 2001 04:49:09 -0400, Dominic Mitchell <dommit@videotron.ca>
wrote:
> I have play around this:
>
> while (<>) {
> if ($_ =~ m{^\\harvarditem\[(.*?)[,].*\]}xms ){
> print $_;
> print "\n\\harvarditem[$1 et al.]";
> }
> }
>
> It captures does the job only if it is on one single line. I have
> tried to use the /m /s modifiers but I must be missing something
> because I can' t figure out what is wrong.
You're reading in one line at a time with your "while (<>)" loop, unless
you set $/ appropriately. So the regex only ever sees one line at a
time. Consider setting $/ to something else -- perhaps "" for paragraph
mode or undef for while-file mode? (In the latter case, you'll probably
need a 'while (/regex/g)' loop rather than an 'if (/regex/)' condition,
using the /g flag to loop through the places found.)
> In the above example the regexp should capture
>
> \harvarditem[{\textsc{Alizadeh}}, {\textsc{Brandt}}, and
> {\textsc{Diebold}}]
Which is hard to do if it sees
\harvarditem[{\textsc{Alizadeh}}, {\textsc{Brandt}}, and
on one line and
{\textsc{Diebold}}]
the next time around :)
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: Wed, 04 Jul 2001 06:18:20 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Retrieving Domain from URL line
Message-Id: <1ew0hb6.1rtz0541jrhfpwN%tony@svanstrom.com>
Blstone77 <blstone77@aol.com> wrote:
> I have a perl program which creates a file with Referrer URL's one on each
> line
[cut]
> etc.. As you probably can guess, i would like to count up the times each
> domain sends someone to my page.
[cut]
> any helpor direction is ppreciated.
Well, since you said any help... =)
#####
@list = ('http://perlnewbies.com/history/searchit.html',
'http://excite.com/search.gw?c=web&lk=excite_home_us&s',
'http://search.msn.co.uk/spbasic.htm?MT=Presidents',
'http://search.msn.com/results.asp?RS=CHECKED&Armada',
'http://search.yahoo.com/bin/search?p=%22Perl',
'http://top.cswap.com:80/cat/?biblestudies');
foreach (@list) {
$_ =~ s!(^.*?//)|([:/].*$)!!g;
$doms{$_}++;
}
foreach my $dom (sort keys(%doms)) {
print "$dom = $doms{$dom}\n"
}
#####
Just change the foreach to a while-thingie as you're reading the file,
and then just change everything else that you have to change. =)
/Tony
--
the truth is dead, faith is gone, reality killed... ruled by the plastic
laws of modern life we're pushed towards the hell of personal doubt,
betrayal, hate, lust and murder... the now has become an illusion, a
paradise of a dead tomorrow... (c)2000-2001 tony@svanstrom.com
------------------------------
Date: Tue, 3 Jul 2001 23:52:55 -0700
From: William Pietri <william-news-102374@scissor.com>
Subject: Re: Retrieving Domain from URL line
Message-Id: <tk5fa7jh1c8me9@corp.supernews.com>
Blstone77 wrote:
> I have a perl program which creates a file with Referrer URL's one on each
> line like so.
>
> http://perlnewbies.com/history/searchit.html
> http://excite.com/search.gw?c=web&lk=excite_home_us&s
> http://search.msn.co.uk/spbasic.htm?MT=Presidents
>
> [...]My question is how would I get Perl to extract just the
> domain names (excite.com, perlnewbies.com, msn.com, etc.) from this file.
Perl's regular expression (aka regexp) facility is made for this. You can
find further information in the perlre man page, and any decent book on
Perl will have plenty of information about regular expressions.
The basic trick with regexps is to say "What's special about the thing I'm
looking for?" There are often a lot of reasonable answers, but we can start
by saying that we want the thing between "http://" and the next "/". One
way of doing this in code would be
($host) = $url =~ m|http://(.*?)/|;
This says "Search the string $url for the stuf between "http://" and "/"
and put it in $host. A complete (if terse) program to do what you want
would look like this:
#!/usr/bin/perl -w
my %hosts;
while (<>) {
my ($host) = m|http://(.*?)/|;
$host = "unknown" unless $host;
$hosts{$host}++;
}
print "referrals\thost\n";
foreach my $host (sort({$hosts{$b} <=> $hosts{$a}} keys(%hosts))) {
print "$host\t$hosts{$host}\n";
}
exit 0;
Now if you really want the domain rather than the host, that's a little
trickier, mainly because it involves a bunch of special cases. I don't know
an easy way to do that, but you could construct your own list of special
cases pretty easily.
Good luck!
William
------------------------------
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 1241
***************************************