[19551] in Perl-Users-Digest
Perl-Users Digest, Issue: 1746 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 14 14:05:30 2001
Date: Fri, 14 Sep 2001 11:05:10 -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: <1000490709-v10-i1746@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 14 Sep 2001 Volume: 10 Number: 1746
Today's topics:
Re: AoH - continued (jason)
Cannot run perl scripts in Apache when file opened via (AcCeSsDeNiEd)
Re: Client Timeout <gortona@cs.man.ac.uk>
Do I need file locking <gortona@cs.man.ac.uk>
Re: Do I need file locking <tsee@gmx.net>
Re: Do I need file locking <thomas@baetzler.de>
Re: Do I need file locking (Malcolm Dew-Jones)
embedding variables in an array <whatever@nevermind.invalid>
Re: embedding variables in an array <thomas@baetzler.de>
Re: embedding variables in an array (Anno Siegel)
Re: file output <kyi@psnw.com>
Re: HELP: File corruption on opening. <gnarinn@hotmail.com>
How can I automate payments to my Merchant Account with (Robert Kattke)
Re: How can I automate payments to my Merchant Account <ultradevusegrp@dergal.com>
Re: How can I automate payments to my Merchant Account (Malcolm Dew-Jones)
Re: http server validation <comdog@panix.com>
Re: max length of keys? <simon.oliver@umist.ac.uk>
Re: max length of keys? <simon.oliver@umist.ac.uk>
Parsing C files (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
Re: parsing large DNA files into smaller files <gruen.lab@yale.edu>
Re: passwd and perl <matt@starnix.com>
Re: passwd and perl <goldbb2@earthlink.net>
Re: passwd and perl (Alex)
Re: Perl (slurping) is TOO much fun (Tad McClellan)
Re: Perl (slurping) is TOO much fun (Anno Siegel)
Re: Perl (slurping) is TOO much fun (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 Sep 2001 09:49:25 -0700
From: jason@gimptroll.com (jason)
Subject: Re: AoH - continued
Message-Id: <45a0e21a.0109140849.61c99f4@posting.google.com>
[snip]
> Now that I know that it's for CGI, that introduces a number of other
> important things you need to be careful of. In particular, what happens
> if the user specifies sort.cg?db_file=/etc/passwd [ok, not that, since
> that would be : seperated, not | seperated, but *something*].
[/snip]
As a precaution, I have the absolute path to the directory where my DB
files are located hard coded. so the only valid value for the db_file
key is a filename within that directory. Does this fill that hole or
do you see other ways this can be exploited?
for example:
...
my $db_dir = '/usr/local/DB/';
$filename = $q->param("db_file") || $filename; #query or default
open(FILE,"<${db_dir}$db_file") || die($!);
...
[snip]
> You really, really, really should make sure your program runs with -T,
> otherwise it's much too easy to make security holes.
[/snip]
Gotcha.
Also, I am having a little trouble understanding how this works, and
which one is correct, if not both.
Benjamin Says:
@goods = map $_->{@sortkeys}, @data;
Anno says:
@goods = map @{$_}{@sortkeys}, @data;
Peace,
TUnne|ing
------------------------------
Date: Fri, 14 Sep 2001 12:10:12 GMT
From: dillon@rm_accessdenied.darktech.org (AcCeSsDeNiEd)
Subject: Cannot run perl scripts in Apache when file opened via Samba
Message-Id: <3ba1f397.2405924@news.cyberway.com.sg>
First, plz forgive me for the cross-post.
I have no idea if this is a Linux, Samba, Apache or Perl issue.
I have a drive on my Win98 machine which is mapped to my Linux machine via Samba.
The reason for this is for ease of editing my html documents and perl/cgi scripts on Apache.
I have given Samba the correct rights and file/driectory modes.
If I have a perl file opened on my Win98 machine, it will not run via the web (Apache)
I do not need to save or change the contents. Just opening it creates the problem.
I can use any program in Win98 to open the file. The problem is still there.
If I close the program that is opening the file, sometimes I can run it from Apache.
Else I have to restart or shut down samba.
Funny thing is, html files are not affected by it.
I have disabled file locking on Samba.
I already have "#!/usr/bin/perl -w -T" on my scripts.
So it's not a dos/linux lines issue.
This is the error reported by Apache:
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your
request."
This is on my Apache error log file:
"
[Fri Sep 14 00:27:05 2001] [error] (26)Text file busy: exec of /cgi-bin/script.pl failed
[Fri Sep 14 00:27:05 2001] [error] [client 10.10.10.11] Premature end of script headers:
/cgi-bin/script.pl
"
I'm sure someone has a similar experience? Else I'll have to do the old ftp :)
To e-mail me, remove "rm_"
------------------------------
Date: Fri, 14 Sep 2001 15:51:51 +0100
From: Andrew Paul Gorton <gortona@cs.man.ac.uk>
Subject: Re: Client Timeout
Message-Id: <3BA21987.2EAB7915@cs.man.ac.uk>
Thanks everyone.
It is sorted. I am using the alarm in an eval block and then catching
the ALRM if it is generated to do the clean up code.
Cheers
------------------------------
Date: Fri, 14 Sep 2001 16:10:29 +0100
From: Andrew Paul Gorton <gortona@cs.man.ac.uk>
Subject: Do I need file locking
Message-Id: <3BA21DE5.7227F1B8@cs.man.ac.uk>
Hi,
I have a number of processes running, which all write to the same file,
maybe at the same time. Each process has a specific line to write to.
Each process first reads the file and then writes over its specific
line.
Will I need to use file locking so I don't get rubbish. Also what
actually happens with file locking. If a process locks a file, and
another process tries and locks the file...what happens. Does the
second process wait for that file to be available and then write to it,
or does it just exit.
Cheers for any help
------------------------------
Date: Fri, 14 Sep 2001 17:49:25 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Do I need file locking
Message-Id: <9nt8l1$eis$05$1@news.t-online.com>
"Andrew Paul Gorton" <gortona@cs.man.ac.uk> schrieb im Newsbeitrag
news:3BA21DE5.7227F1B8@cs.man.ac.uk...
> I have a number of processes running, which all write to the same file,
> maybe at the same time. Each process has a specific line to write to.
> Each process first reads the file and then writes over its specific
> line.
You should indeed lock your files then. Note, however, that unless all
accessing programs / processes do correct file locking, the file may be
corrupted nonetheless.
> Will I need to use file locking so I don't get rubbish.
Very likely.
> Also what
> actually happens with file locking. If a process locks a file, and
> another process tries and locks the file...what happens. Does the
> second process wait for that file to be available and then write to it,
> or does it just exit.
AFAIK, it waits for a given time. After that, flock returns false. If
successful, it returns true.
I think there should be some FAQ material on this topic, so search the FAQ
for 'file locking' or 'flock' or something like that before posting!
Hope this helps,
Steffen
------------------------------
Date: Fri, 14 Sep 2001 19:12:41 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: Do I need file locking
Message-Id: <ohe4qtcua3h25cgghgk8k9c1m5dd8m13t8@4ax.com>
On Fri, 14 Sep 2001, "Steffen Müller" <tsee@gmx.net> wrote:
>"Andrew Paul Gorton" <gortona@cs.man.ac.uk> schrieb im Newsbeitrag
>news:3BA21DE5.7227F1B8@cs.man.ac.uk...
>> I have a number of processes running, which all write to the same file,
>> maybe at the same time. Each process has a specific line to write to.
>> Each process first reads the file and then writes over its specific
>> line.
[...]
>I think there should be some FAQ material on this topic, so search the FAQ
>for 'file locking' or 'flock' or something like that before posting!
"perldoc perlopentut" has a section on file locking. The last example
is probably just the code the OP needs.
HTH,
------------------------------
Date: 14 Sep 2001 10:52:50 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Do I need file locking
Message-Id: <3ba243f2@news.victoria.tc.ca>
Andrew Paul Gorton (gortona@cs.man.ac.uk) wrote:
: Hi,
: I have a number of processes running, which all write to the same file,
: maybe at the same time. Each process has a specific line to write to.
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Your words can mean more than one thing.
If the byte offsets of the portions to be written to not change and do not
overlap (i.e. it's some kind of "databasey" file with *fixed* record
sizes) then you do not need to lock the file.
For example, two processes, each "owns" a different 100 byte portion of
the file, can both update the same file without locking
# in process 1
seek FILE , 100 , 0 ;
print FILE "This portion of the file belongs to this process";
# in process 2
seek FILE , 200 , 0 ;
print FILE "whereas this portion does not";
However, 90% of the time the above is NOT what people mean.
The most common scenario is that you mean that process 1 writes to line 1
and that procces 2 writes to line 2, (and that the lines may change in
size) - then you certainly must lock the file, and *what is more* you have
to ensure the code follows the correct sequence of steps for the opening,
locking, updating, and closing, because blindly sticking a few flocks in
the code is not enough.
(I am ignoring a few uncommon few operating systems which support
record oriented files.)
------------------------------
Date: Fri, 14 Sep 2001 14:16:15 GMT
From: asif <whatever@nevermind.invalid>
Subject: embedding variables in an array
Message-Id: <3BA21128.5030009@nevermind.invalid>
Can someone provide a solution or point me to the perldoc which might
get me started in the right direction:
I'm building an array, some elements of which can't be calculated until
the entire array has been built. I would like to avoid a 2-pass solution
if possible. I should add that these elements occur throughout the
array, not at the end: they're percentages of the whole, thus need the
total values before they can be calculated.
I would like to push a "place holder" onto the array at the appropriate
points as I read data in and then assign the corresponding calculated
value to it as I shift items off. The various escape/quote sequences
I've tried have been unsuccessful.
I guess what I'm trying to do is shield the variable from evaluation
going into the array but allow it to be interpreted on the way out. Is
this possible?
Thanks for any guidance.
------------------------------
Date: Fri, 14 Sep 2001 19:26:23 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: embedding variables in an array
Message-Id: <8qe4qto99t1mt5atg83q9bn2vaos8u6mjk@4ax.com>
On Fri, 14 Sep 2001, asif <whatever@nevermind.invalid> wrote:
>Can someone provide a solution or point me to the perldoc which might
>get me started in the right direction:
>
>I'm building an array, some elements of which can't be calculated until
>the entire array has been built. I would like to avoid a 2-pass solution
>if possible. I should add that these elements occur throughout the
>array, not at the end: they're percentages of the whole, thus need the
>total values before they can be calculated.
The el Cheapo solution would be to insert code references for each
element that needs your described "lazy evaluation". Of course you
would then need a special accessor functions that would execute the
referenced code and update the array with the results.
The clean way would be to write your own class, probably based on the
code in Tie::Array. Check out "perldoc perltie" for more details.
HTH,
------------------------------
Date: 14 Sep 2001 17:44:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: embedding variables in an array
Message-Id: <9ntfl3$3i3$1@mamenchi.zrz.TU-Berlin.DE>
According to asif <whatever@nevermind.invalid>:
> Can someone provide a solution or point me to the perldoc which might
> get me started in the right direction:
>
> I'm building an array, some elements of which can't be calculated until
> the entire array has been built.
Even at this point, this looks like an awkward data structure. If some
elements have a distinctly different status than others, they should
probably not go into the same array.
> I would like to avoid a 2-pass solution
> if possible.
Why? Presumably, you are keeping all the data in memory because you
want random access. Use it.
> I should add that these elements occur throughout the
> array, not at the end: they're percentages of the whole, thus need the
> total values before they can be calculated.
Again, why would you want to store percentages among the data they
are percentages of? Even if you want to display (or otherwise use)
them in that sequence, it will be easier to build the corresponding
lists on the fly, but store them in different places.
> I would like to push a "place holder" onto the array at the appropriate
> points as I read data in and then assign the corresponding calculated
> value to it as I shift items off. The various escape/quote sequences
> I've tried have been unsuccessful.
If the data structure *must* remain as it is, undef would be a good
placeholder. Fill it in as needed, even if what's needed is a second
pass.
> I guess what I'm trying to do is shield the variable from evaluation
> going into the array but allow it to be interpreted on the way out. Is
> this possible?
Yes, things like delayed execution are possible in Perl. You'd use
a closure (perldoc perlsub for that), or (shudder) string eval. But
I don't think you need that relatively sophisticated approach.
Use sum variable(s) to calculate the total(s) as you go along. When
all the data are in, fill in the percentages, where-ever you decide
to store them.
Anno
------------------------------
Date: Fri, 14 Sep 2001 08:49:04 -0700
From: "kyi" <kyi@psnw.com>
Subject: Re: file output
Message-Id: <tq49jndb763b44@corp.supernews.com>
Thanks for all the help guys. I have it producing the file name I now want,
thanks. As for the incorrect subject line, sorry this is my first time
posting to this group. This is also like my second perl script so I'm still
learning.
-Jayson Garrell
"kyi" <kyi@psnw.com> wrote in message
news:tq22n7j4u2cl00@corp.supernews.com...
> Hello Group;
>
> I have a small perl app that I wrote. It take a text file that is
> captured from the serial port, named capture.txt. My app takes this
> captured.txt file and prases all of the info I want in the file and
produces
> an output file that if formatted the way I want. My question is how can I
> have this output file named to what ever the current system date is, like
> (date +%x). Instead of the hard coded filename I have given it. Below is
the
> last few line of my app, where the file is being writen out.
>
> open (OUTPUT_FILE, ">/home/Administrator/phonelogs/phonelog.txt");
>
> while (<INPUT_FILE>) {
> if (m/09/) {s/^\s+//;
> print OUTPUT_FILE "$_";}
>
> }
>
> print "\n\n\nPress <Enter> to continue...";
>
>
> <STDIN>;
>
> So how do I make the output file the current date in, date +%x, format?
> Instead of my phonelog.txt.name.
>
> Any help is greatly apperciated.
>
> -Jayson Garrell
> Fresno Linux User Group
> http://linux.microbsys.com
> lugadmin@microbsys.com
>
>
>
------------------------------
Date: Fri, 14 Sep 2001 17:16:15 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: HELP: File corruption on opening.
Message-Id: <1000487775.0873775682412088.gnarinn@hotmail.com>
In article <1000465869.25539.0.nnrp-08.c1ed7194@news.demon.co.uk>,
IICS <andytolley@hotmail.com> wrote:
>Hi all,
>
>Could anyone possibly shed some light on a little problem im having.
(bizzare problem snipped)
create the shortest possible script that exhibits your problem,
and post it here so we can see what you are doing.
there is a good chance that just by doing that, you will find your bug.
gnari
------------------------------
Date: 14 Sep 2001 08:40:04 -0700
From: invinfo@enteract.com (Robert Kattke)
Subject: How can I automate payments to my Merchant Account with my SSL website ?
Message-Id: <8c144ece.0109140740.52f91cfd@posting.google.com>
Re: How can I automate payments to my Merchant Account with my SSL
website ?
Re: My website has SSL (Merchant Account too)- How can I integrate
them ?
I would like to automate the acceptance of Credit cards on my site.
I would like the customer to register,pay and automatically be mailed
a User_id and Password for Authentication.
If there is an email component to this solution, Can it be made Secure
??
I'm working with both OS hosting platforms: Unix / NT
and am familiar with Servlets, ASP, Perl, CGI
Suggestions welcome. TIA.
I can be contacted at the above email:
invinfo@enteract.com
-R
~~~ ps: Contributors and affiliates welcome ~~~~
Other current development projects include
ASP site - Database driven (MSA)
Servlet/Unix site - Database driven (MySQL)
menu system - JavaScript
XSL web publishing - XML content publishing
Site topics include:
Singles, dating, adult topics, etc.
Investment, financial markets, stocks, options, mutual funds, etc.
------------------------------
Date: Fri, 14 Sep 2001 17:24:25 +0100
From: "Gerry White" <ultradevusegrp@dergal.com>
Subject: Re: How can I automate payments to my Merchant Account with my SSL website ?
Message-Id: <q8qo7.9005$mj6.888480@news6-win.server.ntlworld.com>
best point of interest is to try some of the websites of the payment people,
such as ( my preffered ) WorldPay or SecPay, both popular british ones,
beyond that I don't know, I think there are many in the US...........
btw its not good netiquette to cross post like this....... it gets a little
annoying....
--
http://dergal.com
Hosting
E-Commerce
Web based Apps & More
Tel UK 0870 757 1645
"Robert Kattke" <invinfo@enteract.com> wrote in message
news:8c144ece.0109140740.52f91cfd@posting.google.com...
> Re: How can I automate payments to my Merchant Account with my SSL
> website ?
> Re: My website has SSL (Merchant Account too)- How can I integrate
> them ?
>
> I would like to automate the acceptance of Credit cards on my site.
> I would like the customer to register,pay and automatically be mailed
> a User_id and Password for Authentication.
>
> If there is an email component to this solution, Can it be made Secure
> ??
>
> I'm working with both OS hosting platforms: Unix / NT
> and am familiar with Servlets, ASP, Perl, CGI
>
> Suggestions welcome. TIA.
> I can be contacted at the above email:
> invinfo@enteract.com
> -R
>
> ~~~ ps: Contributors and affiliates welcome ~~~~
> Other current development projects include
> ASP site - Database driven (MSA)
> Servlet/Unix site - Database driven (MySQL)
> menu system - JavaScript
> XSL web publishing - XML content publishing
>
> Site topics include:
> Singles, dating, adult topics, etc.
> Investment, financial markets, stocks, options, mutual funds, etc.
------------------------------
Date: 14 Sep 2001 09:50:35 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: How can I automate payments to my Merchant Account with my SSL website ?
Message-Id: <3ba2355b@news.victoria.tc.ca>
Robert Kattke (invinfo@enteract.com) wrote:
: Re: How can I automate payments to my Merchant Account with my SSL
: website ?
: Re: My website has SSL (Merchant Account too)- How can I integrate
: them ?
I don't know, but I think there is a perl module to interface to "cashcow"
that might be a starting place to look.
------------------------------
Date: Fri, 14 Sep 2001 09:23:29 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: http server validation
Message-Id: <comdog-8B400A.09232914092001@news.panix.com>
In article <m3sndqeh1r.fsf@mumonkan.sunstarsys.com>, Joe Schaefer
<joe+usenet@sunstarsys.com> wrote:
> brian d foy <comdog@panix.com> writes:
> > you have to work harder to check if the server is not alive since some
> > servers do not handle HEAD correctly. ;)
> I'm not sure I understand your point here- I would think that simply
> having a listener on port 80 would constitute most people's definition
> of a "live" server.
if you don't get back something that can be understood as an HTTP
response, HEAD might give you a false negative. this is something
i have had to deal with in practice, rather than theory. ;)
--
brian d foy <comdog@panix.com> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html
------------------------------
Date: Fri, 14 Sep 2001 14:23:59 +0100
From: "Simon Oliver" <simon.oliver@umist.ac.uk>
Subject: Re: max length of keys?
Message-Id: <3ba20857$1@news.umist.ac.uk>
Don't know but like make Perl things I guess it is only limited by your
system resources. I wrote the following script to do a rough test and found
that above 6 orders of magnitude (that's 16777216 characters in length)
things get very slow.
In the real world I would think that if you need to use keys longer than a
few of hundred characters you're there's probably a better way to do things.
for my $order (1..6) {
my $key = '.' x (0x10 ** $order);
$h{$key} = length($key);
}
foreach (keys %h) {
print length($_), " => ", $h{$_}, "\n";
}
------------------------------
Date: Fri, 14 Sep 2001 14:52:35 +0100
From: "Simon Oliver" <simon.oliver@umist.ac.uk>
Subject: Re: max length of keys?
Message-Id: <3ba20eec$1@news.umist.ac.uk>
Perhaps you could store a digest of the key as the hash key and store the
data as a nested hash?
--
Simon Oliver
"Simon Oliver" <simon.oliver@umist.ac.uk> wrote in message
news:3ba20857$1@news.umist.ac.uk...
> Don't know but like make Perl things I guess it is only limited by your
> system resources. I wrote the following script to do a rough test and
found
> that above 6 orders of magnitude (that's 16777216 characters in length)
> things get very slow.
>
> In the real world I would think that if you need to use keys longer than a
> few hundred characters there's probably a better way to do things.
>
> for my $order (1..6) {
> my $key = '.' x (0x10 ** $order);
> $h{$key} = length($key);
> }
>
> foreach (keys %h) {
> print length($_), " => ", $h{$_}, "\n";
> }
>
>
>
------------------------------
Date: 14 Sep 2001 16:16:36 +0200
From: mru@users.sf.net (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
Subject: Parsing C files
Message-Id: <yw1x66aleu2j.fsf@spirello.e.kth.se>
Is there a perl module or similar that will parse a C file for
function/variable declarations/definitions? I have tried C::Scan, but
it doesn't work.
--
Måns Rullgård
e99_mru@e.kth.se
------------------------------
Date: Fri, 14 Sep 2001 14:05:44 -0400
From: "Jeff Gruen" <gruen.lab@yale.edu>
Subject: Re: parsing large DNA files into smaller files
Message-Id: <9ntggp$eth$1@news.ycc.yale.edu>
Dear All:
I am a newbie to perl and unix script writing.
I am looking for a script that will help us to parse a large DNA sequence
file into smaller text files. The larger DNA sequence file contains ~2
million uninterrupted nucleotide sequence letters, generally a c t g, with
occassional n and x, but never any numbers. A typical segment would look
like this:
aaccaataggagagatacatagcg .....etc.
It's basically like one single word made up of 2 million letters.
We would like to parse the larger file into non-overlapping smaller files of
10,000 letters. Each file should contain it's own descriptive name, which
would also be contained in the first line of the sequence file.
For example, the first file should be from nucleotide 1 through 10,000.
The second file should be from nucleotide 10,001 through 20,000.
The third file should be from nucleotide 20,001 through 30,000.
And so on.
It would be helpful if the names of the parsed files had a description of
the contents:
For example the first file name should be 1_10000.seq
The second file name should be 10001_20000.seq
The third file name should be 20001_30000.seq
And so on.
Finally, it would be helpful if each parsed file had a header line with the
following format:
The first file header should be:
>1_10000.seq
The second file header should be:
>10001_20000.seq
The third file header should be:
>20001_30000.seq
And so on.
Please note the ">" sign in the first position of the header.
In all the parsed text files, the sequence should begin on the next line
immediately following the header:
For example, for the first file:
>1_10000.seq
aaccaataggagagatacatagcg....etc.
Thanks very much.
Jeff Gruen
------------------------------
Date: 14 Sep 2001 09:33:44 -0400
From: Matthew Rice <matt@starnix.com>
Subject: Re: passwd and perl
Message-Id: <lv1yl9ucav.fsf@sol.starnix.com>
alx@nordnet.fr (Alex) writes:
> I wrote a script to create a new user with a random password using
> Perl, but i have a problem with the "passwd" command:
> passwd $user<$password doesn't work
Check out Expect. I'm pretty certain that there is a Perl port of it but it
originated for Tcl/Tk.
Changing/Setting passwords is one of the examples.
--
matthew rice <matt@starnix.com> starnix inc.
tollfree: 1-87-pro-linux thornhill, ontario, canada
http://www.starnix.com professional linux services & products
------------------------------
Date: Fri, 14 Sep 2001 09:35:25 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: passwd and perl
Message-Id: <3BA2079D.1F145CF8@earthlink.net>
Alex wrote:
>
> Hi!
> I wrote a script to create a new user with a random password using
> Perl, but i have a problem with the "passwd" command:
> passwd $user<$password doesn't work
First off, passwd generally requires that you enter the particular
password twice -- the second time is to confirm that you typed it right
the first time. Second, <$password means to read from the file named
$password, when you probably want the contents of the $password variable
as the password [not a file of that name]. So, *if* your passwd accepts
input from stdin, then you could do something like:
open CHPASSWD, "|passwd $user" or die horribly;
print CHPASSWD (($passwd, "\n") x 2);
close CHPASSWD or die horribly;
If passwd *doesn't* accept data from stdin, and will only work from a
terminal, then you need to create a psuedo-terminal. The simplest way
to do this is to write an expect script, either with the 'real' expect,
or with perl's Expect.pm:
use Expect;
my $chpasswd = Expect->spawn( "passwd", $user );
print $chpasswd (($passwd, "\n") x 2);
close $chpasswd or die horribly;
Yes, I realize this uses none of Expect's functionality besides creating
a tty, but this is all that's needed.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: 14 Sep 2001 07:24:30 -0700
From: alx@nordnet.fr (Alex)
Subject: Re: passwd and perl
Message-Id: <f7ac04a3.0109140624.4c011789@posting.google.com>
Hi,
First, thankyou for your help.
In fact i just want to use the command "passwd" with Perl, and when it
asks for password, gives the value $password without interactive
prompt.
------------------------------
Date: Fri, 14 Sep 2001 15:18:03 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl (slurping) is TOO much fun
Message-Id: <slrn9q42th.je6.tadmc@tadmc26.august.net>
Damian James <damian@qimr.edu.au> wrote:
>Benjamin Goldberg chose Fri, 14 Sep 2001 00:21:11 -0400 to say this:
>>Zachary Kent wrote:
>>>
>>> > (BTW this is not advocating slurping files, just something I do
>>> sometimes).
>>>
>>> Wha? Is slurping considered bad programming practice
>>When you slurp in a file, it can take up quite a bit of memory. When
>>you read and process a file line by line, you use less memory.
>
>So it depends on how mauch RAM you have, and and how big the file is.
And how many copies of this perl process might be running at the same time.
And how often the program will be run.
And perhaps how much swap space you have.
And I probably forgot yet more.
>If you
>have plenty of RAM to spare after loading the entire file into memory, then
>slurping can be the faster and easier option. However, if the file is so large
>that you don't have enough RAM to load it, then obviously slurping is not
>feasible.
My default approach is to do it line-by-line.
>And some operations are MUCH harder to do without slurping.
_That_ is when I consider a non-default approach, and only then.
(except I'll consider slurping even if l-b-l is only a
"little bit" harder. I claim "good Lazy" there.
)
>Consider
>something as everyday as sorting. I say slurp when you can -- which is
>whenever you are sure the file won't become too big (for values of 'too
>big' that are appropriate to your system, taking into account the overheads
>of the OS, Perl and how many users there will be at any one time).
And for appropriate values of the "sure" in "whenever you are sure".
I have never been bitten by this problem because I have never
been wrong about the "sure" part. (wanna buy a bridge?)
>Remember that these days RAM is cheap and you need a lot of data to use it
>up. And reading from RAM is much faster than reading from disk.
^^^^^^^^^^^
I don't usually slurp to get "faster". I slurp to get "easier to write"
or "easier to maintain" though (labor is my default "thing to optimize").
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 14 Sep 2001 15:54:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl (slurping) is TOO much fun
Message-Id: <9nt978$pr0$1@mamenchi.zrz.TU-Berlin.DE>
According to Bart Lateur <bart.lateur@skynet.be>:
> Uri Guttman wrote:
>
> >that is true but how often do you mung massive files? even slurping in
> >tens of megabytes is simple on most machines these days.
>
> You're acting very selfishly. If there's a chance that there will be
> tens of copies of these scripts runnign at the same time, you'll soon be
> running out of memory.
I think I'll mention his name in the presence of Cardinal Slurphammer.
There may be an unexpected visitation... But I hear a slurping noise
around the corner. You must excuse me now Sire, as I am needed.
Anno
------------------------------
Date: 14 Sep 2001 16:16:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl (slurping) is TOO much fun
Message-Id: <9ntahe$pr0$2@mamenchi.zrz.TU-Berlin.DE>
According to Wyzelli <wyzelli@yahoo.com>:
> "Zachary Kent" <zkent@adelphia.net> wrote in message
> news:Bsfo7.221$3c4.199956@news1.news.adelphia.net...
> > > (BTW this is not advocating slurping files, just something I do
> > sometimes).
> >
> > Wha? Is slurping considered bad programming practice (as well as bad
> > manners at the table)? What is the better solution? I gotta read these
> > posts more often...
>
> Not sp much 'bad practice' as 'a practice which may have some gotchas' ie it
> can take up a lot of memory.
If done routinely, as the default way of file processing, slurping is
definitely bad practice. Unfortunately this is seen too often.
But this will change...
Anno, aide to Cardinal Slurphammer
------------------------------
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 1746
***************************************