[17455] in Perl-Users-Digest
Perl-Users Digest, Issue: 4875 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 13 00:06:15 2000
Date: Sun, 12 Nov 2000 21:05:06 -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: <974091906-v9-i4875@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 12 Nov 2000 Volume: 9 Number: 4875
Today's topics:
Re: A surprise with vec() (Gwyn Judd)
Re: A surprise with vec() <lincmad001@telecom-digest.zzn.com>
Re: A surprise with vec() (Martien Verbruggen)
Re: activeperl: reading registry (gb)
Re: FS: "Programming Perl" (Mark Badolato)
Re: HELP!! MIME attached file <kmonte@columbus.rr.com>
Re: New to perl - Problems with Labels ! Please Help. msalerno@my-deja.com
Re: New to perl - Problems with Labels ! Please Help. <friedman@math.utexas.edu>
Re: New to perl - Problems with Labels ! Please Help. <lincmad001@telecom-digest.zzn.com>
Re: New to perl - Problems with Labels ! Please Help. (Garry Williams)
Re: New to perl - Problems with Labels ! Please Help. (Garry Williams)
Re: New to perl - Problems with Labels ! Please Help. (Garry Williams)
Re: Perl for Win95 <elephant@squirrelgroup.com>
Re: Pushing a hash on to a stack... (Christopher Burke)
Re: Pushing a hash on to a stack... (Christopher Burke)
running telnet automatically erdavila@my-deja.com
Why doesn't this Net::NNTP script work? <bfb@att.net>
Re: Why doesn't this Net::NNTP script work? (Garry Williams)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 12 Nov 2000 23:49:08 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: A surprise with vec()
Message-Id: <slrn90ub3h.rv1.tjla@thislove.dyndns.org>
I was shocked! How could Ilya Zakharevich <ilya@math.ohio-state.edu>
say such a terrible thing:
>[A complimentary Cc of this posting was sent to Gwyn Judd
><tjla@guvfybir.qlaqaf.bet>],
>who wrote in article <slrn90t3sv.pt9.tjla@thislove.dyndns.org>:
>> I get that too (linuxppc with 5.6). Looks like a bug to me.
>
>Hint: which bits are set in $x after $x = 0?
$x = 0;
print unpack 'b*', $x;
This prints:
00001100
$x = "\0";
print unpack 'b*', $x;
This prints:
00000000
Help me out here.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
I've had one child. My husband wants to have another. I'd like to watch
him have another.
------------------------------
Date: Sun, 12 Nov 2000 16:43:38 -0800
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: A surprise with vec()
Message-Id: <121120001643382353%lincmad001@telecom-digest.zzn.com>
In article <slrn90ub3h.rv1.tjla@thislove.dyndns.org>, Gwyn Judd
<tjla@guvfybir.qlaqaf.bet> wrote:
> I was shocked! How could Ilya Zakharevich <ilya@math.ohio-state.edu>
> say such a terrible thing:
> >[A complimentary Cc of this posting was sent to Gwyn Judd
> ><tjla@guvfybir.qlaqaf.bet>],
> >who wrote in article <slrn90t3sv.pt9.tjla@thislove.dyndns.org>:
> >> I get that too (linuxppc with 5.6). Looks like a bug to me.
> >
> >Hint: which bits are set in $x after $x = 0?
>
> $x = 0;
> print unpack 'b*', $x;
>
> This prints:
>
> 00001100
>
> $x = "\0";
> print unpack 'b*', $x;
>
> This prints:
>
> 00000000
>
> Help me out here.
Here's another hint:
$x = 0 versus $x = '0' versus $x = "\0"
for (0..128) {
my $y = unpack 'b*', $_;
print "$_\t$y\n";
}
The answer is on page 236 and page 240 of the Camel book.
------------------------------
Date: Mon, 13 Nov 2000 01:37:46 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: A surprise with vec()
Message-Id: <slrn90uhed.mf.mgjv@verbruggen.comdyn.com.au>
On Sun, 12 Nov 2000 23:49:08 GMT,
Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
> I was shocked! How could Ilya Zakharevich <ilya@math.ohio-state.edu>
> say such a terrible thing:
>>[A complimentary Cc of this posting was sent to Gwyn Judd
>><tjla@guvfybir.qlaqaf.bet>],
>>who wrote in article <slrn90t3sv.pt9.tjla@thislove.dyndns.org>:
>>> I get that too (linuxppc with 5.6). Looks like a bug to me.
>>
>>Hint: which bits are set in $x after $x = 0?
>
> $x = 0;
> print unpack 'b*', $x;
>
> This prints:
>
> 00001100
>
> $x = "\0";
> print unpack 'b*', $x;
>
> This prints:
>
> 00000000
unpack and vec work on the string part of a scalar. A perl scalar has
an integer part, and a string part, and Perl will convert on the fly.
The 0 gets converted to the string '0', and ord('0') is 48. If you
print your bitstring in a more commonly used order, you can see what
happens:
print unpack 'B*', '0';
print ord('0');
00110000
48
Try the same with 1, 'a' and others.
Of course, the "\0" gets converted to a real 0.
Martien
--
Martien Verbruggen |
Interactive Media Division | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Mon, 13 Nov 2000 02:42:46 GMT
From: gbnews@arcticmail.com (gb)
Subject: Re: activeperl: reading registry
Message-Id: <3a0f547c.29097437@news.lineone.net>
On Sun, 12 Nov 2000 12:42:44 -0500, H C <carvdawg@patriot.net> wrote:
>Check the docs for Win32::TieRegistry
>
>EM wrote:
>
>> i have windows me with activeperl installed
>> is there a way to read/write a key from the windows registry?
>>
>> thanks in advance
>
>--
>Q: Why is Batman better than Bill Gates?
>A: Batman was able to beat the Penguin.
The penguin is overrated,has crap usability and hci and doesn't
recognise a lot of hardware.
In ten years it might become as lean and mean as win95
on a pc.
You Linux snobs cannot see past your own bias.
;->
>
------------------------------
Date: 13 Nov 2000 04:44:26 GMT
From: mbadolato@cybernox.com (Mark Badolato)
Subject: Re: FS: "Programming Perl"
Message-Id: <8FEAD94D0mbadolatocybernoxcom@206.165.3.80>
qx11@cornell.edu (David) wrote in
<8FE9E6250qx11cornelledu@132.236.56.8>:
>"Programming Perl"
>by Larry Wall, Tom Christiansen, Randal L. Schwartz, Stephen Potter
>Paperback - 645 pages 2nd edition (October 1996)
>O'Reilly & Associates; ISBN: 1565921496
>Brand New Condition, Asking $25
>
Um, you can get a brand new *3rd* edition from bookpool.com for $29.
--mark
------------------------------
Date: Mon, 13 Nov 2000 04:24:11 GMT
From: "kmonte" <kmonte@columbus.rr.com>
Subject: Re: HELP!! MIME attached file
Message-Id: <L1KP5.1884$vA6.29481@typhoon.columbus.rr.com>
use MIME::Lite;
That module does all of the encoding for you, and there are sufficient
examples included to do what you are looking for.
It will also reduce your script down to a handful of lines.
Good luck.
"leslie" <leslies@santaland.com> wrote in message
news:VSCP5.28532$25.5971678@news1.rdc1.ne.home.com...
> I have figured out how to send a file using sendmail and MIME format. But
> for some reason whenever you receive the mail that it sends out.. the file
> is just empty.. nothing there.. basically the only thing that goes through
> is that there is an attached file and the name of the attached file but
the
> contents of the file dont seem to go through.. Here is a copy of the code
i
> am using .. someone please help.
------------------------------
Date: Sun, 12 Nov 2000 23:00:52 GMT
From: msalerno@my-deja.com
Subject: Re: New to perl - Problems with Labels ! Please Help.
Message-Id: <8un7f1$ir9$1@nnrp1.deja.com>
In article <3A0F1B9D.16DEBE0F@math.utexas.edu>,
Chas Friedman <friedman@math.utexas.edu> wrote:
> Why do you have FIRST in quotes? Next can be followed by a label,
but I
> think this shouldn't be in quotes.
> On the other hand, goto can be followed by an expression (which can
be a
> string.)
>
> chas friedman
>
> msalerno@my-deja.com wrote:
> ...
>
> > #THIS IS THE LINE THAT I AM HAVING PROBLEMS WITH !
> > next "FIRST"; }
>
> ...
>
>
I have removed the quotes from the label, still getting "Label not
found" I only want it to loop 3 times, then I want it to exit.
Anything else that I have missed ?
Thanks,
Matt
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 12 Nov 2000 17:29:50 -0600
From: Chas Friedman <friedman@math.utexas.edu>
Subject: Re: New to perl - Problems with Labels ! Please Help.
Message-Id: <3A0F27EE.2FED8E6A@math.utexas.edu>
Looks to me like your "next FIRST" statement isn't inside the FIRST
block...
chas friedman
------------------------------
Date: Sun, 12 Nov 2000 15:45:04 -0800
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: New to perl - Problems with Labels ! Please Help.
Message-Id: <121120001545041010%lincmad001@telecom-digest.zzn.com>
In article <8un7f1$ir9$1@nnrp1.deja.com>, <msalerno@my-deja.com> wrote:
> In article <3A0F1B9D.16DEBE0F@math.utexas.edu>,
> Chas Friedman <friedman@math.utexas.edu> wrote:
> > Why do you have FIRST in quotes? Next can be followed by a label,
> > but I think this shouldn't be in quotes. On the other hand, goto
> > can be followed by an expression (which can be a string.)
> >
> > chas friedman
> >
> > msalerno@my-deja.com wrote:
> > ...
> >
> > > #THIS IS THE LINE THAT I AM HAVING PROBLEMS WITH !
> > > next "FIRST"; }
> >
> > ...
> >
> >
> I have removed the quotes from the label, still getting "Label not
> found" I only want it to loop 3 times, then I want it to exit.
> Anything else that I have missed ?
More to the point, what is it that you are trying to do? The logic of
your script [posted earlier in this thread] is muddled, to say the
least.
You said that you want the script to validate IP addresses. How exactly
do you want to validate them? Are you just looking for any dotted quad
of decimal numbers 0 to 255? If so, then what is this business with
entering two IP addresses? In your comparison, you should use "eq"
instead of "=~", particularly to guard against cases like 1.2.3.4
matching with 11.2.3.45, besides which it's more efficient.
On the issue of the trailing dot, you match it in your regular
expression. What you want instead of /^[\d.]+$/ is something like this:
/^(\d{1,3}\.){3}\d{1,3}$/
As to the behavior of split, and why it doesn't give you five arguments
if you have a trailing dot, see page 220 of the Camel book.
You might also want to do a search on CPAN <http://www.cpan.org> to see
if there is a module that does what you want. Since there are lots of
Perl things that work with the Internet, it's a good bet.
------------------------------
Date: Mon, 13 Nov 2000 00:43:38 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: New to perl - Problems with Labels ! Please Help.
Message-Id: <_OGP5.302$xb1.16377@eagle.america.net>
On Sun, 12 Nov 2000 22:11:56 GMT, msalerno@my-deja.com
<msalerno@my-deja.com> wrote:
>Sorry about posting the entire script, but I didn't know where the
>best place to cut would be. Please all keep in mind that I am still
>very new at this. The issue is that I need the script to validate Ip
>addresses. I cannot get the script to recognize labels with "next".
>If I change the "next" to a "goto" it will work. But I don't want a
>goto ! Also if I enter the ip address of "10.10.10.10." it accepts
>it, the trailing decimal should be read as an error. Please let me
>know where I have gone wrong.
Maybe you didn't get an answer from your first post because the code
below is so hard to read. You should review the perlstyle manual
page. The use of white space and a consistent indentation style is
suggested there. Anyway, let's give this a go...
I will answer your question below, but I hope you don't mind a bit of
commentary on the code on the way to the answer.
>#!/usr/bin/perl -w
>use strict;
You say you're very new to this, but you have already picked up a
very good habit!
>use vars qw($comp1 $comp2);
There's really no need for package variables here (unless there is
code elsewhere that you don't show that depends on it). A file-scoped
lexical will work fine.
>sub ip_check {
>my @ipa = split /\./, $_[0];
>return "1" unless $_[0] =~ /^[\d.]+$/ and @ipa == 4;
>foreach my $i ( 0..3 ) {
>return "1" unless $ipa[$i] >= 0 and $ipa[$i] < 256;}
>$_[0]=~s/(^|\.)0+(\d)/$1$2/g;
>return $_[0]; }
># END ip_check
Let's reformat that code before we look at it:
sub ip_check {
--> my @ipa = split /\./, $_[0];
return "1" unless $_[0] =~ /^[\d.]+$/ and @ipa == 4;
foreach my $i ( 0..3 ) {
return "1" unless $ipa[$i] >= 0 and $ipa[$i] < 256;
}
$_[0] =~ s/(^|\.)0+(\d)/$1$2/g;
return $_[0];
} # END ip_check
Ah, now I can see the structure.
It looks like you are validating a string as a well-formed IP address.
The convention you're using is a return of the string "1" to mean
"invalid" and otherwise you return the IP address string with possible
leading zeros squeezed out. (The string "1" can simply be the number
1 the way you're using it.) Hmmm.
While your code below relies on this, it is more conventional for Perl
programmers to return the result, if successful and false otherwise.
Your code will work, but it would be less confusing for you to return
undef or "" for the error condition.
One more thing I notice is the "C" style of the foreach statement. A
more perlish way to say that is,
foreach my $i ( @ipa ) {
return 1 unless $i >= 0 and $i < 256;
}
or simply,
for ( @ipa ) {
return 1 unless $_ >= 0 and $_ < 256;
}
To answer your last question, "why is 10.10.10.10. considered valid?",
you need to look at the perlfunc manual page for the description of
the split() function:
split /PATTERN/,EXPR,LIMIT
split /PATTERN/,EXPR
split /PATTERN/
split
...
If LIMIT is specified and positive, splits into no more than that
many fields (though it may split into fewer). If LIMIT is
unspecified or zero, trailing null fields are stripped
You can fix your bug by specifying a third parameter (5) on the marked
line containing your split() call.
Actually, this function (validating an IP address) is so commonly
needed, it has been done before. Here's a complete replacement for
your ip_check() subroutine that uses the Perl module Socket and its
supplied functions inet_aton() and inet_ntoa(). The returned value is
an IP address string in canonical form (no leading zeros). It
properly rejects invalid IP addresses (even if they are simply ending
with an additional period).
use Socket;
sub ip_check {
return 1 unless my $ip = inet_aton($_[0]);
inet_ntoa($ip);
}
># Get the First IP Address
>FIRST: for (1..3)
>{print "Enter the First Ip Address: ";
>chomp(my $ip1 = <STDIN>);
>($comp1) = ip_check($ip1);
> last unless $comp1 eq 1;
> print "\nInvalid Ip Address\n";
> next; }
Reformatting for readability:
# Get the First IP Address
FIRST:
for (1..3) {
print "Enter the First Ip Address: ";
chomp(my $ip1 = <STDIN>);
($comp1) = ip_check($ip1);
last unless $comp1 eq 1;
print "\nInvalid Ip Address\n";
--> next;
}
That marked line is completely redundant and can be removed.
You are prompting for an IP address and checking its validity.
Invalid responses cause you to try again for a total of three times.
If an invalid response is received after three prompts, you use it
anyway by falling through. I can't see how this can be correct.
Perhaps you want to exit the script after three attempts? Maybe you
could count the attempts, then:
# Untested
my $err_cnt;
FIRST:
while (1) {
print "Enter the First Ip Address: ";
chomp(my $ip1 = <>);
$comp1 = ip_check($ip1);
last unless $comp1 eq 1;
print "\nInvalid Ip Address\n";
die "too many errors" if ++$err_cnt == 3;
}
># Get the Second IP Address
>SECOND: for (1..3)
>{print "Enter the Second Ip Address: ";
>chomp(my $ip2 = <STDIN>);
>($comp2) = ip_check($ip2);
>print "\n$comp1\n$comp2";
> last unless $comp2 eq 1;
> print "\nInvalid Ip Address\n";
> print "First IP Address: $comp1\n";
>#THIS IS THE LINE THAT I AM HAVING PROBLEMS WITH !
> next "FIRST"; }
Reformatting for readability:
# Get the Second IP Address
SECOND:
for (1..3) {
print "Enter the Second Ip Address: ";
chomp(my $ip2 = <STDIN>);
--> ($comp2) = ip_check($ip2);
print "\n$comp1\n$comp2";
last unless $comp2 eq 1;
print "\nInvalid Ip Address\n";
print "First IP Address: $comp1\n";
#THIS IS THE LINE THAT I AM HAVING PROBLEMS WITH !
--> next "FIRST";
}
[No need for the parentheses on the marked line. Your ip_check()
function returns a single scalar. There's no need for quotes around a
LABEL in Perl, ether.]
What is your intention here? Do you really want to prompt for the
first IP address again, if the user make three errors on the *second*
IP address? If so, then what makes you think that next is the correct
statement to use? There is *no* containing loop here, so it makes no
sense to say next and mean an outer loop. From the perlsyn manual
page:
Loop Control
The `next' command is like the `continue' statement in C; it
starts the next iteration of the loop:
LINE: while (<STDIN>) {
next LINE if /^#/; # discard comments
...
}
and from the perlfunc manual page;
next LABEL
next
The `next' command is like the `continue' statement in C; it
starts the next iteration of the loop:
LINE: while (<STDIN>) {
next LINE if /^#/; # discard comments
#...
}
Note that if there were a `continue' block on the above, it would
get executed even on discarded lines. If the LABEL is omitted, the
command refers to the innermost enclosing loop.
I'm afraid that you will have to say goto here, since there is no
*outer* loop to start another iteration. (I don't see why you want to
prompt for the *first* IP address again when you get three invalid
replies to the *second*, but that doesn't change the fact that you are
attempting a goto with a next statement.)
>for (1..3)
>{last unless $comp1 =~ $comp2;
>print "\nThe First and Second Addresses need to be different\n";
>next FIRST;}
>END:
>print "\nEND";
for (1..3) {
--> last unless $comp1 =~ $comp2;
print "\nThe First and Second Addresses need to be different\n";
next FIRST;
}
END:
print "\nEND";
Same thing here. You can't use next when you mean goto. There's no
outer loop here.
The marked statement should be changed to
$comp1 eq $comp2
The `=~' operator doesn't mean the same here. You could write,
last unless $comp1 =~ /\Q$comp2/;
but that would be more work and less efficient. (I suspect that this
is just a typo.)
The for statement seems to be unnecessary. It looks like you simply
want to check to see if the IP addresses are different and prompt
again, if they are not. If you want to limit the number of times this
can happen, then use a counter:
$err_cnt = 0;
if ( $comp1 eq $comp2 ) {
die "too many retries" if ++$err_cnt == 3;
goto FIRST;
}
I guess you could place the whole thing in an outer loop (labeled
FIRST) to get around using the goto statement. You would be able to
prompt from the beginning under certain error conditions and exit the
script with an error after three iterations. But why? This seems
like straightforward code. It's short and no more difficult to find a
label for a goto than a next statement.
--
Garry Williams
------------------------------
Date: Mon, 13 Nov 2000 00:54:15 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: New to perl - Problems with Labels ! Please Help.
Message-Id: <XYGP5.306$xb1.16377@eagle.america.net>
On Sun, 12 Nov 2000 15:45:04 -0800, Linc Madison
<lincmad001@telecom-digest.zzn.com> wrote:
>...
>As to the behavior of split, and why it doesn't give you five arguments
>if you have a trailing dot, see page 220 of the Camel book.
It's on your system in the perlfunc manual page.
>You might also want to do a search on CPAN <http://www.cpan.org> to see
>if there is a module that does what you want. Since there are lots of
>Perl things that work with the Internet, it's a good bet.
Actually Perl is one of the Perl things. Again, it's on your system
in the Socket manual page. (The inet_aton() and inet_ntoa() functions
can be used to validate an IP address.)
--
Garry Williams
------------------------------
Date: Mon, 13 Nov 2000 01:12:22 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: New to perl - Problems with Labels ! Please Help.
Message-Id: <WdHP5.309$xb1.16377@eagle.america.net>
On Mon, 13 Nov 2000 00:43:38 GMT, Garry Williams <garry@ifr.zvolve.net> wrote:
> $err_cnt = 0;
> if ( $comp1 eq $comp2 ) {
> die "too many retries" if ++$err_cnt == 3;
> goto FIRST;
> }
That won't work since I left out two lines:
$err_cnt = 0;
FIRST:
...
if ( $comp1 eq $comp2 ) {
die "too many retries" if ++$err_cnt == 3;
goto FIRST;
}
--
Garry Williams
------------------------------
Date: Mon, 13 Nov 2000 15:32:38 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: Perl for Win95
Message-Id: <MPG.147a19ed6ce3ddcb989893@localhost>
[ posted to comp.lang.perl.misc and CCed to gbnews@arcticmail.com ]
gb wrote ..
>I've never done anything with perl yet but I'm looking to start.
>
>Can anyone tell me what software is best for Win95 and a tutorial for
>installation and a beginning tutorial for perl.
>
>I have Perl 5 on cd but no instructions on how to install. I had a
>look at the ActiveState perl 5.6 web page. This seems quite
>complicated to set up and a 5mb download.
>
>Can anyone tell me how to get started using Win95?
you haven't told us what CD this is that you're talking about - or what
distribution of Perl is on it .. but - definitely you should get the
ActiveState distribution of Perl5 (called ActivePerl)
http://www.activestate.com/Products/ActivePerl/
all relevant links on the download page are working
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Sun, 12 Nov 2000 23:29:53 GMT
From: craznar@hotmail.com (Christopher Burke)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <8FEB50224Craznar@24.192.1.17>
tjla@guvfybir.qlaqaf.bet (Gwyn Judd) wrote in
<slrn90t9ac.qlu.tjla@thislove.dyndns.org>:
>>I think we can assume that as someone not quite experienced enough with
>>PERL that I will not get my question answered.
>
>Actually I think we can safely assume that your "I'm right and everyone
>else is wrong, don't ask me for more information, oh and by the way I
>already solved the problem, and don't tell me anything I might not have
>already known because I'm such a genius, don't try to suggest a
>different way to do it because then you *must* be attacking me" attitude
>has landed you in killfiles everywhere. But hey, you're in such good
>company you'd probably think that's a good thing.
I stated I had already solved the problem in the original post - from that
point on I was bombarded with sarcasm and attacks. I also have stated
several times that Perl is new to me - but I am a long term programmer.
--
---
/* Christopher Burke - Spam Mail to craznar@hotmail.com
|* www.craznar.com - International Internet Writing Experiment
\* Real mail to cburke(at)craznar(dot)com
------------------------------
Date: Sun, 12 Nov 2000 23:39:32 GMT
From: craznar@hotmail.com (Christopher Burke)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <8FEB66880Craznar@24.192.1.17>
ren.maddox@tivoli.com (Ren Maddox) wrote in <m3g0kxjefq.fsf@dhcp11-
177.support.tivoli.com>:
>craznar@hotmail.com (Christopher Burke) writes:
>
>> mgjv@tradingpost.com.au (Martien Verbruggen) wrote in
>> <slrn90sihq.gs3.mgjv@martien.heliotrope.home>:
>>
>> >Can we no assume that the question has been answered?
>> >
>>
>> My decades of programming have obviously left the wrong meaning of
>> reference imprinted ... so I have no idea what the perl world actually
>> means by a reference. I'll just plod along with what I have.
>
>Perhaps you could clarify exactly what meaning of reference your
>decades of programming have left you with?
>
>The meaning that we are using is that a reference is a handle, of
>sorts, to another structure in memory. If you assign the reference to
>another variable, you then have *two* references to the same structure
>in memory. Changing either one is visible via both . For example,
>you previously posted code similar to:
>
>$hash{x} = 5;
>$hash{y} = 10;
># some sort of push of the hash onto @array here
>$array[0]{x} == 5 or die; # yes, I added the or die part
>$array[0]{y} == 10 or die;
>
>Here's the kicker, no matter *how* you accomplish the push there, be
>it with an explicit reference (push @array, \%hash), an anonymous
>reference (push @array, { %hash }), or some other method, the fact
>that you are using this syntax to get to the values ($array[0]{x})
>means that you can also do:
>
>$hash_ref = $array[0];
>$hash_ref->{x} = 15;
>$array[0]{x} == 15 or die;
>
>The point here is that $array[0] contains a *reference* to a hash. If
>you assign that reference to another variable, then you now have two
>references to the same hash. Modifying either one of them is the same
>thing.
>
>So, how does this differ from your meaning of reference?
In C .... "a=3" "a[0]=3" "a.x=3" do not contain references (even though I
know that all three deep down are references to address space". Well that
is how I learnt anyway. "a[0]->x = 3" or "a->x = 3" both use references.
>
>> I think we can assume that as someone not quite experienced enough with
>> PERL that I will not get my question answered.
>
>Well, I suppose that depends on your question:
>
>If your question is/was, "Can I enable the syntax $array[0]{x} to work
>without using references?", then the answer is, "No, you cannot, that
>uses references."
No thats not the question - the question is can I use the push syntax - but
still leave $array[0]{x} = unchanged. That is not use '->', Which is what I
meant by not use references.
>If your question is/was, "Can I use push to populate an array such
>that the syntax $array[0]{x} works, without taking a reference to an
>existing structure (i.e. \%hash)?", then the answer is "Yes, you just
>need to use anonymous structures (i.e. { %hash })."
Thats pretty much what my question was, and {%hash} may well be the answer.
>
>If your question is/was neither of these, then you'll probably need to
>restate it to get an answer.
I originally didn't care what syntax the push statement had, as long as the
statements before and after didn't use '->', which unfortunately I
interpret as a reference.
>It is most certainly not true that people here don't want to answer
>your question. I am certainly trying to do so and I know that others
>are as well.
Thank you for your assistance... this is all a basic language problem, I
had no idea until recently in the thread that my definition of references
is different from 'reality'.
--
---
/* Christopher Burke - Spam Mail to craznar@hotmail.com
|* www.craznar.com - International Internet Writing Experiment
\* Real mail to cburke(at)craznar(dot)com
------------------------------
Date: Mon, 13 Nov 2000 01:21:21 GMT
From: erdavila@my-deja.com
Subject: running telnet automatically
Message-Id: <8unfme$p2v$1@nnrp1.deja.com>
I'm trying to develop a Perl script that connects on a remote host
using telnet, logs in, runs some commands and logs out. The commands'
outputs will be processed by the script and then printed. This script
must run in a web server (Apache).
Does it worth to use sockets in the Perl script? Or is there any
solution to automatize the running of commands through telnet (maybe
using telnet scripts...)?
Thanks.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 13 Nov 2000 03:15:37 GMT
From: Bernie <bfb@att.net>
Subject: Why doesn't this Net::NNTP script work?
Message-Id: <3A0F5CD0.5E57152B@att.net>
Can someone please tell me why the script below will not
post the message to the alt.test newsgroup?
-Thanks
----------------
#!/usr/bin/perl -w
use Net::NNTP;
$c = new Net::NNTP('netnews.worldnet.att.net');
@header = ("Newsgroups: alt.test\n", "Subject: testAAA\n", "From: testerAAA\n");
@body = ("This is the body of the article");
$c->postok() or warn "Posting not allowed \n";
$c->post(@header, " ", @body);
------------------------------
Date: Mon, 13 Nov 2000 03:59:23 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Why doesn't this Net::NNTP script work?
Message-Id: <vGJP5.336$xb1.18078@eagle.america.net>
On Mon, 13 Nov 2000 03:15:37 GMT, Bernie <bfb@att.net> wrote:
>
>Can someone please tell me why the script below will not
>post the message to the alt.test newsgroup?
>
>#!/usr/bin/perl -w
>use Net::NNTP;
>$c = new Net::NNTP('netnews.worldnet.att.net');
>@header = ("Newsgroups: alt.test\n", "Subject: testAAA\n", "From: testerAAA\n");
>@body = ("This is the body of the article");
>$c->postok() or warn "Posting not allowed \n";
>$c->post(@header, " ", @body);
It won't post because of a 441 error. The Net::NNTP module will tell
you, if you ask it. Here's what I got from your code when I asked
Net::NNTP to help me:
Net::NNTP: Net::NNTP(2.19)
Net::NNTP: Net::Cmd(2.18)
Net::NNTP: Exporter(5.562)
Net::NNTP: IO::Socket::INET(1.25)
Net::NNTP: IO::Socket(1.26)
Net::NNTP: IO::Handle(1.21)
Net::NNTP=GLOB(0x2d0bb8)<<< 200 Powered by Typhoon --
Net::NNTP=GLOB(0x2d0bb8)>>> MODE READER
Net::NNTP=GLOB(0x2d0bb8)<<< 200 Powered by Typhoon --
Net::NNTP=GLOB(0x2d0bb8)>>> POST
Net::NNTP=GLOB(0x2d0bb8)<<< 340 Send Article to be Posted
Net::NNTP=GLOB(0x2d0bb8)>>> Newsgroups: alt.test
Net::NNTP=GLOB(0x2d0bb8)>>> Subject: testAAA
Net::NNTP=GLOB(0x2d0bb8)>>> From: garry@zvolve.com
Net::NNTP=GLOB(0x2d0bb8)>>> This is the body of the article
Net::NNTP=GLOB(0x2d0bb8)>>> .
Net::NNTP=GLOB(0x2d0bb8)<<< 441 Posting Failed (Article header
post failed
Net::NNTP=GLOB(0x2d0bb8)>>> QUIT
Net::NNTP=GLOB(0x2d0bb8)<<< 205 GoodBye
This version operates as expected:
#!/usr/local/bin/perl -w
use strict;
use Net::NNTP;
my @header = (
"Newsgroups: alt.test\n",
"Subject: testAAA\n",
"From: garry\@zvolve.com\n",
);
my @body = ("This is the body of the article\n");
my $c = new Net::NNTP('news.america.net',
Debug => 1);
#$c->reader;
$c->postok() or die "Posting not allowed \n";
$c->post(@header, "\n", @body) or warn "post failed\n";
Here's what it produced:
Net::NNTP: Net::NNTP(2.19)
Net::NNTP: Net::Cmd(2.18)
Net::NNTP: Exporter(5.562)
Net::NNTP: IO::Socket::INET(1.25)
Net::NNTP: IO::Socket(1.26)
Net::NNTP: IO::Handle(1.21)
Net::NNTP=GLOB(0x2d0bd0)<<< 200 Powered by Typhoon --
Net::NNTP=GLOB(0x2d0bd0)>>> MODE READER
Net::NNTP=GLOB(0x2d0bd0)<<< 200 Powered by Typhoon --
Net::NNTP=GLOB(0x2d0bd0)>>> POST
Net::NNTP=GLOB(0x2d0bd0)<<< 340 Send Article to be Posted
Net::NNTP=GLOB(0x2d0bd0)>>> Newsgroups: alt.test
Net::NNTP=GLOB(0x2d0bd0)>>> Subject: testAAA
Net::NNTP=GLOB(0x2d0bd0)>>> From: garry@zvolve.com
Net::NNTP=GLOB(0x2d0bd0)>>>
Net::NNTP=GLOB(0x2d0bd0)>>> This is the body of the article
Net::NNTP=GLOB(0x2d0bd0)>>> .
Net::NNTP=GLOB(0x2d0bd0)<<< 240 Article Posted
Net::NNTP=GLOB(0x2d0bd0)>>> QUIT
Net::NNTP=GLOB(0x2d0bd0)<<< 205 GoodBye
--
Garry Williams
------------------------------
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 V9 Issue 4875
**************************************