[16975] in Perl-Users-Digest
Perl-Users Digest, Issue: 4387 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 20 14:10:32 2000
Date: Wed, 20 Sep 2000 11:10:18 -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: <969473417-v9-i4387@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 20 Sep 2000 Volume: 9 Number: 4387
Today's topics:
Re: IP Address <stan_no_spam_for_me@nmsua.nmsu.edu>
Re: IP Address (Eric Bohlman)
Re: Looking for perl sample to post to web site?? (Mark-Jason Dominus)
Re: Looking for perl sample to post to web site?? nobull@mail.com
Re: Naked chicks <jeff@vpservices.com>
Netiquette (was: Re: NT File Attribute - archive) <perin@panix.com>
Re: Netiquette (was: Re: NT File Attribute - archive) (Eric Bohlman)
newbie string chopping question <rickyfusion@nospamfusionserver.com>
Re: newbie string chopping question <sariq@texas.net>
Re: Parsing incoming mails to launch a script <digitalj@uswest.net.remove>
Re: Parsing incoming mails to launch a script (NP)
passwd manipulation (Dave Sherohman)
Re: Perl Shell on Windows NT <undergronk@my-deja.com>
Perl working directory in IIS marcusmills@my-deja.com
Problem with CGI -- buffered output? <je@bton.ac.uk>
Re: Problem with CGI -- buffered output? nobull@mail.com
Re: Problems with Mail::Folder and cgi mluebke@my-deja.com
Re: Qualifications for new Perl programmer????? (Tim Hammerquist)
Re: Question: windows system() crash detection (Abigail)
Re: reading from a file <powlow@my-deja.com>
Re: reading from a file nobull@mail.com
Re: Regex Problem <lr@hpl.hp.com>
Re: Regular expression for variable substitution nobull@mail.com
Re: script critique requested <stevea@wrq.com>
Re: script critique requested <stevea@wrq.com>
search a string nodo70@my-deja.com
Re: Shortest code for Fibonacci? <jcook@strobedata.com>
Re: Shortest code for Fibonacci? (Greg Bacon)
Re: Time help (John J. Trammell)
Re: Time help <sariq@texas.net>
translate JavaScript to CGI (read cookie) <nospam@jillanddirk.com>
using awk with perl potato_salad@my-deja.com
Re: using awk with perl (NP)
What's wrong with that regexp? <FX@hasnomail.com>
Re: What's wrong with that regexp? <FX@hasnomail.com>
Re: What's wrong with that regexp? <yanick@babyl.sympatico.ca>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 20 Sep 2000 09:38:55 -0600
From: Stan McCann <stan_no_spam_for_me@nmsua.nmsu.edu>
Subject: Re: IP Address
Message-Id: <39C8DA0F.8CAFBF74@nmsua.nmsu.edu>
Although I didn't place this in a program to test, it should work to get
the IP for you.
A lot of information is placed in the environment, all you have to do is
read the correct variable.
while (($key, $val) = each %ENV) {
if ($key eq "REMOTE_ADDR") {
print "IP is $val<br>\n";
}
}
Marvin wrote:
>
> In article <slrn8sgnd0.5fq.abigail@alexandra.foad.org>, abigail@foad.org
> says...
> > Marvin (ales.romaniuk@zag.si) wrote on MMDLXXVII September MCMXCIII in
> > <URL:news:MPG.14327756f0a68dae98968c@news.siol.net>:
> > ||
> > || Actually I would like to make an oppinion poll and there you can have
> > || only one vote. So I need to check into database if you have already
> > || voted.
> >
> >
> > Can't be done. There's no "proof-of-identity" on the Internet.
> > Some people have an entire class-B network available (65K addresses),
> > but there are also millions of people hiding behind a handful of
> > proxies.
> >
> > And then there are the people sharing a computer. Not the entire world
> > consists of geeks living alone with a Win32 box, you know. There are
> > hundreds of thousands of people behind a firewall, sharing the world
> > visible IP address with hundreds or thousands of co-workers.
> >
> >
> > Please get a clue on how the net and the web works. After that, come back
> > to Usenet, but know these questions are off-topic in this group.
> >
> >
> > Abigail
> >
> Hi Again !
>
> As matters of my problem, the people who will access the script will be
> all in Intranet using single network scheme with 255 hosts. Since I
> don't want to use entering login name and password, I just want to check
> their IP (like javascript knows to do). So I am asking again, if its
> possible to get remote IP number (Apache Server sees that number,cause
> it is logged) into Perl.
>
> Regards
------------------------------
Date: 20 Sep 2000 16:53:25 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: IP Address
Message-Id: <8qaq25$20c$1@slb6.atl.mindspring.net>
Stan McCann (stan_no_spam_for_me@nmsua.nmsu.edu) wrote:
: Although I didn't place this in a program to test, it should work to get
: the IP for you.
: A lot of information is placed in the environment, all you have to do is
: read the correct variable.
:
: while (($key, $val) = each %ENV) {
: if ($key eq "REMOTE_ADDR") {
: print "IP is $val<br>\n";
: }
: }
This kind of defeats the whole purpose of using a hash, doesn't it?
print "IP is $ENV{REMOTE_ADDR}<br>\n" if defined $ENV{REMOTE_ADDR};
------------------------------
Date: Wed, 20 Sep 2000 12:36:18 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Looking for perl sample to post to web site??
Message-Id: <39c8d47c.955$70@news.op.net>
In article <8qafdb$k14$1@nnrp1.deja.com>, <smithj@allnightprod.com> wrote:
>Can anyone please email me some perl code that will do a post to a web
>site??
This is the example from the manual for the perl 'LWP' module:
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->agent("AgentName/0.1 " . $ua->agent);
# Create a request
my $req = new HTTP::Request POST => 'http://www.perl.com/cgi-bin/BugGli
mpse';
$req->content_type('application/x-www-form-urlencoded');
$req->content('match=www&errors=0');
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
print $res->content;
} else {
print "Bad luck this time\n";
}
------------------------------
Date: 20 Sep 2000 17:46:19 +0100
From: nobull@mail.com
Subject: Re: Looking for perl sample to post to web site??
Message-Id: <u9k8c7f1us.fsf@wcl-l.bham.ac.uk>
smithj@allnightprod.com writes:
> Looking for perl sample to post to web site??
No thanks, I already have some.
> Can anyone please email me some perl code that will do a post to a web
> site??
What would be the point? If it didn't use LWP it wouldn't be very
good code. If it did use LWP then you'd need to install LWP to use
it. If you've got to install LWP anyhow you may as well use the
sample code in the LWP docs (lwpcook).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 20 Sep 2000 08:12:24 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Naked chicks
Message-Id: <39C8D3D8.47DDF1AD@vpservices.com>
Powlow wrote:
>
> maybe now someone will look at this....
> anyone?
*plonk*
--
Jeff
------------------------------
Date: 20 Sep 2000 11:20:34 -0400
From: Lewis Perin <perin@panix.com>
Subject: Netiquette (was: Re: NT File Attribute - archive)
Message-Id: <pc73div84zh.fsf_-_@panix3.panix.com>
H C <carvdawg@patriot.net> writes:
> jason wrote:
>
> > [ posted to comp.lang.perl.misc and CCed to tanya_ellis@hotmail.com ]
>
> > please try not to ask the same question twice .. I've already answered
> > this in the other thread that you started entitled "Archive File
> > Attribute on NT"
>
> Again, you could have sent your response to Tanya alone, but you had to make
> sure everyone else knew how smart you are...
Sorry, but the netiquette issues here may be a bit more complex than
you've indicated. Let's say I post a, well, dumb query. Sure, it
dumps an unnecessary article into each subscriber's pile. But until
someone posts (not mails) a reply, there may be any number of helpful
souls who mail replies, following your policy of not exacerbating the
newsgroup's congestion. Each of those people has taken on a far
bigger burden than those of us who merely bypassed the query, likely
without even reading it. How do you weigh the two burdens? I don't
know.
/Lew
--
Lew Perin / perin@mail.med.cornell.edu / perin@acm.org
www.panix.com/~perin/
------------------------------
Date: 20 Sep 2000 17:05:26 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Netiquette (was: Re: NT File Attribute - archive)
Message-Id: <8qaqom$20c$2@slb6.atl.mindspring.net>
Lewis Perin (perin@panix.com) wrote:
: Sorry, but the netiquette issues here may be a bit more complex than
: you've indicated. Let's say I post a, well, dumb query. Sure, it
: dumps an unnecessary article into each subscriber's pile. But until
: someone posts (not mails) a reply, there may be any number of helpful
: souls who mail replies, following your policy of not exacerbating the
: newsgroup's congestion. Each of those people has taken on a far
: bigger burden than those of us who merely bypassed the query, likely
: without even reading it. How do you weigh the two burdens? I don't
: know.
There's another problem that tips the scales in favor of posting. Even
the most competent regulars here sometimes make mistakes. If someone
posts a reply and it contains an error, someone else will almost
certainly catch it and post a followup describing the problem. But if
someone *mails* a reply that contains an error, and the person it's
mailed to is a newbie, the recipient may not be able to recognize the
error, and at best will experience frustration and at worst will learn a
bad habit (if the error is of the sort where the code works under ideal
conditions, but fails otherwise). Posting provides for peer review, and
a brusque but correct answer is preferable to a friendly but incorrect
answer.
------------------------------
Date: Wed, 20 Sep 2000 11:58:21 -0400
From: "Ric Smith" <rickyfusion@nospamfusionserver.com>
Subject: newbie string chopping question
Message-Id: <8qamte$5lg$1@server.cntfl.com>
Is there a function to chop the characters off a
string after a specified character?
$string = "this is a line of text";
RemoveCharacters from $string after the
10th character yields.
$string = "this is a ";
Thanks.
Ric Smith
------------------------------
Date: Wed, 20 Sep 2000 11:45:03 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: newbie string chopping question
Message-Id: <39C8E98F.1A17FB8D@texas.net>
Ric Smith wrote:
>
> Is there a function to chop the characters off a
> string after a specified character?
>
> $string = "this is a line of text";
>
> RemoveCharacters from $string after the
> 10th character yields.
>
> $string = "this is a ";
Perl's functions are documented in the perlfunc page of the manual.
Type:
perldoc perlfunc
at the command line, and perhaps you'll be able to find a function that
returns the substr()ing of an EXPRession.
Good luck with it!
- Tom
------------------------------
Date: Wed, 20 Sep 2000 08:55:38 -0700
From: pdxJohn <digitalj@uswest.net.remove>
Subject: Re: Parsing incoming mails to launch a script
Message-Id: <B5EE2C0A.25B7%digitalj@uswest.net.remove>
in article 8q9tp5$46v$1@wanadoo.fr, Frank Benady at
f.benady@french-connexion.com wrote on 9/20/00 1:45 AM:
> I tried to do it with procmail but I seems it cannot work together
> with sendmail. Is there a way to do it in perl ?
This is a security feaature in RH linux. Sendmail runs under a special
shell that does not permit launching another executable.
This makes it impossible to use .forward to pipe mail to a script.
But as I recall, procmail is the correct solution. Procmail should simply
be reading the mail queue in the account, and so shouldn't be running under
the same restriction as sendmail.
--
I support the Freedom to Innovate: that's why I use a Mac.
------------------------------
Date: Wed, 20 Sep 2000 16:11:39 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: Parsing incoming mails to launch a script
Message-Id: <%k5y5.38023$XT1.605514@news5.giganews.com>
On Wed, 20 Sep 2000 08:55:38 -0700, pdxJohn <digitalj@uswest.net.remove> wrote:
:
: This is a security feaature in RH linux. Sendmail runs under a special
: shell that does not permit launching another executable.
Actually, I think that it's recent sendmail distributions in general.
--
Nate II
------------------------------
Date: Wed, 20 Sep 2000 15:30:32 GMT
From: esper@news.visi.com (Dave Sherohman)
Subject: passwd manipulation
Message-Id: <slrn8shm0n.ndi.esper@pchan.dojo>
Couple questions on working with *nix passwd files that aren't directly
addressed by the getpwfoo functions:
1) Given a username, it's easy to determine whether it's in use (defined
getpwnam(username)). But what's the preferred way to generate a unique
username based on it? (i.e., "Username joe is in use. WOuld you like to be
joe666 instead?") Repeated getpwnams? Use getpwent to read the entire
passwd file into a hash and search that? Something completely different?
2) Once that unique username is determined, what's the preferred way to
create an account for it? Call the system's adduser? Call the system's
useradd? Update /etc/passwd directly? What about handling shadow passwords
and/or NIS?
Thanks for any suggestions.
--
"Two words: Windows survives." - Craig Mundie, Microsoft senior strategist
"So does syphillis. Good thing we have penicillin." - Matthew Alton
Geek Code 3.1: GCS d- s+: a- C++ UL++$ P+>+++ L+++>++++ E- W--(++) N+ o+
!K w---$ O M- V? PS+ PE Y+ PGP t 5++ X+ R++ tv b+ DI++++ D G e* h+ r++ y+
------------------------------
Date: Wed, 20 Sep 2000 15:20:10 GMT
From: Scott Kirk <undergronk@my-deja.com>
Subject: Re: Perl Shell on Windows NT
Message-Id: <8qakij$qfc$1@nnrp1.deja.com>
In article <8qaj2d$ong$1@nnrp1.deja.com>,
charlie.bursell@healthcare.com wrote:
> I'm not much on Windows, but have recently been forced into it.
Welcome to the club. ;-)
> On Windows NT, it seems that perl runs in a sub-shell and not in the
> active shell window. I note that I cannot redirect the standard
> output of my perl scripts via ">" or "|".
This is a common problem - because CMD.EXE is too stoopid to handle
redirection properly.
> Is there a way to make a perl script in Windows NT run in the current
> shell?
There a few things you can do:
1. Open a file handle from inside the script and output to the
filehandle. You can even output to STDOUT and STDERR.
2. Use pl2bat.bat to convert your Perl script to a batch file. You
can redirect the output from these.
3. Get yourself a different command processor. I hear 4DOS is good,
but I have never used it. I use CYGWIN - and I hear Cygnus have been
acquired by Red Hat.
Cygwin Home Page: http://sources.redhat.com/cygwin/
HTH
--
Scott Kirk
My deja.com mailbox is full of spam. Use this instead:
perl -e '$_ = "znvygb: haqretebax\@lnubb.pbz";
tr/A-Za-z/N-ZA-Mn-za-m/; print;'
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Sep 2000 17:48:38 GMT
From: marcusmills@my-deja.com
Subject: Perl working directory in IIS
Message-Id: <8qat9e$562$1@nnrp1.deja.com>
We are having a problem with the working
directory that PERL is using when being called
from Microsoft IIS4
We have setup the script map as normal and tested
a script in the default website:
====================
print "content-type:text.html\n\n";
print `cd`;
====================
On the default web site we get a correct result
of: 'c:\inetpub\wwwroot\'
but on any other web sites we setup we
get: 'c:\winnt' instead of 'c:\inetpub\www2\'
There don't seem to be any settings for a working
directory any where.
Please help!
Marcus Mills
<marcus.mills@bocc.co.uk>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Sep 2000 15:48:06 +0100
From: John English <je@bton.ac.uk>
Subject: Problem with CGI -- buffered output?
Message-Id: <39C8CE26.15D4293D@bton.ac.uk>
I have a CGI script which takes a while to generate its output.
Running it locally from a command line is fine -- some header
output appears immediately, and further stuff appears as it is
produced. When I look at it with a web browser, it seems to be
buffering the output into fairly large chunks -- when I hit the
submit button on the form that launches it, the browser says
"waiting for reply" and eventually displays the header and the
first wad of results all at once, or times out if it doesn't
generate the results fast enough.
Anyone know why this is, or what I can do to work around it?
I'm just using print to generate the output. I thought about
flushing the standard output explicitly but can't find a way
to do it (tried `sync` but that seemed to have a disastrous
effect!). But since the output is fine from a terminal, it's
presumably a browser or HTTP issue... :-(
-----------------------------------------------------------------
John English | mailto:je@brighton.ac.uk
Senior Lecturer | http://www.it.bton.ac.uk/staff/je
Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS **
University of Brighton | -- see http://burks.bton.ac.uk
-----------------------------------------------------------------
------------------------------
Date: 20 Sep 2000 17:56:23 +0100
From: nobull@mail.com
Subject: Re: Problem with CGI -- buffered output?
Message-Id: <u9g0mvf1e0.fsf@wcl-l.bham.ac.uk>
John English <je@bton.ac.uk> writes:
> I have a CGI script which takes a while to generate its output.
> Running it locally from a command line is fine -- some header
> output appears immediately, and further stuff appears as it is
> produced. When I look at it with a web browser, it seems to be
> buffering the output into fairly large chunks...
> I'm just using print to generate the output. I thought about
> flushing the standard output explicitly but can't find a way
> to do it...
Please consult the FAQ using the keywords "flush" or "unbuffer".
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 20 Sep 2000 17:47:26 GMT
From: mluebke@my-deja.com
Subject: Re: Problems with Mail::Folder and cgi
Message-Id: <8qat76$553$1@nnrp1.deja.com>
Can anybody help here? Im desperate!
In article <8q8rnt$q1e$1@nnrp1.deja.com>,
mluebke@my-deja.com wrote:
> Im trying to write a simple script to parse a
> mail folder and to display the subject lines on a
> web page. The scipt I am pasting below -works-
> when I run it through command line (it does what
> it should), but when run as a CGI script it does
> not. It will print the header and anything I tell
> it to before I start opening the mailbox, then
> quits printing anything at all.
>
> --- begin code ---
>
> #!/usr/bin/perl -w
> use Mail::Folder::Mbox;
> $| = 1;
> print "Content-type: text/html\n\n";
> print "TEST1";
> $folder = new Mail::Folder ('mbox', "foldername");
> print "TEST2";
> $mref = $folder->get_header(1);
> print "TEST3";
> $subj = $mref->get('Subject'); chomp($subj);
> print "TEST4";
> print "$subj";
> $folder->close;
>
> --- end code ---
>
> In the example above, from command line, I'll get
> all the TEST# statements printed, along with the
> subject of email #1 in my mailbox, however from
> the web, I get only TEST1TEST2 as the output.
>
> Any thought?
>
> --
> Matt Luebke
> mluebke@resourcenetworks.com
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Sep 2000 16:02:33 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: Qualifications for new Perl programmer?????
Message-Id: <slrn8sholk.ob.tim@degree.ath.cx>
Brendon Caligari <bcaligari@my-deja.com> wrote:
> In article <9%_w5.18267$a5.260437@news1.rdc1.mb.home.com>,
> andrew-johnson@home.com wrote:
> [snip snip]
>
> > No more so than anyone calling herself a programmer having only
>
> just out of curiosity...why do you always use feminine in
> a gender neutral context?
2 Possible Reasons:
1. It's the current Politically Corrupt way to handle something that
doesn't normally mention women. (which everything _should_ be central
to women, since it's been such a male-dominated society since the
beginning, us men have millions of years to make up for, right?) *j/k*
2. {$title =~ m#Mrs?\.#} Johnson knows something we don't (and we
may not want to).
> My Opinion: Perl is too liberal in it's way of doing things.
> it's too forgiving....the syntax, the types. It makes things
> seem too easy.
I believe Brendon meant this in a teaching context, which I agree with
to a point. I don't believe you must be fluent in defining variables
and able to cast variable types in a scrictly typecast language to be a
good programmer. A programmer is as good as the work he accomplishes.
The robustness of his programming experience (level, scale, pragmatism,
complexity, background knowledge), however, often augments his ability
to pick up new languages more easily.
</Rant>
--
-Tim Hammerquist <timmy@cpan.org>
Quidquid latine dictum sit, altum viditur.
"Whatever is said in latin sounds profound."
------------------------------
Date: 20 Sep 2000 15:42:55 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Question: windows system() crash detection
Message-Id: <slrn8shmlo.5fq.abigail@alexandra.foad.org>
Robert Hooper (hooper@research.att.com) wrote on MMDLXXII September
MCMXCIII in <URL:news:39C29443.BC978BC1@research.att.com>:
:} Here's my problem, I'm running a perl script on a Win98 machine and using sys
:} call another program, repeatedly. Sometimes the other program crashes and a
:} window comes up with a details and cancel button ( we've all seen this window
:} Anyway I don't care that it died, but I do care that its stopped on this wind
:} until I click cancel, I just want it to end and the perl script to continue w
:} intervention. Is there anyway to have perl catch this event and keep going?
Djee, that depends on said program, doesn't it? Does it communicate
anything to the parent process? If not, there isn't much you can do,
save from reading the video memory. Else, listen to your child, and
act on it.
Or just upgrade your OS.
And don't write lines longer than 72 characters, and certainly not
longer than 80.
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: Wed, 20 Sep 2000 16:39:16 GMT
From: Powlow <powlow@my-deja.com>
Subject: Re: reading from a file
Message-Id: <8qap7h$vug$1@nnrp1.deja.com>
wooohh!
a response!
thanks. actually i found out how to do it.
it wasn't a newline character.
i used s/\s+$// to remove the trailing space which funnily enough
didn't work with s/ //g or something similar.
drove me nuts.
-paulo
In article <39c8c9b2.3092504495@news.dircon.co.uk>,
toffer@fake.email.co.uk (Toffer) wrote:
> I would use chop, thusly..
>
> $a = <FILE>;
> chop($a);
>
> Chris
>
> Powlow <powlow@my-deja.com> wrote:
>
> >hey,
> >
> >reading two lines from a text file,
> >
> >open(USERFILE,$namein); # open file for reading # lock file here
$eatit =
> ><USERFILE>; # reads first line of USERFILE into variable $mess =
<USERFILE>;
> > # reads next line of USERFILE into variable close(USERFILE); #
close
> >file
> >
> >$eatit and $mess have what looks to me like a space (in html) or a
newline
> >(in unix shell) as the last character. i've tried doing all sorts of
> >substitutions assuming its a space or a newline. i've also used
chomp. none
> >of these seem to work. am i missing something? is there a way to do
this
> >other than adding a space on the end of what i'm comparing them to?
> >
> >can someone please post something as this is really frustrating and i
can't
> >see any obvious solution, being new to perl. -paulo
> >___________________________ http://powlow.com/
___________________________
> >
> >--
> >___________________________
> > http://powlow.com/
> >___________________________
> >
> >
> >Sent via Deja.com http://www.deja.com/
> >Before you buy.
>
>
--
___________________________
http://powlow.com/
___________________________
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 20 Sep 2000 17:47:27 +0100
From: nobull@mail.com
Subject: Re: reading from a file
Message-Id: <u9hf7bf1sw.fsf@wcl-l.bham.ac.uk>
toffer@fake.email.co.uk (Toffer) writes upsidedown:
> I would use chop, thusly..
Most people would use chomp.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 20 Sep 2000 10:26:50 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Regex Problem
Message-Id: <MPG.1432933752d5f49998ad9a@nntp.hpl.hp.com>
In article <39c86a36.420584@news.grnet.gr> on Wed, 20 Sep 2000 07:47:58
GMT, Philip Lees <pjlees@ics.forthcomingevents.gr> says...
> On Tue, 19 Sep 2000 09:56:46 -0700, Larry Rosler <lr@hpl.hp.com>
> wrote:
...
> >The regex is a good effort, though lacking the requisite end-anchors.
...
> Thanks for the tip about the end-anchors, though I'm not clear about
> why they're necessary in this case. Is the idea to avoid matching,
> say, 3344555, or 3334455?
Yes, or any other stuff on either side, for that matter. The original
poster was less than clear about this requirement, though.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 20 Sep 2000 17:45:30 +0100
From: nobull@mail.com
Subject: Re: Regular expression for variable substitution
Message-Id: <u9lmwnf1w5.fsf@wcl-l.bham.ac.uk>
jb4mt@my-deja.com writes:
> Forgive me for not spending hours searching the documentation (no
> sarcasm intended: sincerely!), as I am under a severe deadline, and I
> am not finding it easy to find information as to how to solve this
> problem, either on CPAN or in the Camel book, 3ed.
It's in the FAQ. It's also been asked and answered in this
newsgroup a couple of times.... per week.... for as long as I've been
reading this group.
That said I don't actually agree with the answer in the FAQ.
> I'm reading in a template file that contains text equivalent to Perl
> variables that are valid in my program; for instance, one line looks
> like this:
>
> <td>$emp_data{entity}-$emp_data{location}</td>
>
> I'm trying to write a regular expression to substitute the value of the
> actual hash entry from my program. I thought the following would work:
>
> $line =~ s/\$$&/^\$.*}$/g;
Gawd! That's so far off I can't imagine what you were thinking.
Please see the answer in FAQ if you want to use s///. You'll have to
adapt it a little to handle subscripts.
Personally I prefer not to re-invent the wheel. The Perl compiler
does variable interpolation already so I'd rather use it:
chop ( $line = eval "<<EOL\n$line\nEOL\n" );
This is safe just so long as you trust the file not to contain
malicious input. If you don't then you can use the Safe module.
Note: this also makes the assumption that $line will not contain the
string "\nEOL\n". You can choose a more obscure string if you prefer.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 20 Sep 2000 09:55:18 -0700
From: Steve Allan <stevea@wrq.com>
Subject: Re: script critique requested
Message-Id: <uhf7bknpl.fsf@wrq.com>
nobull@mail.com writes:
>Steve Allan <stevea@wrq.com> writes:
>
>> Any and all criticism (style, efficiency, etc.) are welcome.
>
>Basically I can't fault it.
>
>The only trivial stylistic matters I can think of are that you use the
>explicit concatenation operator where most Perl hackers would use
>interpolation and you unnecessarily explicitly quote words on the LHS
>of a => fat comma.
Thanks for the feedback. I don't know why I didn't think of using
interpolation instead of '.' - much nicer. I've fixed that in my
script.
Thanks again!
--
-- Steve __
------------------------------
Date: 20 Sep 2000 10:00:24 -0700
From: Steve Allan <stevea@wrq.com>
Subject: Re: script critique requested
Message-Id: <ud7hzknh3.fsf@wrq.com>
tjla@guvfybir.qlaqaf.bet (Gwyn Judd) writes:
>I was shocked! How could Steve Allan <stevea@wrq.com>
>say such a terrible thing:
>>
<snip>
>
>>print ONLYONE $stdout ? "=== $dir1 only ===\n" : '',
>> join "\n", sort @dir1_only, "\n" if @dir1_only;
>>print ONLYTWO $stdout ? "=== $dir2 only ===\n" : '',
>> join "\n", sort @dir2_only, "\n" if @dir2_only;
>
>{
> local ($, , $\) = ("\n" , "\n");
>
> print ONLYONE $stdout ? "=== $dir1 only ===" : '';
> print ONLYONE sort keys %dir1only if %dir1only;
>
> # etc...
>}
>
>One of the rare times where it is correct to use "local".
>
Thanks for all of your feedback. I really like this approach to
printing the lists. I wasn't real thrilled with having to join the
list into a big string just to get newlines. Your method is way
better.
Thanks again.
--
-- Steve __
------------------------------
Date: Wed, 20 Sep 2000 17:20:45 GMT
From: nodo70@my-deja.com
Subject: search a string
Message-Id: <8qarkm$37l$1@nnrp1.deja.com>
What's a good algorithm to search a string and get a next string which
are contained in an array? For instance, if I have an array called
@string = ('cc', '-Xa', 'v', '-o', 'hello', 'hello.c', '-I/include');
and I just want to get a string "hello" right after a string "-o". Do
I have to go through the whole array by index or have better idea just
one line would do? Please advise. Thanks.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Sep 2000 08:19:48 -0700
From: Jim Cook <jcook@strobedata.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39C8D594.3BED08CF@strobedata.com>
> // I believe that a bubble sort algorithm is O(n**2) and an "mean"
> // algorithm is O(n). A power algorithm has O(?), meaning that again I
> // don't know number theory here. However, implementing a bubble sort in
> // perl will be O(n**2) and mean will be O(n), and power will be O(1). That
> // was the point I was trying to make.
>
> I've no idea what you're trying to say here.
I'm saying that power (exponentiation) when implemented on a computer
will test out to be O(1).
--
jcook@strobedata.com Live Honourably 4/1 - 4/3 + 4/5 - 4/7 + . . .
2000 Tuesdays: Feb/last 4/4 6/6 8/8/ 10/10 12/12 9/5 5/9 7/11 11/7 3/14
Strobe Data Inc. home page http://www.strobedata.com
My home page O- http://jcook.net
------------------------------
Date: Wed, 20 Sep 2000 15:45:27 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <sshmsnt8qo7g4d@corp.supernews.com>
In article <39C8D594.3BED08CF@strobedata.com>,
Jim Cook <jcook@strobedata.com> wrote:
: I'm saying that power (exponentiation) when implemented on a computer
: will test out to be O(1).
We'd love to see your implementation.
Greg
------------------------------
Date: 20 Sep 2000 15:06:10 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Time help
Message-Id: <slrn8sgq8d.1gb.trammell@nitz.hep.umn.edu>
On Wed, 20 Sep 2000 14:54:30 +0100, Rui Miguel Venancio
<rui.miguel@srd.alcatel.pt> wrote:
>I need to do the following:
>
>I have one variable with the system date (eg. 20000919 - YYYYMMDD),
>And I have another variable with a date in the future
>(eg: 20001005 - YYYYMMDD).
>
>I want to see a message if the second date have less than 4 weeks of
>the first date !!!!
You're looking for the Date::Calc module and its Delta_Days function.
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: Wed, 20 Sep 2000 10:40:06 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Time help
Message-Id: <39C8DA56.BD235DB@texas.net>
"John J. Trammell" wrote:
>
> On Wed, 20 Sep 2000 14:54:30 +0100, Rui Miguel Venancio
> <rui.miguel@srd.alcatel.pt> wrote:
>
> >I need to do the following:
> >
> >I have one variable with the system date (eg. 20000919 - YYYYMMDD),
> >And I have another variable with a date in the future
> >(eg: 20001005 - YYYYMMDD).
> >
> >I want to see a message if the second date have less than 4 weeks of
> >the first date !!!!
>
> You're looking for the Date::Calc module and its Delta_Days function.
That's overkill. The formatted dates shown are very easily parsed for
input into the timelocal() function.
perldoc Time::Local
- Tom
------------------------------
Date: Wed, 20 Sep 2000 14:03:11 -0400
From: "Dirk Koppers" <nospam@jillanddirk.com>
Subject: translate JavaScript to CGI (read cookie)
Message-Id: <8qau3g$ef4cm$1@ID-39012.news.cis.dfn.de>
I set a cookie using JavaScript and want to keep it like that. It
contains information about images that are selected (like
Name, ID, Path, Extension) I can read the cookie using
JavaScript as follows:
++++++++++++++
function readcookie() {
index = document.cookie.indexOf("lightbox");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
itemstart = i+1;
thisitem = 1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemlist=itemlist+1;
document.write('<table><tr><td>'+theName+'<br'+theID+'<br>
'+thePath+'<br>'+theExtension+'</td></tr></table>');
} else if (fulllist.substring(i,i+1) == '|') {
if (thisitem==1) theName = fulllist.substring(itemstart, i);
if (thisitem==2) theID = fulllist.substring(itemstart, i);
if (thisitem==3) thePath = fulllist.substring(itemstart, i);
if (thisitem==4) theExtension = fulllist.substring(itemstart, i);
thisitem++;
itemstart=i+1;
}
}
}
++++++++++++++++
Now my question:
I want to "translate" this function to read this cookie with
CGI-script. With other words: The table that is created need
to be created with CGI so I need to read the variables from
the cookie with CGI.
Thanks in advance if you can help,
Dirk Koppers
------------------------------
Date: Wed, 20 Sep 2000 16:32:06 GMT
From: potato_salad@my-deja.com
Subject: using awk with perl
Message-Id: <8qaoq6$vi1$1@nnrp1.deja.com>
I am wanting to use this line in a perl CGI script to grab the IP
address of the users machine/firewall. when I run the below command
/usr/local/apache/cgi-bin/printenv | grep REMOTE_ADDR|awk '{print $3}'
it returns > REMOTE_ADDR = 200.200.200.2
I want to cut everything but the 200.200.200.2 using awk. But it does
not work that way.
I am new to perl and any help would be great. Thanks, Yamar.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 20 Sep 2000 17:02:29 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: using awk with perl
Message-Id: <F46y5.7$OM.2128@news1.giganews.com>
potato_salad@my-deja.com <potato_salad@my-deja.com> wrote:
: I am wanting to use this line in a perl CGI script to grab the IP
: address of the users machine/firewall. when I run the below command
:
: /usr/local/apache/cgi-bin/printenv | grep REMOTE_ADDR|awk '{print $3}'
Not to beg the question, but...
What's wrong with just using: print $ENV{REMOTE_ADDR} ?
--
Nate II
------------------------------
Date: Wed, 20 Sep 2000 18:30:06 +0200
From: "FX" <FX@hasnomail.com>
Subject: What's wrong with that regexp?
Message-Id: <8qaoid$f98$1@front1.grolier.fr>
I want to check if a filename, contained in a file, is a valid one.
I don't want then to have \ / : * ? " < > |
So I tried this :
if ($fileName =~ /-?[\x03|\x2f|\x3A|\x2A|\x3F|\x22|\x3C|\x3E|\x7C]$/){
print "bad file name : $fileName";
}
but it's not working....
FX
------------------------------
Date: Wed, 20 Sep 2000 18:35:07 +0200
From: "FX" <FX@hasnomail.com>
Subject: Re: What's wrong with that regexp?
Message-Id: <8qaorp$o85$1@front7.grolier.fr>
Ok forget that question
if ($fileName =~ /[\x03|\x2f|\x3A|\x2A|\x3F|\x22|\x3C|\x3E|\x7C]/){
Works !
I must be sleepy
Sorry again
FX a écrit dans le message <8qaoid$f98$1@front1.grolier.fr>...
>I want to check if a filename, contained in a file, is a valid one.
>I don't want then to have \ / : * ? " < > |
>So I tried this :
>
>if ($fileName =~ /-?[\x03|\x2f|\x3A|\x2A|\x3F|\x22|\x3C|\x3E|\x7C]$/){
> print "bad file name : $fileName";
>}
>
>but it's not working....
>
>
>FX
>
>
------------------------------
Date: Wed, 20 Sep 2000 17:03:52 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: What's wrong with that regexp?
Message-Id: <Y56y5.275386$1h3.5911944@news20.bellglobal.com>
FX <FX@hasnomail.com> wrote:
: I want to check if a filename, contained in a file, is a valid one.
: I don't want then to have \ / : * ? " < > |
: So I tried this :
: if ($fileName =~ /-?[\x03|\x2f|\x3A|\x2A|\x3F|\x22|\x3C|\x3E|\x7C]$/){
: print "bad file name : $fileName";
: }
: but it's not working....
Any reason, exception made of masochism, why you aren't using
print "bad file name: $fileName" if $fileName =~ m#-?[/\\:*?"<>|]$#;
?
You realise that the trailing $ means that you only check if the
file name doesn't end with one of those characters, right? And
the '-?' means that a dash may, or may not be before
this final funny character? And that a | is just a I with the
sharp extremities polished off, i.e., it's just a mundance
character without any special meaning?
I don't know on which OS you are operationg, and what exactly
you deem to be a 'bad' filename, but maybe
print "Hey, '$&' is not a cool character to put here"
if $filename =~ /[^\w.]/;
will make you happy.
Joy,
Yanick
--
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;
------------------------------
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 4387
**************************************