[16357] in Perl-Users-Digest
Perl-Users Digest, Issue: 3769 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 21 14:15:37 2000
Date: Fri, 21 Jul 2000 11:15:24 -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: <964203323-v9-i3769@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 21 Jul 2000 Volume: 9 Number: 3769
Today's topics:
Swedish social security number control. (slow code / ge <jimmy.lantz@ostas.lu.se>
Re: Swedish social security number control. (slow code <rhomberg@ife.ee.ethz.ch>
Re: Understanding Perl Idiom (Please Help) kenlaird@my-deja.com
Re: What is the differance? <drummond-m@rmc.ca>
Re: WHERE TO FIND NET::FTP MODULE? <etienno@my-deja.com>
Why doesn't ActivePerl 5.6.0 change my PATH? <andyh@littoralis.co.uk>
Re: Why doesn't ActivePerl 5.6.0 change my PATH? <stumo@bigfoot.com>
Re: Why doesn't ActivePerl 5.6.0 change my PATH? <bart.lateur@skynet.be>
Re: Why doesn't ActivePerl 5.6.0 change my PATH? <DNess@Home.Com>
Writing to a file error <colin_larcombe@hotmail.com>
Re: Writing to a file error <laf@gameonline.co.uk>
Re: Writing to a file error <newsposter@cthulhu.demon.nl>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 21 Jul 2000 17:36:35 +0200
From: Jimmy Lantz <jimmy.lantz@ostas.lu.se>
Subject: Swedish social security number control. (slow code / get it more effective if you can please)
Message-Id: <39786E02.6E62EE95@ostas.lu.se>
Hi,
the below is a working code for checking if a swedish soc. security
number is valid or not,
but I wonder if any of you perlexperts can see ways to make it more
efficient.
It takes a lot of code to check it this way.
####### Facts (working code below) ########
The swedish soc sec nr consists by 10 numbers.
often written yymmdd-nnnn
the last number is a control number.
you can check it by taking
the first nr and multiply it by 2 the second by 1 third by 2 and so on
until all NINE numbers are
multiplied (LEAVE OUT THE CONTROLNUMBER). then add all the digits
NB! if you have the year 56 then you multiply 5 by 2 and 6 by 1 when you
add everything up
you need to take it digit by digit 1+0+6 etc.....
when you get your sum, you count how much it lacks until it ends with 0
(that is the difference between the sum until it gets to a zero in the end.
then you know the control number (or check it with the control number).
###########
#!perl
#
#Swedish soc. sec numbercheck.
#written by Jimmy Lantz webmaster@ostas.lu.se
$inputnr = '560321-8305'; # this is a valid number, not mine but
someones .
$inputnr =~ s/-//;
@numbers = split(//, $inputnr);
$controlnumber = $numbers[9];
$numbers = pop(@numbers);
$no = 0;
foreach $number (@numbers)
{
&do_num_check($number,$no);
$no++;
}
@digits = split(//, $digits);
foreach $digit (@digits)
{
$totalsum = $totalsum + $digit;
}
$controlnumber2 = 0;
if ($totalsum < 10)
{
until ($totalsum == 10)
{
$totalsum++;
$controlnumber2++;
}
}
else
{
until ($totalsum =~ /0/)
{
$totalsum++;
$controlnumber2++;
}
}
if ($controlnumber == $controlnumber2)
{
print "IT's a valid Swedish social security number!!";
}
else
{
print "IT's NOT a valid Swedish social security number!!";
}
exit;
############
sub do_num_check
{
($number1, $no) = @_ ;
my $prod = $no % 2;
if ($prod == 0){
$product = $number1 * 2;
}else{
$product = $number1 * 1;
}
$digits = $digits . $product;
}
------------------------------
Date: Fri, 21 Jul 2000 18:52:12 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Swedish social security number control. (slow code / get it more effective if you can please)
Message-Id: <39787FBC.E768002@ife.ee.ethz.ch>
Jimmy Lantz wrote:
> The swedish soc sec nr consists by 10 numbers.
> often written yymmdd-nnnn
> the last number is a control number.
> you can check it by taking
> the first nr and multiply it by 2 the second by 1 third by 2 and so on
> until all NINE numbers are
> multiplied (LEAVE OUT THE CONTROLNUMBER). then add all the digits
> NB! if you have the year 56 then you multiply 5 by 2 and 6 by 1 when you
> add everything up
> you need to take it digit by digit 1+0+6 etc.....
> when you get your sum, you count how much it lacks until it ends with 0
> (that is the difference between the sum until it gets to a zero in the end.
> then you know the control number (or check it with the control number).
shortened slightly to
#!/usr/bin/perl -w
use strict;
my $num = $_ = '560321-8305';
my $sum; my $factor = 0;
for (/\d/g) {
$sum += $_ + $_ * ($factor ^= 1);
$sum -= 9 if $factor && $_>4;
}
print $sum=~/0$/ ? "good\n" : "bad\n";
------------------------------
Date: Fri, 21 Jul 2000 17:11:58 GMT
From: kenlaird@my-deja.com
Subject: Re: Understanding Perl Idiom (Please Help)
Message-Id: <8la08d$l6i$1@nnrp1.deja.com>
In article <39774039.655DD730@attglobal.net>,
Drew Simonis <care227@attglobal.net> wrote:
> kenlaird@my-deja.com wrote:
> >
> > #!/usr/bin/perl -w
> > @a=`ps -edf`;
> > foreach (@a) {
> > if (/ftp/) {
> > print ;
> > }
> > }
> >
> > It works fine,but trying to understand the Perl idiom I'd like to
> > know why the use of both parenthesis (without them it doesn't work
).
> > Would be grateful to have any explanation.
> >
>
> Do you mean the parens with 'if (/ftp/)' and 'foreach (@a)' ?
> I have to assume that you are, since these are the only ones in
> your example. Called in this way, if() requires parens, as does
> foreach(). I must confess to being a little confused by your
> question (question fragment?)
>
> > It works fine,but trying to understand the Perl idiom I'd like to
> > know why the use of both parenthesis (without them it doesn't work )
>
> You need to reword that to be a complete question.
>
Yes, I mean I'm trying to understand the use of () in the examle above.
Because the first time I wrote this more "naturally" without "()"
#!/usr/bin/perl -w
@a=`ps -edf`;
foreach @a {
if /ftp/ {
print ;
}
}
and it didn't work.It happens to me frequently when I try to write
some Perl code to forget these "parens" unless I know where to put them
right.
Ken Laird
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 21 Jul 2000 10:25:59 -0400
From: "Mark E. Drummond" <drummond-m@rmc.ca>
Subject: Re: What is the differance?
Message-Id: <39785D76.94B3A577@rmc.ca>
Thanks all! Had not considered op precendence.
--
Mark Drummond|ICQ#19153754|mailto:mark.drummond@rmc.ca
UNIX System Administrator|Royal Military College of Canada
The Kingston Linux Users Group|http://signals.rmc.ca/klug/
Saving the World ... One CPU at a Time
Please excuse me if I am terse. I answer dozens of emails every day.
------------------------------
Date: Fri, 21 Jul 2000 16:54:12 GMT
From: Etienne Laverdiere <etienno@my-deja.com>
Subject: Re: WHERE TO FIND NET::FTP MODULE?
Message-Id: <8l9v7b$k7m$1@nnrp1.deja.com>
Install libnet instead.
-- Etienne Laverdiere
In article <8kk335$j7c$1@violet.singnet.com.sg>,
"lova" <nurain@singnet.com.sg> wrote:
> Where Can I get the Net::FTP module from as it is not one of the
standard
> Perl 5 module.
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 21 Jul 2000 15:35:54 +0100
From: "Andy Holyer" <andyh@littoralis.co.uk>
Subject: Why doesn't ActivePerl 5.6.0 change my PATH?
Message-Id: <8l9n24$2kv6$1@grind.server.pavilion.net>
I've used Perl and ActivePerl for a couple of years now. Last week a disk
failure meant that I had to go back to a brand new machine. Since Perl was
on the drive which failed, I've had to reinstall from the distribution.
My old machine ran NT4: the new one runs W98 second edition. The problem is
this: When I install Perl 5.6.0 it doesn't set the environment variables -
so I can't find perl from the command line. I can't see where W98 thinks the
PATH variable should be set - it isn't set in Autoexec.bat, that's for sure.
I think a few other vars are also not set, since PPM seems problematic, as
well.
I need to get my development environment up again! Any advice gratefully
recieved.
Thanks in advance,
Andy Holyer, Lewes, UK
------------------------------
Date: Fri, 21 Jul 2000 16:28:53 +0100
From: "Stuart Moore" <stumo@bigfoot.com>
Subject: Re: Why doesn't ActivePerl 5.6.0 change my PATH?
Message-Id: <8l9q72$6ua$1@supernews.com>
I set my path variable in Autoexec.bat and it seems to work fine.
Andy Holyer <andyh@littoralis.co.uk> wrote in message
news:8l9n24$2kv6$1@grind.server.pavilion.net...
> I've used Perl and ActivePerl for a couple of years now. Last week a disk
> failure meant that I had to go back to a brand new machine. Since Perl was
> on the drive which failed, I've had to reinstall from the distribution.
>
> My old machine ran NT4: the new one runs W98 second edition. The problem
is
> this: When I install Perl 5.6.0 it doesn't set the environment variables -
> so I can't find perl from the command line. I can't see where W98 thinks
the
> PATH variable should be set - it isn't set in Autoexec.bat, that's for
sure.
> I think a few other vars are also not set, since PPM seems problematic, as
> well.
>
> I need to get my development environment up again! Any advice gratefully
> recieved.
>
> Thanks in advance,
>
> Andy Holyer, Lewes, UK
>
>
>
------------------------------
Date: Fri, 21 Jul 2000 17:07:58 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why doesn't ActivePerl 5.6.0 change my PATH?
Message-Id: <2l0hnss8dtuv210ka7qnffndtvliol8vfe@4ax.com>
Andy Holyer wrote:
>The problem is
>this: When I install Perl 5.6.0 it doesn't set the environment variables -
>so I can't find perl from the command line. I can't see where W98 thinks the
>PATH variable should be set - it isn't set in Autoexec.bat, that's for sure.
Oh yes it is.
The problem could be that ifthere wasn't a "SET PATH=" or "PATH"
statement in the AUTOEXEC.BAT file before, then it could be that one
wasn't added by Setup either. If so, that is a Setup bug. Try adding a
SET PATH=%PATH%
line, and reinstall. I bet that Perl's bin directory will now be added.
If all else fails, do it by hand.
--
Bart.
------------------------------
Date: Fri, 21 Jul 2000 17:23:42 GMT
From: David Ness <DNess@Home.Com>
Subject: Re: Why doesn't ActivePerl 5.6.0 change my PATH?
Message-Id: <39788723.7C1BD22F@Home.Com>
Bart Lateur wrote:
>
> Andy Holyer wrote:
>
> >The problem is
> >this: When I install Perl 5.6.0 it doesn't set the environment variables -
> >so I can't find perl from the command line. I can't see where W98 thinks the
> >PATH variable should be set - it isn't set in Autoexec.bat, that's for sure.
>
> Oh yes it is.
>
> The problem could be that ifthere wasn't a "SET PATH=" or "PATH"
> statement in the AUTOEXEC.BAT file before, then it could be that one
> wasn't added by Setup either. If so, that is a Setup bug. Try adding a
>
> SET PATH=%PATH%
>
> line, and reinstall. I bet that Perl's bin directory will now be added.
>
> If all else fails, do it by hand.
>
> --
> Bart.
I might only add that a slightly deceptive thing that you may encounter is
that the SET may not get executed on opening a new DOS window until you have
rebooted your machine once. IIRC, there was a time when I believed that
AutoExec.BAT didn't really `work' because I would change it and then open a new
window and not see effect of the change. However, when I changed it, rebooted
the machine and then opened a DOS window, the change had the proper effect.
------------------------------
Date: Fri, 21 Jul 2000 16:01:47 GMT
From: "Colin Larcombe" <colin_larcombe@hotmail.com>
Subject: Writing to a file error
Message-Id: <Lt_d5.25580$aS.202921@telenews.teleline.es>
The following code reads data from a file and then tries to output it to two
files depending on the results
#!/usr/local/bin/perl
# Put all the bonds into an array, except the first two lines
$filepath="/usr/users/larcombe/";
$isinname="moody_bnd_upd.txt\n";
$accept="acceptable.txt\n";
$notaccept="notaccept.txt\n";
open(ACCEPT,">$filepath.$accept") || "Cannot open $filepath.$accept to write
to";
open(NOTACCEPT,">$filepath.$notaccept") || "Cannot open $filepath.$notaccept
to write to";
open(ISINS,$isinname);
while ($isin = <ISINS>) {
chop($isin); # Does the ISIN meet the criteria of being XX9999999999
if ($isin =~ /[a-zA-Z]{2}[0-9]{10}/) {
print ACCEPT $isin."\n";
} else {
print NOTACCEPT $isin."\n";
}
}
close(ISINS);
close(ACCEPT);
close(NOTACCEPT);
The reading and checking of the $isin works fine but the file writing
doesn't. I have run it under debug but am limited to what I can see.
1) Is there anyway under debug to see if a file has been created.
2) Is there a better way of doing this
3) As a complete beginner (3rd day of Perl) is there another area I should
post to.
Many Thanks
Colin Larcombe
------------------------------
Date: Fri, 21 Jul 2000 17:03:07 +0100
From: "Neil Lathwood" <laf@gameonline.co.uk>
Subject: Re: Writing to a file error
Message-Id: <964195710.25214.0.nnrp-02.c246f12b@news.demon.co.uk>
It may be because of the . between $filepath and $notaccept it should just
be $filepath$notaccept
Neil
"Colin Larcombe" <colin_larcombe@hotmail.com> wrote in message
news:Lt_d5.25580$aS.202921@telenews.teleline.es...
> The following code reads data from a file and then tries to output it to
two
> files depending on the results
>
> #!/usr/local/bin/perl
> # Put all the bonds into an array, except the first two lines
> $filepath="/usr/users/larcombe/";
> $isinname="moody_bnd_upd.txt\n";
> $accept="acceptable.txt\n";
> $notaccept="notaccept.txt\n";
> open(ACCEPT,">$filepath.$accept") || "Cannot open $filepath.$accept to
write
> to";
> open(NOTACCEPT,">$filepath.$notaccept") || "Cannot open
$filepath.$notaccept
> to write to";
> open(ISINS,$isinname);
> while ($isin = <ISINS>) {
> chop($isin); # Does the ISIN meet the criteria of being XX9999999999
> if ($isin =~ /[a-zA-Z]{2}[0-9]{10}/) {
> print ACCEPT $isin."\n";
> } else {
> print NOTACCEPT $isin."\n";
> }
> }
> close(ISINS);
> close(ACCEPT);
> close(NOTACCEPT);
>
> The reading and checking of the $isin works fine but the file writing
> doesn't. I have run it under debug but am limited to what I can see.
>
> 1) Is there anyway under debug to see if a file has been created.
> 2) Is there a better way of doing this
> 3) As a complete beginner (3rd day of Perl) is there another area I should
> post to.
>
> Many Thanks
>
>
> Colin Larcombe
>
>
>
------------------------------
Date: 21 Jul 2000 16:06:19 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Writing to a file error
Message-Id: <8l9sdr$jou$1@internal-news.uu.net>
Colin Larcombe <colin_larcombe@hotmail.com> wrote:
> open(ACCEPT,">$filepath.$accept") || "Cannot open $filepath.$accept to write
> to";
> open(NOTACCEPT,">$filepath.$notaccept") || "Cannot open $filepath.$notaccept
> to write to";
Didn't you mean to use 'die' in the two previous lines?
> open(ISINS,$isinname);
Where is the error checking ?
Erik
------------------------------
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 3769
**************************************