[12299] in Perl-Users-Digest
Perl-Users Digest, Issue: 5899 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 5 15:07:20 1999
Date: Sat, 5 Jun 99 12:00:19 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 5 Jun 1999 Volume: 8 Number: 5899
Today's topics:
A poor man's perl shell <elliotsl@mindspring.com>
Re: A poor man's perl shell (Randal L. Schwartz)
Re: Copying any files <Alar@mtk.ut.ee>
Re: Dating service script needed -matchmaker script (Lee)
Re: extract only characters from string? <gellyfish@gellyfish.com>
Re: extract only characters from string? <uri@sysarch.com>
Re: how do i fucking run perl w32 <aperrin@mcmahon.qal.berkeley.edu>
Re: how do i fucking run perl w32 (Larry Rosler)
I'm looking for some virgin men, send me a message and (Jen Balcmon)
Re: Issuing remote commands without Telnet... <rootbeer@redcat.com>
Re: know Perl to maintain Perl (was: Re: I pass an arra <jdf@pobox.com>
Need help with script <rx@rxlist.com>
Re: Perl and Scheduling Tasks <jdf@pobox.com>
Re: perl script to munge <rootbeer@redcat.com>
Re: perl script to munge <gellyfish@gellyfish.com>
Re: Perl, Y2K, and idiots <cassell@mail.cor.epa.gov>
Re: return code problem <rootbeer@redcat.com>
Re: simple sendmail question (Michael Budash)
Re: Sorting Multidimensional Lists <cassell@mail.cor.epa.gov>
split strings <mpajot@club-internet.fr>
Re: split strings <rootbeer@redcat.com>
Re: whats wrong with this script? (Lee)
Re: whats wrong with this script? (Tad McClellan)
Re: whats wrong with this script? (Cybernetic Bear)
Re: whats wrong with this script? <root@insecurity.org>
Re: whats wrong with this script? <rootbeer@redcat.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 05 Jun 1999 13:05:51 -0400
From: Steven Elliott <elliotsl@mindspring.com>
Subject: A poor man's perl shell
Message-Id: <375958EF.788FD751@mindspring.com>
Just for my own amusement I wrote a VERY simple perl shell that consists
of a script that prints a prompt and runs perl:
----------------
#!/bin/bash
while :
do
echo -n "perl>"
perl
done
----------------
You use it by typing whatever terminated with a ctrl-D. It really just
spares you having to type the "perl -e ''".
If left running in an xterm it comes in handy for doing things that the
shell utilities seem unwilling to do such as deleting files with really
weird characters in them:
perl> unlink '-\^@#$'
Although I have heard of perl shells I have not looked into them so I
don't know how this compares (probably not very well).
Anyway, I just thought I'd post it as it struck me as something falls
into that interesting/surprisingly-easy-todo category.
-Steve
------------------------------
Date: 05 Jun 1999 11:43:42 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: A poor man's perl shell
Message-Id: <m11zfqpjxd.fsf@halfdome.holdit.com>
>>>>> "Steven" == Steven Elliott <elliotsl@mindspring.com> writes:
Steven> Although I have heard of perl shells I have not looked into them so I
Steven> don't know how this compares (probably not very well).
Steven> Anyway, I just thought I'd post it as it struck me as something falls
Steven> into that interesting/surprisingly-easy-todo category.
It's even easier when you simply type:
perl -debug
at the prompt. Then you get the Perl debugger in interactive mode,
on a program that consists solely of
"bug";
But no biggy, you aren't running it anyway. :)
print "Just another Perl hacker,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Sat, 5 Jun 1999 19:34:47 +0300
From: "Alar Pandis" <Alar@mtk.ut.ee>
Subject: Re: Copying any files
Message-Id: <7jbjk0$enl$1@kadri.ut.ee>
Hi and thanks for You patient!
# KAT is directory and FAIL is file; ARHKAT is dest. dir.
open LXHFILE, "<$kat$fail";
copy LXHFILE, $arhkat.$fail || print $!."-".$arhkat.$fail;
close LXHFILE;
== No such file or directory.
If both of files opened then same result (one for reading, othe for
writing).
If just
copy $kat.$fail, $arhkat.$fail;
it works, but binary files is corrupted and timestamps etc. is wrong. Result
is the same if I just open and then writing (print).
Alar.
------------------------------
Date: Sat, 05 Jun 1999 11:40:09 -0500
From: rlb@intrinsix.ca (Lee)
Subject: Re: Dating service script needed -matchmaker script
Message-Id: <B37EBD199668161490@204.112.166.88>
In article <7jasv8$3ki$1@gellyfish.btinternet.com>,
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>> And just about anything you can think of that would be needed in
>> something like this.
>>
>
>Hmmm.
I was thinking of doing it for free...
if (babe() or wealthy() && generous()) {
mailme($phone, $address)
}
Lee
------------------------------
Date: 5 Jun 1999 17:49:58 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: extract only characters from string?
Message-Id: <7jbo06$4jo$1@gellyfish.btinternet.com>
On 02 Jun 1999 00:06:09 -0400 Uri Guttman wrote:
>
> and have you actually tried anything yourself after reading a goo perl
> book,
Ooo we like a 'goo perl' book - is that like 'Perl 5 for Dummies' ;-}
/J\
--
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 05 Jun 1999 13:47:58 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: extract only characters from string?
Message-Id: <x7n1ye8rox.fsf@home.sysarch.com>
>>>>> "JS" == Jonathan Stowe <gellyfish@gellyfish.com> writes:
JS> On 02 Jun 1999 00:06:09 -0400 Uri Guttman wrote:
>>
>> and have you actually tried anything yourself after reading a goo perl
>> book,
JS> Ooo we like a 'goo perl' book - is that like 'Perl 5 for Dummies' ;-}
i meant to say a gooey perl book, like learning perl/tk.
:-)
say hello to mrs. gellyfish. i hope she likes being called that.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Sat, 05 Jun 1999 10:05:42 -0700
From: Andrew J Perrin <aperrin@mcmahon.qal.berkeley.edu>
Subject: Re: how do i fucking run perl w32
Message-Id: <375958E6.34DA4FF5@mcmahon.qal.berkeley.edu>
Amusing you should ask in this way; sort of depends on the position of the
implied commas:
'How do I, (while) fucking, run perl w32?'
Alas, this is not something I've attempted, although unless your sex life
is rather dull the
'at' command might prove more useful than anything else;
'How do I *^%$(*&^% run perl w32?'
As in, s/\*\^\%\$\(\*\&\^\%/$expletive/;
It's particularly amusing because, in my experience, folks who ask questions
like these consider manipulation of the mouse-button akin to a sexual
experience. You have two choices:
1.) Learn to type, open a DOS window, and type 'perl <scriptname>'; or
2.) Insert, at the end of each script, the following code:
print 'Press enter to close the window: ';
scalar <STDIN>;
ap
Marler wrote:
> i just got ActivePerl517. when i run any of the sample scripts, the dos
> window opens quickly then closes. i don't know what the programs do or how
> to run my own programs. can somebody help me please.
>
> sincerely,
> stephen marler
--
-------------------------------------------------------------
Andrew J. Perrin - NT/Unix/Access Consulting - (650)938-4740
aperrin@mcmahon.qal.berkeley.edu (Remove the Junk Mail King)
http://www.geocities.com/SiliconValley/Grid/7544/
-------------------------------------------------------------
------------------------------
Date: Sat, 5 Jun 1999 10:59:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: how do i fucking run perl w32
Message-Id: <MPG.11c30546df49bf42989b75@nntp.hpl.hp.com>
In article <375958E6.34DA4FF5@mcmahon.qal.berkeley.edu> on Sat, 05 Jun
1999 10:05:42 -0700, Andrew J Perrin <aperrin@mcmahon.qal.berkeley.edu>
says...
,,,
> 'How do I *^%$(*&^% run perl w32?'
> As in, s/\*\^\%\$\(\*\&\^\%/$expletive/;
More colloquially,
'How do I *^%$(*&^% run perl w32?'
As in, s/\Q*^%$(*&^%/$expletive/;
:-)
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 5 Jun 1999 18:23:38 GMT
From: joey@hecnyyvr.com (Jen Balcmon)
Subject: I'm looking for some virgin men, send me a message and what you're in to.
Message-Id: <7jbpva$nea$6@newsfeed.smartt.com>
I'm looking for some virgin men, send me a message and what you're in to.
------------------------------
Date: Sat, 5 Jun 1999 09:40:42 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Issuing remote commands without Telnet...
Message-Id: <Pine.GSO.4.02A.9906050937120.16860-100000@user2.teleport.com>
On Sat, 5 Jun 1999, Thurley wrote:
> I need to issue commands on my ISPs servers to "make" Perl modules
> etc. The problem is that they don't support Telnet. Is there any way
> around this? Can I make the modules without Telnet?
Not simply. If switching ISPs isn't a possibility, you should probably
arrange for a system administrator to make the modules and install them in
their standard locations for everyone to use. Most sysadmins can be
bribed, often for the cost of a little pizza and beer. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 05 Jun 1999 13:23:05 -0400
From: Jonathan Feinberg <jdf@pobox.com>
To: tchrist@mox.perl.com (Tom Christiansen)
Subject: Re: know Perl to maintain Perl (was: Re: I pass an array...)
Message-Id: <m3909yimti.fsf@joshua.panix.com>
Tom Christiansen <tchrist@mox.perl.com> writes:
> It is curious, too, that a man who is offended by the use of the
> word "multifaceted" or "energumen" is perfectly capable of
> expressing in a sentence of death-defying mechanical complexity.
Is there a word or phrase missing from that sentence?
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sat, 05 Jun 1999 10:24:37 -0700
From: "Neil Sandow, Pharm.D." <rx@rxlist.com>
Subject: Need help with script
Message-Id: <37595D54.6986B07D@rxlist.com>
The following script is supposed to compare a file (word3.txt)
containing one word per line with all
html files in a directory and replace matching words with an <a href /
javascript tag. The script seems to
process each file as it should and it seems to be reading the text file
as it takes quite a while to run, but
it is not replacing any of the matching words.
Also, the javascript <script> is being inserted at the top of the html
file rather than within the <head> </head> sections.
Any help in making the script work would be greatly appreciated!
-Neil
rx@rxlist.com
====================script
below=========================================
#!/usr/bin/perl
#This program searches thru the current directory
#for all files ending in html or htm and creates
#a link for every word that exists in the html
#file that is also in the wordsfile below
#This program will also create a backup of each
#file in the same directory with the extension .bak
#if desired.
##Config Section##############################
$VERBOSE = 1;
$SAVEBACKUP = 1;
$wordsfile = "word3.txt";
##############################################
-e $wordsfile || die "You need to edit this script and put in a proper
wordsfile!";
open(W,"$wordsfile");
$wordkount = @wordlist = <W>;
close W;
chomp @wordlist;
$SAVEBACKUP && $VERBOSE && print "Saving Backups while processing.\n";
opendir DIR, ".";
while ($thisfile = readdir(DIR)) {
if ($thisfile =~ /\.htm[l]?$/) {
$kount++;
$VERBOSE && print "$kount Processing $thisfile...\n";
open (H,"$thisfile");
$linekount = @lines = <H>;
close H;
open (NEWH,">$thisfile");
$SAVEBACKUP && open (BCK,">$thisfile.bak");
&printJavaScript();
foreach $line (@lines) {
$SAVEBACKUP && print BCK "$line";
foreach $word (@wordlist) {
$line =~ s/[\n ]$word[\n., ]/ <a
href=javascript:defwindow('$word')>$word<\/a> /;
}
print NEWH "$line";
}
close NEWH;
$SAVEBACKUP && close BCK;
}
}
$VERBOSE && print "Done!";
sub printJavaScript() {
print NEWH <<'EOSCRIPT';
<SCRIPT LANGUAGE="JavaScript">
<!--
function defwindow (id) {
window.onerror = null;
url = "http://www.rxlist.com/popupdef.pl?" + id;
window.open
(url,"Definition","width=500,height=330,screenX=100,screenY=100,alwaysRaised=yes,toolbar=no,scrollbars=yes,resize=yes");
}
//-->
</SCRIPT>
EOSCRIPT
}
------------------------------
Date: 05 Jun 1999 13:26:55 -0400
From: Jonathan Feinberg <jdf@pobox.com>
To: tchrist@mox.perl.com (Tom Christiansen)
Subject: Re: Perl and Scheduling Tasks
Message-Id: <m36752imn4.fsf@joshua.panix.com>
Tom Christiansen <tchrist@mox.perl.com> writes:
> [courtesy cc of this posting mailed to cited author]
>
> In comp.lang.perl.misc, "Jalil Feghhi" <jalil@corp.home.net> writes:
> :Is there any support for doing task scheduling in Perl for win32?
>
> Win32 has tasks?
Oh yes, as long as you don't mind that the administrator must choose a
single user or pseudo-user whose permissions and identity are assumed
by all scheduled jobs. Duhhhhhh.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sat, 5 Jun 1999 09:35:02 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: perl script to munge
Message-Id: <Pine.GSO.4.02A.9906050934450.16860-100000@user2.teleport.com>
On Sat, 5 Jun 1999 cmeli@cis.um.edu.mt wrote:
> Is there any ready-made perl script to munge all or particular emails
> within a text file (e.g. a mailing list digest which is going to be
> automatically posted to usenet) ?
If you're wishing merely to _find_ (as opposed to write) programs,
this newsgroup may not be the best resource for you. There are many
freeware and shareware archives which you can find by searching Yahoo
or a similar service. Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 5 Jun 1999 15:50:29 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: perl script to munge
Message-Id: <7jbh05$4jd$1@gellyfish.btinternet.com>
On Sat, 05 Jun 1999 12:51:57 GMT cmeli@cis.um.edu.mt wrote:
> Is there any ready-made perl script to munge all or particular
> emails within a text file (e.g. a mailing list digest which is going to
> be automatically posted to usenet) ?
>
I'm not quite sure what you mean.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 05 Jun 1999 11:19:24 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: Kristina <kristina@greatbasin.net>
Subject: Re: Perl, Y2K, and idiots
Message-Id: <37596A2C.AE8287F9@mail.cor.epa.gov>
Kristina wrote:
>
> On 1 Jun 1999, UUCP wrote:
>
> > From: fl_aggie@thepentagon.com (I R A Aggie)
> >
> > If that's how you feel...then go to you favorite bookstore that stocks
> > O'Reilly books, pick up the Llama book (Learning Perl, Schwartz and
> > Christiansen) and read the Foreward. If my memory is correct, Larry
> > Wall states something akin to: learn what you need to of perl. A
> > knowledge of a subset that accomplishes what you need accomplished
> > is adequate.
>
> <grin!> I have, I think, the first or second edition of _Learning Perl_.
Me too. Tim O'Reilly has *way* too much of my pocket change.
> Actually, that may be one of the problems of script archive authors. We
> write a script waaaaaay back when, and it seems to work and accomplish
> what we need it to. Bug reports eventually slow down to "I'm getting
> Server Error 500," which is almost always fixed by re-uploading in ascii
> or making sure that the shebang line is correct and at the top of the
> file, so we forget to go back and update them to use, say, Perl 5 features
> or even add checks for file openability or pipe closes, etc.
This isn't A Bad Thing if your code was good to start with.
After all, there are Larry Wall and Tom Christiansen scripts
floating around (even in this ng) which were written for
Perl4.. or Perl 3.. or... But they still work. And just
because they don't have cute new features doesn't make them
wrong.
> It's very easy to become complacent.
Especially when your script does what it's supposed to. Who
should ask for more?
> > Just remember that when you ask for clarification on something you
> > should phrase your question like this: The docs say that if I use
> > X on Y, I should get Z, but I get A instead. Why? here's my code
> > snippet that demonstrates my dilema...
>
> Actually, the "justify my existence" thing was referring to the
> anger against "script archive" authors like Matt Wright and (to a
> far lesser extent since my archive isn't that well-known) me, but your
> point is well taken.
Well, the problem that people here have with Matt Wright's
programs is not that they were written with an older Perl
in mind, but that they have actual errors and bad things in
them. Someone here a couple weeks ago was asking about Matt's
formmail [IIRC] script, and when one of the regulars looked
he found that the script had some serious flaws including
a major Y2K bug just waiting to happen because the author
hadn't understood the output of localtime().
Code that works most of the time is okay if that's all you
need, but when you're writing CGI scripts for public use,
they need to work with probability one. I.e., good defensive
programming to handle errors and unexpected conditions.
> > + Anyone have a URL for good Perl programming style over and above where one
> > + should put the whitespace and the curly brackets?
> >
> > 'perldoc perlstyle'??
>
> Yup, that's a good one. Just haven't ... errr ... necessarily applied
> it to all the things I should. <blush!> Working on it, though...
I find that my Perl programming style has improved more from
reading the Wall/Christiansen/Schwartz books [the camel & llama
& ram] than any other source. Second best source for me:
reading this newsgroup [which I have been doing for far longer
than I have been posting answers].
BTW, if this doesn't sound too clueless, where is *your*
script archive?
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Sat, 5 Jun 1999 09:31:07 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: return code problem
Message-Id: <Pine.GSO.4.02A.9906050922580.16860-100000@user2.teleport.com>
On Sat, 5 Jun 1999, Robert Chung wrote:
> I run many things such as `Command1 | Command2 | Command3`. Problem
> is, I need to find return codes from individual commands, ie return
> code from Command1, return code from Command2, and return code from
> Command3. Obviously, just taking a look at $? does not work. To make
> matter worse, I do things like "eval 'somecommandX &' ; eval
> 'somecommandY &';".
I don't think you mean eval there. Maybe you mean exec? But you want
system.... :-)
> somecommandX and somecommandY will terminate at unknown time in
> future, and I need to capture their individual return codes also. Is
> there any absolute way to do it?
You probably want a parent process to wait() for those child processes to
die. If your main process has gone on to bigger and better things, this
parent process will need to communicate with it via a method from the
perlipc manpage.
Of course, for this to work, you'll need to do all of that piping (I/O
redirection) yourself. Any good book on advanced Unix programming should
cover the techniques of making pipes and duping file descriptors
(filehandles), though.
As for the background processes, although the "double fork" technique is
usually recommended, that would discard the exit code. So you'll need to
keep their parent process around, too, until they're all reaped. That
could (should) be the same parent process you use for the other processes.
Or you might implement some of those program's tasks from within Perl,
avoid calling the external program, and discover that your process is
faster as a result. Hey, it could happen! :-)
Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sat, 05 Jun 1999 09:03:36 -0700
From: mbudash@trantracks.com (Michael Budash)
Subject: Re: simple sendmail question
Message-Id: <mbudash-0506990903360001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>
In article <7jbfbh$1am$2@fir.prod.itd.earthlink.net>,
sowmaster@juicepigs.com (Bob Trieger) wrote:
>
>"James Verrill" <james.verrill@cwcom.net> wrote:
>>Using sendmail is it possinle to send a file as an attachment?
>>If so, how?
>
>
>You accidentally sent this to a perl newsgroup instead of a mail one.
yeah, well...
try MIME::Lite, or if you like to roll your own, read up up on
"Content-Type: multipart/mixed" ... it'll do the trick
good luck!
--
| Michael Budash Consulting | 707-252-7670 |
| Perl, Javascript, PHP, MySQL | (603) 250-8679 fax |
| Official Extropia Developer | mbudash@sonic.net |
------------------------------
Date: Sat, 05 Jun 1999 11:04:51 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Sorting Multidimensional Lists
Message-Id: <375966C3.6EC32E74@mail.cor.epa.gov>
follansb@real.com wrote:
>
> Hi,
>
> I'm trying to sort an array of arrays, and I want to sort the array of
> arrays by column 2 (index number 1) alphabetically. I've tried this:
>
> @sortarrays = sort (@sortarrays);
>
> This moves the row that should be first to the top position, but doesn't
> affect any other row. Nothing else seems to work.
>
> Any ideas?
rootbeer already reffed the FAQ and the perlfunc section on sort().
You might also take a look at the perllol page (via man or
perldoc or whatever). It specifically covers working with an
array of arrays, so you'll probably gain some useful insights
there.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Sat, 5 Jun 1999 18:36:30 +0200
From: "Kevin" <mpajot@club-internet.fr>
Subject: split strings
Message-Id: <7jbjfj$72t$1@front5m.grolier.fr>
Hi all,
I just want to split a string on the "space" ((...)=split(/ /, $string,2)),
but there is a problem when 2 paces follows themselves ("toto toto toto"
for exemple).
What can I do to truncate the string from 2 spaces into 1 space (my problem
is I have to get the date under UNIX with $date=localtime; but when the day
number is <10, there are 2 spaces
ex:
Sat Jun 5 (2 spaces)
Sat Jun 10 (1 space)
)
Is there any function which deals with that ?
Sorry for my bad english
Regards,
Sylvain
------------------------------
Date: Sat, 5 Jun 1999 09:47:44 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: split strings
Message-Id: <Pine.GSO.4.02A.9906050943320.16860-100000@user2.teleport.com>
On Sat, 5 Jun 1999, Kevin wrote:
> I just want to split a string on the "space" ((...)=split(/ /, $string,2)),
> but there is a problem when 2 paces follows themselves ("toto toto toto"
> for exemple).
> What can I do to truncate the string from 2 spaces into 1 space
You could make a pattern which matches all consecutive whitespace chars as
a single chunk: /\s+/ . Or you may want to use the special argument ' '
for the pattern; see the perlfunc manpage's entry on split.
> (my problem is I have to get the date under UNIX with $date=localtime;
> but when the day number is <10, there are 2 spaces
Maybe you really want the individual time/date items, which you can get if
you use localtime in a list context. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sat, 05 Jun 1999 11:29:36 -0500
From: rlb@intrinsix.ca (Lee)
Subject: Re: whats wrong with this script?
Message-Id: <B37EBAA09668157FD7@204.112.166.88>
In article <375935b5.72289229@news.istar.ca>,
cybear_x-nospam@geocities.com (Cybernetic Bear) wrote:
>I am trying to limit access to a script by IP address. My gameplan is
>to compare the IP of the user to a hosts.allow file. if it matches,
>the rest of the script runs, if it doesn't match, a die() gets called
>and the script ends.
>
>my code to check the IP is:
>$iphost= $ENV{'REMOTE_ADDR'}; #read in IP address of remote host
>open (HOSTFILE, "<$docroot./hosts.allow");#read in hosts.allow file
>@ipallow=<HOSTFILE>;
>close (HOSTFILE);
>$deny=1;
>print "$iphost";
>foreach $ip (@ipallow){ #compare host IP with hosts.allow
chomp($ip); # remove newline char
> if ($iphost == $ip) {$deny=0;}
> print "$iphost $ip $deny<br>";
>}
>print $deny;
>if ($deny == 1){print ("We will kill script");}
>else {print"allow script: $iphost";}
This and the other hints in the thread should have you up and running.
Lee
------------------------------
Date: Sat, 5 Jun 1999 08:12:33 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: whats wrong with this script?
Message-Id: <h74bj7.m2l.ln@magna.metronet.com>
Cybernetic Bear (cybear_x-nospam@geocities.com) wrote:
: if $iphost = 192.168.0.1 and $ip = 192.168.0.1
: then shouldn't $iphost==$ip be true?
Yes. But only for the specific case that you have given
there. Comparing strings as numbers is a very fragile thing
to do.
So just don't do it :-)
: and following that logic, it shouldn't matter where I get the ip
: values from, as long as they match, the above should work, but it
: doesn't appear to.
Test numbers for numeric equality with ==.
Test strings for string equality with eq.
If you convert the IPs to numbers, _then_ you can use ==,
but eq will work fine as-is, so why bother?
----------------
#!/usr/bin/perl -w
use strict;
my $iphost = 192.168.0.1;
print "iphost '$iphost'\n";
my $ip = 192.168.0.1;
print "ip '$ip'\n";
----------------
output:
iphost '192.1680.1'
ip '192.1680.1'
my $iphost = 192.168.0.1;
can be rewritten:
my $iphost = 192.168 . 0.1; # perl DWIMs both numbers to strings
# then concatenates the 2 strings
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 05 Jun 1999 18:05:08 GMT
From: cybear_x-nospam@geocities.com (Cybernetic Bear)
Subject: Re: whats wrong with this script?
Message-Id: <37596683.84785785@news.istar.ca>
OK, but how does one check the status of the open file? can read in
the data ok, so I assume that the file opens ok.
I checked the Perl FAQ, and Perl Quick Reference (the only resources I
have available) and this answer isn't in them.
Dave
On Sat, 05 Jun 1999 15:43:22 GMT, sowmaster@juicepigs.com (Bob
Trieger) wrote:
>[ courtesy cc sent by mail if address not munged ]
>
>cybear_x-nospam@geocities.com (Cybernetic Bear) wrote:
>>I am trying to limit access to a script by IP address. My gameplan is
>>to compare the IP of the user to a hosts.allow file. if it matches,
>>the rest of the script runs, if it doesn't match, a die() gets called
>>and the script ends.
>>
>>my code to check the IP is:
>>$iphost= $ENV{'REMOTE_ADDR'}; #read in IP address of remote host
>>open (HOSTFILE, "<$docroot./hosts.allow");#read in hosts.allow file
>
>I bet if you were checking the status of your open that a major problem
>in this program would stick out like a sore thumb.
>
------------------------------
Date: Sat, 05 Jun 1999 14:17:28 -0400
From: Sneex <root@insecurity.org>
Subject: Re: whats wrong with this script?
Message-Id: <375969AA.CAD3A422@insecurity.org>
Cybernetic Bear wrote:
> I don't need to account for anyone behind a proxy as I am limiting the
> script to only a few IP's on the same C class as the server that is
> running the script.
>
> if $iphost = 192.168.0.1 and $ip = 192.168.0.1
> then shouldn't $iphost==$ip be true?
>
> and following that logic, it shouldn't matter where I get the ip
> values from, as long as they match, the above should work, but it
> doesn't appear to.
>
> Dave
>
> On Sat, 05 Jun 1999 11:12:03 -0400, "Bill Jones" <bill@fccj.org>
> wrote:
>
> >In article <375935b5.72289229@news.istar.ca>, cybear_x-nospam@geocities.com
> >(Cybernetic Bear) wrote:
> >
> >
> >> open (HOSTFILE, "<$docroot./hosts.allow");#read in hosts.allow file
> >
> >Didn't check for failure - lookup $!
> >
> >> print "$iphost $ip $deny<br>";
> >
> >If this is a CGI, you should lookup correct CGI.pm usage...
> >
> >I think you have a logic error...
Still doesn't account for NAT and Ip Masquarding...
Still didn't answer/address my other suggestions...
-Sneex-
__________________
"Yes, it's me; I am without 'Net today :("
------------------------------
Date: Sat, 5 Jun 1999 11:32:07 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: whats wrong with this script?
Message-Id: <Pine.GSO.4.02A.9906051123440.463-100000@user2.teleport.com>
On Sat, 5 Jun 1999, Cybernetic Bear wrote:
> >>open (HOSTFILE, "<$docroot./hosts.allow");#read in hosts.allow file
> OK, but how does one check the status of the open file?
It's the return value from open(). The traditional (but not the only) way
to do this is with 'or die':
open HOSTFILE, "<$docroot./hosts.allow"
or die "Can't open '$docroot./hosts.allow' for read: $!";
This error message includes the three most valuable pieces of information:
the name of the file you tried to open, how you were trying to open it
(for read), and the system's reason why that didn't work (from $!,
something like "file not found" or "permission denied", often). And, as a
bonus, since the die message doesn't end with a newline, perl will throw
in something like "at yourprog.perl line 1234", which you'll probably also
want.
If for whatever reason die() isn't suitable, you can handle the error in
any way you choose:
unless (open HOSTFILE, 'whatever') { ...whatever you need... }
Have fun with Perl!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5899
**************************************