[22242] in Perl-Users-Digest
Perl-Users Digest, Issue: 4463 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 24 21:05:58 2003
Date: Fri, 24 Jan 2003 18: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)
Perl-Users Digest Fri, 24 Jan 2003 Volume: 10 Number: 4463
Today's topics:
Re: Changing the context of a code block <eric.anderson@cordata.net>
Re: Changing the context of a code block (Tad McClellan)
Re: Checking IP Ranges in one line <charlest@indysoft.com>
Re: Checking IP Ranges in one line <charlest@indysoft.com>
Re: Checking IP Ranges in one line (Ben Morrow)
Re: Checking IP Ranges in one line (Tad McClellan)
ExtUtils::MakeMaker / @INC <usenet@tinita.de>
Re: Perl & CGI Security <me@privacy.net>
Re: Perl & CGI Security (Tad McClellan)
perl email question <CalinG@cfgroup.ca>
Re: perl email question <tassilo.parseval@post.rwth-aachen.de>
Re: perl email question (Ben Morrow)
Re: perl email question <bigj@kamelfreund.de>
Re: perl email question (Tad McClellan)
Problem w ref within Modules & OO <penny1482@attbi.com>
Re: Problem w ref within Modules & OO <bkennedy@hmsonline.com>
Re: Problem w ref within Modules & OO (Jay Tilton)
Re: reflected form of $/ (Jay Tilton)
Socket server <news2@tvreclames.nl>
Re: Socket server (Ben Morrow)
Re: Socket server <news2@tvreclames.nl>
Re: unlink() <goldbb2@earthlink.net>
Re: unlink() Andrew Lee
Re: unlink() (Tad McClellan)
Where to find documentation for syntax on "if"? <jcornwall@cox.net>
Re: Where to find documentation for syntax on "if"? (Malcolm Dew-Jones)
Re: Where to find documentation for syntax on "if"? <krahnj@acm.org>
Re: Where to find documentation for syntax on "if"? (Tad McClellan)
Re: Where to find documentation for syntax on "if"? <jurgenex@hotmail.com>
Re: Where to find documentation for syntax on "if"? <JCornwall@cox.net>
Re: win32 tieregistry html (Jay Tilton)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 24 Jan 2003 07:05:18 -0500
From: "Eric Anderson" <eric.anderson@cordata.net>
Subject: Re: Changing the context of a code block
Message-Id: <pan.2003.01.24.12.05.16.234409@cordata.net>
On Fri, 24 Jan 2003 17:25:30 +0000, Brian McCauley wrote:
> package is a compile-time directive. Even if package() could use a
> variable it wouldn't help you since you'd have to have already set the
> variable at compile time.
In the actual program it is getting the package name from an object which
has not determined the package name until runtime. I am just using what I
gave you as an example to show what I am trying to achieve.
> You may need to use eval(STRING) but I suspect this is XY.
When I eval(STRING) then it does not change the context of the following
code. I think this is because the evaluated code must execute in it's own
context or something.
> What is your X?
Not sure I understand your question.
--
Eric Anderson
------------------------------
Date: Fri, 24 Jan 2003 19:46:26 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Changing the context of a code block
Message-Id: <slrnb33r3i.gft.tadmc@magna.augustmail.com>
Eric Anderson <eric.anderson@cordata.net> wrote:
> On Fri, 24 Jan 2003 17:25:30 +0000, Brian McCauley wrote:
>> You may need to use eval(STRING) but I suspect this is XY.
>> What is your X?
>
> Not sure I understand your question.
----------------------------------------
From: mjd@plover.com (Mark Jason Dominus)
Newsgroups: comp.lang.perl.misc
Date: Fri, 08 Jun 2001 14:34:03 GMT
Message-ID: <3b20e25a.320b$214@news.op.net>
An XY problem is when you want to do X, but you ask how to do Y
instead, because you've decided that Y is the best way to accomplish X.
----------------------------------------
Brian is asking what the ultimate problem that you are trying
to solve is (X), it might be that you don't really need to
do "silly package tricks" (Y), but we can't tell unless we
know what the X is.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Jan 2003 15:48:59 -0500
From: "Charles R. Thompson" <charlest@indysoft.com>
Subject: Re: Checking IP Ranges in one line
Message-Id: <v339lsl11iiib6@corp.supernews.com>
It's gonna take me awhile to wrap my brain around that :) . From first few
tests though it doesn't appear to be working. Again.. I need to really look
at it before I even venture to hard what's not quite right. At first glance
though...
$ipblock =~ /^64\.(\d+)\.
Shouldn't that be...
$ipblock =~ /^64\.
It appears there are 4 .'s instead of three in the regexp.
Just a dummy first look :)
"Abigail" <abigail@abigail.nl> wrote in message
news:slrnb32nfu.dce.abigail@alexandra.abigail.nl...
> Charles R. Thompson (charlest@indysoft.com) wrote on MMMCDXXXII September
> MCMXCIII in <URL:news:v30h3b9igr2g90@corp.supernews.com>:
> '' There is mention of this in various posts, and I even question it in a
> '' recent post, but have broken it off here for clarity. Is it possible
to
> '' match a range of numbers located in a string with a one line regexp?
Using
> '' IPs as an example... keep in mind we aren't looking to see if this is
a
> '' valid IP, etc ad nauseum that's not what this thread should be
about... How
> '' might one go about checking a provided IP to see if set of numbers
matches
> '' a range?
> ''
> '' example...
> ''
> '' Given this regexp: ^64.(152|153|154|155|156|157|158|159).(.*?)$
> '' -or-
> '' if ($ipblock =~ /^64.(152|153|154|155|156|157|158|159).(.*?)$/) { #
do
> '' stuff }
> ''
> '' easily matches
> '' 64.152.0.0 through 64.159.255.255
> ''
> '' How can it be modified in the same one line regexp to do without the
> '' excessive or'ing? Is this a job for backreferencing?
>
>
> Untested code:
>
> $ipblock =~ /^64\.
> (\d+)\.(?(?{152 <= $^N && $^N <= 159})|(?!X)X)
> (\d+)\.(?(?{0 <= $^N && $^N <= 255})|(?!X)X)
> (\d+)\.(?(?{0 <= $^N && $^N <= 255})|(?!X)X)
> $/x;
>
>
> Abigail
> --
> I'll put "ranges" to Regexp::Common's TODO list.
------------------------------
Date: Fri, 24 Jan 2003 15:56:19 -0500
From: "Charles R. Thompson" <charlest@indysoft.com>
Subject: Re: Checking IP Ranges in one line
Message-Id: <v33a3mt4sfruef@corp.supernews.com>
I understand what you are saying pretty clearly, but I have read numerous
threads where it has been banged into newbie heads that a scalar is a scalar
is a scalar.. you can do stuff like
print "4" + 8;
$this = '9';
print $this + 15;
Essentially saying that there is little difference between a string and an
integer. I guess I'm just stepping one foot too deep in the pond by asking
why, since you can perform simple math on what appears to be a string, you
cannot check integer values in a string using a regexp...
Not trying to change the language mind you.. just trying to learn a little.
CT
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb30qr5.brq.tadmc@magna.augustmail.com...
> Charles R. Thompson <charlest@indysoft.com> wrote:
>
> > How
> > might one go about checking a provided IP to see if set of numbers
matches
> > a range?
>
>
> You wouldn't.
>
> Regexs are for working on _strings_, you should use numeric
> operators for working on numbers (though you may need a regex
> to pluck out the numberish parts).
>
>
> > is this a job for backreferencing?
>
>
> No, it is a job for > and/or < :-)
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Fri, 24 Jan 2003 23:05:09 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Checking IP Ranges in one line
Message-Id: <b0sgr5$mp0$1@wisteria.csv.warwick.ac.uk>
[Top-posting fixed. Please don't do it again.]
"Charles R. Thompson" <charlest@indysoft.com> wrote:
>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>news:slrnb30qr5.brq.tadmc@magna.augustmail.com...
>> Charles R. Thompson <charlest@indysoft.com> wrote:
>>
>> > How
>> > might one go about checking a provided IP to see if set of numbers
>matches
>> > a range?
>>
>>
>> You wouldn't.
>>
>> Regexs are for working on _strings_, you should use numeric
>> operators for working on numbers (though you may need a regex
>> to pluck out the numberish parts).
>>
>>
>> > is this a job for backreferencing?
>>
>>
>> No, it is a job for > and/or < :-)
>>
>I understand what you are saying pretty clearly, but I have read numerous
>threads where it has been banged into newbie heads that a scalar is a scalar
>is a scalar.. you can do stuff like
>
>print "4" + 8;
>
>$this = '9';
>print $this + 15;
>
>Essentially saying that there is little difference between a string and an
>integer. I guess I'm just stepping one foot too deep in the pond by asking
>why, since you can perform simple math on what appears to be a string, you
>cannot check integer values in a string using a regexp...
Perl allows you to perform numeric operations on string data, and string
operations on numeric data, and will inter-convert as necessary. Range
checking is a numeric operation, so you use numeric operators. If what you
apply the numeric operators to happens to be a string extracted out of
another string with a regex, that doesn't matter. But regexes don't do
numeric comparisons: they do pattern matching and substring-extraction.
Ben
------------------------------
Date: Fri, 24 Jan 2003 18:14:25 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Checking IP Ranges in one line
Message-Id: <slrnb33ln1.g70.tadmc@magna.augustmail.com>
Ben Morrow <mauzo@mimosa.csv.warwick.ac.uk> wrote:
> [Top-posting fixed.
I decided not to respond because of that.
> Please don't do it again.]
He was doing it right back in 1999, must've forgotten. :-)
> "Charles R. Thompson" <charlest@indysoft.com> wrote:
Assuming that that was the same Charles R. Thompson of course.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 24 Jan 2003 22:01:57 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: ExtUtils::MakeMaker / @INC
Message-Id: <tinh98nss$1fe$tina@news01.tinita.de>
hi,
i'm trying to find out in which directory a module
is installed. if it is installed into the default
location, i could look up the paths in %Config,
but if PREFIX is changed, i probably would have
to take all the install dirs from %Config and
remove $Config{prefix}.
however, i hope there is an easier way, as i'm not
sure which of the many %Config keys i have to take.
i'm distributing an application, that means i wrote
a package, let's say MyPackage. in this package there
is the script itself, script.pl (and some config files), and i'm
installing them via EXE_FILES, INSTALLSCRIPT and INST_SCRIPT.
I'm asking the user for the PREFIX and save it into $PREFIX.
The script requires some additional modules from CPAN,
e.g. XML::Simple. to make it
as easy as possible for the user to install (they might not
be familiar with installing modules or perl at all),
i packed the required module tar files into my package,
and them i'm calling
"perl Makefile.PL PREFIX=$PREFIX;make;make install"
for every module that is not installed.
now in script.pl i have to use lib "...", so
that it finds MyPackage and XML::Simple;
normally it would be necessary to say:
use lib "$PREFIX/site-perl/...";
use lib "$PREFIX/site-perl/5.6.1";
use lib "$PREFIX/site-perl/5.6.1/i586-linux";
and so on.
i managed to get around that by setting
INSTALLARCHLIB, INSTALLSITELIB, and INSTALLSITEARCH to $PREFIX, too,
so that MyPackage is directly under $PREFIX and i can just say:
use lib $PREFIX;
use MyPackage;
how can i force XML::Simple (and the other modules) to be
installed there, too?
just calling perl Makefile.PL PREFIX=$PREFIX INSTALLARCHLIB=$PREFIX ...
for every module?
i'm wondering if this will safely work for all modules, or
if i missed something.
appreciating any hints, tina
followp to c.l.p.modules
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Sat, 25 Jan 2003 10:27:15 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Perl & CGI Security
Message-Id: <b0si4m$s9844$1@ID-172104.news.dfncis.de>
"codeWarrior" <GPatnude@adelphia.net> wrote in message
news:GCcY9.1169$ni5.718675@news1.news.adelphia.net...
> "Alex Banks" <alex@alexbanks.com> wrote in message
> news:3e3110c9$0$232$cc9e4d1f@news.dial.pipex.com...
> > Would be grateful if someone could recommend an up-to-date security
guide
> > for CGI Perl.
>
> Look into SSL....
Insecure Perl CGI scripts are still insecure running over HTTPS
------------------------------
Date: Fri, 24 Jan 2003 18:20:15 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl & CGI Security
Message-Id: <slrnb33m1v.g70.tadmc@magna.augustmail.com>
Tintin <me@privacy.net> wrote:
> "codeWarrior" <GPatnude@adelphia.net> wrote in message
> news:GCcY9.1169$ni5.718675@news1.news.adelphia.net...
>> "Alex Banks" <alex@alexbanks.com> wrote in message
>> news:3e3110c9$0$232$cc9e4d1f@news.dial.pipex.com...
>> > Would be grateful if someone could recommend an up-to-date security
> guide
>> > for CGI Perl.
>>
>> Look into SSL....
>
> Insecure Perl CGI scripts are still insecure running over HTTPS
But... but... but one of the "S"s in SSL is for "Secure",
so using SSL must be in the same universe of discourse.
That's all it takes for the Warrior to offer his "knowledgable" "help".
Isn't there a TFM somewhere that you should be reading smartie pants?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Jan 2003 16:25:55 -0500
From: "Tester" <CalinG@cfgroup.ca>
Subject: perl email question
Message-Id: <p4iY9.245192$C8.821823@nnrp1.uunet.ca>
Hi there,
Is there a way I can print out the body of an email message?
I know I can print the header(Subject line) with the following:
#! /usr/bin/perl -w
use strict;
open(OUTFILE, ">test") or die "Cannot open file test:$!\n";
while(<>){
if (/^Subject:/){
print OUTFILE $_;
}
}
close OUTFILE;
Thanks,
Calin
------------------------------
Date: 24 Jan 2003 23:07:37 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: perl email question
Message-Id: <b0sgvp$aog$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Tester:
> Is there a way I can print out the body of an email message?
> I know I can print the header(Subject line) with the following:
> #! /usr/bin/perl -w
> use strict;
> open(OUTFILE, ">test") or die "Cannot open file test:$!\n";
> while(<>){
> if (/^Subject:/){
> print OUTFILE $_;
> }
> }
> close OUTFILE;
The body is separated by one blank line from the header of an email.
Surely, getting anything after the first blank line can't be that hard:
{
local $/ = "\n\n";
my (undef, @body) = <>;
print OUTFILE join "\n", @body;
}
This makes use of the paragraph mode (or not, depending on whether you
consider '$/ = ""' to be the only real paragraph mode; there was a
discussion on that recently). See 'perldoc perlvar' for details on $/.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Fri, 24 Jan 2003 23:20:35 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: perl email question
Message-Id: <b0sho3$n5h$1@wisteria.csv.warwick.ac.uk>
"Tester" <CalinG@cfgroup.ca> wrote:
>Hi there,
>
>Is there a way I can print out the body of an email message?
>I know I can print the header(Subject line) with the following:
>#! /usr/bin/perl -w
>use strict;
>open(OUTFILE, ">test") or die "Cannot open file test:$!\n";
>while(<>){
>if (/^Subject:/){
>print OUTFILE $_;
>}
>}
>close OUTFILE;
No you can't. Given the (invalid and incomplete) message
From: me
To: you
Subject: stuff
This is the first line of body.
Subject: This is the second
.
you will get a spurious line out of the body. If the mail doesn't _have_ a
subject (yes, it should, but it might not) but does have a matching line in
the body, you won't even notice anything's gone wrong.
You can get all the headers in one var and all the body in another with
my (@head, $body);
{
local $/ = "\n\n";
my $head = <>;
$/ = undef;
$body = <>;
@head = split "\n", $head;
}
. If you're doing anything complex you may be better off looking for a
module to do it on CPAN.
Ben
------------------------------
Date: Fri, 24 Jan 2003 23:06:48 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: perl email question
Message-Id: <pan.2003.01.24.21.54.05.982902@kamelfreund.de>
On Fri, 24 Jan 2003 16:25:55 +0000, Tester wrote:
> Is there a way I can print out the body of an email message?
> I know I can print the header(Subject line) with the following:
> #! /usr/bin/perl -w
> use strict;
> open(OUTFILE, ">test") or die "Cannot open file test:$!\n";
> while(<>){
> if (/^Subject:/){
> print OUTFILE $_;
> }
> }
> close OUTFILE;
One way is to search for an empty line that separates the header and the
body:
...
while (<>) {
chomp;
last unless $_;
}
print OUTFILE (<>);
# assuming the bodies aren't too large
# otherwise do something like print $_ while <>;
Of course, that becomes difficult if there are attachments. Another way is
just to use one of the MIME:: or Mail:: modules from CPAN.
Best Wishes,
Janek
------------------------------
Date: Fri, 24 Jan 2003 17:49:01 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl email question
Message-Id: <slrnb33k7d.g38.tadmc@magna.augustmail.com>
Tester <CalinG@cfgroup.ca> wrote:
> Is there a way I can print out the body of an email message?
> I know I can print the header(Subject line) with the following:
> #! /usr/bin/perl -w
> use strict;
> open(OUTFILE, ">test") or die "Cannot open file test:$!\n";
> while(<>){
> if (/^Subject:/){
> print OUTFILE $_;
The print() can only be evaluated when the line starts with "Subject:".
If you want to print all the lines, just remove the test.
> }
> }
> close OUTFILE;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Jan 2003 21:26:00 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Problem w ref within Modules & OO
Message-Id: <IbiY9.21431$VU6.18656@rwcrnsc52.ops.asp.att.net>
I have a problem and maybe an answer. Am going to try to explain w/o posting
whole routines.
Advice from any of you gurus appreciated.
I created a module/pkg that maintains a fixed size stack in an annon array
by 'unshift'ing and 'pop'ing. Thus newest item is in [0] and oldest in
[n-1]. I add data through a 'method', but I read data via $$v[0] or $$v[2],
etc. where my $v = new stack(5). ((Five being the size of the stack.)) It
works FINE & resulting script is very READABLE. I create 10-20 'stack
variables' this way.
Now I am trying use this pkg within another pkg (say B) and want the 'end
use' of B to make it easy to use the zeroth value of some of the 'stack
variables'. So in B initializing I have something like
$self->{V} = \$v->[0];
and then in the using/calling/main script, I get the at the value(s) via
${$foo->{V}};
But the PROBLEM is I do not get the current zeroth value of 'stack variable'
$v. I seem to get the value that existed at the creation of annon array $v.
Through Dumper the values in $v look fine.
So does the ref point at the current value of $$v[0] inspite of the
'unshiftin' and 'pop'
ing, or does it point at the value at the time the ref was saved into
$self->{V}?
And what can I do about it, or is this why I MUST go through an accessor
sort of like
$foo->get('V').
Thanks in advance.
--
Dick Penny
------------------------------
Date: Fri, 24 Jan 2003 16:55:31 -0500
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Problem w ref within Modules & OO
Message-Id: <E8ScnRagJKHgK6yjXTWcqw@giganews.com>
"Dick Penny" <penny1482@attbi.com> wrote in message
news:IbiY9.21431$VU6.18656@rwcrnsc52.ops.asp.att.net...
>
> But the PROBLEM is I do not get the current zeroth value of 'stack
variable'
> $v. I seem to get the value that existed at the creation of annon array
$v.
> Through Dumper the values in $v look fine.
>
> So does the ref point at the current value of $$v[0] inspite of the
> 'unshiftin' and 'pop'
> ing, or does it point at the value at the time the ref was saved into
> $self->{V}?
>
> And what can I do about it, or is this why I MUST go through an accessor
> sort of like
> $foo->get('V').
>
Here is a snippet that verifies your issue:
my @array = qw(A B C D E);
my $i = 0;
foreach (@array) {
print "* Index: $i | Value - $_ | Mem location: " , \$_, "\n";
$i++;
}
shift @array;
print "* post shifting\n";
my $j = 0;
foreach (@array) {
print "* Index: $j | Value - $_ | Mem location: " , \$_, "\n";
$j++;
}
As you can see, the reference to index N in an array will change with the
contents - however, a good OO principle is to limit what calling code can do
to the internals of your code (encapsulation). Giving away a reference to
an internal part of your data structure would qualify as something you
generally don't want to do. You could theoretically maintain an array of
scalar references, and give your calling code the reference of a particular
slot, but then you'd have to constantly be copying your "real" stack into
the stack of scalar references, which is not very efficient.
Giving your calling code a scalar reference also makes life more difficult
if you want to do any of the following at some point in the future:
* Limit access to stack (read-write vs read-only considerations)
* Validate what get stored there (numbers only?)
* Log when/where storage occurs (debugging)
* Create derived class that wants to add new behavior
So go ahead and make an accessor method, it is for reasons like this that
they exist!
--Ben Kennedy
------------------------------
Date: Fri, 24 Jan 2003 23:04:11 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Problem w ref within Modules & OO
Message-Id: <3e31c451.23933191@news.erols.com>
"Dick Penny" <penny1482@attbi.com> wrote:
: I have a problem and maybe an answer. Am going to try to explain w/o posting
: whole routines.
That's good, and that's bad.
Hesitance to post a flood of code is commendable.
But a convoluted prose explanation is a struggle to understand. A
reader will have to scribble out some code of his own, distilling the
explanation to its essence, just to grasp the problem.
A short (less than 30 lines) complete script that demonstrates the
problem is the best compromise.
: I created a module/pkg that maintains a fixed size stack in an annon array
[ Snip. Synopsis of relevant parts: $v is an array reference. ]
: Now I am trying use this pkg within another pkg (say B) and want the 'end
: use' of B to make it easy to use the zeroth value of some of the 'stack
: variables'. So in B initializing I have something like
: $self->{V} = \$v->[0];
: and then in the using/calling/main script, I get the at the value(s) via
: ${$foo->{V}};
:
: But the PROBLEM is I do not get the current zeroth value of 'stack variable'
: $v. I seem to get the value that existed at the creation of annon array $v.
Like this?
#!perl -l
use warnings;
use strict;
my $v = [ qw/foo bar baz/ ];
my $foo = { V => \$v->[0] };
$v = [ qw/qux quux quuux/ ];
print ${$foo->{V}}; # prints 'foo', not 'qux'
__END__
: So does the ref point at the current value of $$v[0] inspite of the
: 'unshiftin' and 'pop'
: ing, or does it point at the value at the time the ref was saved into
: $self->{V}?
$foo->{V} is a reference to a scalar, not to a specific element of the
array. Anything done to the array will have no effect on $foo->{V}.
: And what can I do about it, or is this why I MUST go through an accessor
I wouldn't say "must," but that is the Right Thing. It would also
keep a clumsy programmer from clobbering something important.
------------------------------
Date: Fri, 24 Jan 2003 22:55:08 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: reflected form of $/
Message-Id: <3e31c2f5.23585206@news.erols.com>
ctcgag@hotmail.com wrote:
: I was tempted to say the opposite of $/, but I figure that that would be
: $\. So I will call this reflected rather than opposite.
:
: I often have to process data that is a concatenation of a bunch of files.
: The first line of each subfile is distinctive, but the last lines are
: not.
:
: I want a functionality similar to that given by $/, but having the
: separator be at the front of the record, rather than the end.
Read, chomp, then glue $/ onto the beginning.
The first read should probably be discarded (YMMV), as it will contain
everything up to and including the first record separator.
#!perl -l
use warnings;
use strict;
{
local $/ = 'begin record';
while( <DATA> ) {
next if $. == 1;
chomp;
$_ = $/ . $_;
print; # whatever you need to do with $_
}
}
__DATA__
this is junk before the first record
begin record 1
this is the first record
begin record 2
this is the second record
etc
------------------------------
Date: Fri, 24 Jan 2003 21:00:02 +0100
From: "Bart van den Burg" <news2@tvreclames.nl>
Subject: Socket server
Message-Id: <b0s607$5c9$1@reader10.wxs.nl>
Hi
I'm trying to build an FTP client as part of a larger program
the PASV part works fine, so I stepped into the PORT part
i create a server socket:
sub create_socket {
my ($proto_name) = @_;
my ($proto, $socket, $flags);
local(*S);
$proto = getprotobyname($proto_name);
if (socket(S, PF_INET, SOCK_STREAM, $proto)) {
$socket = *S{IO};
$flags = fcntl($socket, F_GETFL, 0);
$flags |= O_NONBLOCK;
fcntl($socket, F_SETFL, $flags);
}
else {
$errno = $!;
}
return $socket;
}
sub create_server_socket {
my $id = $_[0];
my $proto = getprotobyname('tcp');
$server_info[$id]->{'socket2'} = create_socket('tcp');
setsockopt($server_info[$id]->{'socket2'}, SOL_SOCKET, SO_REUSEADDR,
pack("l", 1)) || die "setsockopt: $!";
bind($server_info[$id]->{'socket2'},
sockaddr_in($server_info[$id]->{"actport"}, INADDR_ANY)) || die "bind: $!";
listen($server_info[$id]->{'socket2'}, SOMAXCONN) || die "listen: $!";
print $server_info[$id]->{"actport"}."!\n";
while (1) {
if (accept(Client, $server_info[$id]->{'socket2'})) {
print Client "test!\n";
my $buffer;
print "$!\n";
while(defined(my $length = sysread($server_info[$id]->{'socket2'},
$buffer, 1024))){
print $buffer;
}
}
}
}
the output is, for example:
"51381" (a.k.a., port which it's connected to)
then I use telnet to connect this port.
the telnet receives:
"test!"
and instantly after that:
"Connection to host lost."
and then the program says:
"Illegal seek"
could anyone tell me what's happening here? I'm kind of clueless
thanks
Bart
------------------------------
Date: Fri, 24 Jan 2003 21:46:25 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Socket server
Message-Id: <b0sc7h$kl6$1@wisteria.csv.warwick.ac.uk>
"Bart van den Burg" <news2@tvreclames.nl> wrote:
>Hi
>
>I'm trying to build an FTP client as part of a larger program
>the PASV part works fine, so I stepped into the PORT part
>i create a server socket:
Use Net::FTP. Don't reinvent wheels, it's never worth it.
Ben
------------------------------
Date: Fri, 24 Jan 2003 22:57:12 +0100
From: "Bart van den Burg" <news2@tvreclames.nl>
Subject: Re: Socket server
Message-Id: <b0scru$bf8$1@reader10.wxs.nl>
Ben Morrow wrote:
> "Bart van den Burg" <news2@tvreclames.nl> wrote:
>> Hi
>>
>> I'm trying to build an FTP client as part of a larger program
>> the PASV part works fine, so I stepped into the PORT part
>> i create a server socket:
>
> Use Net::FTP. Don't reinvent wheels, it's never worth it.
>
> Ben
can't use Net::FTP, because it needs to be non-blocking.
I can't use POE either, nor IO::Socket::INET.
please, don't ask me why
Bart
------------------------------
Date: Fri, 24 Jan 2003 14:21:57 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: unlink()
Message-Id: <3E319255.E825B12D@earthlink.net>
Helgi Briem wrote:
>
> On 24 Jan 2003 11:41:57 GMT,
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> >Alternatively make STDOUT auto-flushing. The second line
> >of all my scripts reads
> >
> > use strict; use warnings; $| = 1;
>
> I wonder about this. Randal does the same. Was all
> the effort OS designers expended on buffering output
> really that much of a waste? You would have thought
> they had some reason for doing it.
Well, any time that you're doing 2>&1 on the commandline (usually since
you're sending output to a file to page through later, or sending output
to the pager directly), then you want to autoflush, since your regular
output and your stdout would not otherwise be properly interleaved.
But if you're sending stdout to a file (or web browser, or somewhere
else other than a terminal), and stderr is going to your terminal (or
perhaps to another log file), then yes, it is a waste of time to turn on
autoflush.
But note, though, that setting $| to 1 only autoflushes the currently
selected filehandle -- not *all* filehandles. So even if you're
unnecessarily autoflushing stdout, it's not going to do much harm, since
the other handles still do normal buffering.
> I never unbuffer output except in CGI scripts and have
> never had problems as a result.
Actually, I would generally leave CGI scripts buffered, unless I'm doing
CGI-push (in which case I turn on autoflush before printing the end-of-
section divider, then turn it back off right after).
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Fri, 24 Jan 2003 16:48:31 -0500
From: Andrew Lee
Subject: Re: unlink()
Message-Id: <guc33vsd7k4lvhtj6f83g6rmdbumgrgdnk@4ax.com>
On Fri, 24 Jan 2003 12:45:52 GMT, helgi@decode.is (Helgi Briem) wrote:
>On Fri, 24 Jan 2003 11:12:27 +0100, Bernard El-Hagin
><bernard.el-hagin@DODGE_THISlido-tech.net> wrote:
>
>>>Then you dare call him rude names.
>>>
>>>*plonk*
>>
>>How can you plonk a Code Warrior, Helgi!?
>
>Using my very own Plonk::Warrior module.
Are you going to put that on CPAN? I volunteer to be a beta tester.
------------------------------
Date: Fri, 24 Jan 2003 17:08:43 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: unlink()
Message-Id: <slrnb33hrr.g38.tadmc@magna.augustmail.com>
Andrew Lee <AndrewLee> wrote:
> On Fri, 24 Jan 2003 12:45:52 GMT, helgi@decode.is (Helgi Briem) wrote:
>>On Fri, 24 Jan 2003 11:12:27 +0100, Bernard El-Hagin
>><bernard.el-hagin@DODGE_THISlido-tech.net> wrote:
>>
>>>>Then you dare call him rude names.
>>>>
>>>>*plonk*
>>>
>>>How can you plonk a Code Warrior, Helgi!?
>>
>>Using my very own Plonk::Warrior module.
>
> Are you going to put that on CPAN? I volunteer to be a beta tester.
It should be generalized a bit before being uploaded, and renamed:
Plonk::Wannabe
or
Plonk::ScriptKiddie
perhaps?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 24 Jan 2003 21:37:37 GMT
From: "James F. Cornwall" <jcornwall@cox.net>
Subject: Where to find documentation for syntax on "if"?
Message-Id: <3E31B221.A4DD9DB6@cox.net>
Hello, I have been given a script to work on (snippet below), and need
some help finding the right place to look up some syntax in the Perl
docs.
This script takes a Fortran 77 module, reads the header comment blocks
our organization puts in there, and builds an HTML file based on the
text found after certain key words.
I have been coding Fortran for years, have only done a couple of trivial
scripts in Perl. The syntax in the "if" statement below has me
searching for a reference and so far I have not found anything in the
perldoc or the one reference book I have that clearly explains it.
Pointers to info will be greatly appreciated.
Book is "Perl: The complete Reference", Martin C. Brown, 1999
# snippet begin
# Initialize "Found_XXX" flags
$header_fg = 0;
# Loop thru each line in the file, for each line we'll scan for
keywords:
while (<>){
# Remove the line feed from the end of the line we are looking at
chomp;
if (/C \* MODULE:/) {
$header_fg = 1;
s/C \* MODULE://;
print "<B>Module: </B> <I>";
print $_;
print "</I> <BR> \n";
}
....
# snippet end
I can see that the "(/C \* MODULE:/)" is setting up an expression that
has to evaluate to true if it finds the string "C * MODULE:" in the
line, but so far all the docs have shown examples that look more like
"($string =~ /MODULE:/). Where can I find a good clear reference that
would hopefully include this syntax?
Jim Cornwall
jcorn@usgs.gov or jcornwall@cox.net
------------------------------
Date: 24 Jan 2003 14:23:57 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Where to find documentation for syntax on "if"?
Message-Id: <3e31bcfd@news.victoria.tc.ca>
James F. Cornwall (jcornwall@cox.net) wrote:
: Hello, I have been given a script to work on (snippet below), and need
: some help finding the right place to look up some syntax in the Perl
: docs.
: would hopefully include this syntax?
Try the online documentation, two suggestions
perldoc perlop
perldoc perlsyn
Look for the m// operator.
------------------------------
Date: Fri, 24 Jan 2003 23:46:57 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Where to find documentation for syntax on "if"?
Message-Id: <3E31D014.E12C612B@acm.org>
"James F. Cornwall" wrote:
>
> Hello, I have been given a script to work on (snippet below), and need
> some help finding the right place to look up some syntax in the Perl
> docs.
perldoc perlsyn
> This script takes a Fortran 77 module, reads the header comment blocks
> our organization puts in there, and builds an HTML file based on the
> text found after certain key words.
>
> I have been coding Fortran for years, have only done a couple of trivial
> scripts in Perl. The syntax in the "if" statement below has me
> searching for a reference and so far I have not found anything in the
> perldoc or the one reference book I have that clearly explains it.
> Pointers to info will be greatly appreciated.
You need to lookup the $_ variable in perlvar
perldoc perlvar
> Book is "Perl: The complete Reference", Martin C. Brown, 1999
>
> # snippet begin
> # Initialize "Found_XXX" flags
> $header_fg = 0;
>
> # Loop thru each line in the file, for each line we'll scan for
> keywords:
> while (<>){
>
> # Remove the line feed from the end of the line we are looking at
> chomp;
>
> if (/C \* MODULE:/) {
> $header_fg = 1;
> s/C \* MODULE://;
^^^^^^^^^^^^^^
You don't need to do this twice.
if ( s/C \* MODULE:// ) {
$header_fg = 1;
> print "<B>Module: </B> <I>";
> print $_;
> print "</I> <BR> \n";
> }
> ....
> # snippet end
>
> I can see that the "(/C \* MODULE:/)" is setting up an expression that
> has to evaluate to true if it finds the string "C * MODULE:" in the
> line, but so far all the docs have shown examples that look more like
> "($string =~ /MODULE:/). Where can I find a good clear reference that
> would hopefully include this syntax?
$_ is the default for many of Perl's operators and functions (chomp,
print, m//, etc.) so that an explicit variable is not required. If you
used an explicit variable your snippet would look like:
# snippet begin
# Initialize "Found_XXX" flags
my $header_fg = 0;
# Loop thru each line in the file, for each line we'll scan for
keywords:
while ( my $line = <> ) {
# Remove the line feed from the end of the line we are looking at
chomp $line;
if ( $line =~ s/C \* MODULE:// ) {
$header_fg = 1;
print "<B>Module: </B> <I>";
print $line;
print "</I> <BR> \n";
}
....
# snippet end
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 24 Jan 2003 17:46:45 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Where to find documentation for syntax on "if"?
Message-Id: <slrnb33k35.g38.tadmc@magna.augustmail.com>
James F. Cornwall <jcornwall@cox.net> wrote:
> some help finding the right place to look up some syntax in the Perl
> docs.
> The syntax in the "if" statement below has me
> searching for a reference and so far I have not found anything in the
> perldoc or the one reference book I have that clearly explains it.
> Pointers to info will be greatly appreciated.
See the "Regexp Quote-Like Operators" section in:
perldoc perlop
> Book is "Perl: The complete Reference", Martin C. Brown, 1999
That is a horrid book!
Sell it on Ebay and buy a Real Perl Book.
Learning to program in Perl will be easier if you burn it than if
you read it. It is chock full of errors and bad advice.
It was heartily ridiculed in this newsgroup in the thread rooted at:
Message-ID: <7gnc7e$k9i$1@nnrp1.dejanews.com>
> if (/C \* MODULE:/) {
> $header_fg = 1;
> s/C \* MODULE://;
> print "<B>Module: </B> <I>";
> print $_;
> print "</I> <BR> \n";
> }
That is Silly Perl. This does the same thing:
if ( s/C \* MODULE:// ) {
$header_fg = 1;
print "<B>Module: </B> <I>";
print $_;
print "</I> <BR> \n";
}
There is no need to test for a match before you do a substitution
with the same pattern.
> I can see that the "(/C \* MODULE:/)" is setting up an expression that
> has to evaluate to true if it finds the string "C * MODULE:" in the
> line, but so far all the docs have shown examples that look more like
> "($string =~ /MODULE:/).
The above match is the same as:
$_ =~ s/C \* MODULE://;
> Where can I find a good clear reference that
> would hopefully include this syntax?
The pattern match operator needs a string to try and match against.
If you don't give it one, it uses Perl's Favorite Default, namely $_;
If you want it to try and match a string that is somewhere besides
in $_, then you need to use the "binding operator" (=~) to tell
perl which string to use.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 25 Jan 2003 00:40:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Where to find documentation for syntax on "if"?
Message-Id: <E1lY9.3321$cJ6.46@nwrddc02.gnilink.net>
James F. Cornwall wrote:
[...]
> # snippet begin
[...]
> # Remove the line feed from the end of the line we are looking at
> chomp;
>
> if (/C \* MODULE:/) {
[...]
> I can see that the "(/C \* MODULE:/)" is setting up an expression
> that has to evaluate to true if it finds the string "C * MODULE:"
> in the line,
Right. It is the short form of the 'm' operator (aka match) which is
explained in 'perldoc perlop'.
> but so far all the docs have shown examples that look
> more like "($string =~ /MODULE:/).
That is still the same match operator, but instead of matching the default
$_ this code uses the binding operator "=~" to make "m" to match $string
instead of $_.
Again, this binding operator "=~" can be found in 'perldoc perlop'.
> Where can I find a good clear
> reference that would hopefully include this syntax?
BTW: this has nothing to do with 'if' as your subject would imply. You can
use those operators anywhere you want.
jue
------------------------------
Date: Sat, 25 Jan 2003 01:29:54 GMT
From: "J. F. Cornwall" <JCornwall@cox.net>
Subject: Re: Where to find documentation for syntax on "if"?
Message-Id: <mMlY9.43104$1b.17762@news1.central.cox.net>
Jürgen Exner wrote:
> James F. Cornwall wrote:
> [...]
>
Thank you, everyone, for the pointers and explanations. I'll see if I
can get my bosses to spring for a better book, that's just the one I
have currently available. I'll look at the online docs now that I have
an idea *where* to look in them. As far as the scripts go, I inherited
them, but I am supposed to clean them up so I appreciate the suggestions
everyone made.
Jim Cornwall
------------------------------
Date: Fri, 24 Jan 2003 22:47:49 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: win32 tieregistry html
Message-Id: <3e31c27e.23466182@news.erols.com>
"Nuno Cancelo" <nac@advancecare.com> wrote:
: use Win32::TieRegistry;
: $username=$Registry->{"HKEY_CURRENT_USER\\Software\\Microsoft\\"
: . "Windows\\CurrentVersion\\Explorer\\\\Logon User Name"};
Is there a reason for not using Perl's own getlogin() function?
------------------------------
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 4463
***************************************