[19588] in Perl-Users-Digest
Perl-Users Digest, Issue: 1783 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 20 18:05:38 2001
Date: Thu, 20 Sep 2001 15:05:10 -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: <1001023509-v10-i1783@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 20 Sep 2001 Volume: 10 Number: 1783
Today's topics:
A couple of Win9x Perl questions <DrDebug@att.net>
Re: Creating a file <clay@panix.com>
Re: Creating a file <please@no.spam>
Deleting variables (shaz)
Dream Login Script <lmoran@wtsg.com>
Re: Hash problem... <guardian@chello.be>
Re: Hash problem... (Randal L. Schwartz)
Re: Hash problem... <mikesl@wrq.com>
How to pass hashes to function as parameter? <hmarson@attglobal.net>
Re: How to pass hashes to function as parameter? <tex@lager.engsoc.carleton.ca>
Re: How to pass hashes to function as parameter? <dtweed@acm.org>
Re: How to pass hashes to function as parameter? <jeff@vpservices.com>
Re: How to pass hashes to function as parameter? <hmarson@attglobal.net>
Re: How to recomple regular expression ? <bart.lateur@skynet.be>
Re: html 2 xml <dave@nospam.stratumonline.com.del>
Re: Interrupted Server Socket Connections (Lyle Goldman)
Net::DNS doesn't work when trying to query a nameserver <Usenet@bNamed.be>
Re: only allowing characters from a list to be inputed <gnarinn@hotmail.com>
Re: pattern matcher for embedded seperators. <ychandra@cisco.com>
Re: pattern matcher for embedded seperators. <ychandra@cisco.com>
Re: Perl Compiler <mischief@velma.motion.net>
Re: Perl English only?????? <mischief@velma.motion.net>
Re: Perl English only?????? <weiss@kung.foo.at>
Re: Perl English only?????? <lmoran@wtsg.com>
Processing page between two other pages. (Justin)
Re: Reading cookies from a different path <iltzu@sci.invalid>
Re: s/// modifies @_ ? <pilsl_@goldfisch.at>
Re: Schwartzian Transform problem <matthew.garrish@sympatico.ca>
search, replace, functions, text wrapping (hard questio (Richard Lawrence)
Re: Unusual error message... <philip@zaynar.demon.co.uk>
Re: Unusual error message... <iltzu@sci.invalid>
Re: Use symbol table like 'real' hash <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 20 Sep 2001 21:34:42 GMT
From: "DrDebug" <DrDebug@att.net>
Subject: A couple of Win9x Perl questions
Message-Id: <Shtq7.3248$W8.294619@bgtnsc04-news.ops.worldnet.att.net>
Hi all--
A couple of Perl/Win9x questions, if I may:
1) Is there a way, via a Perl script, to discover the CPU speed
in MHz?
2) Is there a way, via a Perl script, to reboot a Win9x machine?
I have done a cursory search on CPAN, especially the Win32 modules,
but nothing popped into focus... I also searched for a manual
Win9x command line command to reboot, but again, could not find
one. Everything is so damned GUI based.
Perhaps I am missing something obvious, but if anyone has a clue,
could you please chime in?
By the way, the machines I am working on are Win98 and WinMe machines,
not WinNT or Win2000 (which did have some help in that area on CPAN).
Thanks!
------------------------------
Date: 20 Sep 2001 19:52:58 GMT
From: Clay Irving <clay@panix.com>
Subject: Re: Creating a file
Message-Id: <slrn9qkiau.57t.clay@panix1.panix.com>
In article <9od8pg$lor$1@cyan.nl.gxn.net>, Rogier wrote:
> Change open(FILE, ">> $file") || die....
> The >> is important
How so? Maybe the person didn't want to append to an existing file.
--
Clay Irving <clay@panix.com>
Kansas:
First Of The Rectangle States
------------------------------
Date: Thu, 20 Sep 2001 20:18:07 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: Creating a file
Message-Id: <87g09hehzc.fsf@homer.cghm>
"Rogier" <rogier@arpadrive-in.com> writes:
> Lorimer <djdjokic@yahoo.com> schreef in berichtnieuws
> a18e5d95.0109200913.688a8c90@posting.google.com...
>
> > Here is the problem: I want to open a file if exist and if it is
> > not exist then I want to create it and then open for writting in
> > it. Opening existing one is not a problem but how to create new
> > one.
> >
> > open (FILE, "> $file") || die "Could not open $!"; print FILE
> > 'nesto'; close (FILE);
> >
> > And I am getting this message
> >
> > Could not open No such file or directory at line 650
> >
> > if there is no such file
> >
> > Can someone help?
>
> Change open(FILE, ">> $file") || die.... The >> is important
No it isn't. "> $file" should create the file. It must be either
that the string $file is empty, or the directory that the the file is
in does not exist. If it were a permission problem the error would be
permission denied. The only difference between ">" and ">>" is that
">" will use O_TRUNC, truncating the file to zero bytes.
------------------------------
Date: 20 Sep 2001 12:28:46 -0700
From: ssa1701@yahoo.co.uk (shaz)
Subject: Deleting variables
Message-Id: <23e71812.0109201128.bd7c2af@posting.google.com>
$look = (<NN>)
I have no difficulty with this part of the code.
while (/(\w+)($look)/g)
{
$store{$1}++;
delete @store{@list};
}
@list contains words that I do not want added to @store.
What I need help on is the code below.
$look = (<NN>)
while (/(\w+)($look)\s(?=(\w+)($look))/g)
{
$words = $1 $2;
$store{$words}++;
delete @store{@list};
}
Because the variable $words contains two words, how would I delete it
from @store if ONE or BOTH of the words are in @list?
------------------------------
Date: Thu, 20 Sep 2001 16:29:07 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Dream Login Script
Message-Id: <fuikqt0lqt8dlspt43s7ibjqmhn96he4i2@4ax.com>
I am currently using a standard batch file for my NT/Win9X user login
scripts. It does the following:
Maps H:\
Sets the Host file for webserver access for internal users
Renames games from .exe to .old to befuddle my users
Set the time
We have a mix of Win9x and NT/2000 machines which creates the problem
of not being able to use the %username% variable to set (map) a home
directory. Currently users get mapped to Home and then need to find
their login name to save files. If I had all NT users or used KiXart
I could accomplish this.
I wish I had a script that did the following:
Win 9X or NT/2000?
Who just logged in?
Memeber of which groups?
Map H:\Server\Group\Username
Set Word, Excel & Powerpoint save directories to above
Grab the current AnitVirus file and place in Local directory
Set Hosts file
Get and Set time
I am thinking Perl. I have loaded it on every set in the domain. My
main uses for Perl are for reading logs & making reports. I never do
anything "interesting" like DBI or CGI with Perl and have exactly 1
script that has user input. (My laptop users get a script that asks
them Are you IN or OUT of the office? and sets their host file
accordingly.) Which is to say I'm no Perl guru.
What I need help with here is:
Is Perl a good fit for this?
What modules will I need?
Any sites to see? Books to buy? (I own Programming Per, Learning
Perl on W32, Cookbook and Elements of Programming with Perl (thank you
A Johnson))
thanks
--
TMTOWTDI: My way tends to be wrong...
lmoran@wtsg.com
------------------------------
Date: Thu, 20 Sep 2001 18:06:41 GMT
From: "GuaRDiaN" <guardian@chello.be>
Subject: Re: Hash problem...
Message-Id: <Reqq7.864$2a.50487@news.chello.be>
Many thanks ;o)
Just one more question ;o)
Could you give me some interresting url's about perl ?
Just found one or two which were very usefull.
"Randal L. Schwartz" <merlyn@stonehenge.com> a écrit dans le message de
news: m1r8t1bw1y.fsf@halfdome.holdit.com...
> >>>>> "GuaRDiaN" == GuaRDiaN <guardian@chello.be> writes:
>
> Please stop top-posting! Google here for "jeopardy posting" to see
> why.
>
> GuaRDiaN> Any idea how I could store something like that ?
>
> Yes. Move it down one level. Never make a hash element try
> to do double duty as a reference and as a value.
>
> Change:
>
> [ broken code ]
> if ( $event1 = "killed" ) {
> $$player_name{kills}++; # Player kills
> $$player_name{kills}{victim}{$player_name2}++;
> $$player_name{kills}{weapon}{$noun2}++;
> $$player_name2{death}++; # Player death
> $$player_name2{death}{killer}{$player_name}++;
> $$player_name2{death}{weapon}{$noun2}++;
> }
>
> to
>
> if ( $event1 = "killed" ) {
> $$player_name{kills}{count}++; # Player kills
> $$player_name{kills}{victim}{$player_name2}++;
> $$player_name{kills}{weapon}{$noun2}++;
> $$player_name2{death}{count}++; # Player death
> $$player_name2{death}{killer}{$player_name}++;
> $$player_name2{death}{weapon}{$noun2}++;
> }
>
> Notice that $$player_name{kills} is now always a reference. Never
> a data.
>
> print "Just another Perl hacker,"
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
------------------------------
Date: 20 Sep 2001 11:25:28 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Hash problem...
Message-Id: <m1zo7pafdz.fsf@halfdome.holdit.com>
>>>>> "GuaRDiaN" == GuaRDiaN <guardian@chello.be> writes:
GuaRDiaN> Many thanks ;o)
GuaRDiaN> Just one more question ;o)
GuaRDiaN> Could you give me some interresting url's about perl ?
GuaRDiaN> Just found one or two which were very usefull.
PLEASE STOP TOP-POSTING. DO I NEED TO SCREAM IT FOR YOU TO HEAR IT?
Sheesh.
www.perl.org has many good links.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 20 Sep 2001 18:48:37 GMT
From: Michael Slass <mikesl@wrq.com>
Subject: Re: Hash problem...
Message-Id: <m3adzpwvei.fsf@thneed.na.wrq.com>
merlyn@stonehenge.com (Randal L. Schwartz) writes:
>>>>>> "GuaRDiaN" == GuaRDiaN <guardian@chello.be> writes:
>
>GuaRDiaN> Many thanks ;o)
>GuaRDiaN> Just one more question ;o)
>GuaRDiaN> Could you give me some interresting url's about perl ?
>GuaRDiaN> Just found one or two which were very usefull.
>
>PLEASE STOP TOP-POSTING. DO I NEED TO SCREAM IT FOR YOU TO HEAR IT?
>Sheesh.
>
>www.perl.org has many good links.
>
>--
>Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
><merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
>Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
>See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Perahps the OP, clearly not a native english speaker, did not
recognize the "Top-Posting" idiom.
-Mike
------------------------------
Date: Thu, 20 Sep 2001 19:32:52 +0100
From: Hamish Marson <hmarson@attglobal.net>
Subject: How to pass hashes to function as parameter?
Message-Id: <3BAA3653.E0563F4C@attglobal.net>
OK. I"m having problems here and I just can't work out why... Probbaly
blindingly obvious but...
I can't seem to pass a has as a parameter to a function... I have a
scalar & a hash I want to pass to a function... e.g.
$result = myfunction($value, %hash);
and want the function to be able to manipulate something base don the
scalar & the hash...
But I can't seem to get the hash in the funcion being called... The best
I seem to be able to manage is to access the first element of the hash
keys... IN fact if I drop it back to
$result = myfunction(%hash);
then I still can't seem to get a has at the function... I've got the
Perl CD bookshelf, but it seems to be utterly devoid of ANY examples of
how to pass a has as a parameter to a fucntion & retrieve it within the
function for use...
Any hints here?
TIA
--
I don't suffer from Insanity...
I enjoy every minute of it...
------------------------------
Date: 20 Sep 2001 18:45:21 GMT
From: "Clayton L. Scott" <tex@lager.engsoc.carleton.ca>
Subject: Re: How to pass hashes to function as parameter?
Message-Id: <9oddg1$56s$1@bertrand.ccs.carleton.ca>
Hamish Marson <hmarson@attglobal.net> wrote:
> OK. I"m having problems here and I just can't work out why... Probbaly
> blindingly obvious but...
> I can't seem to pass a has as a parameter to a function... I have a
> scalar & a hash I want to pass to a function... e.g.
> $result = myfunction($value, %hash);
sub myfunction {
my $value = shift;
my %hash = @_;
}
What is happening is that the hash gets flattened into a list and put into
@_ with the rest of your function parameters.
So you can coerce a list or array with and even number of elements (i.e.
one key per value) into a hash by assignment as above.
You may want to consider passing the hash by reference if you want there to be more parameters after the hash:
$result = myfunction($value, \%hash, $otherval);
sub myfunction {
my $value = shift;
my $hash_ref = shift;
my $otherval = shift;
}
Clayton
------------------------------
Date: Thu, 20 Sep 2001 18:51:43 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: How to pass hashes to function as parameter?
Message-Id: <3BAA3980.15E93207@acm.org>
Hamish Marson wrote:
> I can't seem to pass a has as a parameter to a function... I have a
> scalar & a hash I want to pass to a function... e.g.
There are two ways, depending on whether you want to be able to modify
the hash inside the function and have the changes persist after the
function returns.
> $result = myfunction($value, %hash);
sub myfunction {
my ($value, %copy_of_hash) = @_;
# ...
my $foo = $copy_of_hash{$value};
}
This takes apart the original hash, flattening it into a list of key,
value pairs, and then uses that list to build a replica hash inside
the subroutine. Any changes made to %copy_of_hash will be discarded
once the subroutine returns.
Alternatively, you can pass a reference to the original hash. Changes
made inside the subroutine affect the caller's hash directly.
$result = myfunction ($value, \%hash);
sub myfunction {
my ($value, $hashref) = @_;
# ...
my $foo = $hashref->{$value};
}
Note the difference in how you refer to the hash inside the subroutine.
"perldoc perlref" for all the details.
-- Dave Tweed
------------------------------
Date: Thu, 20 Sep 2001 12:04:39 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: How to pass hashes to function as parameter?
Message-Id: <3BAA3DC7.1179B154@vpservices.com>
Hamish Marson wrote:
>
> OK. I"m having problems here and I just can't work out why... Probbaly
> blindingly obvious but...
>
> I can't seem to pass a has as a parameter to a function... I have a
> scalar & a hash I want to pass to a function... e.g.
>
> $result = myfunction($value, %hash);
Pass the hash as a reference and then dereference it in the function:
my $value = 'foo';
my %hash = ( a=> 'bar', b=>'baz' );
my $result = func($value,\%hash);
print $result;
sub func {
my($value,$hashref) = @_;
return $value . $hashref->{a} . $hashref->{b};
# OR INSTEAD OF THAT LINE, THESE TWO:
my %hash = %{ $hashref };
return $value . $hash{a} . $hash{b};
}
__END__
--
Jeff
------------------------------
Date: Thu, 20 Sep 2001 21:55:13 +0100
From: Hamish Marson <hmarson@attglobal.net>
Subject: Re: How to pass hashes to function as parameter?
Message-Id: <3BAA57B0.A27C84F8@attglobal.net>
"Clayton L. Scott" wrote:
> Hamish Marson <hmarson@attglobal.net> wrote:
>
> > OK. I"m having problems here and I just can't work out why... Probbaly
> > blindingly obvious but...
>
> > I can't seem to pass a has as a parameter to a function... I have a
> > scalar & a hash I want to pass to a function... e.g.
>
> > $result = myfunction($value, %hash);
>
> sub myfunction {
> my $value = shift;
> my %hash = @_;
> }
Thanks... It was a stupid mistake... I had $_ instead of @_
It still took me re-reading this 20 times to spot it...
H
--
I don't suffer from Insanity...
I enjoy every minute of it...
------------------------------
Date: Thu, 20 Sep 2001 21:29:47 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How to recomple regular expression ?
Message-Id: <qinkqt89o07okurmk2dmlguaq2shdi6ucp@4ax.com>
<addady@hotmail.com> wrote:
>Here is a small program that demonstrate the problem:
>
>$template="aaaabcdaaa";
>for($i=1;$i<=5;$i++){
>print $i."\n";
>eval {
>$template =~ s/abcd/$i/;
>};
>print "This is template: $template \n---------------------\n";
Urm, you misunderstood your problem. Once you do your substitution, your
template is modified. the string "abcd" is no longer there.
>eval {
>$template =~ s/abcd/$i/;
>};
This does NOT recompile anything. You need to eval STRING then, noteval
BLOCK. So this would recompile the code:
eval <<'END';
$template =~ s/abcd/$i/;
END
But there's even no need to recompile anything. Substitution on the RHS
works fine with variables, as long as you use a COPY of your template,
leaving the template itself intact.
$template="aaaabcdaaa";
for($i=1;$i<=5;$i++){
print $i."\n";
(my $text = $template) =~ s/abcd/$i/; # modify the copy
print "This is the result: $text \n---------------------\n";
}
BTW the regex is the part on the left. You only need recompilation if it
contains variables that are changed, and you used the /o option.
--
Bart.
------------------------------
Date: Thu, 20 Sep 2001 21:11:10 GMT
From: "Dave Palmer" <dave@nospam.stratumonline.com.del>
Subject: Re: html 2 xml
Message-Id: <OXsq7.938$Rj.385239@news1.rdc1.md.home.com>
"Chris Fedde" <cfedde@fedde.littleton.co.us> wrote in message
news:QENp7.512$Owe.288877056@news.frii.net...
> I like to procss most of my HTML through tidy before doing anything with
it
> using a perl script http://www.w3.org/People/Raggett/tidy/ If your goal
is
> just a conversion to well formed XHTML then tidy is just what you want.
>
> Good Luck
Thanks, Tidy does the trick perfectly using output-xhtml option
./dave
------------------------------
Date: 20 Sep 2001 14:35:20 -0700
From: Lyle_Goldman@ibi.com (Lyle Goldman)
Subject: Re: Interrupted Server Socket Connections
Message-Id: <ed639144.0109201335.34c76aee@posting.google.com>
So nobody has ANY idea?
- Lyle Goldman
Lyle_Goldman@ibi.com (Lyle Goldman) wrote in message news:<ed639144.0109170810.38da4e66@posting.google.com>...
> -
> Hello. I am trying to write a client-server system using sockets. In the
> code that I have written, the client reads lines of text from standard input and
> sends them to the server, which prints the lines to standard output. Under
> normal situations, it work fine. However, when I interrupt the server process,
> the client does not realize that the server has disconnected until it sends
> two (not one, but two!) more lines of output. Why is this happening, and how
> can I detect when the connection has closed sooner?
>
> The code follows. I am running under Solaris 5.6. Thank you for any help
> you can provide me.
>
>
> Here is the server code (testserver.pl):
>
> #!/usr/local/bin/perl -w
> use strict;
>
> use sigtrap;
> use Socket;
>
> $SIG{PIPE} = sub { die "Broken Pipe.\n"; };
>
> $| = 1;
>
> my $port = $ARGV[0] || 2345;
> socket SERVER, PF_INET, SOCK_STREAM, getprotobyname 'tcp' or die "socket: $!";
> setsockopt SERVER, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)
> or die "setsockopt: $!";
> bind SERVER, sockaddr_in($port, INADDR_ANY) or die "bind: $!";
> listen SERVER, SOMAXCONN or die "listen: $!";
>
> my $paddr;
> while($paddr = accept CLIENT, SERVER) {
> my ($port, $iaddr) = sockaddr_in($paddr);
> my $name = gethostbyaddr($iaddr, AF_INET);
>
> while(<CLIENT>) {
> print;
> };
>
> close CLIENT;
> };
>
> --------------------------------------------------------------------------------
>
> Here is the client code (testclient.pl):
>
> #!/usr/local/bin/perl -w
> use strict;
>
> use sigtrap;
> use Socket;
>
> my ($remote, $port, $iaddr, $paddr);
>
> $SIG{PIPE} = sub { die "Broken Pipe.\n"; };
>
> $remote = shift || 'localhost';
> $port = shift || 2345; # random port
> $port =~ /\D/ and $port = getservbyname($port, 'tcp');
> die "No port" unless $port;
> $iaddr = inet_aton($remote) or die "No host: $remote";
> $paddr = sockaddr_in($port, $iaddr);
>
> socket SOCKET, PF_INET, SOCK_STREAM, getprotobyname 'tcp' or die "socket: $!";
> connect SOCKET, $paddr or die "connect: $!";
> select SOCKET;
> $| = 1;
> select STDOUT;
>
> while(<STDIN>) {
> print SOCKET or die "print: $!";
> }
>
> close SOCKET or die "close: $!";
>
> --------------------------------------------------------------------------------
>
> - Lyle Goldman
------------------------------
Date: Thu, 20 Sep 2001 18:51:26 GMT
From: Bart Mortelmans <Usenet@bNamed.be>
Subject: Net::DNS doesn't work when trying to query a nameserver by domain and not by IP-address
Message-Id: <3BAA3A5E.3040903@bNamed.be>
Greetings,
I've got this small script that does a NSLookup. It uses Net::DNS, I run
it on a Windows2000-machine. It works 100% in my own test-machine, but
it will only work on my providers machine if I provide the IP-address of
the nameserver I want to query and not the domainname.
A query for ns1.mydomain.com won't work at my provider, but will work on
my own computer, a query for 216.34.13.236 works on both computers.
I know I could work around this by performing an A-record lookup on a
standard nameserver (of which I hardcode the IP-address) for every
nameserver I want to query, but I hope there's a faster and nicer solution.
Is there some parameter that should be set so Net::DNS knows how to
resolve ns1.mydomain.com into 216.34.13.236 automaticly? My test-machine
has got its own nameserver (port 127.0.0.1, if you want...), the machine
at my provider doesn't. Is there some way I can point Net::DNS to an
other location for this?
I tried the script both within ASP and in a .pl-file. Within .pl I don't
get an error (I don't get anything...), within ASP I get this error:
===
Invoking main::NSLookup error '80004005'
Can't use an undefined value as a symbol reference at
C:/perl/lib/IO/Select.pm line 60.
/nslookupok2.asp, line 0 error '80004005'
Unspecified error
/nslookupok2.asp, line 95
===
My code:
========
sub NSLookup {
my ($domain, $server, $question) = @_;
my $socket;
my $res;
my $answer = ' ';
my $vAnd = ' ';
$res = new Net::DNS::Resolver;
$res->nameservers($server);
$socket = $res->bgsend($domain, $question);
if(IO::Select->new( $socket )->can_read( 5 )) {
my $packet = $res->bgread($socket);
if($packet) {
foreach my $rr ($packet->answer) {
$answer .= $vAnd . $rr->rdatastr;
$vAnd = ';';
}
}
}
$answer;
}
#my $server = 'ns1.mydomain.com'; #This won't work at Vibus
my $server = '216.34.13.236'; #This will work on both computers
my @Uitvoer = NSLookup("bim.be", $server, "NS");
print $q->p(@Uitvoer[0]);
===
Thanks for any extra info!
Sincerely,
Bart Mortelmans
------------------------------
Date: Thu, 20 Sep 2001 19:39:43 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: only allowing characters from a list to be inputed
Message-Id: <1001014783.683608592953533.gnarinn@hotmail.com>
"Kiaya" <kiaya_halilah@yahoo.com> wrote in message
news:e5340dbc.0109190706.f59ab28@posting.google.com...
> We have a cgi form that inputs to a pipe-delimited file. We want to
> prevent people from inputing symbols, hard returns, etc. which mess up
> the flat file. We tried using:
>
> elsif ($email !~ /A-Za-z,.\;'\/\@\-_/) {
> $field="E-mail";
> $character="E-mail";
> &error;
> exit(0);
> }
>
> But this is not working. Any ideas? We only want to allow A-Z a-z , .
> ; / @ - _ We should probably allow parenthesis also. Thanks, Kiaya
others have mentioned the email validation issues, but if you still
want an answer to your question, then you forgot to create an character
class with [], and either anchor it at both ends (after adding a * or +)
or put the negation inthe class instead of the test.
if you want $x to only contain characters A-Z then
if ($x !~ /^[A-Z]+$/) {# does not only contain allowed chars }
or
if ($x =~ /[^A-Z]/) {# does contain a non-allowed char}
gnari
------------------------------
Date: Thu, 20 Sep 2001 12:07:46 -0700
From: Chandra Yemparala <ychandra@cisco.com>
Subject: Re: pattern matcher for embedded seperators.
Message-Id: <3BAA3E82.6065AAB6@cisco.com>
An example of the string is
<Hosts:<host1><host2><host3>>
The check will reject any format other than this one.
I tried this /<[^<]*(?:<[^>]*>){4}>/, but it fails.
^^^^^^
Can you tell me what this does <[^<]* in the above line.
thanks
chandra
David Hilsee wrote:
> "Chandra Yemparala" <ychandra@cisco.com> wrote in message
> news:3BA932A2.F78D731A@cisco.com...
> > Is there a way to write pattern matcher for the following pattern:
> >
> > <x:<a><b><c><d>>
> >
> > x,a,b,c,d are going to some value. I want to check if a line is
> > according to this format.
> >
> > I wrote up something like this - if( $line =~ /(<.*>){5}/ ) to check for
> > five <..>, but this is stopping at <c>,
> > I guess it is taking <x:<a> as one set.
> >
> > thx
> > chandra
> >
>
> Your code suggests that the angle brackets are the only thing significant in
> the regular expression. That is, <<><><><>> would be considered valid. If
> so, then this would work:
>
> /<[^<]*(?:<[^>]*>){4}>/
>
> I think it would be good if you clarified what the input data can and can't
> be. If there must be values, then the quantifiers should probably be + and
> not *. Perhaps you also want to match the colon. Is whitespace to be
> ignored? How many embedded tagged items can there be? It's hard to write
> code without knowing these things (mine amounts to a random guess).
>
> By the way, the camel book has an example for matching balanced parenthesis
> that could possibly be modified to help you here. Again, that depends on
> what the input data can be.
>
> --
> David Hilsee
------------------------------
Date: Thu, 20 Sep 2001 12:32:29 -0700
From: Chandra Yemparala <ychandra@cisco.com>
Subject: Re: pattern matcher for embedded seperators.
Message-Id: <3BAA444D.4CC32A55@cisco.com>
oops! I am sorry. This one works
/<[^<]*(?:<[^>]*>){4}>/,
But can you tell me how it works? the pattern matcher looks complex!
Thanks a lot
chandra
Chandra Yemparala wrote:
> An example of the string is
> <Hosts:<host1><host2><host3>>
>
> The check will reject any format other than this one.
>
> I tried this /<[^<]*(?:<[^>]*>){4}>/, but it fails.
> ^^^^^^
> Can you tell me what this does <[^<]* in the above line.
>
> thanks
> chandra
> David Hilsee wrote:
>
> > "Chandra Yemparala" <ychandra@cisco.com> wrote in message
> > news:3BA932A2.F78D731A@cisco.com...
> > > Is there a way to write pattern matcher for the following pattern:
> > >
> > > <x:<a><b><c><d>>
> > >
> > > x,a,b,c,d are going to some value. I want to check if a line is
> > > according to this format.
> > >
> > > I wrote up something like this - if( $line =~ /(<.*>){5}/ ) to check for
> > > five <..>, but this is stopping at <c>,
> > > I guess it is taking <x:<a> as one set.
> > >
> > > thx
> > > chandra
> > >
> >
> > Your code suggests that the angle brackets are the only thing significant in
> > the regular expression. That is, <<><><><>> would be considered valid. If
> > so, then this would work:
> >
> > /<[^<]*(?:<[^>]*>){4}>/
> >
> > I think it would be good if you clarified what the input data can and can't
> > be. If there must be values, then the quantifiers should probably be + and
> > not *. Perhaps you also want to match the colon. Is whitespace to be
> > ignored? How many embedded tagged items can there be? It's hard to write
> > code without knowing these things (mine amounts to a random guess).
> >
> > By the way, the camel book has an example for matching balanced parenthesis
> > that could possibly be modified to help you here. Again, that depends on
> > what the input data can be.
> >
> > --
> > David Hilsee
------------------------------
Date: Thu, 20 Sep 2001 20:07:47 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Perl Compiler
Message-Id: <tqkj4j4to0rd20@corp.supernews.com>
eDeveloper <webmaster@kwakeb.net> wrote:
> Hi
> I heared that there is a compilers for a perl ?
Did you really? That's great! There's actually more than one. perlcc has some problems
and perl2exe has some others.
> is there a graphical compiler for perl for Linux ? or Windows?
...But Perl is not a graphical language. It's based on a text grammar.
Chris
--
If they can get you asking the wrong questions, they don't
have to worry about the answers.
-- Thomas Pynchon, Gravity's Rainbow
------------------------------
Date: Thu, 20 Sep 2001 19:53:21 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Perl English only??????
Message-Id: <tqki9hkrbkjl6d@corp.supernews.com>
Damian Conway <damian@cs.monash.edu.au> wrote:
> "Anonymoose" <nospam@newsranger.com> wrote in
>>> Is Perl written in one language based? Like are all the strings in
>>> English, or say if you are German do you write the strings in German.
> There's also:
> http://search.cpan.org/search?dist=Lingua-Romana-Perligata
> so you can program in Latin, and the forthcoming
> Lingua::tlhInganHol::yIghun -- so you can program in Klingon.
So you can write Perl programs in two mostly dead langauges? Is Sanskrit next? ;-)
What has creating 'Lingua-Romana-Perligata' pointed out to you, Damian, that
would be good to share with the rest of us?
Chris
--
If they can get you asking the wrong questions, they don't
have to worry about the answers.
-- Thomas Pynchon, Gravity's Rainbow
------------------------------
Date: Thu, 20 Sep 2001 22:46:28 +0200
From: "Stefan Weiss" <weiss@kung.foo.at>
Subject: Re: Perl English only??????
Message-Id: <1001019086.813009@newsmaster-04.atnet.at>
"Chris Stith" <mischief@velma.motion.net> wrote:
> > so you can program in Latin, and the forthcoming
> > Lingua::tlhInganHol::yIghun -- so you can program in Klingon.
>
> So you can write Perl programs in two mostly dead langauges?
> Is Sanskrit next? ;-)
Klingon's not dead, petaQ.
Hab SoSlI' Quch!
SCNR,
stefan
------------------------------
Date: Thu, 20 Sep 2001 16:57:58 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: Perl English only??????
Message-Id: <mrlkqtssh0seb90f6mddjbc405vb4saafa@4ax.com>
On Thu, 20 Sep 2001 22:46:28 +0200, "Stefan Weiss" <weiss@kung.foo.at>
wrote wonderful things about sparkplugs:
SNIP
OT but...
Discalimer :: I am not now nor have I ever been a "trekkie"
>
>Klingon's not dead, petaQ.
>Hab SoSlI' Quch!
I still laugh when someone mentions Klingon. Years ago (96-97) Wired
wrote an article about Klingon and they translated some phrases and
b/c Klingon has only about 2000 words and 1500 of them about war some
of them were really funny:
"Sunny day, Chasing the Clouds Away" -- From Seasame Street
became
"The clouds are filled with dread and forced to flee"
Which still makes me laugh. I swear I'm laughing right now.
>
>SCNR,
>stefan
>
--
TMTOWTDI: My way tends to be wrong...
lmoran@wtsg.com
------------------------------
Date: 20 Sep 2001 12:57:16 -0700
From: amiwebguy@yahoo.com (Justin)
Subject: Processing page between two other pages.
Message-Id: <19caa707.0109201157.1a91c34d@posting.google.com>
I am looking for code to create a processing page between two other
pages.
For example on page one you fill out a form and submit it.
Some database magic happens that takes about 10 seconds and then the
confirmation page is displayed. Well, I'd like to show a processing
page between page one and two. Does anyone have sample code on how to
do this?
Thanks,
Justin
------------------------------
Date: 20 Sep 2001 21:32:48 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Reading cookies from a different path
Message-Id: <1001021039.5096@itz.pp.sci.fi>
In article <3ba971cb.7403$b4@news.op.net>, Mark Jason Dominus wrote:
>
>(I don't get those warnings, and I've tried running the program under
>versions of Perl back to 5.000, so I'm mystified about what is going
>wrong. Sorry that it didn't work for you.)
FWIW, I get them too:
zsh: 3726 suspended slrn
[0:23] simpukka ~ % perl
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
__END__
JuModification of a read-only value attempted at - line 2.
Modification of a read-only value attempted at - line 2.
Modification of a read-only value attempted at - line 2.
Modification of a read-only value attempted at - line 2.
Modification of a read-only value attempted at - line 2.
Modification of a read-only value attempted at - line 2.
[0:23] simpukka ~ % st anothrl /
[0:23] simpukka ~ % perl -v
This is perl, version 5.004_04 built for sun4-solaris
This is my ISP's perl. I've got 5.005_03, 5.7.1 and bleadperl installed
on Linux, and none of those have any problems with the script.
I'm also having trouble isolating the bug. With a deparsed version, the
line number points to "($q*=2)+=$f=!fork;", but that statement on its
own causes no trouble. So I'm assuming the problem is instead in the
statement after that, but I've no idea which part of it is causing it.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Thu, 20 Sep 2001 21:55:39 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: s/// modifies @_ ?
Message-Id: <3baa49bf@e-post.inode.at>
Philip Newton wrote:
> On Sun, 16 Sep 2001 23:20:50 +0200, peter pilsl <pilsl_@goldfisch.at>
> wrote:
>
>> Like you imagined, I passed $1 as argument to my function. (which cant be
>> avoided easily, cause I use this function inside a different
>> s///e-operation).
>
> Wouldn't it be possible to pass (my $match = $1) instead? Or "$1" to
> generate an anonymous string copy? Or $1 . '', for a similar effect?
>
> Somehow, the "passing $1 directly can't be avoided" strikes me as
> implausible.
I said 'cant be avoided easily', but obviously I was wrong.
my $match=$1 would not be easy, but $1.'' would be easy or "$1" even
easier. Any drawbacks on this ?
Beside, this is the whole operation:
$temp=~s/\$\$(\$|_|\.)(.+?):(.*?):/
sub{%$func_ptr=(%$func_ptr,%{$_[1]});
@$var_ptr=(@$var_ptr,@{$_[2]});
@$val_ptr=(@$val_ptr,@{$_[3]});$_[0]}->
(fetch_template($ptr,$p[0],
$presubst?substitute($var_ptr,$val_ptr,$2,$func_ptr):$2,$p[2]+1,
$p[3],
$3?$1.($presubst?substitute($var_ptr,$val_ptr,$3,$func_ptr):$3):'')
)/ge if $tempsubst;
the expressions should be replaced by return of fetchtemplate-sub, but this
function delivers back more variables that need to be stored and will be
used on the following replacements. On the other side the arguments
deliverd to fetchtemplate need modifications depending on $presubst and $3
The whole thingy is part of a parser for a contentmanagement-system.
peter
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Thu, 20 Sep 2001 18:01:54 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Schwartzian Transform problem
Message-Id: <zItq7.21052$386.2995208@news20.bellglobal.com>
"Michael Carman" <mjcarman@home.com> wrote in message
news:3BA9E727.73B9C8BC@home.com...
> What?! That's completely wrong.
>
What?! However did you come to that conclusion nearly 12 hours after Randal
posted his message!?! As I mentioned to Randal in an off-group email, I
quickly replied without stopping to think. So colour me stupid! But now I
feel better knowing there are bigger dunces out there.
Thanks for making me feel better!
Matt
------------------------------
Date: 20 Sep 2001 12:07:18 -0700
From: ralawrence@my-deja.com (Richard Lawrence)
Subject: search, replace, functions, text wrapping (hard question! I think!)
Message-Id: <b1b8a8d6.0109201107.78f08004@posting.google.com>
Hi all,
I wonder if anyone can help me? I've got some output from a socket
which I'm converting to HTML on the fly and I'd like it to
automatically convert url's to hyperlinks.
The problem is that when url's are wrapped, the regexp fails. So I
tweeked it a little and came up with the following:
$output =~ s#(http://[^\!\"\£\$\^\*\(\)\{\}\[\]\;\:\'\@\,\<\>
]+)#make_link($1)#egis;
sub make_link
{
my $display = $_[0];
my $url = $_[0];
$url =~ s/\n//g;
return "<a href=\"$url\">$display</a>";
}
Now I know that the regexp for catching URL's isn't perfect, but it
seems to work for the majority of what I need so I'm not too
concerned.
However, this is the problem:
The output when it comes to me, is already pre-wrapped and this
wrapping code automatically inserts two spaces at the beginning of
each indented line. So you get output that looks like this:
this is a very long line
which has been wrapped
by the program.
when you start a new line
the program puts the first
line two spaces in to make
it a little clearer.
Now my regexp utterly breaks because there are two spaces in there
that have to be taken into consideration. What I'm looking for is the
input of
this is a really good site i
found it at http://www.fish
andchips.com and its great.
to become:
this is a really good site i
found it at <a href="http://www.fishandchips.com">http://www.fish
andchips.com and its great.
(note how the fishandchips domain within the href is lacking the
newline and takes into account the double spacing).
I'm totally stuck. Can anyone help at all?
Thanks in advance.
Rich
------------------------------
Date: Thu, 20 Sep 2001 21:06:59 +0100
From: Philip Taylor <philip@zaynar.demon.co.uk>
Subject: Re: Unusual error message...
Message-Id: <CWG+vFAjxkq7Ewl4@zaynar.demon.co.uk>
In article <319333f5.0109200512.731d6b94@posting.google.com>, JR
<tommyumuc@aol.com> writes
>In the following script, I receive an error message on the line that
>reads:
>
> $sum += $item{$_} = $code_detail{$code}{$_} || 0 for qw(C P T);
>
>of:
>
> Missing $ on loop variable at process.cgi line 182.
Might you need to use
... for (qw(C P T));
so that it doesn't think qw is meant to be a variable? I'm not sure if
that's the problem, but it seems like a reasonable guess :-)
--
Philip Taylor
philip @ zaynar . demon . co . uk
http://robowarriors.ultrastore.com/legoworld.shtml
-- If the Earth was made of Lego...
------------------------------
Date: 20 Sep 2001 21:17:48 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Unusual error message...
Message-Id: <1001019886.4353@itz.pp.sci.fi>
In article <319333f5.0109200512.731d6b94@posting.google.com>, JR wrote:
>
> $sum += $item{$_} = $code_detail{$code}{$_} || 0 for qw(C P T);
>
> Missing $ on loop variable at process.cgi line 182.
Diagnosis: Used perl 5.005+ syntax on perl 5.004 or earlier.
Solution: If perl version is below 5.004, upgrade to 5.005_03 or 5.6.1.
If using version 5.004, and do not want to or cannot upgrade,
rewrite above line as:
for (qw(C P T)) {$sum += $item{$_} = $code_detail{$code}{$_} || 0}
Notes: The "EXPR for LIST;" syntax was introduced in perl 5.005. It is
exactly equivalent to "for (LIST) {EXPR}", which is valid in all
versions of perl 5. Perl versions before 5.004 are considered
obsolete and have known security problems. They should not be
used.
Can you tell I've been exposed to Microsoft TechNet recently?
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Thu, 20 Sep 2001 21:34:54 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Use symbol table like 'real' hash
Message-Id: <81okqt4rlflct0gr0d6tsq489gd8mmq9sk@4ax.com>
Bianka Martinovic wrote:
>The real question is, as I think: How to pass a symbol table to a function
>which expects a 'normal' hash?
You can't. Not because the symbol table isn't a normal hash (it is!) ,
but what it contains are typeglobs and not just normal scalars. So the
sub at least needs to be aware of *that*.
But perhaps I understand the question wrong.
>&template( <path>, { %IN:: });
Perhaps try
template( <path>, \%IN::);
(I don't know really. It looks too weird for me to be actually
considered a good idiom.)
--
Bart.
------------------------------
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 1783
***************************************