[19619] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1814 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 25 14:10:31 2001

Date: Tue, 25 Sep 2001 11:10:12 -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: <1001441412-v10-i1814@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 25 Sep 2001     Volume: 10 Number: 1814

Today's topics:
        quick question <na>
    Re: quick question <Laocoon@eudoramail.com>
    Re: quick question <jurgenex@hotmail.com>
        quick regular expression question, please help! <jw005i@mail.rochester.edu>
    Re: quick regular expression question, please help! <Laocoon@eudoramail.com>
    Re: quick regular expression question, please help! <jw005i@mail.rochester.edu>
        Socket question (Paul Neubauer)
    Re: Socket question <joe+usenet@sunstarsys.com>
    Re: Socket question (Randal L. Schwartz)
    Re: Transforming HTML <peb@bms.umist.ac.uk>
    Re: Transforming HTML <oneconcept@yahoo.co.uk>
        using .netrc and Net::Netrc in Win32 <stephen_jowitt@flyingpig.com>
    Re: What good is the hyphen for named parameters? (Anno Siegel)
        What's wrong with this code ? (Laird)
    Re: Why are tabs converted to spaces? (Jonadab the Unsightly One)
    Re: Why are tabs converted to spaces? <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 25 Sep 2001 17:27:58 +0100
From: "NEWS" <na>
Subject: quick question
Message-Id: <3bb0b090$0$231$ed9e5944@reading.news.pipex.net>

im very new to perl and programming.

i want to enter a number using standard input, assign that to a scalar and
then another figure entered by standard input and multiply the scalars
together,

my script goes something like

print "type a number?\t";
$a = <STDIN>;
chomp $a;

print "type another number\t";
$b = <STDIN>;
chomp $b;


$a*$b = $c;

print $c;


BUT it wont work, why ???




------------------------------

Date: Tue, 25 Sep 2001 18:30:36 +0200
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: quick question
Message-Id: <Xns9127BDA5BC85CLaocooneudoramailcom@62.153.159.134>

Because values are always assigned from right to left..

>$a*$b = $c;

$c = $a*$b;

>
>print $c;



------------------------------

Date: Tue, 25 Sep 2001 10:54:35 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: quick question
Message-Id: <3bb0c4db$1@news.microsoft.com>

"NEWS" <na> wrote in message
news:3bb0b090$0$231$ed9e5944@reading.news.pipex.net...
> i want to enter a number using standard input, assign that to a scalar and
> then another figure entered by standard input and multiply the scalars
> together,
> my script goes something like
>
> print "type a number?\t";
> $a = <STDIN>;
> chomp $a;
>
> print "type another number\t";
> $b = <STDIN>;
> chomp $b;
> $a*$b = $c;
> print $c;
>
> BUT it wont work, why ???

"It won't work" is not a very useful description of your problem (or any
problem for that matter).
- Does it substract instead of multiply?
- Does it erase your HD instead of multiplying the numbers?
- Are you unable to read the numbers from the input?
- Does it print the text to a file instead of to the screen?
- ...

Well, copying your snippet into a file and just trying it gives a
compilation error:
    Can't modify multiplication (*) in scalar assignment at C:\tmp\t.pl line
9, near "$c;"
(don't know if this is the problem you have because you didn't tell us what
your problem was).

Anyway, to fix this issue have a look at the line "$a*$b = $c;".
This is a frequent mistake novice programmers make if they are coming from a
mathematics background. In mathematics this would be a logical assertion,
asserting that $c has the same value as $a multiplied by $b.
However in programming this is an assignment. The value of the right side
will be assigned to the left side. Well, how to you assign something to a
multiplication?

Flip it around ($c = $a*$b;), then the result of the multiplication of $a
and $b will be assigned to $c and at least this problem is solved.

On a side note: you want to utilize all the help you can get from Perl
itself. Therefore I strongly recommend to use "use strict; use warnings;" in
every Perl program you write.

jue





------------------------------

Date: Tue, 25 Sep 2001 12:17:21 -0400
From: "James Wexler" <jw005i@mail.rochester.edu>
Subject: quick regular expression question, please help!
Message-Id: <9oqaos$d25q1@biko.cc.rochester.edu>

hey all, im new to perl (about 2 hours) and i want to evaluate a regular
expression kinda like "if( $l =~ s/^Desig:\s+// )" but the regular
expression (that would be "s/^Desig:\s+//" is in a string, lets say $regex).
how do i evaluate this?  thanks for your help

-james




------------------------------

Date: Tue, 25 Sep 2001 18:46:05 +0200
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: quick regular expression question, please help!
Message-Id: <Xns9127C0460D917Laocooneudoramailcom@62.153.159.134>

"James Wexler" <jw005i@mail.rochester.edu> wrote in
news:9oqaos$d25q1@biko.cc.rochester.edu: 

> hey all, im new to perl (about 2 hours) and i want to evaluate a
> regular expression kinda like "if( $l =~ s/^Desig:\s+// )" but the
> regular expression (that would be "s/^Desig:\s+//" is in a string, lets
> say $regex). how do i evaluate this?  thanks for your help

with eval.. perldoc -f eval..

example

$x = '$test =~ s/\s+$//g;';
eval $x;

is same as

$test =~ s/\s+$//g;

> 
> -james
> 
> 



------------------------------

Date: Tue, 25 Sep 2001 13:00:41 -0400
From: "James Wexler" <jw005i@mail.rochester.edu>
Subject: Re: quick regular expression question, please help!
Message-Id: <9oqda8$o52b2@biko.cc.rochester.edu>

thanks a million!

-james

> $x = '$test =~ s/\s+$//g;';
> eval $x;
>
> is same as
>
> $test =~ s/\s+$//g;





------------------------------

Date: 25 Sep 2001 09:45:41 -0700
From: Paul.Neubauer@bsu.edu (Paul Neubauer)
Subject: Socket question
Message-Id: <3711e117.0109250845.151b3c1a@posting.google.com>

Hi folks,

I seem to be having a problem connecting to a socket on a remote
machine. I've boiled it down to a minimal program, which I include
here:

#---------- Cut here -------------#
#! /bin/perl -w
use Socket;
use strict;
my ($host, $port, $iaddr, $paddr, $proto);

$host  = 'foo.bsu.edu';
$port  = 22;

$iaddr = inet_aton($host) or die "no host: $host : $!";
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');

socket  (SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
connect (SOCK, $iaddr) or die "connect: $!";
close   (SOCK) or die "close: $!";
exit;
#---------- Cut here -------------#

The hostname "foo" has been changed. There is no foo.bsu.edu, but when
I run it with a real hostname, I get the following message:

connect: Address family not supported by protocol family at testsock
line 14.

The program above is a cut-down to bare minimum version of the program
on p. 349 of the 2nd ed. of the Camel book.  The full program from the
Camel book doesn't work either.  It dies on the connect line too, even
with "localhost" instead of a remote host.

In this version, I've specified port 22, which is the sshd and is
running. Eventually, what I want to do is check port 1521 to make sure
an Oracle database is running on the remote host before I do other
things on the machine where I intend to run something that would
include this code (or preferably something that works :-) ). I'm not
even trying to read or write to the socket yet and I'm not sure I will
ever need to (for present purposes). All I want to do right now is
determine that foo is accepting connections on that port so I can
start up another program that requires the database to be present.

I haven't managed to make sense of the error message. The connection
is failing, but I can't see why. The address family (?) port 22 on
foo.bsu.edu ought to make sense. The sample client code on p.349 even
picks what it calls a "random port". The ssh protocol *is* a tcp. So
why is port 22 not supported by the "protocol family" (which
presumably (?) means "tcp")?  I'm missing something big here.

Thanks for reading this. If you have any suggestions, I'd love to hear
them. I'd also really appreciate an e-mail copy since our newsfeed has
been abominable lately. It seems that the newsfeed goes south every
time I really need to post a very serious question. It's so bad right
now that I've resorted to posting through google, which is real
desperation for me. I will check groups.google.com for responses, so I
hope not to miss any, but I really would appreciate the kindness of an
e-mail copy to ensure that I don't.  Thanks.

-- 
Paul
Paul.Neubauer@bsu.edu


------------------------------

Date: 25 Sep 2001 13:15:25 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Socket question
Message-Id: <m3vgi7chua.fsf@mumonkan.sunstarsys.com>

Paul.Neubauer@bsu.edu (Paul Neubauer) writes:

> $iaddr = inet_aton($host) or die "no host: $host : $!";
> $paddr = sockaddr_in($port, $iaddr);
> $proto = getprotobyname('tcp');
> 
> socket  (SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
> connect (SOCK, $iaddr) or die "connect: $!";
                 ^^^^^^

I think you want $paddr here - too many hoops!  IMO the $proto/$paddr 
variables are superfluous, so I'd recommend something like

  socket  SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp') or die $!;
  connect SOCK, sockaddr_in( $port, inet_aton($host) )      or die $!;

-- 
Joe Schaefer   "A foolish consistency is the hobgoblin of little minds, adored
                      by little statesmen and philosophers and divines."
                                               -- Ralph Waldo Emerson



------------------------------

Date: 25 Sep 2001 10:25:50 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Socket question
Message-Id: <m18zf3npwh.fsf@halfdome.holdit.com>

>>>>> "Paul" == Paul Neubauer <Paul.Neubauer@bsu.edu> writes:

Paul> Hi folks,
Paul> I seem to be having a problem connecting to a socket on a remote
Paul> machine. I've boiled it down to a minimal program, which I include
Paul> here:

Paul> #---------- Cut here -------------#
Paul> #! /bin/perl -w
Paul> use Socket;
Paul> use strict;
Paul> my ($host, $port, $iaddr, $paddr, $proto);

Paul> $host  = 'foo.bsu.edu';
Paul> $port  = 22;

Paul> $iaddr = inet_aton($host) or die "no host: $host : $!";
Paul> $paddr = sockaddr_in($port, $iaddr);
Paul> $proto = getprotobyname('tcp');

Paul> socket  (SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
Paul> connect (SOCK, $iaddr) or die "connect: $!";
Paul> close   (SOCK) or die "close: $!";
Paul> exit;
Paul> #---------- Cut here -------------#

I'll shorten it down much tighter:

use IO::Socket;
my $host  = 'foo.bsu.edu';
my $port  = 22;
my $socket = IO::Socket::INET->new("$host:$port") or die "$!";

Stop using hard-to-use interfaces!

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Tue, 25 Sep 2001 15:30:37 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Transforming HTML
Message-Id: <3BB0950D.B14CD8DD@bms.umist.ac.uk>

Raj wrote:

> Thanks to all who helped with my socket problem earlier.  Now I have another
> problem.  I am using a Perl script to output HTML.  I need to take the
> values that I have in an associative array and plug them into text boxes.
> This is what I currently have, and it doesn't work:
> 
> while(<PAGE>) {
>                         print;
>                         if (/<FORM/) {
>                                 if (/<INPUT TYPE="text" NAME="x(.*?)" /) {
>                                         tr/$&/$& VALUE="$address{$1}"/;
>                                 }
>                         }
> }
> 
> I have text boxes in the HTML file which is opened which are named the same
> as the corresponding key in the associative array, preceded by an "x", e.g.
> The text box NAME="xFname" needs to have the value from $address{"Fname"}.
> 
> Any ideas please?

The tr operator is not what you want here. Have a look at the s///
operator.  Specifically with the 'e' modifier. i.e. s///e;

If you haven't got a good Perl book then the documentation that comes
with Perl is good.  Try looking at the perlre pod (by typing 'perldoc
perlre' on the command line).

HTH

Paul


------------------------------

Date: Tue, 25 Sep 2001 18:33:51 +0100
From: "Raj" <oneconcept@yahoo.co.uk>
Subject: Re: Transforming HTML
Message-Id: <1001439225.25716.0.nnrp-02.c2d95a2c@news.demon.co.uk>

Paul Boardman" <peb@bms.umist.ac.uk> wrote in message
news:3BB0950D.B14CD8DD@bms.umist.ac.uk...
> > I have text boxes in the HTML file which is opened which are named the
same
> > as the corresponding key in the associative array, preceded by an "x",
e.g.
> > The text box NAME="xFname" needs to have the value from
$address{"Fname"}.
> >
> > Any ideas please?
>
> The tr operator is not what you want here. Have a look at the s///
> operator.  Specifically with the 'e' modifier. i.e. s///e;

I get OK printed under each text box with this code so I know the match is
working correctly, however the value is not being plugged into the text box.
I have checked and the associative array is being populated.

if (/<INPUT TYPE="text" NAME="x(.*?)" /i) {
                                s/$&/$& VALUE="$address{$1}"/;
                                print "<P>OK</P>";
                        }

I know that $& represents the matched part of the reg exp but does this
value remain for the next line or do I need to put it into a scalar
variable?

Basically, I would like to turn:

<INPUT TYPE="text" NAME="xFname">

into:

<INPUT TYPE=text" NAME="xFname" VALUE="Raj">

I'm sure its quite simple but I guess so am I! :o(




------------------------------

Date: Tue, 25 Sep 2001 16:40:12 +0100
From: Stephen Jowitt <stephen_jowitt@flyingpig.com>
Subject: using .netrc and Net::Netrc in Win32
Message-Id: <3BB0A55C.3640057D@flyingpig.com>

Hi,

I need to use some of the networking functionality provided
by the Net modules in Perl.

Specifically, I would like to use a .netrc file for automated FTP
from a win2k client. Where can I find this file? Is it even called
 .netrc on windows?

Help?



------------------------------

Date: 25 Sep 2001 16:44:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <9oqca6$ff9$3@mamenchi.zrz.TU-Berlin.DE>

According to Michael Carman  <mjcarman@home.com>:
> "Stephen O. Lidie" wrote:
> > 
> > my $therm = $mw->Thermometer(
> >     -label  => 'Reactants Temp',
> >     -tscale => 'Celsius',
> > )->pack;
> > 
> > And yes, it does make the option distinct from its value.
> 
> Much of the time, perhaps, but not always. (Which is what Bart was
> taking issue with.) There's no reason you can't say
> 
>     my %hash = (-key => '-sometext', -nextkey => '-moretext');
> 
> At any rate, if you format your code as above, the leading '-' doesn't
> add anything anyway. All you have to do is look at which side of the =>
> the text is on.
> 
> [To Bart] I don't think there's a particularly useful reason (from a
> perl perspective) for doing it -- it's just tradition.

Yes, but this kind of tradition can spread like a fashion.  In the
Tk world, the "-key" format serves a purpose, simplifying the transition
from other sources, so by all means let them have it.  But I've seen
unrelated modules where the leading minus was introduced for no good
reason, and then it's just silly.

Anno


------------------------------

Date: 25 Sep 2001 08:40:29 -0700
From: kenlaird@yahoo.com (Laird)
Subject: What's wrong with this code ?
Message-Id: <94a02505.0109250740.7fb3c52c@posting.google.com>

Hi everybody ,

I've got this file

---
#       name-1
service         numberone              COMMENTS
#       name-2
service         numbertwo              COMMENTS
#       name-3
service         numberthree
#       name-4  name-5                  COMMENTS
service         numberfour
service         numberfive
#       name-6  name-7                  COMMENTS
#service        numbersix
#service        numberseven
#       name-other                      COMMENTS
service         numberother

---


I'm trying to put numberone after name-1
numbertwo after name-2
numberthree after name-3
numberfour after name-4
numberfive after name-5
numberother after name-other


The lines with name-6,name-7 and service numbersix and numberseven
should be skipped because the service is commented.

This is my code

open (IN,"data");
while( <IN> ) {
                push @names, /\b(name-\S+)/g ;
      		( ($service) = /^\S+\s+(\S+)/) 
                print "name    = ", shift(@names), "\n";
                print "service = $service\n";
		}

And this is the outcome

name    = name-1
service = numberone
name    = name-2
service = numbertwo
name    = name-3
service = numberthree
name    = name-4
service = numberfour
name    = name-5
service = numberfive
name    = name-6
service = numberother



I tried
 
push @names, /\b(name-\S+)/g if(next=~/^ser/)

but it won't work either .


Any idea how to make work ?


Ken Laird


------------------------------

Date: Tue, 25 Sep 2001 15:20:16 GMT
From: jonadab@bright.net (Jonadab the Unsightly One)
Subject: Re: Why are tabs converted to spaces?
Message-Id: <3bb0a081.9849273@news.bright.net>

"Jürgen Exner" <jurgenex@hotmail.com> wrote:

> "Laocoon" <Laocoon@eudoramail.com> wrote in message
> news:Xns9124E3171F6A2Laocooneudoramailcom@62.153.159.134...
> > One Tab = 8 spaces..
> > What else do you expect to be printed?
> 
> Actually it's 0-8 spaces, depending on where the next tab stop is.

The number of spaces varies, depending on user setup.  
(Tabs are no more than four spaces on my system...)

-- 
$_=$j="(.";s/$/.)/;$o=$_;s/..//;$k=reverse;($a,$b,$c,)="U r bad"=~
"$j$k$j$k$j+)";($f,$d)="lyons"=~"$o.$o";$_=$d;s/s/o/;$;=reverse($c
 ."a$_");s/o/e/ ;$e="O$_";$g="h";s/$/t/;$ := ".$_";($i) =/(.)$/;$,=
"ig$g$i";$\="he $a$d$,$f $e <j$;\@b$b$,$:>$/";print"$/-- $/J$; $i";


------------------------------

Date: Tue, 25 Sep 2001 16:57:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why are tabs converted to spaces?
Message-Id: <eqd1rtgm115ifvnomaoh8p2as5llve34v7@4ax.com>

Jürgen Exner wrote:

>"Laocoon" <Laocoon@eudoramail.com> wrote in message
>news:Xns9124E3171F6A2Laocooneudoramailcom@62.153.159.134...
>> One Tab = 8 spaces..
>> What else do you expect to be printed?
>
>Actually it's 0-8 spaces, depending on where the next tab stop is.

It's 1 to 8 spaces, not 0 to 8.

-- 
	Bart.


------------------------------

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 1814
***************************************


home help back first fref pref prev next nref lref last post