[18188] in Perl-Users-Digest
Perl-Users Digest, Issue: 356 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 26 06:05:34 2001
Date: Mon, 26 Feb 2001 03:05:08 -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: <983185508-v10-i356@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 26 Feb 2001 Volume: 10 Number: 356
Today's topics:
Re: #!/usr/local/bin/perl -w || /usr/bin/perl -w (Rafael Garcia-Suarez)
Re: Any way to modify a script while executing it? <godzilla@stomp.stomp.tokyo>
Re: Any way to modify a script while executing it? <ianb@ot.com.au>
Re: Calling SMBPASSWD from a CGI script (Rafael Garcia-Suarez)
Re: Executing perl on Win98 obscuremu@riftsmux.dhs.org
Re: file size <peb@bms.umist.ac.uk>
Re: GUI interface for Perl program <ron@savage.net.au>
Re: How is @INC populated (Martien Verbruggen)
Is there a neural network module? <meisl@amvt.tu-graz.ac.at>
Re: Is there a neural network module? (Anno Siegel)
Re: Mysql and Perl (Rafael Garcia-Suarez)
Re: One form submit to many servers (Rafael Garcia-Suarez)
Re: overloading. A mess? <dev@trahojen.REMOVETHIS.com>
Perl and (public) mysql <gtoomey@usa.net>
Re: Perl and (public) mysql (Rafael Garcia-Suarez)
Re: Perl on a shell account: how to use UNIX commands i <michael@NOSPAM.vilain.com>
Re: perl thread woes.. (Anno Siegel)
regexp clarification <inkswamp@nas.com>
Re: regexp clarification (Rafael Garcia-Suarez)
Re: regexp clarification <inkswamp@nas.com>
Re: Should this work?. Beginners db question. Please h <tore@extend.no>
Re: timeout connect() with select? (Anno Siegel)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 26 Feb 2001 09:30:39 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: #!/usr/local/bin/perl -w || /usr/bin/perl -w
Message-Id: <slrn99k8h7.jlu.rgarciasuarez@rafael.kazibao.net>
Michael Wang wrote in comp.lang.perl.misc:
> On Solaris 8, an old version of Perl is installed in
> /usr/bin/perl, and a new version in /usr/local/bin/perl.
>
> I want to use the newer version if it is there, otherwise
> I want to use the older version. How do I convey the idea
> in #! line?
You can try this :
#!/usr/bin/perl
use Config;
if ($Config{version} =~ /^5\.0/ && -x '/usr/local/bin/perl') {
exec('/usr/local/bin/perl', $0, @ARGV) or die $!;
}
... the script here ...
Note that switches found on the shebang line will not be applied when
/usr/local/bin/perl is used.
Note also that this method is not very efficient...
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Mon, 26 Feb 2001 00:05:54 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Any way to modify a script while executing it?
Message-Id: <3A9A0E62.2E77E99B@stomp.stomp.tokyo>
Dick wrote:
> Is there a way to modify a script while executing it?
(snipped)
Godzilla!
--
#!perl
print "Content-type: text/plain\n\n";
$number = 53;
$new_number = int(rand(99));
print "Old Number Is: $number\n",
"New Number Is: $new_number\n";
open (OLD_SCRIPT, $0);
@Array = <OLD_SCRIPT>;
close (OLD_SCRIPT);
open (NEW_SCRIPT, ">$0");
foreach $element (@Array)
{
if ($element =~ /= $number/)
{ $element =~ s/$number/$new_number/; }
print NEW_SCRIPT $element;
}
close (NEW_SCRIPT);
exit;
------------------------------
Date: Mon, 26 Feb 2001 21:42:07 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: Any way to modify a script while executing it?
Message-Id: <3A9A32FF.41E8F05C@ot.com.au>
Dick wrote:
> Is there a way to modify a script while executing it?
Well, it appears that you really want to ask "How do I modify default values?".
Modifying the script itself is pretty dicey, and makes maintenance difficult.
You would be far better off having a configuration file. That is to say, a
separate file that contains data or settings that modify the behaviour of the
script. If you need close control over what settings can be made, you can roll
your own format and parse it. If you are happy to allow a fair degree of
flexibility and user initiative (i.e. don't do this on the internet), you can
make an executable config file. Create a file with the settings in it in plain
perl, and "require" it, or slurp it into a string and "eval" it, letting perl
do the parsing for you.
If an executable config file is intended only for the script itself to write
and read back, you can just get the script to write out a simple set of
(syntactically correct) assignment statements to the config file at the right
time, replacing its existing contents, so when this is evaluated next time, the
changed settings will be made. Of course in this case, any manual additions to
the config file would be lost.
If you really had to modify the script (for some bizarre reason you could only
use a single file), you could do the same thing with the __DATA__ section at
the end of the script file, which would be somewhat safer and much easier than
searching in the script itself for the correct bits to modify. But
configuration files are your friends.
> Each time I run this it of course says the default is 33. What I'd like to
> be able to do is to have a change in the default value "stick". For example
> if the second time I run the script I change the default to 100, then the
> third run of the script would say the default is 100, not 33. It seems to
> this newbie that this would involve somehow rewriting the "$n = 33;" line to
> "$n = 100;" at some point in the execution of the script. Is this
> impossible? And if not, how can this be done?
Yes it can be done. You need to find the script's location, open the file and
search using regular expressions for the bits to change, and make
substitutions, then write back out to the file. Since I'm trying to persuade
you not to do it, I'm not goin to go to the effort of writing an example.
You don't want to do this while someone else might be trying to execute it,
unless you use file locking. You need to be careful to keep safe copies all the
time in case you screw up the modifying code and lose or corrupt the program.
The whole idea is more suited to an obfuscated perl contest or a virus than
normal perl programming.
Regards,
Ian
------------------------------
Date: Mon, 26 Feb 2001 08:06:27 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Calling SMBPASSWD from a CGI script
Message-Id: <slrn99k3ja.j0g.rgarciasuarez@rafael.kazibao.net>
stag1400 wrote in comp.lang.perl.misc:
> Hi All,
>
> I am a sysadmin and set up a linux box for sendmail, pop3, and imap. so far
> so good.
>
> Then manegement wanted to use Outlook and be able to publish free/busy data.
> This I did by using Samba. As users are added they get a home dir and access
> to a shared public dir.
>
> I found a web-based password changer, and it will change the UNIX password
> but not the Samba password.
>
> I looked at the perl code and thought i could simply add a line to use
> SMBPASSWD and use the variables $username and $newpassword.
>
> here is the line I am using now:
>
> `system("/usr/bin/smbpasswd -s $username $newpasswd")`;
smbpasswd doesn't take the new password as a command-line argument
(according to the man page).
Moreover, the above line is nonsense: you are trying to execute
system(..etc..) as a shell command ! You should read about the backticks
and about system() in the perl documentation. `` are described in
the perlop man page, system in perlfunc.
To feed smbpasswd with arbitrary input, use the Expect module, from the
CPAN.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Mon, 26 Feb 2001 10:53:34 GMT
From: obscuremu@riftsmux.dhs.org
Subject: Re: Executing perl on Win98
Message-Id: <3a9a3525.14002976@news.inreach.com>
Short answer. Nope, there isn't.
Better answer:
As long as the extention of pl is linked to the perl interpeter you can always
point and click using the mouse. :)
Shain
On Mon, 26 Feb 2001 01:24:54 -0800, "Brian McCann" <bmccann@naisp.net> wrote:
>I usually run perl scripts on Sun or Win NT and to execute a script
>all you have to do at the prompt is type filename.pl and the script executes
>but on Win98 to get the script to execute you have to type
>
>perl filename.pl
>
> is there a way to run the script without calling the interpreter
>before the filename?
>
>tia
>Brian
>
>
------------------------------
Date: Mon, 26 Feb 2001 10:54:00 +0000
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: file size
Message-Id: <3A9A35C8.69FFDD3@bms.umist.ac.uk>
Tore Aursand wrote:
>
> In article <3A9668C2.98DF8A2E@bms.umist.ac.uk>, peb@bms.umist.ac.uk
> says...
> > If you're only interested in the file size then you can use
> > the -s file test operator which returns the size of the file
> > in bytes.
> >
> > e.g. print -e "/etc/passwd";
>
> Hmm? I think that one needs some clarification; '-e' checks if the
> file exists, while '-s' returns the filesize. Example;
>
> my $filename = '/etc/passwd';
> my $filesize = undef;
> if (-e $filename) {
> $filesize = -s $filename;
> }
>
> ...to be on the safe side. :)
oops... I meant print -s "/etc/passwd";
cheers for pointing out that typo.
Paul
------------------------------
Date: Mon, 26 Feb 2001 20:23:16 +1100
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: GUI interface for Perl program
Message-Id: <npom6.6220$v4.259845@ozemail.com.au>
See below
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
Mirek Rewak <cave@pertus.com.pl> wrote in message
news:fqtj9tchkkhd2sj7v2e15qtgblvkmhhomb@4ax.com...
Hi,
I want to to write program that will be interfaced by a GUI on Win32.
I don't know what interface will I use: Win32, GTK or Tk. I know that
[snip]
Consider CGI.
Also, there already exist various interfaces to databases. One -
myadmin.pl - is at: http://savage.net.au/Perl.html#myadmin.pl
------------------------------
Date: Mon, 26 Feb 2001 19:51:33 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: How is @INC populated
Message-Id: <slrn99k68l.gro.mgjv@martien.heliotrope.home>
On 26 Feb 2001 07:45:08 GMT,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> [A complimentary Cc of this posting was NOT sent to Martien Verbruggen
><mgjv@tradingpost.com.au>],
> who wrote in article <slrn99jogl.gro.mgjv@martien.heliotrope.home>:
>> >> They're compiled in:
>> >>
>> > Thank you for the explanation. Do I correctly understand this to mean
>> > that I cannot permanently change @INC without recompiling perl? All I
>> > want to do is add another directory to it, permanently and globally.
>>
>> I don't know of any ways, which doesn't mean there aren't any.
>
> I think that your replies are absolutely off-the-key. I do not know
> anything about how Win* ports work, but I know that compiling the
> paths in works only on the systems where you are *supposed* to
> recompile the package separately for each machine/network.
>
> With binary distributions *this does not work*. So it cannot be so
> for the ActivePerl port.
As far as I knew, the ActiveState port and the Unix versions use the
same perl.c nowadays. The code I referred to earlier only shows reading
of environment variables, and the activation of compile-time defines.
Obviously, the ports do other things.
>> Maybe manipulation of some of the variables in Config.pm works.
>
> How would it find Config.pm?
>
> Here is how the OS/2 port does it: the paths are compiled in, but you
> can specify a-kind-of s/// translation to do on the compiled-in paths
> in $ENV{PERLLIB_PREFIX}.
Hmm... so... It uses an environment variable, as mentioned in Perl faq
part 8. Interestingly enough, this one isn't mentioned there.
S_init_perllib doesn't mention PERLLIB_PREFIX, but it is mentioned in
o2s/os2.c.
win32/win32.c defines a few places where libraries seem to get set, but
I only really see references to win32_get_xlib. I'm not good at reading
win32 sources, but it seems to get these things from the registry. I
don't know if it's possible to add to these keys. There are two calls to
this function:
win32_get_xlib(pl, "sitelib", "site");
and
win32_get_xlib(pl, "vendorlib", PERL_VENDORLIB_NAME);
I'll leave the rest of the detective work up to anyone who wants to read
this code.
> Another approach would be to do the translation w.r.t. the Perl
> executable path. [The problem with this is that there are two equally
> good - in different situations - ways to organize the directory
> structure: if $DIR is the directory of Perl, you may want to look for
> modules in $DIR/../lib/perllib, or $DIR/libperl.]
>
> So the answer should be: read the ActivePerl docs....
Yep. That is the best answer, provided they documented it.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia |
------------------------------
Date: 26 Feb 2001 09:51:39 +0100
From: Christian Meisl <meisl@amvt.tu-graz.ac.at>
Subject: Is there a neural network module?
Message-Id: <m3bsrpddyc.fsf@famvtpc59.tu-graz.ac.at>
I want to write a simple neural network simulation using a feedforward
network and backpropagation. Is there any module available that I
could use. I have searched the CPAN, but the only thing I have found
is AI::jNeural, which seems not to be suitable...
Regards,
Christian
--
Christian Meisl <meisl@amvt.tu-graz.ac.at> www.amft.tu-graz.ac.at
Inst. f. Apparatebau, Mech. Verfahrenstechnik und Feuerungstechnik
---------------------- Spelling is a lossed art. -----------------------
PGP fingerprint: DF48 2503 0411 F0EF 149C 851B 1EF0 72B9 78B6 034A
------------------------------
Date: 26 Feb 2001 09:51:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Is there a neural network module?
Message-Id: <97d8uo$c1v$2@mamenchi.zrz.TU-Berlin.DE>
According to Christian Meisl <meisl@amvt.tu-graz.ac.at>:
> I want to write a simple neural network simulation using a feedforward
> network and backpropagation. Is there any module available that I
> could use. I have searched the CPAN, but the only thing I have found
> is AI::jNeural, which seems not to be suitable...
A search for "neural" on http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search
finds three more.
Anno
------------------------------
Date: Mon, 26 Feb 2001 09:39:55 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Mysql and Perl
Message-Id: <slrn99k92i.jlu.rgarciasuarez@rafael.kazibao.net>
Victor Prasad wrote in comp.lang.perl.misc:
>
> I am trying to take a web form with different fields and have them insert
> into a mysql database with one script. The point of the script is to be
> able to use it for any form. The problem is the script runs with out error
> on the web page - but does not insert. What is wrong?
> When I do a perl xx.cgi - it runs - no error - except there is not data..
> help?
[ script deleted ]
The first thing to do is :
don't parse the CGI parameters yourself. Use a module, e.g. the
well-known and robust CGI.pm.
If your script doesn't work after this correction, you're welcome to
continue looking for advice here.
Another remark : don't construct a MySQL statement blindly with the CGI
parameters. Validate the input. What will happen if a parameter contains
");delete from table;" ? Look at the DBI::quote function for quoting values,
and don't allow other characters than \w in keys.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Mon, 26 Feb 2001 08:01:36 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: One form submit to many servers
Message-Id: <slrn99k3a8.j0g.rgarciasuarez@rafael.kazibao.net>
DrewWatk wrote in comp.lang.perl.misc:
>
> How could one persuade PERL to initiate multiple form submissions to other
> servers from one submit element.
Use a wrapper CGI script, to which your form is submitted, and that
forwards the form submission request to the other URLs, possibly by
using LWP::UserAgent or another LWP module.
Javascript may be also able to do something like that, but it's IMHO
less clean.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Mon, 26 Feb 2001 08:48:27 +0100
From: "Trahojen" <dev@trahojen.REMOVETHIS.com>
Subject: Re: overloading. A mess?
Message-Id: <WGom6.4441$hi2.13162@nntpserver.swip.net>
I thank you all for your help.
I'll buy that Camel now.
all the best,
- Samuel [dev@trahojen.REMOVETHIS.com]
------------------------------
Date: Mon, 26 Feb 2001 20:38:55 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Perl and (public) mysql
Message-Id: <39qm6.3834$v5.12140@newsfeeds.bigpond.com>
My ISP has Perl but not mysql.
Is there a public mysql server on the net that I could connect to,
to try out mysql?
Thanks,
gtoomey
------------------------------
Date: Mon, 26 Feb 2001 10:49:19 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Perl and (public) mysql
Message-Id: <slrn99kd4n.jvq.rgarciasuarez@rafael.kazibao.net>
Gregory Toomey wrote in comp.lang.perl.misc:
> My ISP has Perl but not mysql.
>
> Is there a public mysql server on the net that I could connect to,
> to try out mysql?
If you want to try out MySQL, the best is probably to download and
install it (from http://www.mysql.com/). If you want to build a site
with a MySQL backend, you'll have to look for an hosting service that
provides this feature, along with Perl/CGI.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Mon, 26 Feb 2001 00:24:18 -0800
From: "Michael Vilain <michael@NOSPAM.vilain.com>"
Subject: Re: Perl on a shell account: how to use UNIX commands in a perl script?
Message-Id: <michael-58BE97.00241826022001@corp.supernews.com>
In article <9787h9$u1s$1@newssvr06-en0.news.prodigy.com>,
egwong@netcom.com wrote:
> Dick <donkan7@yahoo.com> wrote:
> >
> > "Gregory Toomey" <gtoomey@usa.net> wrote in message
> > news:ePLl6.2456$v5.8161@newsfeeds.bigpond.com...
> >> Try someting like $var=system('uptime').
> >> You may need to use substr to get the value you need.
> >
> > $var=system('uptime');
> > print $var, "\n";
> >
> > gets me what I want, e.g.
> > "3:32am up 130 days, 58 min, 3 users, load average: 0.01, 0.04, 0.01".
> > Thanks very much.
> >
> > But I also get a "0" on the next line. What's that, and how can I get rid of
> > it?
>
> This is excellent! I'm sure a lot of us made a similar mistake
> when we started out too.
>
> What's happening is that the "uptime" line is being printed when
> system calls uptime -- it's *not* being captured by perl into the
> variable $var. That's why $var prints out as "0" in the second
> line. To see what I mean, compare these two from the command line:
>
> perl -e 'my $var=system("uptime");'
> perl -e 'my $var=`uptime`;'
>
> Only in the second line (which uses the backticks) is the output
> from uptime captured by perl. That's why adding a "print $var"
> to the first line is essentially a no-op, whereas adding it to
> the second line will actually print what you want. As has been
> previously mentioned, see "Quote and Quote-like Operators" in
> the perlop manpage.
>
> I'm glad to hear that you're using strict. You're starting off
> right :) What you need to do is to declare your package (global)
> variables with 'use vars' or "our" (if you're using perl 5.6+),
> or, declare the variables as a lexical with "my", as I did above
> (see the strict, vars and perlfunc manpages).
>
try
open (UP,"uptime|");
@uptime = <UP>;
close UP;
@uptime should be a 1 element array with an embedded \n
--
Michael Vilain
Certified Advanced Rolfer(r)
rolfer@vilain.com
http://www.vilain.com
------------------------------
Date: 26 Feb 2001 09:33:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl thread woes..
Message-Id: <97d7sl$c1v$1@mamenchi.zrz.TU-Berlin.DE>
According to Morgan Freeman <mjf@efortress.com>:
> I am having some difficulty making perl threads work right for me.
>
> I have a list of websites that I want to retrieve information from
> in parallel, so that no matter the order called, the fastest
> website would return its data first.
>
> So I wrote a test program, trying to create a new thread for each
> site, where I use LWP to retrieve the website, when I get the
> response object back, I want to return it so it can be passed
> on to another sub for parsing and processing. So In theory, I thought
> that the fastest sites would return first if they finished, but
> in practice, all the sites were accessed seriallly, the first site in the
> list returned first, and the last site in the list returned last.
>
> My first thoughts are that LWP is blocking the other threads but i'm not
> really sure
> whats going on. Any advice?
Who knows? You're not showing any code.
> I was thinking of other ways to do this
> like just do forks and IPC, but I can't pass around perl objects
> through sockets, so i'm not sure what is the best way to do this.
Ah, but you can. Use one of the serialization modules like Data::Dumper
(this one comes with Perl). They transform Perl data (including objects)
to and from a stream of ASCII characters which can be sent over a
socket.
Anno
------------------------------
Date: Mon, 26 Feb 2001 00:49:54 -0800
From: Inkswamp <inkswamp@nas.com>
Subject: regexp clarification
Message-Id: <260220010049544157%inkswamp@nas.com>
I'm currently reading a PERL tutorial that I found on the web and I ran
across a regexp example that I have a question about. Here it is:
$pet =~ s/\bcat\b/feline/ig;
The example is supposed to demonstrate replacing the word "cat" with
the word "feline" and the \b (non-word character) around the "cat" is
there to avoid replacing occurences of "cat" in words like "catharsis"
and "staccato".
That makes sense, but wouldn't the word "feline" replace the two \b
characters too? Am I not understanding this properly?
In other words, the way I'm reading it, a sentence like this:
My cat is gray.
would end up like this:
Myfelineis gray.
Is that wrong?
--Rick
------------------------------
Date: Mon, 26 Feb 2001 09:22:13 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: regexp clarification
Message-Id: <slrn99k81c.jlu.rgarciasuarez@rafael.kazibao.net>
Inkswamp wrote in comp.lang.perl.misc:
> I'm currently reading a PERL tutorial that I found on the web and I ran
> across a regexp example that I have a question about. Here it is:
>
> $pet =~ s/\bcat\b/feline/ig;
>
> The example is supposed to demonstrate replacing the word "cat" with
> the word "feline" and the \b (non-word character) around the "cat" is
> there to avoid replacing occurences of "cat" in words like "catharsis"
> and "staccato".
>
> That makes sense, but wouldn't the word "feline" replace the two \b
> characters too? Am I not understanding this properly?
\b is not a character, it's a "zero-length assertion" : in other words,
a marker introduced in regular expressions to modify the matcher
automaton to verify additional constraints. \b matches not only where a
space is next to a letter, but also at the beggining of a string like
"catharsis ". Perl provides many regexp assertions like this one; other
simple examples are the well-known ^ and $. It's also possible to define
one's own assertions. Those features are extensively described in the
perlre section of the docs. Hope this helps.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Mon, 26 Feb 2001 02:38:25 -0800
From: Inkswamp <inkswamp@nas.com>
Subject: Re: regexp clarification
Message-Id: <260220010238250919%inkswamp@nas.com>
In article <slrn99k81c.jlu.rgarciasuarez@rafael.kazibao.net>, Rafael
Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> \b is not a character, it's a "zero-length assertion" : in other words,
> a marker introduced in regular expressions to modify the matcher
> automaton to verify additional constraints. \b matches not only where a
> space is next to a letter, but also at the beggining of a string like
> "catharsis ". Perl provides many regexp assertions like this one; other
> simple examples are the well-known ^ and $. It's also possible to define
> one's own assertions. Those features are extensively described in the
> perlre section of the docs. Hope this helps.
Thanks! That helps a great deal. I wasn't making any differentiation
between actual characters and assertions as you describe them. I guess
I was thinking of it being more like a search and replace function in a
word processor which is probably way off-base.
BTW, I should have said in my previous post that I don't have access to
a machine or web server where I can test this out which is why I asked
here.
------------------------------
Date: Mon, 26 Feb 2001 10:29:32 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: Should this work?. Beginners db question. Please help
Message-Id: <MPG.15044065234b565a9898c4@news.online.no>
In article <l6Tl6.20810$5n4.440299@news6-win.server.ntlworld.com>,
pi@mty.com says...
> $dbh = DBI->connect('dbi:mysql:maindb');
Add this...
unless (defined $dbh) {
# output error message
}
...to be sure that the database handle really _is_ defined.
--
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/
------------------------------
Date: 26 Feb 2001 10:43:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: timeout connect() with select?
Message-Id: <97dc0n$i65$1@mamenchi.zrz.TU-Berlin.DE>
According to h. <perlCHEESE@CHEESEatlaswebmail.com>:
> Hello,
> I need to timeout a Socket connect() to a POP3 server. I know how to do
> it using alarm(), but I'd much rather use the more reliable and more widely
> supported select() call. I have know idea how select() really works, I've
> only
> seen examples with File handles and the IO::select methods. I've tried
> numerous random ways of calling the select function with Sockets. I finally
There is absolutely no difference in the use of select() on sockets
and its use on other filehandles. At least there shouldn't be.
Trying "random ways" to find how a feature works isn't the way to
go. Read the documentation.
> settled on one that, if connected, returns immediately, and if not
> connected, returns after a specified $timeout instead of whatever timeout
> the underlying TCP mechnism sets (75 seconds on my machine).
>
> Here is the subroutine I'm using:
>
> sub timedConnect
> {
> use Socket;
> my $socket_handle=shift;
> my $packed_address=shift;
> my $timeout=shift;
> my ($ein,$eout); #only using $ein though...
No, you're using $eout.
> vec($ein, fileno($socket_handle), 1) = 1; # set Socket to non
> blocking???
vec() here just prepares a bit vector the way select() needs it.
The statement doesn't change the behavior of the socket. You can
use IO::Select for an interface that does the bit fiddling internally.
> while(select(undef,undef,$eout=1,$timeout))
Here you're using $eout in the position where the file numbers
to be checked for errors are expected. Also, you're setting it
to the integer 1, but it must be a bit string of file numbers.
This doesn't make sense.
> {
> # since $eout=1, I always get here
> # ( immediately if connected, after $timeout if not)
> connect($socket_handle,$packed_address);
> my $saved_fh=select($socket_handle);
> $|=1; # autoflush
> select($saved_fh);
> return 1;
> }
> # If I set $eout=$ein, I always get here..
> # if I set $eout=undef, I always get here
> return 0;
> }
>
> Notice I set $ein=1 in the select call. This is what always forces it to
> return 1.
If it does, it's only incidental.
[rest of code snipped]
You should acquaint yourself with select by reading perldoc select
and man select. The way you're using it here looks pretty random
indeed.
Anno
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 356
**************************************