[19897] in Perl-Users-Digest
Perl-Users Digest, Issue: 2092 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 8 09:05:33 2001
Date: Thu, 8 Nov 2001 06:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005228309-v10-i2092@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 8 Nov 2001 Volume: 10 Number: 2092
Today's topics:
Re: A Newbie's Question (Tad McClellan)
Re: Best language for low IQ programmers? <israelrt@optushome.com.au>
Re: Best language for low IQ programmers? <israelrt@optushome.com.au>
Re: Best language for low IQ programmers? <israelrt@optushome.com.au>
Re: Best language for low IQ programmers? <gperkins@gperkins.co.uk>
Error: install_driver(CSV) failed <abuse@abuse.net>
Re: How to find length of scalar var? <jasper@guideguide.com>
Linking a Keyword search in HTML to Perl and Display R (Xerc)
Mail Script Has Just Stopped Working!?!?! <ross@timeplan.ltd.uk>
Re: Mail Script Has Just Stopped Working!?!?! (Tad McClellan)
Re: Mail Script Has Just Stopped Working!?!?! <wyzelli@yahoo.com>
Matching an Input string <martin_andersen_90@yahoo.com>
Re: Matching an Input string (Anno Siegel)
Re: Matching an Input string <martin_andersen_90@yahoo.com>
Re: Matching an Input string (Anno Siegel)
Re: Matching an Input string <bernard.el-hagin@lido-tech.net>
Re: Matching an Input string <martin_andersen_90@yahoo.com>
Re: Matching an Input string <bernard.el-hagin@lido-tech.net>
Re: Matching an Input string <martin_andersen_90@yahoo.com>
Re: Matching an Input string (Anno Siegel)
Re: RE for SQL columns <jasper@guideguide.com>
Re: Serving HTML images <angenent@kabelfoon.nl>
srand or rand question <alan@headru.sh>
Re: Store an object reference as hash key? (Anno Siegel)
Win2K Perl fork Http server <angenent@kabelfoon.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 08 Nov 2001 13:55:04 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: A Newbie's Question
Message-Id: <slrn9ul0vf.ion.tadmc@tadmc26.august.net>
James Sullivan <JJSUSA2001@yahoo.com> wrote:
>$input = "I am new";
>
>What is the difference between:
>
>@data = split (' ', $input) and
>@data = split(/ /, $input)
None as far as execution goes.
One hides what it is doing and one is explicit about what
it is doing.
A pattern match should *look like* a pattern match. So the
first one is sub-optimal.
>What would I get for $data[0],
I am new
>$data[1], $data[2] in both cases?
There would be no $data[1], $data[2].
>Are they
>any differences?
What happened when you tried it?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 08 Nov 2001 22:38:46 +1100
From: IsraelRT <israelrt@optushome.com.au>
Subject: Re: Best language for low IQ programmers?
Message-Id: <ekrkutopjkjnmvtf55u957q8dekp7l5i08@4ax.com>
>"Brian Metc" <BrianMetc@aol.com> wrote in message
>news:1004990076967295@aol.com...
>> I would like to get into the programing field. My problem is that I have
>low IQ due to
>> early childhool learning deprivation and TV overdose. Simply said I am
>stuped, I am
>> pretty good amongst my friends, but not solving problems. You know what I
>> mean. Anyways, I want to go into computor programing because of money
>> issue. I now need to choose languege for programming, simple enough
>> for me.
Go away troll...
Go to MS land and use their brain damaged designed for trolls
language..
------------------------------
Date: Thu, 08 Nov 2001 22:41:03 +1100
From: IsraelRT <israelrt@optushome.com.au>
Subject: Re: Best language for low IQ programmers?
Message-Id: <uprkut0u2jri67tchvco2bajsd195aj4ab@4ax.com>
On Mon, 05 Nov 2001 23:09:21 +0000, Richard Heathfield
<binary@eton.powernet.co.uk> wrote:
>Brian Metc wrote:
>>
><snip>
>>
>> Would any one sugest the best language for me.
>
>APL.
ATL: A Trolling Language
------------------------------
Date: Thu, 08 Nov 2001 22:42:34 +1100
From: IsraelRT <israelrt@optushome.com.au>
Subject: Re: Best language for low IQ programmers?
Message-Id: <fsrkut06l01ihmbq57fgg6tbc5jk0nog3v@4ax.com>
On Tue, 6 Nov 2001 05:37:53 -0700, Kenny Chaffin <kenny@kacweb.com>
wrote:
>IQ is inherent, like personality. It has nothing to do with
>learning/deprivation/TV.
How about oxygen deprivation :-)
------------------------------
Date: Thu, 08 Nov 2001 11:48:48 +0000
From: Graham Perkins <gperkins@gperkins.co.uk>
Subject: Re: Best language for low IQ programmers?
Message-Id: <3BEA7120.8A979611@gperkins.co.uk>
jmburton wrote:
>
> > C++ is the best choice for dull programmers. The quality of your code will
> > be indistinguishable from that of a the C++ guru.
>
> Are you a troll?
> In case if you are genuine, which I doubt, I disagree.
Lighten up! It was a joke!
> Eiffel ...
Now you say four false things (not controversial, actually
FALSE):
Garbage collection is inefficient
Eiffel is front end for C++
Programmer has to know C++ to use Eiffel
Eiffel programmer has to call C++ for anything useful like OS calls
which makes us think YOU are a troll. Please, if you have some
sensible questions to ask, about Eiffel and other technologies,
don't spoil it by making assertions from a position of ignorance.
-------------+ http:/www.gperkins.co.uk/
------------------------------
Date: Thu, 8 Nov 2001 20:30:03 +0800
From: "multiplexor" <abuse@abuse.net>
Subject: Error: install_driver(CSV) failed
Message-Id: <9sdtt6$hre7@rain.i-cable.com>
When I run the program below:
####
use DBI;
$dbh = DBI->connect("DBI:CSV:f_dir=.")
or die "Cannot connect: " . $DBI::errstr;
####
I got the following error message:
install_driver(CSV) failed: Text::CSV_XS object version 0.21 does not match
boot
strap parameter 0.22 at C:/Perl/lib/DynaLoader.pm line 188.
BEGIN failed--compilation aborted at C:/Perl/site/lib/DBD/CSV.pm line 47.
at dbd_csv.pl line 2
I am running ActivePerl 522 on Windows ME. I want to use the DBD::CSV module
to access csv files.
Thank you in advance.
------------------------------
Date: Thu, 08 Nov 2001 13:40:00 +0000
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: How to find length of scalar var?
Message-Id: <3BEA8B30.79C26C46@guideguide.com>
Murvin Ming-Wai Lai wrote:
>
> Hi all,
>
> I have a question on scalar variable.. Which is, how to find its
> length? If it is a scalar array, then I know I can use $#array for
> @array. How about this:
>
> $abc = "123FFF";
>
> how to find the length of that string? Is there any build in function?
> (by the way, what is the function "index" used for?). I know that i can
> use a while loop like this:
> while ($abc =~ /\d|\w/g) {
> $length++;
> }
>
> to find the length.. but it will be too slow to have a while loop like
> this. (imagine if I want to find the length of 10 thousand scalar
> variables).
>
> Anyone has any idea? I'm appreciated with any suggestion. =)
This came up before on this newsgroup (so you should have browsed the
archives first), and I knocked up some possibilities you could try. I
have not tested these for speed.
my $string = "eat,run,sleep";
my @ray = split '', $string;
my $length = scalar @ray;
print "$length\n";
# or
$length = $#ray + 1;
print "$length\n";
$length = 0;
my $copy = $string;
$length++ while chop $copy;
print "$length\n";
$length = 0;
length $string while substr $string, ++$length, 1;
print "$length\n";
sub length_of_string {
my ($string, $length) = (@_, 0);
$string ? length_of_string( (substr $string, 1), ++$length) : $length;
}
$length = length_of_string($string);
print "$length\n";
sub len { my @m = $_[0] =~ m/(.)/gs; scalar @m }
$length = len($string);
print "$length\n";
I hope that one of these methods might be of some help Murvin.
Jasper
--
@a=0..63;g(o($_),a($_)?$_<24?"w":$_>39?"b":0:0)for@a;$w=$b=12;while($w||
$b){$z=!$z;$i=" 01234567\n";print$i,(join"",map{($x,$y)=o($_);($x?"":$y)
.(a($_)?`tput smso`:`tput rmso`).(g(o($_))||" ").`tput rmso`.($x==7?"$y
":"")}@a),$i;$z?n(""):c();g($f,$g,($g==7&&$z)||(!$z&&!$g)?uc w():g($d,$e
));g($d,$e,0);t(1)}sub n{print"\n$_[0]go xyxy\n";($d,$e,$f,$g)=split"",
<STDIN>;v()||n("nfg-")}sub t{@t=($f>$d?$d+1:$d-1,$g>$e?$e+1:$e-1);if($s
==4&&g(@t)&&lc(g(@t))ne w()){if(shift){g(@t,0);$z?--$b:--$w}1}else{0}}sub
v{$s=($d-$f)**2;(lc(g($d,$e))ne w()||$s!=($e-$g)**2||g($f,$g)||($f>7||$f
<0)||($g>7||$g<0)||(($z?$e-$g:$g-$e)>0)&&!(g($d,$e)eq uc w())||!($s==1||
t()))?0:1}sub c{for(sort{rand}@a){($d,$e)=o($_);next if lc(g(o($_)))ne w
();for(@a){($f,$g)=o($_);next if!v();return 1 if t();unshift@q,[$d,$e,$f,
$g]}}($d,$e,$f,$g)=@{$q[0]}or die"win\n"}sub w{$z?"w":"b"}sub o{($_[0]%8,
int($_[0]/8))}sub a{(($_[0]%8)+(int($_[0]/8)))%2}sub g{$n=$_[0]+8*$_[1];
defined$_[2]?$position[$n]=$_[2]:$position[$n]}die$w?"win":"lose"."\n"
------------------------------
Date: 8 Nov 2001 03:39:32 -0800
From: xercsees@hotmail.com (Xerc)
Subject: Linking a Keyword search in HTML to Perl and Display Results
Message-Id: <ffaeb435.0111080339.514e3500@posting.google.com>
I have a project to retrieve a keyword from a .DAT file in perl and
display it in a certain way, which i have now managed to do, but now I
need to create a HTML page where a user can input a keyword and it
will then display the results. Now all this is OK until I try to link
the keyword put into the HTML to the perl script, all I get is
nothing. In essence I want to put a keyword into a search, it then
goes to the perl script which then organises the records in the .dat
file and displays the results in html, which hopefully will be all
records containing the HTML keyword.
Here is the HTML script and the Perl script I have created:
HTML:
<html>
<head>
<title>Search Dat File</title>
</head>
<body bgcolor=#FFFFFF text=#000000>
<center>
<h1>Product Dat Search Engine</h1>
</center>
<p>
<hr size=7 width=75%><p>
<form method=POST action="http:/itmachine/testsearch.pl">
<center><table border>
<tr>
<th>Text to Search For: </th><th><input type=text name="terms"
size=40><br></th>
</tr><tr>
<th>Boolean: <select name="boolean">
<option>AND
<option>OR
</select> </th> <th>Case <select name="case">
<option>Insensitive
<option>Sensitive
</select><br></th>
</tr><tr>
<th colspan=2><input type=submit value="Search!"> <input
type=reset><br></th>
</tr></table></form></center>
<hr size=7 width=75%><p>
</body></html>
PERL:
#!/usr/bin/perl -w
use strict ;
my $filename = 'prod.dat' ;
open (DATAFILE, "<$filename")
or die "$0: cannot open file \"$filename\" for reading: $!\n" ;
my (@record, @records) ;
while (<DATAFILE>) {
tr/\r\n//d ;
push @record, $_ ;
if (@record == 11) {
push @records, join ("\t", @record) ;
@record = () ;
}
}
close (DATAFILE) ;
#below in $keyword = 'SOMEDATA' I think I need to get the HTML to
input the #keyword below
my $keyword = 'SOMEDATA';
print "Content-type: text/html\n\n";
print "<H3>RESULTS:</H3>";
(print map {"<br>$_\n"} grep /\Q$keyword\E/, @records);
print "<html></html>\n";
die "$0: incomplete record (line count = ", scalar @record, ") at end
+of file \"$filename.\"\n"
unless @record == 0 ;
Thanks for any help
------------------------------
Date: Thu, 8 Nov 2001 11:48:50 -0000
From: "Ross Holmes" <ross@timeplan.ltd.uk>
Subject: Mail Script Has Just Stopped Working!?!?!
Message-Id: <1005220112.18295.0.nnrp-10.9e98ebed@news.demon.co.uk>
I have only just recently started to try and write a few scripts in perl,
and one of these was supposed to email some results to me. I had it working
and it was e-mailing fine. I then went to change the text of the email
message, and found that now it will not work at all. I have put it back to
what I thought was exactly the same as it was, and it still will not work.
I keep getting Error 500's.
The URL I use to link to the script is
http://cgi.www.timeplan.ltd.uk/cgi-bin/www.timeplan.ltd.uk/form-mail2.pl
I know this look weird, but trust me when I say that there is nothing wrong
with that link. I know this as I use the same format for other scripts, and
they work fine.
I have put a copy of the script at http://www.timeplan.ltd.uk/form-mail2.pl
If anyone can figure out why this has stopped working then I would be
extremely grateful.
Thank You in advance
Ross Holmes
------------------------------
Date: Thu, 08 Nov 2001 13:55:03 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Mail Script Has Just Stopped Working!?!?!
Message-Id: <slrn9ul0ll.ion.tadmc@tadmc26.august.net>
Ross Holmes <ross@timeplan.ltd.uk> wrote:
>I have put a copy of the script at http://www.timeplan.ltd.uk/form-mail2.pl
>
>If anyone can figure out why this has stopped working then I would be
>extremely grateful.
If you enable warnings, perl itself will tell you that
there is a problem with this line:
print MAIL "<a href="mailto:$FORM{'email'}">$FORM{'name'}</a>\n";
^ ^ ^
^ ^ ^
[ A "here-doc" would make your code much easier for you to read.
Read about it in perldata.pod.
]
Your script does not enable warnings, though you appear to be
attempting to enable them.
#!/bin/perl -- -*-perl-*- -w
perl starts parsing at the first mention of "perl" and stops
when it hits "--" which marks the end of the switches. So
the "-w" is never seen.
#!/bin/perl -w
ought to work.
Or, just try it at the command line:
perl -cw form-mail2.pl
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 9 Nov 2001 00:01:08 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Mail Script Has Just Stopped Working!?!?!
Message-Id: <5ewG7.6$KH6.670@vicpull1.telstra.net>
"Ross Holmes" <ross@timeplan.ltd.uk> wrote in message
news:1005220112.18295.0.nnrp-10.9e98ebed@news.demon.co.uk...
> I have only just recently started to try and write a few scripts in perl,
> and one of these was supposed to email some results to me. I had it
working
> and it was e-mailing fine. I then went to change the text of the email
> message, and found that now it will not work at all. I have put it back to
> what I thought was exactly the same as it was, and it still will not work.
> I keep getting Error 500's.
>
> The URL I use to link to the script is
> http://cgi.www.timeplan.ltd.uk/cgi-bin/www.timeplan.ltd.uk/form-mail2.pl
> I know this look weird, but trust me when I say that there is nothing
wrong
> with that link. I know this as I use the same format for other scripts,
and
> they work fine.
>
> I have put a copy of the script at
http://www.timeplan.ltd.uk/form-mail2.pl
>
> If anyone can figure out why this has stopped working then I would be
> extremely grateful.
You have a syntax error on line 38 (the double quote...
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Thu, 8 Nov 2001 12:11:37 +0100
From: "Martin" <martin_andersen_90@yahoo.com>
Subject: Matching an Input string
Message-Id: <9sdo1k$luo$1@newstoo.ericsson.se>
Hi
I was wondering if some one could tell me how i could match a string like :
my $inputString = "AA BB CC , DD EE # My Coment";
I know how to macth the first three letteres, but dont know the others.
result = ~m/(\w+\s*) {3}/;
Thanks in advance Martin
------------------------------
Date: 8 Nov 2001 12:01:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Matching an Input string
Message-Id: <9sds6o$5gm$1@mamenchi.zrz.TU-Berlin.DE>
According to Martin <martin_andersen_90@yahoo.com>:
> Hi
>
> I was wondering if some one could tell me how i could match a string like :
>
> my $inputString = "AA BB CC , DD EE # My Coment";
Giving us a single example of a string saying you want to match "strings
like that" isn't going to give you useful replies. We'd need to know
what other strings are "like that" and more importantly, which are not
"like that".
> I know how to macth the first three letteres, but dont know the others.
>
> result = ~m/(\w+\s*) {3}/;
You didn't test that, did you?
This bit of code doesn't help either. Even with the more or less obvious
corrections
my ( $result) = $inputString =~ m/(\w+\s*) {3}/;
it turns out it doesn't match your example string.
You need to think about your problem some more. When you can come up with
an actual problem description, ask again.
Anno
------------------------------
Date: Thu, 8 Nov 2001 13:40:45 +0100
From: "Martin" <martin_andersen_90@yahoo.com>
Subject: Re: Matching an Input string
Message-Id: <9sdt8p$8m8$1@newstoo.ericsson.se>
Sorry i dident wrot my program complitly, but here is my code
my $inputString = "AA BB CC , DD EE # My Comments";
print "Matched \n" if ( $inputString =~ m/^(\w+\s*){3}/);
I dont know how can i chang it so it could test the other letters too.
Regards Martin
------------------------------
Date: 8 Nov 2001 13:01:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Matching an Input string
Message-Id: <9sdvne$871$1@mamenchi.zrz.TU-Berlin.DE>
According to Martin <martin_andersen_90@yahoo.com>:
> Sorry i dident wrot my program complitly, but here is my code
>
> my $inputString = "AA BB CC , DD EE # My Comments";
>
> print "Matched \n" if ( $inputString =~ m/^(\w+\s*){3}/);
>
> I dont know how can i chang it so it could test the other letters too.
Well, since you still don't say what properties of your example string
are fixed and which can vary, there is no reasonable way to generalize
the regex for you. m/^.*$/ would match all of it, as would
m/AA BB CC , DD EE # My Comments/ and a million others. Which parts
of the string do you want to match, and how can the environment (the
parts you don't care about) vary?
Anno
------------------------------
Date: 8 Nov 2001 13:09:31 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Matching an Input string
Message-Id: <slrn9ul42p.mi5.bernard.el-hagin@gdndev25.lido-tech>
On Thu, 8 Nov 2001 13:40:45 +0100, Martin <martin_andersen_90@yahoo.com> wrote:
> Sorry i dident wrot my program complitly, but here is my code
>
> my $inputString = "AA BB CC , DD EE # My Comments";
>
> print "Matched \n" if ( $inputString =~ m/^(\w+\s*){3}/);
>
> I dont know how can i chang it so it could test the other letters too.
You're not very precise as to the data you're using. We can't
help you with a regex to match your data if we don't know what
your data looks like. The above input string can be matched by:
m/AA BB CC , DD EE # My Comments/;
But that's probably not what you're after. You vaguely say something
about testing letters. Does that mean you'd like to capture all of
the letters to the left of the comment? If so you can try;
my @letters = $inputString =~ m/([A-Z]{2})(?=.*#)/g;
$" = ')(';
print "(@letters)";
But, again, this may not be what you want. Please try to rephrase
your problem and give a more general description of your data.
Cheers,
Bernard
------------------------------
Date: Thu, 8 Nov 2001 14:19:35 +0100
From: "Martin" <martin_andersen_90@yahoo.com>
Subject: Re: Matching an Input string
Message-Id: <9sdvhi$oa$1@newstoo.ericsson.se>
Hi Anno,
Thanks for replaying my mail
I want to save them in to some variables like:
my $Words1 = The First three leters like AA BB CC
my $Words2 = The Letter after , and before # In my case like : DD EE
My $Words3 = The letter after # until we have a new line, like My Comments
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:9sdvne$871$1@mamenchi.zrz.TU-Berlin.DE...
> According to Martin <martin_andersen_90@yahoo.com>:
> > Sorry i dident wrot my program complitly, but here is my code
> >
> > my $inputString = "AA BB CC , DD EE # My Comments";
> >
> > print "Matched \n" if ( $inputString =~ m/^(\w+\s*){3}/);
> >
> > I dont know how can i chang it so it could test the other letters too.
>
> Well, since you still don't say what properties of your example string
> are fixed and which can vary, there is no reasonable way to generalize
> the regex for you. m/^.*$/ would match all of it, as would
> m/AA BB CC , DD EE # My Comments/ and a million others. Which parts
> of the string do you want to match, and how can the environment (the
> parts you don't care about) vary?
>
> Anno
------------------------------
Date: 8 Nov 2001 13:26:18 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Matching an Input string
Message-Id: <slrn9ul528.mi5.bernard.el-hagin@gdndev25.lido-tech>
On Thu, 8 Nov 2001 14:19:35 +0100, Martin <martin_andersen_90@yahoo.com> wrote:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:9sdvne$871$1@mamenchi.zrz.TU-Berlin.DE...
>> According to Martin <martin_andersen_90@yahoo.com>:
>> > Sorry i dident wrot my program complitly, but here is my code
>> >
>> > my $inputString = "AA BB CC , DD EE # My Comments";
>> >
>> > print "Matched \n" if ( $inputString =~ m/^(\w+\s*){3}/);
>> >
>> > I dont know how can i chang it so it could test the other letters too.
>>
>> Well, since you still don't say what properties of your example string
>> are fixed and which can vary, there is no reasonable way to generalize
>> the regex for you. m/^.*$/ would match all of it, as would
>> m/AA BB CC , DD EE # My Comments/ and a million others. Which parts
>> of the string do you want to match, and how can the environment (the
>> parts you don't care about) vary?
>
> Hi Anno,
> Thanks for replaying my mail
>
> I want to save them in to some variables like:
>
> my $Words1 = The First three leters like AA BB CC
>
> my $Words2 = The Letter after , and before # In my case like : DD EE
>
> My $Words3 = The letter after # until we have a new line, like My Comments
Even though I'm not Anno I hope you don't mind:
my ($words1, $words2, $words3) = $inputString =~ /^([^,]*),([^#]*)#(.*)$/;
Cheers,
Bernard
------------------------------
Date: Thu, 8 Nov 2001 14:33:29 +0100
From: "Martin" <martin_andersen_90@yahoo.com>
Subject: Re: Matching an Input string
Message-Id: <9se0bk$9s1$1@newstoo.ericsson.se>
Thanks allots, that was exactly, what i was asking for .
Regards Martin
------------------------------
Date: 8 Nov 2001 14:00:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Matching an Input string
Message-Id: <9se366$d7b$1@mamenchi.zrz.TU-Berlin.DE>
According to Martin <martin_andersen_90@yahoo.com>:
(Please put your reply after the quoted text. I have moved it there)
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:9sdvne$871$1@mamenchi.zrz.TU-Berlin.DE...
> > According to Martin <martin_andersen_90@yahoo.com>:
> > > Sorry i dident wrot my program complitly, but here is my code
> > >
> > > my $inputString = "AA BB CC , DD EE # My Comments";
> > >
> > > print "Matched \n" if ( $inputString =~ m/^(\w+\s*){3}/);
> > >
> > > I dont know how can i chang it so it could test the other letters too.
> >
> > Well, since you still don't say what properties of your example string
> > are fixed and which can vary, there is no reasonable way to generalize
> > the regex for you. m/^.*$/ would match all of it, as would
> > m/AA BB CC , DD EE # My Comments/ and a million others. Which parts
> > of the string do you want to match, and how can the environment (the
> > parts you don't care about) vary?
> Hi Anno,
> Thanks for replaying my mail
Well, it isn't exactly mail...
> I want to save them in to some variables like:
>
> my $Words1 = The First three leters like AA BB CC
>
> my $Words2 = The Letter after , and before # In my case like : DD EE
>
> My $Words3 = The letter after # until we have a new line, like My Comments
Well, now we're getting somewhere. So you expect three parts in a string:
before the comma, after the comma and before #, and everything following
a #. I'll assume that the three parts are always there and that the
separating characters "," and "#" don't appear elsewhere in the string.
In a first step, we can separate the parts like this:
my ( $part1, $part2, $comment) = $inputString =~ /([^,]*),([^#]*)#(.*)/;
This picks up everything that isn't a comma (the first ()) and puts it
into $part1, then everything that isn't a # (the second ()) goes into
$part2, and the rest goes in $comment.
In a second step, we can isolate the groups of uppercase letters
in $part1 and $part2.
my @parts1 = $part1 =~ m/[A-Z]+/g;
my @parts2 = $part2 =~ m/[A-Z]+/g;
does this. See perldoc perlre for the /g modifier in list context
for how it works. See perldoc -f split for an alternative.
You are now ready to use @parts1, @parts2 and $comment in any way.
To report your findings:
print "Found before comma: ", join( ', ', @parts1), "\n";
print "Found after comma: ", join( ', ', @parts2), "\n";
print "Comments are: ", $comment;
Anno
------------------------------
Date: Thu, 08 Nov 2001 13:46:05 +0000
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: RE for SQL columns
Message-Id: <3BEA8C9D.3FD4D122@guideguide.com>
Nan wrote:
>
> Hello:
>
> Here is a sample perl that I need some help...
>
> $sql =<<EOF;
> select
> emp_name, emp_salary,
> emp_id
> from employee_table where
> emP_id = :1
> EOF
>
> I need a regular expression to retain the
> text from {select} through {from} in the above string.
> Basically the resultant string (after the regular expression)contains
> only the columns (i.e. emp_name,emp_salary,empId).
>
> I can have upper and lower cases in select and from while
> trying to match them.
>
> Thanks for any help/suggestions..
Why don't you select a hash ref, and get the keys of the hash returned
from the database select. DBI will do this for you.
If I'm misunderstanding the reasons for doing this, apologies.
Jasper
--
@a=0..63;g(o($_),a($_)?$_<24?"w":$_>39?"b":0:0)for@a;$w=$b=12;while($w||
$b){$z=!$z;$i=" 01234567\n";print$i,(join"",map{($x,$y)=o($_);($x?"":$y)
.(a($_)?`tput smso`:`tput rmso`).(g(o($_))||" ").`tput rmso`.($x==7?"$y
":"")}@a),$i;$z?n(""):c();g($f,$g,($g==7&&$z)||(!$z&&!$g)?uc w():g($d,$e
));g($d,$e,0);t(1)}sub n{print"\n$_[0]go xyxy\n";($d,$e,$f,$g)=split"",
<STDIN>;v()||n("nfg-")}sub t{@t=($f>$d?$d+1:$d-1,$g>$e?$e+1:$e-1);if($s
==4&&g(@t)&&lc(g(@t))ne w()){if(shift){g(@t,0);$z?--$b:--$w}1}else{0}}sub
v{$s=($d-$f)**2;(lc(g($d,$e))ne w()||$s!=($e-$g)**2||g($f,$g)||($f>7||$f
<0)||($g>7||$g<0)||(($z?$e-$g:$g-$e)>0)&&!(g($d,$e)eq uc w())||!($s==1||
t()))?0:1}sub c{for(sort{rand}@a){($d,$e)=o($_);next if lc(g(o($_)))ne w
();for(@a){($f,$g)=o($_);next if!v();return 1 if t();unshift@q,[$d,$e,$f,
$g]}}($d,$e,$f,$g)=@{$q[0]}or die"win\n"}sub w{$z?"w":"b"}sub o{($_[0]%8,
int($_[0]/8))}sub a{(($_[0]%8)+(int($_[0]/8)))%2}sub g{$n=$_[0]+8*$_[1];
defined$_[2]?$position[$n]=$_[2]:$position[$n]}die$w?"win":"lose"."\n"
------------------------------
Date: Thu, 8 Nov 2001 14:19:56 +0100
From: "GOGAR" <angenent@kabelfoon.nl>
Subject: Re: Serving HTML images
Message-Id: <9se0mo$2ttm$1@news.kabelfoon.nl>
maybe in the urls to the images you could add a random query string..
i am assuming the html page is generated by cgi..
like
<img src="http://www.blah.com/images/image.jpg?random=3534545">
cheers,
Chris
"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3BE9F68F.B9EACBB0@earthlink.net...
> Maarten wrote:
> >
> > Using perl I'm not sure whether this is the right group to ask, but
> > anyway: does anybody know how to get a browser to not load a image
> > from the cache but from the server instead while using the html IMG
> > tag?
> >
> > Simply setting the last-update header doesn't seem to suffice,
> > because the browser doesn't seems look at the header if an obsolete
> > (dynamically served) image of the same name can be found in the
> > cache.
>
> Have the image loaded from a cgi, and put in the cgi's headers "pragma:
> no-cache"
>
> Something like this:
>
> #!/usr/local/bin/perl -wT
> # imageloader.cgi
> # invoke as http://foo.bar.com/cgi-bin/imageloader.cgi/foo.gif
> my ($file) = $ENV{PATH_EXT} =~ m[^([^/]*)\z];
> my $dir = "/home/me/myimages/foo/";
> unless( open FILE, "<", $dir . $file ) {
> print "Status: 404 Not found\n";
> print "Content-type: text/plain\n\n";
> print "Sorry, can't find $file on this server.\n"
> exit;
> }
> { local $| = 1;
> # Because *these* newlines need to have their \n
> # translated into the system dependent newline sequence,
> # STDOUT must be in textmode at this time. Since
> # some perls don't flush the filehandle when we change
> # from textmode to binmode, we need to flush before
> # changing STDOUT to binmode. Since perl doesn't provide
> # an explicit flush, I just set autoflush when printing
> # the cgi headers.
> print "Content-type: image/gif\n";
> print "Pragma: no-cache\n"; # <-- this line prevents caching.
> print "Content-length: ", -s FILE, "\n";
> print "\n";
> }
> binmode STDOUT;
> binmode FILE;
> print while sysread FILE, $_, 8192;
> exit;
>
> --
> Klein bottle for rent - inquire within.
------------------------------
Date: Thu, 8 Nov 2001 14:02:41 -0000
From: "alan@" <alan@headru.sh>
Subject: srand or rand question
Message-Id: <9se3a6$fob$1@newsg3.svr.pol.co.uk>
Hi,
Now this is to do with Perl, even though I call the script from a web page.
I have a script that creates random passwords and then encrypts them using
crypt().
It all works fine, but...
I want to create more than one password at a time. If I set a "for" loop
going, I get the same password generated again and again.
I understand that Perl ver 5.004 and higher, sets srand automatically at the
start of the script, and to reset srand will most likely make for less
random figures being generated.
I have tried generating 1 password. Then generating the next, 1 by 1 I get
the result I want. This leads me to suspect that the current process id
holds the key to the random values.
So, Any ideas on how I can loop the random generation, with a new srand
value for each iteration, without exiting the script time after time ?
(I haven't included code because the code works, it's the principle of
getting round srand thats bugging me ! )
Thanks in advance.
Alan
------------------------------
Date: 8 Nov 2001 11:05:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Store an object reference as hash key?
Message-Id: <9sdoue$25l$1@mamenchi.zrz.TU-Berlin.DE>
According to Markus Dehmann <markus.cl@gmx.de>:
> Can I store a reference to a whole object as hash key?
>
> I tried this code but it didn't work:
>
> use Test;
> my $t = Test->new();
> $t->setValue("abc");
>
> my $hash{ \$t } = 1;
Using "\$t" for the hash key introduces an extra level of indirection
($t is a reference already). It isn't clear if you really want that,
but it doesn't matter much for the discussion below.
> foreach( keys %hash ){
> my $a = $$_;
> print $a->getValue(); # should say abc
> }
>
>
> Is there a possibility to do sth like that?
Not directly. Hash keys must be strings, so your objects are stringified
before being used as such. If you want to recover a functioning object,
you will have to store it in a place where any scalar can go. You could
use another hash or extend the data structure that make up the values of
the one you have.
Note that this means that you keep another reference to the underlying
object, so it won't go out of scope when it otherwise would. If you
do this with many (or large) objects, the effect may matter.
Anno
------------------------------
Date: Thu, 8 Nov 2001 14:32:08 +0100
From: "GOGAR" <angenent@kabelfoon.nl>
Subject: Win2K Perl fork Http server
Message-Id: <9se1dk$2uli$1@news.kabelfoon.nl>
Alloha,
for the past few days i've been messing with example code from perldoc in an
attempt to get a forking http server to work on win2k.... i'm starting to
wonder if this is actually possible..
i've tried a few approaches like forking as the request comes in and
pre forking the max # of child processes.. and then give them tasks through
pipes.. no luck yet though..
i'm not that much of an expert anyways
i'm wondering if anybody else tried to achieve this??
Cheers,
Chris
------------------------------
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 2092
***************************************