[16924] in Perl-Users-Digest
Perl-Users Digest, Issue: 4336 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 15 14:16:09 2000
Date: Fri, 15 Sep 2000 11:15:26 -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: <969041725-v9-i4336@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 15 Sep 2000 Volume: 9 Number: 4336
Today's topics:
Re: Substitution <stephenk@cc.gatech.edu>
Re: Substitution nobull@mail.com
Re: Substitution <jluongonospam@draper.com>
Re: Substitution <ren.maddox@tivoli.com>
Re: Substring Golf? (Abigail)
System Not Recognizing Perl <jimve@ yahoo.com>
Re: System Not Recognizing Perl <eric.kort@vai.org>
Re: Text manipulation: translating several token at onc <lr@hpl.hp.com>
Re: Text manipulation: translating several token at onc (Abigail)
Re: Web Client multipart-data POST tebrusca@my-deja.com
Re: What the joke, no host!? <cds@jediseek.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Sep 2000 12:02:24 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Substitution
Message-Id: <39C24810.F54024C5@cc.gatech.edu>
"James M. Luongo" wrote:
> In Windows, I would like to replace the full pathname of a file with
> just the filename.
>
> for instance
>
> $dir = ARGV[0]; # a directory is sent
> @files = glob ("$dir\\*.*"); # get all the files in $dir
>
> foreach $file (@files) {
> $file =~ s/$dir\\//; # take out $dir and replace with nothing
> print "$file\n";
> }
>
> Yet, this doesn't work. $dir\\ is not matched. Why? And how can I do
> this better?
Use s/.*\\// or s/\Q$dir\E\\// instead of s/$dir\\// if you must use
globbing.
You might want to consider using opendir and readdir instead.
perldoc -f opendir
perldoc -f readdir
perldoc perlre
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: 15 Sep 2000 17:07:22 +0100
From: nobull@mail.com
Subject: Re: Substitution
Message-Id: <u91yylskp1.fsf@wcl-l.bham.ac.uk>
"James M. Luongo" <jluongonospam@draper.com> writes:
> $dir = ARGV[0]; # a directory is sent
> @files = glob ("$dir\\*.*"); # get all the files in $dir
Avoid glob() like the plague. opendir() and readdir() are usually a
better approach.
> foreach $file (@files) {
> $file =~ s/$dir\\//; # take out $dir and replace with nothing
> print "$file\n";
> }
>
> Yet, this doesn't work. $dir\\ is not matched. Why?
You'll probably find $dir contains regular expression metacharacters.
You need to quote them by interpolating with \Q
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 15 Sep 2000 12:51:16 -0400
From: "James M. Luongo" <jluongonospam@draper.com>
Subject: Re: Substitution
Message-Id: <39C25384.521EA3BA@draper.com>
nobull@mail.com wrote:
ok, the \Q thing works. But just a question, why avoid glob? Whats so
wrong with it?
>
> "James M. Luongo" <jluongonospam@draper.com> writes:
>
> > $dir = ARGV[0]; # a directory is sent
> > @files = glob ("$dir\\*.*"); # get all the files in $dir
>
> Avoid glob() like the plague. opendir() and readdir() are usually a
> better approach.
>
> > foreach $file (@files) {
> > $file =~ s/$dir\\//; # take out $dir and replace with nothing
> > print "$file\n";
> > }
> >
> > Yet, this doesn't work. $dir\\ is not matched. Why?
>
> You'll probably find $dir contains regular expression metacharacters.
> You need to quote them by interpolating with \Q
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
--
------------------------
James M. Luongo x1427
Draper Laboratory Room 4207
------------------------
------------------------------
Date: 15 Sep 2000 10:04:07 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Substitution
Message-Id: <m3hf7hzogo.fsf@dhcp11-177.support.tivoli.com>
"James M. Luongo" <jluongonospam@draper.com> writes:
> In Windows, I would like to replace the full pathname of a file with
> just the filename.
>
> for instance
>
[Obligatory mention of -w and 'use strict;']
> $dir = ARGV[0]; # a directory is sent
Missing a "$". Should be:
$dir = $ARGV[0];
or, simply:
$dir = shift;
Of course, this is a syntax error, so it isn't the real problem, just
a typo.
> @files = glob ("$dir\\*.*"); # get all the files in $dir
You don't really need to use "\\" as a directory separator unless you
plan to pass the path to an external program. Perl will work fine
using "/" on NT. But that still isn't the problem. Also, "*.*" may
not do what you expect, and if it does, then you probably just want
"*" (at least on my NT system using "*.*" seems to behave as a simple
"*", though on my Linux box it has the expected behavior of only
matching files that actually contain a ".").
> foreach $file (@files) {
> $file =~ s/$dir\\//; # take out $dir and replace with nothing
> print "$file\n";
> }
>
> Yet, this doesn't work. $dir\\ is not matched. Why? And how can I do
> this better?
How do you know that it isn't matched? What output are you getting?
Once I fixed the missing "$", your script gave me the expected
output. Still, I would probably do something like this instead:
#!/usr/local/bin/perl -w
use strict;
my $dir = shift || "."; # default to the current directory
chdir $dir or die "Could not change directory to $dir, $!\n";
print "$_\n" for <*>;
__END__
Or, if chdir is not appropriate:
#!/usr/local/bin/perl -w
use strict;
my $dir = shift || "."; # default to the current directory
opendir DIR, $dir or die "Could not opendir $dir, $!\n";
print "$_\n" while $_ = readdir DIR;
closedir DIR or die "Problem with closedir $dir, $!\n";
__END__
Of course, on a UNIX system this will find "hidden" files. Change the
print line to:
/^\./ or print "$_\n" while $_ = readdir DIR;
to avoid that, if desired.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 15 Sep 2000 16:04:47 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Substring Golf?
Message-Id: <slrn8s4i2u.4mc.abigail@alexandra.foad.org>
Wyzelli (wyzelli@yahoo.com) wrote on MMDLXXII September MCMXCIII in
<URL:news:hBew5.16$eI1.3742@vic.nntp.telstra.net>:
!! I am looking for a neater/shorter way of achieving the following:
!!
!! my $num = shift;
!! $num =~ s/ //g;
!!
!! my $numa = substr $num,0,4;
!! my $numb = substr $num,4,4;
!! my $numc = substr $num,8,4;
!! my $numd = substr $num,12,4;
!!
!! Any ideas? One liners?
Here's a one-liner:
do{my$i;map{/ /|$i==16 or${num.(qw(a b c d))[$i++/4]}.=$_}split//,shift};
Abigail
--
perl -we 'eval {die ["Just another Perl Hacker\n"]}; print ${$@}[$#{@${@}}]'
# A spider eats beside
# a stream. A warrior
# sits beside a lake.
------------------------------
Date: Fri, 15 Sep 2000 11:55:16 -0400
From: "Jim Verzino" <jimve@ yahoo.com>
Subject: System Not Recognizing Perl
Message-Id: <8pthjf$9ml$1@bob.news.rcn.net>
I have downloaded and installed ActivePerl for Win98 from ActiveState.com.
I took all of the defaults on the installation. However, when I do a
perl -v
at the command line I get the Bad Command or File Name response. I have
been all over the documentation and cant find anything out of whack. Any
ideas. ActiveState does not give an option for email or any other sort of
tech support that costs less than $100 so I am going this route. Any help
would be appreciated.
Jim Verzino
------------------------------
Date: Fri, 15 Sep 2000 12:13:51 -0400
From: "Eric" <eric.kort@vai.org>
Subject: Re: System Not Recognizing Perl
Message-Id: <8pthpq$791$1@msunews.cl.msu.edu>
"Jim Verzino" <jimve@ yahoo.com> wrote in message
news:8pthjf$9ml$1@bob.news.rcn.net...
> I have downloaded and installed ActivePerl for Win98 from ActiveState.com.
> I took all of the defaults on the installation. However, when I do a
>
> perl -v
>
> at the command line I get the Bad Command or File Name response.
Is c:/perl/bin (or wherever perl/bin is on your system) in your PATH?
------------------------------
Date: Fri, 15 Sep 2000 10:13:13 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Text manipulation: translating several token at once
Message-Id: <MPG.142bf883e7aab95e98ad6f@nntp.hpl.hp.com>
In article <39C22283.62369A5A@kernelconsult.com> on Fri, 15 Sep 2000
15:22:11 +0200, TM <tm@kernelconsult.com> says...
> Larry Rosler a écrit :
...
> > my %elements =
> > ( H => 'Hydrogen', O => 'Oxygen', N => 'Nitrogen', Ne => 'Neon', );
> > my $text = 'H2O N Ne Foo';
> >
> > $text =~ s/([A-Za-z]+)/$elements{$1} || $1/eg;
> > print "$text\n";
>
> That's even better!!
This is better yet, considering the restricted domain of the hash keys:
$text =~ s/([A-Z][a-z]?)/$elements{$1} || $1/eg;
One can be even more elaborate, depending on whether one wants to
convert, say, 'Neon' to 'Neonon' or to leave it alone:
$text =~ s/([A-Z][a-z]?)(?![a-z])/$elements{$1} || $1/eg;
Should 'Ox' become 'Oxygenx'? I think not.
$text =~ s/(([A-Z][a-z])|[A-Z])(?![a-z])/
$2 && $elements{$2} || $elements{$1} || $1/eg;
And one can peek back at the previous context. And on and on...
Ultimately this comes down to requiring a more precise problem statement
than:
> > > here's the question let's take a text or even a line of text. with
> > > let's say many atoms symbols from the periodic chart of elements. And
> > > now we whant to translate each of them into their full name.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 15 Sep 2000 17:32:04 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Text manipulation: translating several token at once
Message-Id: <slrn8s4n6i.4mc.abigail@alexandra.foad.org>
Larry Rosler (lr@hpl.hp.com) wrote on MMDLXXII September MCMXCIII in
<URL:news:MPG.142b54664e549bde98ad6e@nntp.hpl.hp.com>:
.. In article <JRhw5.1682$jC4.274850@typhoon.southeast.rr.com>,
.. philipg@atl.mediaone.net says...
..
.. > my %elements = ( H => 'Hydrogen', O => 'Oxygen', N => 'Nitrogen' );
.. > my $text = 'H O N';
.. >
.. > $text =~ s/(\w)/$elements{$1}/g;
.. > print "$text\n";
..
.. my %elements =
.. ( H => 'Hydrogen', O => 'Oxygen', N => 'Nitrogen', Ne => 'Neon', );
.. my $text = 'H2O N Ne Foo';
Well, H2O isn't in the periodic chart.
..
.. $text =~ s/([A-Za-z]+)/$elements{$1} || $1/eg;
.. print "$text\n";
That would turn 'H2O' into 'Hydrogen2Oxygen'. Maybe that's wanted, but then
it wouldn't quite work for 'CH4'. Not to mention what happens to 'CH2O'.
Abigail
--
print 74.117.115.116.32.97.110.111.116.104.101.114.
32.80.101.114.108.32.72.97.99.107.101.114.10;
------------------------------
Date: Fri, 15 Sep 2000 17:54:46 GMT
From: tebrusca@my-deja.com
Subject: Re: Web Client multipart-data POST
Message-Id: <8ptnou$alh$1@nnrp1.deja.com>
In article <9shw5.47046$QW4.546759@news1.rdc1.mi.home.com>,
"Bill Hess" <billhess2000@home.com> wrote:
> I am trying to write a web client to upload files to a web server (in
Perl)-
> I know the CGI side on the server works, because I can upload
successfully
> using a web browser. But I cannot seem to get the headers correct.
Here is
> what I think the headers should look like - Am I missing
something??? I am
> trying to reverse engineer what IE is doing...
Bill,
I modified a script to listen on port 80 and print what it hears.
I then set up my upload script on a remote browser.
I shut down my real server and started my little script.
This is what it printed (slightly modified, took IPs out):
POST /cgi-bin/upload.cgi HTTP/1.0
Referer: http://hostname/cgi-bin/upload.cgi
Connection: Keep-Alive
User-Agent: Mozilla/4.7C-SGI [en] (X11; I; IRIX64 6.5 IP27)
Host: xxx.xxx.xxx.xxx
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png,
*/*
Accept-Encoding: gzip
Accept-Language: en
Accept-Charset: iso-8859-1,*,utf-8
Content-type: multipart/form-data; boundary=---------------------------
251372556626966
Content-Length: 409
-----------------------------251372556626966
Content-Disposition: form-data; name="sent_to"
tebrusca
-----------------------------251372556626966
Content-Disposition: form-data; name="subject"
-----------------------------251372556626966
Content-Disposition: form-data; name="upload"; filename="hello.txt"
Content-Type: text/plain
Hello world
-----------------------------251372556626966--
I then cat'ed this to a telnet hostname 80 on a remote system
and whamo it worked. Now I can use this as a template for
uploading files to my web server with a perl script.
Here's what's left of the phttpd.pl script I pimped off CPAN:
I severely hacked stuff out of it.
#!/usr/local/bin/perl -w
use strict;
use Socket;
my $port = 80;
$|=1;
my $tcp = getprotobyname('tcp');
socket(Server, PF_INET, SOCK_STREAM, $tcp) || die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR,pack("l", 1))
||die "setsockopt: $!";
bind(Server, sockaddr_in($port, INADDR_ANY))|| die "bind: $!";
listen(Server,SOMAXCONN)|| die "listen: $!";
my $addr;
for ( ; $addr = accept(Client,Server); close Client)
{
*STDIN = *Client;
*STDOUT = *Client;
while ( <STDIN> )
{
print STDERR $_;
}
}
I'll post the upload perl script when I write it, unless
somebody else posts it first, I've worked on this enough
today.
I want upload on cmd line myself, because I want to
backup files I'm working on remotely to my webserver.
backup.pl file ( uploads to my web server )
get.pl file ( downloads a file from server perl directory )
Here's my get.pl script "it's crude but effective":
#!/usr/sbin/perl
my $query = "/PERL/$ARGV[0]";
my @data = `echo "GET $query HTTP/1.0 \n" |
telnet hostname 80 2> /dev/null`;
until ( $data[0] =~ /^#!/ ) { shift @data; }
print @data;
Hope this helps, hope even more that others have done something
like this so I can use it.
PS
I don't have the HTTP, LWP, MIME, ... modules available
on my remote systems so I need to do this without them.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 15 Sep 2000 17:28:34 GMT
From: <cds@jediseek.com>
Subject: Re: What the joke, no host!?
Message-Id: <ss4n22lrdc675@corp.supernews.com>
Try www.pagespin.net for cgi and no banners...
Tom Fotheringham wrote:
>
>
> I love it, but I need to love it more. What I really want is to get some
> Perl powered web sites up on the web.
>
> Can somebody please tell me where I can get free CGI-BIN hosting. I know
> theres one in the UK somewhere and that its linux based but I can
remember
> where I read it.
>
> Thanks
> Tom F
>
>
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4336
**************************************