[12056] in Perl-Users-Digest
Perl-Users Digest, Issue: 5657 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 14 03:07:35 1999
Date: Fri, 14 May 99 00:02:49 -0700
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, 14 May 1999 Volume: 8 Number: 5657
Today's topics:
Re: pattern matching ? (Andrew Johnson)
Re: pattern matching ? <ebohlman@netcom.com>
Re: perldoc question <swarren@www.wwwdotorg.org>
Re: perldoc question (Larry Rosler)
Re: Re-reading CGI form data. <emschwar@rmi.net>
Re: Re-reading CGI form data. <emschwar@rmi.net>
Re: read file assign variables mikecard@my-dejanews.com
Re: read file assign variables (Lee)
Re: read file assign variables mikecard@my-dejanews.com
Re: read file assign variables (Larry Rosler)
Re: read file assign variables (Tad McClellan)
Re: regexp ?: how to ignore escaped delimiter? (Bart Lateur)
Re: Shopping Cart <bogart@exis.net>
Using perl for access control <jrogersmith@yahoo.com>
Re: Vax username/passwd check via Net::Telnet <jay@rgrs.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 13 May 1999 19:22:31 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: pattern matching ?
Message-Id: <XDF_2.3915$L4.195912@news2.rdc1.on.home.com>
In article <7he678$te6$1@nnrp1.deja.com>,
tvn007@my-dejanews.com <tvn007@my-dejanews.com> wrote:
! Hi,
!
! Would someone help me on this ?
!
! Problem:
!
! I have to read every single line from a file and search for
! a keyword such as si1_code , si2_code, si3_code.
!
! below is a small sample of input file:
!
! si1_code = 135'b110011;
! si2_code = 2413'b11010010;
! si3_code = 2513'b0010101101;
!
!
! The only thing I would like to get from
! si1_code is 110011
! and si2_code is 11010010
! ....
!
! My solution on this problem require many steps as shown below:
[snip]
here's one way (adjust to taste):
#!/usr/bin/perl -w
use strict;
my %codes = ( si1_code => \&si_1,
si2_code => \&si_2,
si3_code => \&si_3,
);
while(<>){
next unless m/^(si\d_code)\s*=[^']+'b([01]+);/;
$codes{$1} && ($codes{$1}->($2) , next);
warn "unrecognized code: '$1' at line $. in $ARGV\n";
}
sub si_1 {my $code = shift; print "si1:$code\n"}
sub si_2 {my $code = shift; print "si2:$code\n"}
sub si_3 {my $code = shift; print "si3:$code\n"}
__END__
regards
andrew
------------------------------
Date: Thu, 13 May 1999 19:30:43 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: pattern matching ?
Message-Id: <ebohlmanFBorJ7.M0p@netcom.com>
Peter Bowen <bowen@imall.com> wrote:
: Normally I just sit back and let the reg exp gurus go wild, but this
: really is more than a simple pattern match. The pattern match was
: fine, but catching the correct keyword, and then applying the switch was
: what caught my eye...
: # Perl init stuff here :)
: my %list = ("si1_code" => 1,
: "si2_code" => 1,
: "si3_code" => 1);
: open(FILE,"myfile.txt");
: while (my $line=<FILE>) {
: my $junk;
: my ($keyword,$value) = split / = /, $line;
: if ($list{$keyword}) { # why go further if we don't need to...
: ($junk,$value) = split /b/,$line;
: chomp $value;
: $value =~ s/\;//;
: # execute a subroutine for this keyword.
: &{$keyword}($value);
: }
: }
: sub si1_code {
[snip]
Rather than using symbolic references to subroutine names, which are
error-prone (and therefore forbidden under use strict), why not fill your
hash with subroutine references instead?
my %list = (si1_code => \&si1_code,
si2_code => \&si2_code,
si3_code => \&si3_code);
#note that => automatically quotes the Perl identifier on its left,
#so we can lose the quote marks.
open(FILE,"myfile.txt");
open(FILE,'myfile.txt') or die "Can't open myfile.txt: $!";
#checking the return values of system calls saves you debugging time
while (my $line=<FILE>) {
my ($keyword,$value) = split /\s*=\s*/, $line;
#correctly handle any number of spaces, including zero, around the '='
if ($list{$keyword}) { # why go further if we don't need to...
($undef,$value) = split /b/,$line;
# $undef gives you a built-in "ignore me" variable
chomp $value;
$value =~ tr/;//d;
# tr/// is preferable to s/// when just deleting or changing single chars
# execute a subroutine for this keyword.
$list{$keyword}->($value);
# note cool syntax for using subroutine refs
}
}
------------------------------
Date: Thu, 13 May 1999 19:13:01 GMT
From: "Stephen Warren" <swarren@www.wwwdotorg.org>
Subject: Re: perldoc question
Message-Id: <1vF_2.756$6x6.1078@news.rdc1.sfba.home.com>
Larry Rosler <lr@hpl.hp.com> wrote in message
news:MPG.11a4a7b3d749c16989a5b@nntp.hpl.hp.com...
>
> In article <373A1509.3567554E@mail.cor.epa.gov> on Wed, 12 May 1999
> 16:55:53 -0700, David Cassell <cassell@mail.cor.epa.gov> says...
>
> > David, who many consider to *be* deserving of a section 8...
>
> And no Section 8 either. Catch 22...
That would be "Maintenance Commands", on Solaris at least.
--
Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
mailto:swarren@techhouse.com http://www.techhouse.com/
mailto:swarren@wwwdotorg.org http://www.wwwdotorg.org/
MIME, S/MIME and HTML mail are acceptable
------------------------------
Date: Thu, 13 May 1999 13:48:47 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: perldoc question
Message-Id: <MPG.11a4da88420f37e9989a60@nntp.hpl.hp.com>
In article <1vF_2.756$6x6.1078@news.rdc1.sfba.home.com> on Thu, 13 May
1999 19:13:01 GMT, Stephen Warren <swarren@www.wwwdotorg.org> says...
> Larry Rosler <lr@hpl.hp.com> wrote in message
> news:MPG.11a4a7b3d749c16989a5b@nntp.hpl.hp.com...
> >
> > In article <373A1509.3567554E@mail.cor.epa.gov> on Wed, 12 May 1999
> > 16:55:53 -0700, David Cassell <cassell@mail.cor.epa.gov> says...
> >
> > > David, who many consider to *be* deserving of a section 8...
> >
> > And no Section 8 either. Catch 22...
>
> That would be "Maintenance Commands", on Solaris at least.
In HP-UX, that is the Section 1M to which I referred in the rest of this
post.
David was talking about Section 8 in a quite different problem domain.
My reference to Catch 22 might help you to identify it. Ask him or me
offline if you are still baffled. :-)
End of non-Perl discussion?
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 13 May 1999 13:07:26 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Re-reading CGI form data.
Message-Id: <xkfwvyckcup.fsf@valdemar.col.hp.com>
brian@llinderman.dental.nyu.edu (Brian Seitz) writes:
> Does anyone know if it is possible to determine if the form data in a CGI
> script has already been parsed based on the $ENV variables?
Please read the FAQ for comp.infosystems.www.authoring.cgi. Your
question has nothing to do with Perl.
-=Eric
------------------------------
Date: 13 May 1999 13:07:29 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Re-reading CGI form data.
Message-Id: <xkfvhdwkcum.fsf@valdemar.col.hp.com>
brian@llinderman.dental.nyu.edu (Brian Seitz) writes:
> Does anyone know if it is possible to determine if the form data in a CGI
> script has already been parsed based on the $ENV variables?
Please read the FAQ for comp.infosystems.www.authoring.cgi. Your
question has nothing to do with Perl.
-=Eric
------------------------------
Date: Thu, 13 May 1999 18:48:37 GMT
From: mikecard@my-dejanews.com
Subject: Re: read file assign variables
Message-Id: <7hf6q5$mna$1@nnrp1.deja.com>
In article <373B06E2.669F2A86@vt.edu>,
Brian Rectanus <brectanu@vt.edu> wrote:
> You cannot use uninitialized variables whaen using the -w flag.
>
i removed the -w now when i run the script uhm nothing gets printed out.
I would expect the last two lines of the txt document to be printed
since (i thought) they would be assigned to the $link and $description
variables.
mike cardeiro
> #!/usr/bin/perl -w
>
> open (LINKS, "linkdata.txt") or die "can't open
file\n";
> while (<LINKS>) {
> chomp ($link = <LINKS>);
> chomp ($description = <LINKS>);
> }
> close LINKS;
>
> print "$link";
> print "$description";
>
> #the end
>
> linkdata.txt is a txt file with this:
>
> www.place.com
> a groovy place to visit
> ppp.he.net
> oh this one rox
>
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Thu, 13 May 1999 17:06:50 -0500
From: rlb@intrinsix.ca (Lee)
Subject: Re: read file assign variables
Message-Id: <B360B72A9668A6F8C5@0.0.0.0>
In article <7hev72$fk9$1@nnrp1.deja.com>,
mikecard@my-dejanews.com wrote:
>hi
>
>i am trying to get the basics of perl down, i have written a script
>which seems to be correct but won't work:
>
>
>#!/usr/bin/perl -w
>
>open (LINKS, "linkdata.txt") or die "can't open file\n";
>while (<LINKS>) {
> chomp ($link = <LINKS>);
> chomp ($description = <LINKS>);
>}
>close LINKS;
>
>print "$link";
>print "$description";
>
>#the end
>
>linkdata.txt is a txt file with this:
>
>www.place.com
>a groovy place to visit
>ppp.he.net
>oh this one rox
>
>what i want is for the first line to be assigned to $link and the second
>line to be $description (i am aware that the next time through the loop
>these variables will be reassigned, this program is meant to be
>educational not functional)
>
>when i run the script i get this message
>
>Use of uninitialized value at test2.cgi line 5, <LINKS> chunk 4.
>Use of uninitialized value at test2.cgi line 6, <LINKS> chunk 4.
>Use of uninitialized value at test2.cgi line 10.
>Use of uninitialized value at test2.cgi line 11.
>
>
>why?
The error message *says* uninitialized, but *means* undefined.
As someone else pointed out, your loop reads three lines per pass. The
second time through, you get:
>while (<LINKS>) { # $_ = "oh this one rox\n"
> chomp ($link = <LINKS>); # $link = undef
> chomp ($description = <LINKS>); # $description = undef
>}
Lee
------------------------------
Date: Thu, 13 May 1999 20:24:11 GMT
From: mikecard@my-dejanews.com
Subject: Re: read file assign variables
Message-Id: <7hfcd7$r23$1@nnrp1.deja.com>
thanks for all your help!
I followed larry roslers code and it solved my problem (except now the
periods won't print out but i won't waste your time with that one...back
to the book!)
thank you
mike cardeiro
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Thu, 13 May 1999 13:23:43 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: read file assign variables
Message-Id: <MPG.11a4d4ab65d29c1c989a5e@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7hf6q5$mna$1@nnrp1.deja.com> on Thu, 13 May 1999 18:48:37
GMT, mikecard@my-dejanews.com <mikecard@my-dejanews.com> says...
> In article <373B06E2.669F2A86@vt.edu>,
> Brian Rectanus <brectanu@vt.edu> wrote:
> > You cannot use uninitialized variables whaen using the -w flag.
>
> i removed the -w now when i run the script uhm nothing gets printed out.
> I would expect the last two lines of the txt document to be printed
> since (i thought) they would be assigned to the $link and $description
> variables.
Removing the '-w' is like taking the batteries out of the smoke detector
because you don't want to be bothered by the racket it makes when there
is a fire. (I think I saw a similar analogy here yesterday.)
Without the '-w', an undefined value is treated as a null string "" or
as a 0, in appropriate contexts. You just don't know that it represents
a program bug.
By now, enough of us have told you what is wrong that you can fix the
problem *and* continue using '-w' in every one of your programs. And
'use strict;' also, for different but equally important reasons.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 13 May 1999 11:56:51 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: read file assign variables
Message-Id: <3oseh7.732.ln@magna.metronet.com>
mikecard@my-dejanews.com wrote:
: In article <373B06E2.669F2A86@vt.edu>,
: Brian Rectanus <brectanu@vt.edu> wrote:
: > You cannot use uninitialized variables whaen using the -w flag.
: >
: i removed the -w now when i run the script uhm nothing gets printed out.
Brian's followup was a bunch of hooey.
Ignore it.
Larry Rosler has answered your question, wait until his
reply gets to your server.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 13 May 1999 19:28:51 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: regexp ?: how to ignore escaped delimiter?
Message-Id: <373b2509.2152345@news.skynet.be>
Spica wrote:
>I'm just getting started here and I've run into a snag. I've got a
>text file that is delimited with the vertical bar: |. However, there
>are a few fields that have an excaped vertical bar: \|. I would like
>to ignore these. So, here is what my script looks like so far:
Try this on for size. I do have the impression that it returns one
(empty) field too many.
($_ = <<'_') =~ tr/\n//d; # one line
master.pln|Unit_Testing\Scripts\LogicalView\LV_DataObject.t|ModifyObjectName|
5, "\|MyTable", 3|0||0||1999-05-11 18.23.49|0:00:09
_
@fields = /((?:\\.|[^\|])*)\|?/sg; # <<< THIS IS IT!
($\,$,) = ("\n","\n"); #every item on it's own line
print @fields;
Bart.
------------------------------
Date: Thu, 13 May 1999 15:59:54 -0500
From: Ed Bogart <bogart@exis.net>
Subject: Re: Shopping Cart
Message-Id: <373B3D4A.77D92C4E@exis.net>
waxpack@my-dejanews.com wrote:
>
> I am looking for a programmer to finish DcShop for use on my site.
> DcShop is a shopping cart script made by DcScripts
> (http://www.dcscripts.com), which I feel is the start of the best cart
> script on the net.
> Unfortunately the script won't be done by them for many months and I
> would like it now.
> Only thing that needs to be done, is the allowance of items to be added
> by browser.
> Currently you may only add items, through the cgi script itself.
> If anyone would like to accept this job please contact me at
> waxpack@waxpack.com.
> This job pays $100 flat. $50 up front. $50 on completion.
> David Choi of DcScripts will allow anyone to edit his script, so please
> don't worry about that.
Let me see if I understand correctly. This is a script that a Perl developer(?)
can't finish in less than less than "many months" and you want someone to do it
for you for $100. I can't speak for the Perl develper/consultants here (I am a
LabVIEW developer/guru) but $100 wouldn't pay for an hour of my time, even if I
was familiar with the problem to be solved, no follow-up or support was expected
and I could deliver the product via FTP. You may be able to find someone who is
willing to take on a major project like this just for the experience though, so
good luck. Just remember, never try to save money on consultants or parachutes.
Ed, the GPE guy
------------------------------
Date: Thu, 13 May 1999 18:23:21 -0400
From: John <jrogersmith@yahoo.com>
Subject: Using perl for access control
Message-Id: <373B50D8.57179CEF@yahoo.com>
I need to have a protected page in my website with the specifications
below. Anyone able to do it please reply to me personally ASAP.
I want to be able to give visitors access to page when they enter a
username and a password that is related by a function. For example if
the username is 10 and the password is 1 they get access, i.e. the
username and password have a function divided by 10.
So the following usernames and passwords should be able to access the
protected page.
10/1
100/10
1000/100
500/50
400/40
I want to be able to create this protected page so that I don't have to
maintain usernames/passwords etc and have it all taken care by one
functional relationship between the username and password. If anyone can
do it or can give me pointers, would really appreciate it. Also, the
perl script should be able to send password info to access the file in a
password protected directory (so that the file is not accessible untill
people go through the username/password routine).
Many Thanks.
------------------------------
Date: 13 May 1999 15:01:02 -0400
From: Jay Rogers <jay@rgrs.com>
Subject: Re: Vax username/passwd check via Net::Telnet
Message-Id: <82aev8eqvl.fsf@shell2.shore.net>
"Sheila Eugenio" <seugenio@man.amis.com> writes:
> Is it possible to check a web-based login with the username/password
> combination of an existing Vax account? I am planning to create a
> company-wide, web-based application. It is necessary to have login
> authentication. I was thinking of using the existing individual Vax
> accounts of each employee, like so, when they login to the application,
> Net::Telnet will output successful/unsuccessful logins for valid/invalid
> username/password. When login is OK, an HTML page will appear.
Yes, you can use Net::Telnet to check a user login and password.
However, from a security standpoint you really should setup the
web server to do the authentication as opposed to a CGI program.
--
Jay Rogers
jay@rgrs.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5657
**************************************