[22856] in Perl-Users-Digest
Perl-Users Digest, Issue: 5077 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 5 03:06:06 2003
Date: Thu, 5 Jun 2003 00:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 5 Jun 2003 Volume: 10 Number: 5077
Today's topics:
checking for files (david)
Re: checking for files <jurgenex@hotmail.com>
Daemon Script n' system() function - for gurus: Randal (Euler)
Help with a list file to tar. <pengtaoli@hotmail.com>
Re: Help with a list file to tar. <jurgenex@hotmail.com>
Re: html parser questions <bigj@kamelfreund.de>
New script (newbie alert) <abuse@sgrail.org>
Re: New script (newbie alert) <bigj@kamelfreund.de>
Re: New script (newbie alert) <jurgenex@hotmail.com>
Re: New script (newbie alert) <abuse@sgrail.org>
Re: Perl Daemon and inittab <goodcall__1@hotmail.com>
Re: perl (Tad McClellan)
Re: Problems with gmtime function on activestate 5.8.0 <kalinabears@hdc.com.au>
Re: Problems with suidperl on AIX, "Can't reswap uid an <persicom@acedsl.com>
Re: Problems with suidperl on AIX, "Can't reswap uid an (David Efflandt)
Re: regex based on numeric value (Tad McClellan)
Re: regex based on numeric value (Tad McClellan)
Re: Regex with numeric evaluation (Rick Ferrante)
Re: Remove first character in a string? <bigj@kamelfreund.de>
Re: Replacing Unsafe HTML Characters <sammie@greatergreen.com>
Re: Replacing Unsafe HTML Characters (Jay Tilton)
Re: Replacing Unsafe HTML Characters <sammie@greatergreen.com>
Re: Replacing Unsafe HTML Characters (Tad McClellan)
Re: Replacing Unsafe HTML Characters <sammie@greatergreen.com>
Re: Replacing users password input with asterisks (Steven Danna)
Re: strange perl behaviour with cgi (Tad McClellan)
Re: strange perl behaviour with cgi (Sam Holden)
Re: use()ing a module by pasting it in code <ubl@schaffhausen.de>
Yabb woes. <someone@microsoft.com>
Re: Yabb woes. <jurgenex@hotmail.com>
Re: Yabb woes. <someone@microsoft.com>
Re: Yabb woes. <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Jun 2003 22:59:18 -0700
From: dwlepage@yahoo.com (david)
Subject: checking for files
Message-Id: <b09a22ae.0306042159.1f4e34de@posting.google.com>
I've got a directory where I want to take a snapshot of the list of
files. I store this list to be checked against later. I want to report
when a file is missing or when a file is added. Could someone point me
in the right direction?
d
------------------------------
Date: Thu, 05 Jun 2003 06:01:48 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: checking for files
Message-Id: <g1BDa.20664$JW6.5401@nwrddc02.gnilink.net>
david wrote:
> I've got a directory where I want to take a snapshot of the list of
> files. I store this list to be checked against later. I want to report
> when a file is missing or when a file is added. Could someone point me
> in the right direction?
perldoc -f opendir
perldoc -f readdir
perldoc -f open
perldoc -f print
And you may also want to check
perldoc -q intersection
"How do I compute the difference of two arrays? How do I compute the
intersection of two arrays?"
in order to compute the difference between your old and your new file list.
jue
------------------------------
Date: 4 Jun 2003 22:00:23 -0700
From: eulerpereira@hotmail.com (Euler)
Subject: Daemon Script n' system() function - for gurus: Randal L. Schwartz, Larry Wall, Joseph N. Hall, and others
Message-Id: <f94db63e.0306042100.2fc2f75e@posting.google.com>
hey folks,
Please helpe-me, i wrote the following script - daemon perl script,
but when i try execute system( 'system_command' ) function from
daemon, the return code ( $? ) from system() is -1. The same happens
when i try use quotation `system_command` or exec( 'system_command' ).
but, the command is executed sucefully!!! What's wrong?
Thanks in advance,
Euler!
=-Code-==-Code-==-Code-==-Code-==-Code-==-Code-==-Code-==-Code-==-Code-=
#!/usr/bin/perl
# -- load modules
use strict;
use IO::File;
use File::Basename;
use Fcntl qw(:flock);
use POSIX qw(setsid WNOHANG);
# -- constants
use constant DEBUG => 0;
use constant NOTICE => 1;
use constant WARNING => 2;
use constant CRITICAL => 3;
use constant PIDPATH => '/var/tmp';
use constant LOGPATH => '/var/log/scripts';
# -- globals
my @desks;
my ($pid, $PRIORITY, $fh);
my $program = basename($0, '.pl');
my $quit = 0; # control the main loop
# -- manipulate traps
$SIG{CHLD} = sub { while ( waitpid(-1, WNOHANG) > 0 ) { ;; } };
$SIG{TERM} = $SIG{INT} = sub { $quit++; };
#-- the program start here --
$fh = open_pid_file("$program.pid");
warn("Starting $program...\n");
$pid = daemon_init();
print($fh "$pid");
close($fh);
init_log("foo.log");
log_debug("Starting...\n");
log_debug("PID: $pid\n");
#--- MAIN LOOP ---
while ( !$quit ) {
#---------------------------------------
if ( !system("ls /tmp") ) {
print("Command Executed!!!\n");
} else {
die("Can't execute command.\n");
}
#---------------------------------------
sleep( 60 );
}
#--- MAIN LOOP ---
# -*- functions -*-
sub daemon_init
{
# process creation
die("Nao foi possivel realizar fork() para o daemon: $program:
$!\n")
unless ( defined(my $child = fork()) );
# exit from initial process
exit( 0 ) if ($child);
# set this process with process leader
setsid();
# reopen descriptors
open(STDIN, "</dev/null");
open(STDOUT, ">/dev/null");
open(STDERR, ">&STDOUT");
chdir('/');
umask(0644);
# set PATH
$ENV{PATH} = '/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin';
# return number of process
return( $$ );
}
sub open_pid_file
{
my $pidfile = PIDPATH . '/' . shift();
if ( -e $pidfile ) {
my $file = IO::File->new($pidfile) || return();
my $pid = <$file>;
die("$program ja esta ativo com PID: $pid\n")
if ( kill(0 => $pid) );
warn("Removendo pidfile: $pidfile do processo <defunct> PID:
$pid\n");
die("Erro ao remover o pidfile: $pidfile do processo <defunct>
PID: $pid\n")
unless ( -w $pidfile && unlink( $pidfile ) );
}
return( IO::File->new($pidfile, O_WRONLY|O_CREAT|O_EXCL, 0644) ) or
die("Nao foi possivel criar/acessar: $pidfile: $!\n");
}
sub init_log
{
my $file = LOGPATH . '/' . shift();
$fh = IO::File->new($file, O_WRONLY|O_APPEND|O_CREAT, 0644) ||
return();
$fh->autoflush(1); # limpa o buffer
$PRIORITY = DEBUG;
# manipulate warn() n' die()
$SIG{__WARN__} = \&log_warn;
$SIG{__DIE__} = \&log_die;
return(1);
}
sub _msg
{
my $priority = shift();
my $time = localtime();
chomp( my $host = `/bin/hostname` );
my $msg = join('', @_) || "Nao ha mensagem para logar";
my ($module, $filename, $line) = caller(1);
$msg .= " $filename,$line.\n" unless ( $msg =~ m/\n$/ );
return("$time $host $program [$priority] $msg");
}
sub _log
{
my $message = shift();
flock($fh, LOCK_EX);
print($fh "$message");
flock($fh, LOCK_UN);
}
sub log_debug
{
return() unless ( DEBUG >= $PRIORITY );
_log(_msg('debug', @_));
}
sub log_notice
{
return() unless ( NOTICE >= $PRIORITY );
_log(_msg('notice', @_));
}
sub log_warn
{
return() unless ( WARNING >= $PRIORITY );
_log(_msg('warning', @_));
}
sub log_die
{
return() unless ( CRITICAL >= $PRIORITY );
_log(_msg('critical', @_));
die(@_);
}
END { unlink ( PIDPATH . '/' . "$program.pid" ) if ( $$ == $pid ); }
=-Code-==-Code-==-Code-==-Code-==-Code-==-Code-==-Code-==-Code-==-Code-=
------------------------------
Date: Thu, 5 Jun 2003 14:13:11 +0800
From: "Franklin Lee" <pengtaoli@hotmail.com>
Subject: Help with a list file to tar.
Message-Id: <bbmn1p$g3i@netnews.proxy.lucent.com>
Hi All,
I have one hash %file and I want to make them to one tar file.
Now I did it as below:
foreach(keys %file)
{
system("tar rvf $tar_file $_");
}
system("gzip $tar_file");
system("mv $tar_file.gz $tar_file");
I'm using Solaris9 and %file maybe is a large files.
So do you have a better idea? Just use one command include pipe to finish
the task. May look like:
system("tar cvf - keys %file| gzip>$final_file"). I tried it, but it doesn't
work.
Thank you in advance!
Franklin
------------------------------
Date: Thu, 05 Jun 2003 06:53:41 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Help with a list file to tar.
Message-Id: <VNBDa.20677$JW6.20211@nwrddc02.gnilink.net>
Franklin Lee wrote:
> Hi All,
>
> I have one hash %file and I want to make them to one tar file.
> Now I did it as below:
> foreach(keys %file)
> {
> system("tar rvf $tar_file $_");
Why don't you do it in Perl? There is a TAR module on CPAN.
> }
> system("gzip $tar_file");
Why don't you do it in Perl? There are several GZIP modules on CPAN.
> system("mv $tar_file.gz $tar_file");
Why don't you do it in Perl? See perldoc -f rename
jue
------------------------------
Date: Thu, 05 Jun 2003 05:00:38 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: html parser questions
Message-Id: <pan.2003.06.05.02.58.29.86939@kamelfreund.de>
j wrote at Wed, 04 Jun 2003 19:48:55 +0000:
> In perldoc, they give the example below to parse the title from an html
> document. Can someone explain what shift->eof if shift eq "title"; does
> in the line marked with ->? What I could use is a code example of a
> start handler that can pass the title text back in the return value.
I would guess that the first argument to the handler routine contains the
currently parsed tag.
If you are only interested in the title tag it is logical to
return unless it's 'title'.
The line marked by you is explained in another part of the perldoc to
HTML::Parser:
Calling $p->eof inside a handler will terminate
parsing at that point and cause $p->parse to return a
FALSE value. This also terminates parsing by
$p->parse_file().
Alltogether (including the line before), the result is that the text of
the title is printed.
> use HTML::Parser ();
>
> sub start_handler
> {
> return if shift ne "title";
> my $self = shift;
> $self->handler(text => sub { print shift }, "dtext");
> -> $self->handler(end => sub { shift->eof if shift eq "title"; },
> "tagname,self");
> }
> }
> my $p = HTML::Parser->new(api_version => 3); $p->handler( start =>
> \&start_handler, "tagname,self"); $p->parse_file(shift || die) ||
> die $!; print "\n";
Greetings,
Janek
------------------------------
Date: Thu, 05 Jun 2003 06:25:54 GMT
From: derek / nul <abuse@sgrail.org>
Subject: New script (newbie alert)
Message-Id: <daotdvkff87nvqnbnoemuba7b19obqistj@4ax.com>
I have written a script to find files using File::Find.
The script will find files like:-
dash9.eng
artengill.s
Reading perlre, perlop, I don't seem to be able to find a right operator like
VB.
I need to be able to find only files ending in eng.
Thanks for any tips.
Derek
#!c:/perl/bin/perl -w
# win32
use warnings;
use strict;
use File::Find;
use File::Copy;
sub wanted;
my @directories = "../../program files/microsoft games/train simulator";
find(\&wanted, @directories);
sub wanted {
# print $_,"\n";
if (/eng/) {
print $_,"\n";
}
}
------------------------------
Date: Thu, 05 Jun 2003 07:17:43 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: New script (newbie alert)
Message-Id: <pan.2003.06.05.05.17.41.274258@kamelfreund.de>
derek / nul wrote at Thu, 05 Jun 2003 06:25:54 +0000:
> I have written a script to find files using File::Find.
>
> The script will find files like:-
>
> dash9.eng
> artengill.s
>
> Reading perlre, perlop, I don't seem to be able to find a right operator
> like VB.
>
> I need to be able to find only files ending in eng.
> [...]
>
> if (/eng/) {
Try
/eng$/
(matching everything that ends on eng)
or
/\.eng/
(matching everything that has .eng in its name)
or
/\.eng$/
combinining both.
Greetings,
Janek
------------------------------
Date: Thu, 05 Jun 2003 06:56:22 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: New script (newbie alert)
Message-Id: <qQBDa.20679$JW6.11023@nwrddc02.gnilink.net>
derek / nul wrote:
> I have written a script to find files using File::Find.
>
> The script will find files like:-
>
> dash9.eng
> artengill.s
>
> Reading perlre, perlop, I don't seem to be able to find a right
> operator like VB.
I don't know what a right operator is but ...
> I need to be able to find only files ending in eng.
... then simply anchor your RE to the end of the string
[...]
> if (/eng/) {
if (/eng$/) {
jue
------------------------------
Date: Thu, 05 Jun 2003 07:00:05 GMT
From: derek / nul <abuse@sgrail.org>
Subject: Re: New script (newbie alert)
Message-Id: <jiqtdvcaift6d75r5gs4g6tpf7khc9f99j@4ax.com>
On Thu, 05 Jun 2003 07:17:43 +0200, "Janek Schleicher" <bigj@kamelfreund.de>
>Try
>/eng$/
>(matching everything that ends on eng)
>or
>/\.eng/
>(matching everything that has .eng in its name)
>or
>/\.eng$/
>combinining both.
>
>
>Greetings,
>Janek
many thanks, the last one would be the safest.
------------------------------
Date: Thu, 05 Jun 2003 03:45:38 GMT
From: "Jack D." <goodcall__1@hotmail.com>
Subject: Re: Perl Daemon and inittab
Message-Id: <C1zDa.11813$MM4.2032736@news0.telusplanet.net>
"Carlton Brown" <carltonbrown@hotmail.com> wrote in message
news:aa611a32.0306040920.34ebd7f7@posting.google.com...
> "Jack D." <goodcall__1@hotmail.com> wrote in message
news:<QlcDa.6348$QF2.1666995@news2.telusplanet.net>...
> > I want to have a program running as a daemon. (Linux RH7.2) So I daemonize
using
> > the subroutine as shown at:
> >
> > http://webreference.com/perl/tutorial/9/3.html
> >
> > I want this running all the time, so I put the perl command as a 'respawn'
in
> > the inittab.
> > 1. Am I doing this wrong?
>
> The solution at the URL you've provided will cause the running daemon
> to have a different PID than what was spawned out of inittab. It is
> not a bad solution, I've used it in the past. But if you put it in
> the inittab, init sees this as a program that exits immediately and
> constantly needs respawning.
>
> The right way to do it? Try your above solution without the
> pid-changing code - don't fork, don't exit, don't setsid. Create a
> signal handler to catch or ignore HUP signals.
And so I finally figured out *after* my post. Isn't that always the case?
>
> This should work from init, but it leaves a minor problem if you run
> it from the command line. If you run it from the command line, you'd
> have to run it in the background if you wanted your prompt back.
> That's because you don't detach from the parent tty if you don't fork.
> Init doesn't run on a tty, so it should work fine there.
What I ended up doing was to add a command-line switch "-D" which will daemonize
the
program. One would only do this if run from a shell prompt. In /etc/inittab
however, I leave the -D
out and everything works as it should.
Thanks to all for the answers to a "not so perlish" question.
Jack
------------------------------
Date: Wed, 4 Jun 2003 21:52:42 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl
Message-Id: <slrnbdtc3q.nvd.tadmc@magna.augustmail.com>
j <john62@electronmail.com> wrote:
> Subject: perl
Please put the subject of your article in the Subject of your article.
> could someone recommend a good book on perl for me?
No, because we do not know what you need, nor what you already have.
Tell what you need and what you already have.
Have you programmed before?
Have you programmed in Perl already and want to learn how to do more?
Want a tutorial? A reference book?
Want to learn more about general Perl stuff, regular expressions?
Modules? Data structures? ...
A different answer to any of those would change the book I'd recommend.
You are not giving us much to work with...
Have you seen the docs about Perl books?
perldoc -q book
perldoc perlbook
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 5 Jun 2003 15:04:31 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: Problems with gmtime function on activestate 5.8.0 version of perl
Message-Id: <3eded081$0$24073@echo-01.iinet.net.au>
"Mothra" <mothra@nowhereatall.com> wrote in message
news:3ede1e54@usenet.ugs.com...
>
> "Mothra" <mothra@nowhereatall.com> wrote in message
> news:3ede170c@usenet.ugs.com...
> > Hi All,
> >
> > I am having problems with the gmtime function on dates before Jan 1
1970.
> > Below you
> > will find a script that uses timegm (from the Time::Local module) and
> gmtime
> > (from default perl installation). This script will run under HPUX 10.20
> > using perl version 5.8.0 but will not run under windows :(
> > what is odd is that the timegm function produces the correct output
> > but to convert back (using gmtime) the script generates this error
>
> After taking another look at this. It seems that perl is using mktime
> File config.vc:
> d_mktime='define'
>
> I checked the microsoft web site on this.
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HT
> ML/_crt_mktime.asp
>
> The most important information is
> If timeptr references a date before midnight, January 1, 1970, or if the
> calendar time cannot be represented, the function returns -1 cast to type
> time_t.
>
> MORONS!!!!
> Why did microsoft do this stupid thing? Now what?
>
> Anyone up to creating a POSIX compliant gmtime() out of whole cloth for
the
> poor
> souls running Win32???
>
>
> Mothra
>
>
I always assumed that localtime() and gmtime() worked back as far as 1900 on
Win32 - but you're right ... they don't.
Someone on ActiveState's perl-win32-users mailing list might have some
advice on this (if there's none forthcoming here).
Cheers,
Rob
------------------------------
Date: Wed, 04 Jun 2003 22:23:50 -0400
From: "Matthew O. Persico" <persicom@acedsl.com>
Subject: Re: Problems with suidperl on AIX, "Can't reswap uid and euid."
Message-Id: <1054779830.619343@nntp.acecape.com>
LOlson wrote:
> I need to get suid PERL scripts working on AIX.
> First, let me say I know suid scripts are "bad" and suidperl is
> deprecated, but we already have a number of PERL scripts that work on
> Linux, Tru64, and SCO and I need to get them working ASAP on AIX as
> well and do not have the time to rewrite them all, and would very much
> like to keep them as portable as they are now.
> I am trying to get PERL 5.6.1 working on AIX 4.3.3 and 5.1, but so far
> I keep getting the "Can't reswap uid and euid." error. There are many
> posts out here about this subject, some claiming that they have gotten
> it working, but I have not found any with a solution that I can make
> work for me, and most seem to refer to much older versions of PERL.
> If anyone knows how to get suid PERL scripts working on AIX please let
> me know.
> Thanks,
> Leif
I am also interested to know how to "fix" this, but for a different
reason. I'm using 5.6.1 on Solaris 2.7. I want to change the group for
the program so that files written by the program are sharable by others
in the group. The login running the scripts is in four groups, but the
one I need is not the default group. I tried to use the 'newgrp' command
before I start the perl script, but that starts a new shell and never
gets to my script.
I tried all the setXgid functions in Perl proper and POSIX, but I never
seem to get the group changed. What am I doing wrong?
Thanks
--
Matt
------------------------------
Date: Thu, 5 Jun 2003 02:44:50 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Problems with suidperl on AIX, "Can't reswap uid and euid."
Message-Id: <slrnbdtbl1.1ub.efflandt@typhoon.xnet.com>
On 4 Jun 2003 14:13:40 -0700, LOlson <lolson@lynx.nisc.cc> wrote:
> I need to get suid PERL scripts working on AIX.
> First, let me say I know suid scripts are "bad" and suidperl is
> deprecated, but we already have a number of PERL scripts that work on
> Linux, Tru64, and SCO and I need to get them working ASAP on AIX as
> well and do not have the time to rewrite them all, and would very much
> like to keep them as portable as they are now.
> I am trying to get PERL 5.6.1 working on AIX 4.3.3 and 5.1, but so far
> I keep getting the "Can't reswap uid and euid." error. There are many
> posts out here about this subject, some claiming that they have gotten
> it working, but I have not found any with a solution that I can make
> work for me, and most seem to refer to much older versions of PERL.
> If anyone knows how to get suid PERL scripts working on AIX please let
> me know.
Reswap sounds like you are trying to swap uid and euid and then swap them
back. Generally you need to do whatever you want to do as euid before
switching to uid. Unless the real uid is root, there is usually no going
back.
--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Wed, 4 Jun 2003 19:57:11 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regex based on numeric value
Message-Id: <slrnbdt5b7.nvd.tadmc@magna.augustmail.com>
Joe Hasting <hasting@agere.com> wrote:
> "Rick Ferrante" <rferrante@tnsi.com> wrote in message
> news:726cd874.0306041033.4438b289@posting.google.com...
>> Given a string like "Level 87.34"
>>
>> Is there a regex that will match if the string is like "Level
>> ([0-9.]+)" and \1 is > 75 ?
> Here is a simple regex approach:
>
> $tmp = "75.75665";
It gives the wrong answer with:
$tmp = "75.75000";
> if ($tmp =~ /\.[7][5-9][0-9]+/ || $tmp =~ /\.[8-9][0-9]+/) { print
^^^^^^
^^^^^^
Don't need to match that stuff.
> ">X.75\n";}
And it will need to be carefully re-crafted when the condition
changes to <= .20, for example.
Treating numbers as strings is most often the road to wasting
great gobs of time.
Use numeric operators for operating on things intended to be numbers.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 4 Jun 2003 20:01:21 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regex based on numeric value
Message-Id: <slrnbdt5j1.nvd.tadmc@magna.augustmail.com>
Rick Ferrante <rferrante@tnsi.com> wrote:
> Given a string like "Level 87.34"
>
> Is there a regex that will match if the string is like "Level
> ([0-9.]+)" and \1 is > 75 ?
Why do you want to do mathematics with string operators?
Perl comes with numeric operators for working with numbers,
use them for your comparisons:
if ($num =~ /(\d+\.\d+)/ and $1 > 75 )
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 4 Jun 2003 20:05:17 -0700
From: rferrante@tnsi.com (Rick Ferrante)
Subject: Re: Regex with numeric evaluation
Message-Id: <726cd874.0306041905.27efea5c@posting.google.com>
Stephen,
That works in general. But in my case, the regex are stored in an
oracle table, and when I try to eval the expression you listed perl
gives me an error saying that it will not do eval code (?{}) in regex
at runtime. (a security feature I guess).
I was looking for this solution because users enter the regex in the
database, so I cannot know what expressions are needed.
Thanks again!
Rick
> if (/Level ([\d.]+) \(threshold ((?>[\d.]+))(??{($1>=$2)? '\)' : '\d'})/)
------------------------------
Date: Thu, 05 Jun 2003 05:08:14 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Remove first character in a string?
Message-Id: <pan.2003.06.05.03.08.12.811059@kamelfreund.de>
Tad McClellan wrote at Tue, 03 Jun 2003 14:51:58 -0500:
>> Nah, that would imply having an opposite to chomp() as well,
>
>
> sub pmohc { # the anti-chomp
> $_[0] .= $/;
$_[0] .= $/ unless $_[0] =~ /\Q$/\E$/;
chomp removes an existing new line,
pmohc should only add a new line unless it exists already :-)
And we should also work for whole an array as chomp does:
for (@_) {
$_ .= $/ unless /\Q$/\E$/;
}
> }
> }
> :-)
:-))
Greetings,
Janek
------------------------------
Date: Thu, 05 Jun 2003 01:08:21 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: Replacing Unsafe HTML Characters
Message-Id: <9KwDa.22546$d51.69921@sccrnsc01>
> my %entities = ( '&' => '&', '<' => '<', '>' => '>' );
> ...
> @htmlparams[1] =~ s/[&<>]/$entities{$&}/e;
> ----
Found my mistake... forgot to add the 'g' modifier:
@htmlparams[1] =~ s/[&<>]/$entities{$&}/eg;
Thanks,
Brad
------------------------------
Date: Thu, 05 Jun 2003 01:10:46 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Replacing Unsafe HTML Characters
Message-Id: <3ede97dd.94674536@news.erols.com>
"Brad Walton" <sammie@greatergreen.com> wrote:
: I am trying to replace unsafe HTML characters with safe ones. The following
: works, but it only replaces the first instance, and I need to replace ALL of
: them. For example, if I had a word:
:
: '<something><somethingmore>'
:
: It would replace the first '<' with '<', but leave everything else
: untouched.
:
: This is the code:
: ----
: my %entities = ( '&' => '&', '<' => '<', '>' => '>' );
: ...
: @htmlparams[1] =~ s/[&<>]/$entities{$&}/e;
: ----
use HTML::Entities qw(encode_entities);
$htmlparams[1] = encode_entities( $htmlparams[1], '&<>' );
------------------------------
Date: Thu, 05 Jun 2003 01:17:07 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: Replacing Unsafe HTML Characters
Message-Id: <nSwDa.867408$Zo.197872@sccrnsc03>
> use HTML::Entities qw(encode_entities);
> $htmlparams[1] = encode_entities( $htmlparams[1], '&<>' );
I could not get that module to install on any of my Perl installations. My
only guess is it doesn't like ActiveState installation for Win32, or nmake.
This has happened to me on a couple of other modules also, notably DBI.
------------------------------
Date: Wed, 4 Jun 2003 22:23:34 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Replacing Unsafe HTML Characters
Message-Id: <slrnbdtdtm.o4d.tadmc@magna.augustmail.com>
Brad Walton <sammie@greatergreen.com> wrote:
> forgot to add the 'g' modifier:
>
> @htmlparams[1] =~ s/[&<>]/$entities{$&}/eg;
^
^
^ You should always enable warnings when developing Perl code.
and forgot to remove the unnecessary 'e' modifier. :-)
The replacement string is "double quotish", and will interpolate
without an eval.
I would consider using explicit memories instead of $&
for maintenance reasons.
$htmlparams[1] =~ s/([&<>])/$entities{$1}/g;
If $htmlparams[1] = 'Tom & Jerry', then it should be output
as 'Tom &amp; Jerry' ?? (that is what your code will do)
Use a module that can Get It Right _for_ you.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 05 Jun 2003 05:13:38 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: Replacing Unsafe HTML Characters
Message-Id: <6kADa.1116030$F1.134951@sccrnsc04>
> I would consider using explicit memories instead of $&
> for maintenance reasons.
>
> $htmlparams[1] =~ s/([&<>])/$entities{$1}/g;
>
>
> If $htmlparams[1] = 'Tom & Jerry', then it should be output
> as 'Tom &amp; Jerry' ?? (that is what your code will do)
>
>
> Use a module that can Get It Right _for_ you.
Good advice! Actually though, this situation will not arise, as I do want it
to be exactly as stored.
------------------------------
Date: 4 Jun 2003 18:45:41 -0700
From: MissingWords@hotmail.com (Steven Danna)
Subject: Re: Replacing users password input with asterisks
Message-Id: <e78d8c5a.0306041745.3db71d45@posting.google.com>
"Sisyphus" <kalinabears@hdc.com.au> wrote in message news:<3ede4887$0
> That doesn't quite work for me - hitting the backspace button once removes
> one asterisk from the screen, but moves the cursor back 2 spaces (not sure
> why that's happening). If I hit the backspace button twice in succession
> things start to look really weird.
> 'print "\b \b";' does however produce the desired result. I would suggest
> changing to that (assuming it also works for you).
That works in the same manner for me, so I took your advice and
changed it. I am still sort of puzzled why they original "\b\0\b" did
not work. I would assume there is a difference between the how the
different shells/OS(I am on WinXP) handle the /0 string....
> Using "\b" instead of "\r" is a much cleaner solution, btw.
Yeah, plus I think it may be marginally faster since you aren't
rewriting the whole line everytime a person backspaced. However, the
speed increase is so small, it would probably be hard to tell without
using very large strings for $password.
> After I posted I started to wonder whether, with some shells, it might still
> be necessary to ReadMode('noecho') ...... don't know ... still wondering :-)
Actually, I _had_ to take ReadMode('noecho') out of the script or it
wouldn't work.
Thanks again for the heads up on the error with my string. It is an
error I never would have seen, since I am not able to test on
different operating systems.
------------------------------
Date: Wed, 4 Jun 2003 22:03:50 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: strange perl behaviour with cgi
Message-Id: <slrnbdtcom.nvd.tadmc@magna.augustmail.com>
Jürgen Exner <jurgenex@hotmail.com> wrote:
> Tassilo v. Parseval wrote:
>> Also sprach Jürgen Exner:
>>> Jes Naulen wrote:
>>
>>>> #!/usr/bin/perl
>>>> print "Content-type: text/html\n\n";
>>>> print $test;
>>>>
>>>> and it starts counting {1,2,3...).
>>> You never define any value for $test.
>> Querying an uninitialized value will result in undef
> Based on your explanation the OPs program should always print the empty
> string because there is no assignment to $test at all.
Right.
> Then why is it being increment as the OP claims?
Because there is something else important going on, but the
OP hasn't told us what it is.
The code above cannot produce the behavior that is described.
Something is missing. Is it the wrong code or is it the wrong description?
<shrug>
My guess is that we are not looking at the "real code".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 Jun 2003 05:45:31 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: strange perl behaviour with cgi
Message-Id: <slrnbdtm7r.lej.sholden@flexal.cs.usyd.edu.au>
On Wed, 04 Jun 2003 21:35:18 GMT, Jürgen Exner <jurgenex@hotmail.com> wrote:
> Tassilo v. Parseval wrote:
>> Also sprach Jürgen Exner:
>>
>>> Jes Naulen wrote:
>>
>>>> #!/usr/bin/perl
>>>> print "Content-type: text/html\n\n";
>>>> print $test;
>>>>
>>>> and it starts counting {1,2,3...). When I open another browser and
>>>> call the script, that brouwser starts counting from 1 again. Here
>>>> too, obviously the variable $test is being remembered between
>>>> browser sessions.
>>>>
>>>> What is wrong (with perl, with apache?) and what can I do about it?
>>>
>>> You never define any value for $test. That is very bad programming
>>> style. Therefore perl is correct when it prints some random value.
>>
>> Perhaps from an educational standpoint correct. But it's not what
>> actually happens. Querying an uninitialized value will result in undef
>> which depending on the actual context (numerical or stringish) results
>> in 0 or "". Perl wont ever return a 'random' value, unlike C for
>> instance.
>
> Well, in that case things don't fit together at all.
> Based on your explanation the OPs program should always print the empty
> string because there is no assignment to $test at all.
> Then why is it being increment as the OP claims?
Because the OP is either lieing about the code, or is completely
misunderstanding what their code is actually doing.
I suspect the second. In fact I suspect it isn't CGI at all, but is in fact
mod_perl and somewhere else $test is being incremented. There's obviously
a $test++ somewhere, but the OP has decided not to bother showing that bit...
--
Sam Holden
------------------------------
Date: Thu, 05 Jun 2003 08:31:59 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: use()ing a module by pasting it in code
Message-Id: <bbmr9h$qs5$1@news.dtag.de>
Vlad Tepes wrote:
>>Alfonso <piz_dek@yahoo.com.au> wrote:
>>
>>I heard that use A is the same as pasting in the code
>>of the module, but I can't get that to work.
>
>
> What you've heard was not correct. Try
>
> perl -MCPAN -e 'install PAR'
>
> instead
This is not a commercial newsgroup. Please place your ads on msn.com.
:)
------------------------------
Date: Wed, 4 Jun 2003 19:20:56 -0700
From: "john smith" <someone@microsoft.com>
Subject: Yabb woes.
Message-Id: <bbm99d$518$1@bob.news.rcn.net>
I just installed a Yabb board on my computer and I can't get it to work to
save my life.
If I try to register a user or even log in with the admin account it just
says an error has occurred- you should fill out a username. This is as far
as I can get, everything else so far appears to be working.
The FAQ address listed in the instructions is dead and I have no idea what's
causing the error.
Can anybody help me?
Brief thanks in advance.. More later = )
------------------------------
Date: Thu, 05 Jun 2003 04:13:35 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Yabb woes.
Message-Id: <PrzDa.46276$da1.41565@nwrddc03.gnilink.net>
john smith wrote:
> I just installed a Yabb board on my computer and I can't get it to
> work to save my life.
And your Perl question/issue/contribution/discussion/note/... is exactly
what?
jue
------------------------------
Date: Wed, 4 Jun 2003 22:14:03 -0700
From: "john smith" <someone@microsoft.com>
Subject: Re: Yabb woes.
Message-Id: <bbmjdu$soj$1@bob.news.rcn.net>
Yabb is a perl board.
I just figured someone here might know what line in the script of whatever
file would cause such an error and be so good as to tell me.
I couldn't find a Yabb newsgroup, so perl was my best shot.
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:PrzDa.46276$da1.41565@nwrddc03.gnilink.net...
> john smith wrote:
> > I just installed a Yabb board on my computer and I can't get it to
> > work to save my life.
>
> And your Perl question/issue/contribution/discussion/note/... is exactly
> what?
>
> jue
>
>
------------------------------
Date: Thu, 05 Jun 2003 06:06:22 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Yabb woes.
Message-Id: <y5BDa.20665$JW6.18517@nwrddc02.gnilink.net>
[Joepardectomy performed; please do not top post]
john smith wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:PrzDa.46276$da1.41565@nwrddc03.gnilink.net...
>> john smith wrote:
>>> I just installed a Yabb board on my computer and I can't get it to
>>> work to save my life.
>>
>> And your Perl question/issue/contribution/discussion/note/... is
>> exactly what?
>
> Yabb is a perl board.
Well, I know what a motherboard is. I am familiar with keyboards. I have
some experience with a board of directors. But what is a perl board?
> I just figured someone here might know what line in the script of
> whatever file would cause such an error and be so good as to tell me.
>
> I couldn't find a Yabb newsgroup, so perl was my best shot.
Well, I hope someone else knows what you are talking about
jue
------------------------------
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 5077
***************************************