[18610] in Perl-Users-Digest
Perl-Users Digest, Issue: 778 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 27 06:05:46 2001
Date: Fri, 27 Apr 2001 03:05:09 -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: <988365908-v10-i778@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 27 Apr 2001 Volume: 10 Number: 778
Today's topics:
Re: Accessing other servers in cgi without LWP <bart.lateur@skynet.be>
Re: Appending to files and flock. <taka@yarn.demon.co.uk>
Re: Benchmark.pm is REALLY inaccurate? <bart.lateur@skynet.be>
Re: best way to evaluate $1 so it's not read-only? <bart.lateur@skynet.be>
Re: best way to evaluate $1 so it's not read-only? <jonni@ifm.liu.se>
Re: best way to evaluate $1 so it's not read-only? <xris@dont.send.spam>
Bijeenkomst Amsterdam Perl Mongers, Dinsdag 1 Mei 2001 (Johan Vromans)
BUG? => Cannot delete file which has more than 19 chara <howc@cyberway.com.sg>
compile <daniel.heiserer@bmw.de>
Re: compile <ubl@schaffhausen.de>
Embedding: why namespace DynaLoader when I use FileHand <nospam@newsranger.com>
Re: Embedding: why namespace DynaLoader when I use File <nospam@newsranger.com>
Re: Functional equivant to =~ operator? <jonni@ifm.liu.se>
Re: match a range of number <andrew_lee@nospamearthlink.net>
problem with seek <pef@trasra.noXX>
Re: referencing elements of a string <bart.lateur@skynet.be>
Re: referencing elements of a string nobull@mail.com
Re: require "file.pl" (vs use ?) to access subroutine i <bart.lateur@skynet.be>
Re: Single character reads on sockets nobull@mail.com
The most complete C interpreter in the world is availab <announce@softintegration.com>" <announce@softintegration.com>
Re: Things I'm just not getting in Perl <andrew_lee@nospamearthlink.net>
Re: Things written to socket not flushed? (Rafael Garcia-Suarez)
Re: Things written to socket not flushed? (Villy Kruse)
Re: Things written to socket not flushed? nobull@mail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 27 Apr 2001 08:13:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Accessing other servers in cgi without LWP
Message-Id: <42aieto9cb39rpf0crdj3q61009kfh7lqq@4ax.com>
Bert DeBoer wrote:
>We are also NOT allowed to use MODULES, and
>every example I find that does something like this uses LWP from the
>libwww-perl-5.53 library. I have tried to understand the module Simple.pm and
>write my own code, but it needs 14 other modules, and all that code pasted
>together gives about a 300k text file. This is way too much to learn for the
>assignment.
The bulk of the action is in LWP::UserAgent. You can see how other
modules, as LWP::Simple, use this, and disect that part of the code.
But, I'd advice you to check out samples on how to get a page through
HTTP using Telnet alone. If you see what you're supposed to send, and
how the server responds, it's not hard to put something together using
bare sockets that works for simple cases like this. For example, I found
this page through a web search:
"Best Viewed with telnet to port 80"
<http://sartre.dgate.org/~brg/bvtelnet80/>
HTH,
Bart.
------------------------------
Date: 27 Apr 2001 10:27:58 +0100
From: Paul the Nomad <taka@yarn.demon.co.uk>
Subject: Re: Appending to files and flock.
Message-Id: <87r8ye4rq9.fsf@euterpe.yarn.demon.co.uk>
abigail@foad.org (Abigail) writes:
> Paul the Nomad (taka@yarn.demon.co.uk) wrote on MMDCCXCV September
> MCMXCIII in <URL:news:87ae53fya8.fsf@euterpe.yarn.demon.co.uk>:
> \\ abigail@foad.org (Abigail) writes:
> \\
> \\ > Paul the Nomad (taka@yarn.demon.co.uk) wrote on MMDCCXCV September
> \\ > MCMXCIII in <URL:news:87oftk0w2a.fsf@euterpe.yarn.demon.co.uk>:
> \\ > ;;
> \\ > ;;
> \\ > ;; I've just been looking at someone's code for a very basic survey/poll
> \\ > ;; cgi. You know, the sort of thing that you see on Slashdot.
> \\ > ;;
> \\ > ;; Every time someone votes the result is appended to a file...something
> \\ > ;; like this:
> \\ > ;;
> \\ > ;; open (FH, ">> results.txt");
> \\ > ;; print FH $result;
> \\ > ;; close FH;
> \\ > ;;
> \\ > ;; However, the author of this code doesn't lock the file at all. Surely
> \\ > ;; as a CGI you might get many attempts to append to the file at the same
> \\ > ;; time. My question is shouldn't flock be used here? Or is there
> \\ > ;; something about 'print FH ...' that makes it atomic?
> \\ >
> \\ >
> \\ > No, it's something about the open mode.
> \\ >
> \\ >
> \\ > Did you study perlopentut?
> \\ >
> \\
> \\ Eh??? That just says the way to lock is to use flock and using lock
> \\ files may cause race conditions.
>
>
> Locking isn't involved here, now is it?
>
What we want to ensure is our exclusive access to a file while we
append to it.
> perlopentut will tell you about the relation of Perls open, and the
> system calls. If you then look up the documentation of the system calls
> you should pay attention to the mode the file is opened.
>
In the code I was talking about the author used just normal 'open' and
not 'sysopen'. In any case, opening the file with sysopen does not
lock it. In fact, a quick look at my system's man page shows that the
C system call 'open' doesn't support locking. It does say, however,
that if two or more people try to append to a file at the same time it
could corrupt the file.
All the examples in perlopentut use flock for file locking, as far as
I can see, and not any fancy bitwise ORing of flags.
>
>
> Abigail
>
--
-----------
Paul
http://www.seditiousdiaries.com/Donald10.html
------------------------------
Date: Fri, 27 Apr 2001 07:52:19 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Benchmark.pm is REALLY inaccurate?
Message-Id: <s09iet409oukqjdgkmm1ojrnh3hf3cndd2@4ax.com>
xris wrote:
>and here everyone was telling me that Benchmark was such a good
>indicator of the speed of various routines... so how come when I run
>the same test three times in a row, I get three VERY different results?
At an average time of between 1.5 and 1.8 seconds, you get a difference
of at most 30 ms. That is under 2 percent. That isn't half bad. If you
also take into account that measurement of start and ending times might
not be too exact, depending on the resolution, half of the variation
might even be caused by this inaccuracy. So you get a speed variation
of, say, 20ms. A bit over 1%.
The rest of the variation will depend on what else the computer was
doing at the time. Disk caching is generally one cause.
IMO you're nitpicking.
--
Bart.
------------------------------
Date: Fri, 27 Apr 2001 07:42:57 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: best way to evaluate $1 so it's not read-only?
Message-Id: <u78iets4b8e0rb90bcesatjoprc71sd8h2@4ax.com>
xris wrote:
>ok, after recently learning that $_[0] (and related vars) are hard
>references to subroutine parameters (and apparently the ONLY way to get
>a hard reference to them), I've started modifying a lot of my functions
>to get some minor speed increases here and there.
This is called micro-optimization. It'll only save you unmeasurable
fractions of percents of execution time. I wouldn't even bother. It's
not worth it.
>Anyway, one of my
>problems is that a lot of these functions are called both on regular
>variables and on substitution patterns. The problem is that $1 and its
>companions are read-only, which causes an error. My sample code is
>below (yes, I know this can be done easier, I'm just using it for
>testing).
>
> sub t {
> $_[0] =~ tr/a-z/A-Z/;
> return $_[0];
> }
This not only returns the new value, but also modified the passed
argument. Unless this is intentional, this coding practice is considered
a very bad habit.
It gives the impression that you are not ready to write code for large,
professional applications.
>but I'm wondering if there's a more efficient way to "evaluate" $1. Or,
>a test I can do on $_[0] to determine if it's accessing a read-only
>value or not. Any suggestions?
Nevertheless, this is a good question. But not for this purpose.
--
Bart.
------------------------------
Date: Fri, 27 Apr 2001 09:48:40 +0200
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: best way to evaluate $1 so it's not read-only?
Message-Id: <9cb88f$2sn$1@newsy.ifm.liu.se>
> >but I'm wondering if there's a more efficient way to "evaluate" $1. Or,
> >a test I can do on $_[0] to determine if it's accessing a read-only
> >value or not. Any suggestions?
>
> Nevertheless, this is a good question. But not for this purpose.
Check out:
clpm april 25 2001, title: Lvalue
/jN
--
_______________________________
Jonas Nilsson
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:u78iets4b8e0rb90bcesatjoprc71sd8h2@4ax.com...
------------------------------
Date: Fri, 27 Apr 2001 03:14:33 -0500
From: xris <xris@dont.send.spam>
Subject: Re: best way to evaluate $1 so it's not read-only?
Message-Id: <xris-58D253.03143327042001@news.evergo.net>
In article <u78iets4b8e0rb90bcesatjoprc71sd8h2@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
> This is called micro-optimization. It'll only save you unmeasurable
> fractions of percents of execution time. I wouldn't even bother. It's
> not worth it.
maybe. but that's just how I am.
> > sub t {
> > $_[0] =~ tr/a-z/A-Z/;
> > return $_[0];
> > }
> This not only returns the new value, but also modified the passed
> argument. Unless this is intentional, this coding practice is considered
> a very bad habit.
actually, it IS intentional; that was the whole point my my question. I
have several routines.. things like:
sub ISOLatin1ToHTML {
$_[0] =~ s/([\xA0-\xFF]|&(?!(?:#\d+|[a-z0-9]+);))/'&#' . ord $1 .
';'/sgieo;
return $_[0];
}
sub HTMLToISOLatin1 {
$_[0] =~ s/&#(\d+);/chr $1/sgeo;
return $_[0];
}
that used to read something like:
sub ISOLatin1ToHTML {
(my $str = shift) =~ s/([\xA0-\xFF]|&(?!(?:#\d+|[a-z0-9]+);))/'&#'
. ord $1 . ';'/sgieo;
return $str;
}
sub HTMLToISOLatin1 {
(my $str = shift) =~ s/&#(\d+);/chr $1/sgeo;
return $str;
}
I was hoping to be able to use them as general functions, so I could
have:
&ISOLatin1ToHTML($var);
(or go so far as to do a "use subs" for them) instead of:
$var = &ISOLatin1ToHTML($var);
> It gives the impression that you are not ready to write code for large,
> professional applications.
I've been programming in perl for over 6 years now (most of it
professional), but have NO formal training (thus, I'm good, but only
within a certain scope). I came across the $_[0] thing a few days ago
when someone here suggested it, and thought I'd try it out for some
optimization (and it does help - speeds some of these routines up by
about a factor of 7 - granted, it's not noticeable if they're only run
once or twice, but I'd like to think that everything helps).
passing by a normal reference won't really do what I want to do here, so
I'm looking for other options.
> Nevertheless, this is a good question. But not for this purpose.
so, is there an answer? benchmark seemed to show that "$1" was the
best. But as I tried to use it, I found that it still results in
"undefined" variables and causes errors when I try to modify them.
Anyway, thanks for the help.
-Chris
------------------------------
Date: 26 Apr 2001 17:42:13 +0200
From: JVromans@Squirrel.nl (Johan Vromans)
Subject: Bijeenkomst Amsterdam Perl Mongers, Dinsdag 1 Mei 2001
Message-Id: <m2k847wtuy.fsf@phoenix.squirrel.nl>
[English version follows the dutch text]
Amsterdam.pm staat voor de "Amsterdamse Perl Mongers", een groep van
gebruikers van Perl. In tegenstelling tot wat de naam suggereert is
Amsterdam.pm niet beperkt tot alleen Amsterdam, maar functioneert, tot
er meer gebruikersgroepen in Nederland zijn, als Nederlandse
gebruikersgroep.
Amsterdam.pm organiseert informele bijeenkomsten waar Perl gebruikers
kunnen samenkomen en informatie en gebruikservaringen met betrekking
tot Perl kunnen uitwisselen. Deze bijeenkomsten vinden normaliter
plaats op elke eerste dinsdag van de maand. De voertaal binnen
Amsterdam.pm is in pricipe Nederlands, maar indien nodig zal Engels
worden gebruikt, b.v. om te communiceren met niet-Nederlandssprekende
aanwezigen.
De eerstvolgende bijeenkomst vindt plaats op dinsdag 1 mei 2001 van
20:00 tot 22:00 uur op het kantoor van Dijkmat, Sarphatistraat 708,
Amsterdam. Voor meer details, waaronder een routebeschrijving, zie
http://www.amsterdam.pm.org/Meetings/next_meeting.html
Liefhebbers van een etentje vooraf kunnen tussen 17:45 en 18:15
verzamelen bij Dijkmat. Om 18:15 (écht om 18:15!) zoeken we een
restaurantje in de buurt om een hapje te eten.
Bezoek onze Web site http://www.Amsterdam.pm.org voor meer details.
[English version]
Amsterdam.pm stands for the Amsterdam Perl Mongers. We're basically a
Perl user group. Despite its name, it is not local to the Amsterdam
environment, but it welcomes Perl mongers from all over the
Netherlands.
Amsterdam.pm organises informal meetings where Perl users can meet,
and exchange information and experiences with regard to using Perl.
The meetings are normally held every first Tuesday of the month.
Although the preferred language for communication is Dutch, English
will be spoken if necessary.
Our next meeting is Tuesday May 1st, from 20:00 till 22:00 at the
office of Dijkmat, Sarphatistraat 708, Amsterdam. See
http://www.amsterdam.pm.org/Meetings/next_meeting.html for more details
and the directions to get there.
Should you want to join some of us for dinner, please gather between
17:45 and 18:15 at Dijkmat. At 18:15 sharp we'll leave for a
restaurant somewhere nearby for dinner.
See http://www.Amsterdam.pm.org for more details.
------------------------------
Date: Fri, 27 Apr 2001 16:58:53 +0800
From: "Ken" <howc@cyberway.com.sg>
Subject: BUG? => Cannot delete file which has more than 19 character <==
Message-Id: <3ae933e1@news.starhub.net.sg>
hi,
I'm now trying to use the Perl FTP.pm to delete
a file inside my AIX system.
The syntax is $ftphandle->delete(filename);
When the file name length is 19 characters and less,
the deletion is OK. But when the file name
is more than 19 chacters, the deletion will FAIL.
Is there a limitation to the perl module,
or which version of the FTP.pm must i use?
Thanx.
------------------------------
Date: Fri, 27 Apr 2001 09:44:11 +0200
From: Daniel Heiserer <daniel.heiserer@bmw.de>
Subject: compile
Message-Id: <3AE9234B.C3903D7E@bmw.de>
Hi,
is there a way to compile/precompile perl and perl/Tk code
so:
a) it is faster at execution time
b) all the code is checked before
c) I can hide what I am doing
daniel
------------------------------
Date: Fri, 27 Apr 2001 10:53:27 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: compile
Message-Id: <3AE94198.9D4B9216@schaffhausen.de>
Daniel Heiserer schrieb:
>
> Hi,
> is there a way to compile/precompile perl and perl/Tk code
> so:
> a) it is faster at execution time
> b) all the code is checked before
> c) I can hide what I am doing
http://www.perl.com/pub/doc/manual/html/pod/perlfaq3.html#How_can_I_compile_my_Perl_progra
->malte
------------------------------
Date: Fri, 27 Apr 2001 07:34:28 GMT
From: Joachim Müller <nospam@newsranger.com>
Subject: Embedding: why namespace DynaLoader when I use FileHandle
Message-Id: <8i9G6.434$SZ5.35003@www.newsranger.com>
This is how I embed perl (t.c):
#include <EXTERN.h>
#include <perl.h>
EXTERN_C void boot_DynaLoader _((CV *cv));
EXTERN_C void xs_init(){
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__);
}
int main(int argc, char **argv, char **env){
PerlInterpreter *my_perl; STRLEN n_a; SV *sv;
perl_construct((my_perl=perl_alloc()));
perl_parse(my_perl, xs_init, argc, argv, (char **)NULL);
perl_run(my_perl);
sv = perl_eval_pv("main::t", TRUE);
}
-------------------------------------------------------------------------------
t.pl:
use FileHandle;
sub t {
print STDERR "*** sub t:";
my @stack = caller(1);
print STDERR "caller:$stack[0],$stack[1], $stack[2]\n";
}
-------------------------------------------------------------------------------
$ cc `perl -MExtUtils::Embed -e ccopts -e ldopts` t.c
$ ./a.out t.pl
*** sub t:caller:DynaLoader,(eval 1), 0
Why am I in namespace 'DynaLoader'? What am I doing wrong ?
How can I switch to namespace 'main' from within 't.c' ?
Thanks for your interest.
Joachim Mueller
Mueller-Joachim at web.de
------------------------------
Date: Fri, 27 Apr 2001 08:56:04 GMT
From: Joachim Müller <nospam@newsranger.com>
Subject: Re: Embedding: why namespace DynaLoader when I use FileHandle
Message-Id: <EuaG6.488$SZ5.37020@www.newsranger.com>
In article <8i9G6.434$SZ5.35003@www.newsranger.com>, Joachim Müller says...
>$ cc `perl -MExtUtils::Embed -e ccopts -e ldopts` t.c
>$ ./a.out t.pl
>*** sub t:caller:DynaLoader,(eval 1), 0
>
>Why am I in namespace 'DynaLoader'? What am I doing wrong ?
>How can I switch to namespace 'main' from within 't.c' ?
>Thanks for your interest.
>
>Joachim Mueller
I forgot to mention the perl version: 5.005_03.
Recently, I made the test with perl 5.6.1.
In perl 5.6.1 I get the namespace main (as expected). So I assume it is
a bug that is not present in the current version.
Joachim Mueller
Mueller-Joachim at web.de
------------------------------
Date: Fri, 27 Apr 2001 09:44:23 +0200
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: Re: Functional equivant to =~ operator?
Message-Id: <9cb80d$2ks$1@newsy.ifm.liu.se>
"Gregory Toomey" <gtoomey@usa.net> wrote in message
news:f47G6.12343$482.60960@newsfeeds.bigpond.com...
>
> We can use the assignment
> $var1 =~ tr/a-z/A-Z/;
It isn't an assignment, but a binder to tell tr to work on $var1 (instead of
$_)
>
> Is there an equivalent tr function? Something like
> $var2 = tr/a-z/A-Z/ ($var1);
Use_
($var2=$var1)=~tr/a-z/A-Z/;
> If there is, then we could use function composition along the following
> lines
> $var2 = s/123/456/g (tr/a-z/A-Z/ ($var));
Use anyone of theese instead, or write your own tr function.
($var2=(($var2=$var1)=~s/123/456/,$var2))=~tr/a-z/A-Z/;
$var2=($_=$var1,s/123/456/,tr/a-z/A-Z/,$_); #This one, I think is
clearest...
($var2=$var1)=~s/123/456/;
$var2=~tr/a-z/A-Z/;
/jN
_______________________________
Jonas Nilsson
------------------------------
Date: Fri, 27 Apr 2001 09:28:02 GMT
From: Andrew Lee <andrew_lee@nospamearthlink.net>
Subject: Re: match a range of number
Message-Id: <3AE93C82.F7B884E@nospamearthlink.net>
Abigail wrote:
> David Bouman (david.bouman@nl.xo.com) wrote on MMDCCXCV September
> MCMXCIII in <URL:news:3AE7DA90.6DE3C6A2@nl.xo.com>:
> ?? Abigail wrote:
> ??
> ?? > sub strictly_sorted {
> ?? > strictly_sorted (scalar (@_), 2) ||
> ?? > $_ [0] < $_ [1] && strictly_sorted @_ [1 .. $#_];
> ?? > }
> ??
> ?? Ehm.., doesn't this spell "infinite recursion" ?
>
> We were talking how a mathematician would do it. Certainly smart math
> people won't limit themselves to evaluate an expression in just one way!
> They'll pick the right path.
As opposed to dumb math people?
Thank god that mathematicians have Turing machines ... if it be countable, then it
be resolvable .. etc etc
--
Andrew F. Lee
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When I say, "Ignore the man behind the curtain."
That is because there is no man behind the curtain.
------------------------------
Date: Fri, 27 Apr 2001 11:04:05 +0200
From: "P.Eftevik" <pef@trasra.noXX>
Subject: problem with seek
Message-Id: <3AE93605.212355CD@trasra.noXX>
I want to position the file pointer to the previous line of a file,
using seek:
example:
print $_ ;
seek ( FILE, -1, 1); ## should move pointer one line backwards
print $_;
But the two print statements prints out exactly the same line.
Any idea on where I stumble here ?
thanx for hints.
PEftie
------------------------------
Date: Fri, 27 Apr 2001 08:02:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: referencing elements of a string
Message-Id: <bf9iet0bd96cmmahb717csom7ocic41l0v@4ax.com>
cyberian bear wrote:
>I need to create a tic-tac-toe program. So I need to have three arrays and
>one hash.
>
>#!/usr/bin/perl
>%board = (1, "---", 2, "---",3, "---");
Why not an ordinary array?
@board = ('---', '---', '---');
Note that the array index starts at 0, not 1, though.
>But in perl is language where string is not an array itself so we can't
>access individual elements.
Three solutions.
A: using substr(), you can access (read/modify) individual characters
from a string.
substr($board[0], 1, 1) = "X";
B: replace the strings with anonymous arrays, and you can access
individual items.
@board = (['-', '-', '-'], ['-', '-', '-'], ['-', '-', '-']);
$board[1][1] = 'X'; # middle cell
C: using vec(), you can treat a string as an array of integers. You have
to decide on the size of the array elements in bits, so storing '-', 'X'
and 'O' isn't really an option. Storing 0, 1, 2 is, and just as good,
except for printing.
@board = ('', '', ''); # empty board
vec($board[1],1 , 2) = 1; # middle cell, (1,1)
# A cell can contain 2 bits of information (3rd param).
--
Bart.
------------------------------
Date: 27 Apr 2001 08:47:05 +0100
From: nobull@mail.com
Subject: Re: referencing elements of a string
Message-Id: <u97l06iuhn.fsf@wcl-l.bham.ac.uk>
"cyberian bear" <cyberian_bear@hotmail.com> writes:
> Newsgroups: comp.lang.perl.misc,comp.lang.perl.modules
Can you please explain the thought process by which you reached the
conclusion that anything here was even remotely related to modules?
> I need to create a tic-tac-toe program. So I need to have three arrays and
> one hash.
>
> #!/usr/bin/perl
Get into the habit of "warnings" and "strict" sooner rather than
later. The sooner you do it the less pain you will suffer both before
and after you finally give in and accept that you need it.
> %board = (1, "---", 2, "---",3, "---");
Why are you using a hash (aha associative array) with consecutive
numeric subscripts? If you want an array with consecutive numeric
subscripts then a plain array is the natural choice.
BTW: When writing list that is to be used to initialise a hash it is
conventional to replace alternate commas with the synonymous operator
=> as an aid to readability.
> But in perl is language where string is not an array itself so we can't
> access individual elements.
You can but the syntax is different: perldoc -f substr
> So here I have the first problem. Let's say I want to see if a certain
> position in a table has already been taken up by either "0" or "1". So I
> have to check whether or not the location contains "-".
The operator to test for string equality is eq.
> Second Let say location does contain "-". Then I might decide to either fill
> it in with either "0" or "1". Again I don't see how I can do it since we
> can't access individual elements of a string.
Find the person who told you that you can't access individual elements
of a Perl string, grasp them firmly by the throat and shove a copy of
"perldoc -f substr" somewhere painfull. (That's somewhere painfull on
them, unless of course you are into that sort of thing).
> Can someone please give me a clue on how to get around that problem.
Use substr() or a 2D array.
> PS: One of my classmates gave me a suggestion which I didn't completely
> understand.
Not supprosing, it is full of mistakes.
> Here it is:
> @tictactoe = (['x', '.' ,'0'], ['0', '.', 'x'], ['0', '.' ,'x']);
This is a 2D array in Perl see "perldoc lol"
> $tic[0] => [0] == 'x';
Firstly there is a typo here, => should be -> and it can be (an
usually is) ommited completely anyhow.
Secondly there's another typo here, == should be eq.
Thirdly there's another typo here, tic should be tictactoe since
that's what the variable was called .
Fourthly this is an expression without side effects in a void context
so it does nothing. It probably should have appeared as the condition
in an if ().
Ammusingly, unless you fix the typo the above expression not only does
nothing but always evaluates to false and actually gets completely
optomized away during compliation.
> @new= @{\@tic}
This is just an obfsucated way of saying
@new=@tic
This is a shallow array copy. I have no idea what this was about but
shallow copies of multidementional arrays are not often something you
want to do.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 27 Apr 2001 07:28:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: require "file.pl" (vs use ?) to access subroutine in file.pl ?
Message-Id: <6o7iets04fd3ooeeiq1ev5tfsq3mg6n8f1@4ax.com>
Yeoh Yiu wrote:
>This code works as intended if I leave this block in s.pl:
>
> my $result = chk_ps("bashing");
> open (NULL, ">/dev/null") or die "No null ! $! \n";
> print NULL "Result = $result\n";
> close(NULL);
>
>If I comment out these filehandle lines, as shown below, I get
>
>$ ./m.pl
> s.pl did not return a true value at ./m.pl line 3.
>$
require() demands that the execution of your library file, which also
happens to define variables and subs, to return a true value. The above
code does that. Snipping it makes the library file return undef or
another fals value. So, insert
1;
at the end of the library file, and Bob's your uncle.
>Interestingly, my perldoc -f require gives no example of the form
>require "filename.pl";
>
>So do I need s.pl to return a value to m.pl, or do I need only
>chk_ps() to return the value ?
You don't need to check anything. Just add the above line at the end of
your script to tell require() that the file got properly loaded.
--
Bart.
------------------------------
Date: 27 Apr 2001 08:55:58 +0100
From: nobull@mail.com
Subject: Re: Single character reads on sockets
Message-Id: <u93dauiu1j.fsf@wcl-l.bham.ac.uk>
"David J. Marcus" <djmarcus@ex-pressnet.com> writes:
> On the both the reader and listener side I have used $| = 1 but to no avail.
Are you sure the $|=1 was applied to correct handle?
See FAQ: "How do I flush/unbuffer an output filehandle?..."
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 27 Apr 2001 07:11:33 GMT
From: " SoftIntegration <announce@softintegration.com>" <announce@softintegration.com>
Subject: The most complete C interpreter in the world is available from SoftIntegration.com
Message-Id: <3AE91CA5.E96AFA7A@softintegration.com>
SoftIntegration, Inc. has launched Ch 2.0,
a superset of C interpreter with classes in C++.
Ch is the most complete C interpreter in the world.
Ch makes hard thing easy and easy thing easier.
Ch extends C/C++ with following major features
for programmers to learn C language once,
use it anywhere for almost any programming purposes.
(1) Complete C interpreter supporting all features in
the ISO C90 Standard. C programs can readily run in
Ch across different platforms without tedious
edit/compile/link/debug cycle.
(2) Support major new features such as complex numbers and
variable length arrays (VLA) in the C99 standard.
(3) Support classes in C++ for object-oriented programming.
(4) As interactive portable shell in different platforms.
(5) As a very-high level language (VHLL) environment
for shell programming and system administration.
(6) Built-in secure sandbox and safe Ch applets for
cross-network internet computing.
(7) Advanced numerical computing features such as computational
array as first-class object for linear algebra and
matrix computations.
(8) Auto array bound checking.
(9) Adjustable array bounds, i.e. int a[1:10].
(10) Built-in string type with automatic memory management
and advanced text processing capabilities for shell
programming and script computing.
(11) Support wide characters.
(12) Support POSIX and socket/WinSock.
(13) User-friendly high-level 2D/3D graphical plotting.
(14) Advanced high-level numerical functions for differential
equation solving, integration, Fourier analysis, etc.
(15) Classes for easy CGI programming.
Ch for Windows 95/98/ME/NT/2000, Linux, Solaris,
and HP-UX is available for downloading.
For more information on Ch version 2.0, visit our Web
site at http://www.softintegration.com .
Please feel free to redistribute this announcement.
SoftIntegration, Inc.
http://www.softintegration.com
------------------------------
Date: Fri, 27 Apr 2001 09:16:03 GMT
From: Andrew Lee <andrew_lee@nospamearthlink.net>
Subject: Re: Things I'm just not getting in Perl
Message-Id: <3AE939B2.3D01BA08@nospamearthlink.net>
Abigail wrote:
SNIP ....
> This is certainly not always the case. index(), the boolean function [1]
> that returns true if one string doesn't start with the other does not
> always return 1 for "true".
Read your history, C returns an error state (0 is no error). Did you never hear
the joke about the fall of the Roman Empire?
>
> Hell, not even '||' returns 1 for "true".
'||' is a binary operator ... it takes two arguments ... e.g. True OR true is
true .... write a program and see for yourself.
> [1] boolean function? In *Perl*?!? There are no flippin' booleans in Perl.
> It just inherits the moronic behaviour of C. Real languages have boolean.
Wrong.
Languages (human and others) can do what they want. It is perfectly acceptable
(by definition) to define "yes", "no" -- "true", "false" as logical inverses of
each other (resp.). The issue is whether the syntax matches the semantics. C is
hardly moronic. It follows a perfectly logical pattern (for anyone who as ever
used it).
So ... please define a "real" language ...
--
Andrew F. Lee
Remove 'nospam' to reply
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When I say, "Ignore the man behind the curtain."
That is because there is no man behind the curtain.
------------------------------
Date: 27 Apr 2001 07:09:25 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Things written to socket not flushed?
Message-Id: <slrn9ei6qp.pce.rgarciasuarez@rafael.kazibao.net>
kalasend at YAHOO dot COM wrote in comp.lang.perl.misc:
} hi,
} I'm very new to Perl. (best defender anyway :-)
} I wrote a simple program to just grab the index page of any web server
} given. It uses socket to connect to port 80 of a host, and then do this:
[...]
Do you know that there's modules to do exactly that?
Search the CPAN for LWP.
Example:
perl -MLWP::Simple -e 'print get("http://hostname/")'
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 27 Apr 2001 08:21:09 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Things written to socket not flushed?
Message-Id: <slrn9eiavk.ida.vek@pharmnl.ohout.pharmapartners.nl>
On Thu, 26 Apr 2001 19:21:53 -0700,
kalasend at YAHOO dot COM <dontuspamme@nospammers.com> wrote:
>hi,
> I'm very new to Perl. (best defender anyway :-)
> I wrote a simple program to just grab the index page of any web server
>given. It uses socket to connect to port 80 of a host, and then do this:
>
> my $EOL = "\015\012";
> print SOCK "GET / HTTP/1.1", $EOL;
>
> Then it hangs there forever...I think it could be that the buffer for
>that socket is not flushed? (I can read things from the socket without
>problems, by the way).
>
It is often a good thing to enable autoflush on sockets. Check for
$| in perldoc perlvar.
Villy
------------------------------
Date: 27 Apr 2001 08:34:10 +0100
From: nobull@mail.com
Subject: Re: Things written to socket not flushed?
Message-Id: <u9ae52iw1b.fsf@wcl-l.bham.ac.uk>
"kalasend at YAHOO dot COM" <dontuspamme@nospammers.com> writes:
> I'm very new to Perl. (best defender anyway :-)
This is not relevant, you do not apparently have a Perl probem here.
If you are new to Perl why are making life so difficult? The great
strength of Perl is it's wealth of modules to simplify most common
tasks such as performing HTTP requests.
> Newsgroups: comp.lang.perl.misc,comp.lang.perl.modules
Since you are evidently determined to avoid modules at any cost why are
you posting to clp.modules?
> I wrote a simple program to just grab the index page of any web server
> given.
Using HTTP/1.1!? You are joking right? Implementing the HTTP/1.1
protocol with the manatory requirement to support
"Content-tranfer-encoding: chunked" is far from simple. Hell the
standard Perl module implementing HTTP client hasn't (AFAIK) bitten
that particular bullet yet.
As someone new to Perl think you should start there!?
> It uses socket to connect to port 80 of a host, and then do this:
>
> my $EOL = "\015\012";
> print SOCK "GET / HTTP/1.1", $EOL;
You are using the old (unmodular) socket interface? I thought you
were new to Perl. If you are learning Perl in the 21st centuary the
old socket interface should be studied only out of historical interest
and to allow you to understand/extend low-level and/or legacy code.
> Then it hangs there forever...
Yes is does. If you want to roll your own implementation of an
HTTP/1.1 client then go read the HTTP/1.1 protocol definition.
> I think it could be that the buffer for that socket is not flushed?
You do not show us enough code to know if you've remembered to put
SOCK in autoflush mode.
See FAQ: "How do I flush/unbuffer an output filehandle? Why must I
do this?"
Anyhow, the above code would hang indefinitely whether or not SOCK is
flushed because it has not sent a complete HTTP/1.x request
transaction. This has nothing to do with the choice of Perl as the
implementation language.
Oh, I've just seen your jeopardy style[1] self followup. You are now
(assuming you've got the flushing sorted) sending a complete but
invalid HTTP/1.1 request. Change 1.1 to 1.0 and you may get somewhere
- but you realy should be using LWP.
[1] You are new to Perl and you choose to indulge in rudeness that you
know[2] is likely to get you killfiled by many of the most
knowledgible and helpful people in these groups. Seems kinda
self-destructive to me.
[2] Assuming you've followed these groups at all.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
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 778
**************************************