[12619] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 28 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 6 22:17:12 1999

Date: Tue, 6 Jul 1999 19:06:49 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 6 Jul 1999     Volume: 9 Number: 28

Today's topics:
        Folders & Files <troyknight@troyknight.eurobell.co.uk>
    Re: Folders & Files (Martien Verbruggen)
    Re: Folders & Files (elephant)
    Re: Folders & Files (brian d foy)
        force it to match? bing-du@tamu.edu
    Re: force it to match? (John Borwick)
        form elements and Perl <tan.ses@Sun.COM>
    Re: form elements and Perl (Abigail)
        Form to Fax <customk9@home.com>
    Re: Forms Processing - thread started in HTML group (Ken)
    Re: Forms Processing - thread started in HTML group <gellyfish@gellyfish.com>
    Re: Forms Processing - thread started in HTML group (Laar)
    Re: Forms Processing - thread started in HTML group (Abigail)
        from shell to perl <technology@workmail.com>
    Re: from shell to perl <walton@frontiernet.net>
    Re: from shell to perl <elaine@wustl.edu>
        gethostbyname problem (David Quinton)
    Re: gethostbyname problem <gellyfish@gellyfish.com>
    Re: gethostbyname problem (David Quinton)
    Re: gethostbyname problem <gellyfish@gellyfish.com>
    Re: gethostbyname problem (David Quinton)
    Re: gethostbyname problem (David Quinton)
        getpwent and getpwuid interaction problem <robin.bowes@i.am>
    Re: getpwent and getpwuid interaction problem <uri@sysarch.com>
    Re: getpwent and getpwuid interaction problem (Greg Andrews)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Mon, 5 Jul 1999 03:08:32 +0100
From: "Troy Knight" <troyknight@troyknight.eurobell.co.uk>
Subject: Folders & Files
Message-Id: <7lp3ud$2mg5$1@slrn.eurobell.net>

When using the readir function after opening a directory it ruturns a list
of files and subdirectories in that directory(@list = readdir dir). In the
returned list, how can you tell the difference bewteen a subdirectory and a
file with no extension? Thanks




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

Date: Mon, 05 Jul 1999 02:47:11 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Folders & Files
Message-Id: <P0Vf3.77$dk3.6720@nsw.nnrp.telstra.net>

In article <7lp3ud$2mg5$1@slrn.eurobell.net>,
	"Troy Knight" <troyknight@troyknight.eurobell.co.uk> writes:
> When using the readir function after opening a directory it ruturns a list
> of files and subdirectories in that directory(@list = readdir dir). In the
> returned list, how can you tell the difference bewteen a subdirectory and a
> file with no extension? Thanks

Directories can have extensions too. Files and directories aren't
really very different.

Have a look at the stat function and the -X file tests:

# perldoc -f stat
# perldoc -f -X
(this works in 5.004, not in later versions, you can also just use
# perldoc perlfunc
)

Also read the manual on readdir to make sure you know how to use the
return values correctly:

# perldoc -f readdir

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd.       | enough features yet.
NSW, Australia                      | 


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

Date: Mon, 5 Jul 1999 12:40:16 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: Folders & Files
Message-Id: <MPG.11eac61c5152b8cb989ae1@news-server>

Troy Knight writes ..
>When using the readir function after opening a directory it ruturns a list
>of files and subdirectories in that directory(@list = readdir dir). In the
>returned list, how can you tell the difference bewteen a subdirectory and a
>file with no extension? Thanks

check out the -X functions in your perl documentation .. it's the 
perlfunc section of the manual

-f will be one of them and is probably what you're looking for

-- 
 jason - remove all hyphens for email reply -


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

Date: Mon, 05 Jul 1999 18:29:35 -0400
From: brian@pm.org (brian d foy)
Subject: Re: Folders & Files
Message-Id: <brian-ya02408000R0507991829350001@news.panix.com>

In article <P0Vf3.77$dk3.6720@nsw.nnrp.telstra.net>, mgjv@comdyn.com.au (Martien Verbruggen) posted:

> # perldoc -f stat

is someone developing perl programs as root? ;)

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>


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

Date: Tue, 06 Jul 1999 16:49:53 GMT
From: bing-du@tamu.edu
Subject: force it to match?
Message-Id: <7ltc3c$isr$1@nnrp1.deja.com>

Hello there,

I need to compare two big files.  $test1 is used to represent each
line in file1 and $test2 is used to represent each line in file2.  Some
entries in these files look similar to the following $test1 and $test2.

#!/usr/local/bin/perl
$test1 = '(a...';
$test2 = '(a...';

if ($test2 =~ /$test1/i)
{ print "match\n";}
else { print "do not match\n";}

The output of the above code snippet was:

/(a/: unmatched () in regexp at ./zzzz line 5.

Can you show me how to let the code output "match"?

I need to handle not only '(', but also '[' and whatever characters that
should always go in pair.

Your help will be greatly appreciated.

Bing


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Tue, 6 Jul 1999 17:48:51 GMT
From: John.Borwick@sas.com (John Borwick)
Subject: Re: force it to match?
Message-Id: <3786414a.20584569@newshost.unx.sas.com>

On Tue, 06 Jul 1999 16:49:53 GMT, bing-du@tamu.edu wrote:

>I need to compare two big files.  $test1 is used to represent each
>line in file1 and $test2 is used to represent each line in file2.  Some
>entries in these files look similar to the following $test1 and $test2.

>#!/usr/local/bin/perl
>$test1 = '(a...';
>$test2 = '(a...';

>if ($test2 =~ /$test1/i)
>{ print "match\n";}
>else { print "do not match\n";}

>/(a/: unmatched () in regexp at ./zzzz line 5.


perldoc -f quotemeta
perldoc File::Compare

-- 
John Borwick


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

Date: Tue, 06 Jul 1999 13:47:16 +0200
From: tan ses <tan.ses@Sun.COM>
Subject: form elements and Perl
Message-Id: <3781ECC4.F4368CD3@Sun.COM>

Hi there,

i have written script which processes formular data entries and writes
them to an email.
I have also included an option that the user can revise his/her data by
pressing the "Back button". Is there a way to get the referring page URL
without all the form data which has been entered will be deleted.
I know this works with a script but that's not what I intend to do.
There should be simply a link (HREF) going back to the page without the
data being deleted  Doing this with ENV variable "HTTP_REFERRER" just
gets me back /cgi-bin...
Maybe someone has found a slution or workaround for this problem.
Thanx in advance,

Tan


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

Date: 6 Jul 1999 08:20:41 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: form elements and Perl
Message-Id: <slrn7o40kj.tch.abigail@alexandra.delanet.com>

tan ses (tan.ses@Sun.COM) wrote on MMCXXXV September MCMXCIII in
<URL:news:3781ECC4.F4368CD3@Sun.COM>:
== Hi there,
== 
== i have written script which processes formular data entries and writes
== them to an email.

You send email to data entries?

== I have also included an option that the user can revise his/her data by
== pressing the "Back button".

Well, you didn't invent that. It comes with any browser.

==                             Is there a way to get the referring page URL
== without all the form data which has been entered will be deleted.

No. Don't try to reinvent the wheel. You cannot simulate "going back"
with HTML and/or CGI. See
<URL:http://www.foad.org/%7Eabigail/HTML/Misc/back_button.html> for
details on why not.

== I know this works with a script but that's not what I intend to do.

It doesn't. Trust me on this one.

== There should be simply a link (HREF) going back to the page without the
== data being deleted  Doing this with ENV variable "HTTP_REFERRER" just
== gets me back /cgi-bin...

It won't work. You cannot simulate going back reliably. But it isn't
necessary to simulate it. All browsers come with back buttons. Don't
assume your readers are too stupid to use a browser; if they are, they
wouldn't be on your page in the first place.

== Maybe someone has found a slution or workaround for this problem.

The problem is that you make a problem out of something that isn't
a problem.

Followups set, as your "problem" has less to do with Perl than with fish.



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Sat, 03 Jul 1999 12:32:49 GMT
From: "Don Stefani" <customk9@home.com>
Subject: Form to Fax
Message-Id: <Rpnf3.3368$w4.41332@news1.frmt1.sfba.home.com>

Hello,

I have a client who asked me if I could have his HTML form input sent to his
fax machine.
I have found a perl script that says it will do it, but it does not say how.
Has anyone done this before? Can you tell me what's needed?

Thanks,
Don




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

Date: Sat, 03 Jul 1999 04:22:45 GMT
From: kloomis@it-resourcesNOSPAM.com (Ken)
Subject: Re: Forms Processing - thread started in HTML group
Message-Id: <377d8b32.51383653@news.tiac.net>

Eric The Read <emschwar@rmi.net> wrote:

>kloomis@it-resourcesNOSPAM.com (Ken) writes:
>> I guess that too tough a question for you?
>
>Is searching FAQs too tough for you?  You can find the answer there.
>
>> I still don't understand your problem.  I'm trying to accomplish
>> something using Perl language and you're having a hissy fit.
>
>No, I'm pointing out (rather calmly, actually) that using Perl to solve a 
>problem doesn't make the problem a Perl problem.  If your question is
>"How do I do <foo>?" then it's not really a Perl question, it's you not
>understanding what needs to be done.  And that lack of understanding is
>irrelevant to the language you're using.
>
>If your question is, "I tried to do it this way, but instead of output
><X>, I got output <Y>.  I read the documentation and the FAQs, and I
>still don't see what I'm doing wrong!", then it's most likely a Perl
>question.
>
>Do you see the distinction?
>
>-=Eric

Nope, I really don't.

My question was how do I write code to interrupt form processing if
certain conditions are met, ie. certain answers disqualify someone.

A kindly soul showed me the Perl code to do it. it was: 

 if ($FORM{'radio1'} eq "condition") {
    &sorry("Sorry, we cannot assist you.");

and then the code for the subroutine.  And showed me where to put it
in the Perl script. 

That was the answer I was looking for and it was about Perl.  If you
want to put a finer point on it just to be difficult, so be it.  While
you and Abigail were trying to assert your supposed superiority
because you have some specialized knowledge that I do not, a rather
nice person was helping me out.

As a result of his help I also discovered how to include style sheet
in my perl code, how to develop sub routines, and had a fun time of
it.

I posed another question here about the order of the output, which was
coming out not as i wanted it.  I read the FAQ to no avail, and
someone posted some incomprehensible, to me, discussions.  Meanwhile,
my friend, figured out a way.

I'm not going to pursue this any longer and if you feel the need to
have the last word, go at it, but you should know that you have been
unhelpful, unpleasant, and basically a bummer.  Why anyone would want
to have that effect on people is beyond me.

Good day. 

 



Ken Loomis
IT Resources
Lexington, MA
www.it-resources.com


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

Date: 3 Jul 1999 10:21:46 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Forms Processing - thread started in HTML group
Message-Id: <7lko7q$2pa$1@gellyfish.btinternet.com>

On Fri, 02 Jul 1999 18:18:42 GMT Ken wrote:
> 
> When form info is fed back into a mail program it comes back in e-mail
> in jumbled order.  How can I format the info so it comes back in the
> order I want?  In perl!
> 

Presumably because you are taking the information from a hash.  If that
is the case then you will have to find some method to arrange for it to 
be in the correct order.

If it is not the case then you will need to post the smallest amount of 
Perl code that demonstrates this behaviour.

But please try to refrain from posting the HTML and the whole damn script
all we need to see is how you are storing and referencing the form data.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 03 Jul 1999 22:32:28 GMT
From: laar@ix.netcom.com (Laar)
Subject: Re: Forms Processing - thread started in HTML group
Message-Id: <377e8ed6.1462586@nntp.ix.netcom.com>

On 02 Jul 1999 16:23:39 -0600, Eric The Read <emschwar@rmi.net> wrote:

>No, I'm pointing out (rather calmly, actually) that using Perl to solve a 
>problem doesn't make the problem a Perl problem.  If your question is
>"How do I do <foo>?" then it's not really a Perl question, it's you not
>understanding what needs to be done.

Sheeeit, that *must* be the finest hair I've ever seen split.

>Do you see the distinction?

Are you oblivious to the inevitable overlap between *Perl* itself and
the common *tasks* for which it used?

--
Laar
www.netcom.com/~laar/index.html


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

Date: 3 Jul 1999 18:00:45 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Forms Processing - thread started in HTML group
Message-Id: <slrn7nt5gb.31h.abigail@alexandra.delanet.com>

Laar (laar@ix.netcom.com) wrote on MMCXXXII September MCMXCIII in
<URL:news:377e8ed6.1462586@nntp.ix.netcom.com>:
\\ 
\\ Are you oblivious to the inevitable overlap between *Perl* itself and
\\ the common *tasks* for which it used?

Are you oblivious to the inevitable overlap between *Computers* themselves and
the command *tasks* for which they are used?

Go ask your questions in a group discussing computers.


Abigail
-- 
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Sat, 03 Jul 1999 15:56:58 -0700
From: Raj <technology@workmail.com>
Subject: from shell to perl
Message-Id: <377E953A.5B4B19B3@workmail.com>

can a shell program return a value/flag/message to the calling CGI/Perl
program? if so, how? TIA,
Raj



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

Date: Sun, 04 Jul 1999 00:16:46 -0400
From: Bob Walton <walton@frontiernet.net>
To: Raj <technology@workmail.com>
Subject: Re: from shell to perl
Message-Id: <377EE02D.5CA6C3E5@frontiernet.net>

Raj wrote:

> can a shell program return a value/flag/message to the calling CGI/Perl
> program? if so, how? TIA,
> Raj

Yes, the exit status of the shell program is available as the return value
from "system", and the standard output of the shell program is available as
the output of the backtick operator.  Check perlfunc for the "system"
function:

The return value is the exit status of the program as returned by the
wait() call. To get the actual exit
     value divide by 256. See also exec. This is NOT what you want to use
to capture the output from a
     command, for that you should use merely backticks or qx//, as
described in perlop.

or check perlop for qx:

qx/STRING/
`STRING`

     A string which is (possibly) interpolated and then executed as a
system command with /bin/sh or its
     equivalent. Shell wildcards, pipes, and redirections will be honored.
The collected standard output of the
     command is returned; standard error is unaffected. In scalar context,
it comes back as a single
     (potentially multi-line) string. In list context, returns a list of
lines (however you've defined lines with $/
     or $INPUT_RECORD_SEPARATOR).

Thus, you can use the exit status for a flag or numeric value, or the
standard output if you need a message.



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

Date: Sat, 3 Jul 1999 19:58:24 -0500
From: elaine ashton <elaine@wustl.edu>
Subject: Re: from shell to perl
Message-Id: <Pine.GSO.4.05.9907031954241.454-100000@chaos.wustl.edu>

> can a shell program return a value/flag/message to the calling CGI/Perl
> program? if so, how? TIA,

http://language.perl.com/newdocs/pod/perlfaq8.html
or
'perldoc perlfaq8' from your command line.

e.
-- 

         -=]) elaine ashton // elaine@chaos.wustl.edu // bofh ([=-
   -=]) A dismal wasteland of banality, cliche' and casual obscenity ([=- 



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

Date: Tue, 06 Jul 1999 11:50:39 GMT
From: davidq@NOSPAMpost.almac.co.uk (David Quinton)
Subject: gethostbyname problem
Message-Id: <3782ecea.261615575@news.almac.co.uk>

Hi - I'm newish to perl and have lurked, Deja-d and WebSearched - to
no avail!

We have a Logfile that contains lines of text
Each line has, as part of it, an IP address.

This is the pertinent part of the Script - that writes its output to a
Web page.....

	foreach $line (@lines) {
		$line =~ s/^(\d*) - //g;
$linelength = length($line);
$host = substr($line,12,($linelength-12)); # all from start of IP
addr.
# print $host; # just to test... - yup; it's nnn.nnn.nnn.nnn
# print "\n";
$AF_INET = 2; 
($name,$aliases,$type,$len,$addr) = gethostbyname($host);
($hname,$aliases,$type,$len,@addrs) =gethostbyaddr($addr,$AF_INET);
($a,$b,$c,$d) = unpack('C4',$addr );
		print $line;
#		print "\t"; # Tab
		print $hname;
		print "\n";
	}

The result is that I get "localhost" rather than the resolved Name.

However, when I run *this*, from a Telnet session - i.e. it writes its
output to stout:-

$line = "21:25 - E - 148.176.239.59";
$linelength = length($line);
$host = substr($line,12,($linelength-12)); # all from start of IP
addr.
$AF_INET = 2; 
($name,$aliases,$type,$len,$addr) = gethostbyname($host);
($hname,$aliases,$type,$len,@addrs) =gethostbyaddr($addr,$AF_INET);
($a,$b,$c,$d) = unpack('C4',$addr );
print $hname;

It resolves the address just fine!

Any suggestions much welcomed!
-- 
I'm currently reading:
<http://www.amazon.co.uk/exec/obidos/ASIN/0436201305/bizorginternetse>
FREE Personal Numbers: 0709 119 1500
<http://www.ThisBritain.com/personalnos.htm>


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

Date: 6 Jul 1999 15:01:21 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: gethostbyname problem
Message-Id: <37820c31@newsread3.dircon.co.uk>

David Quinton <davidq@NOSPAMpost.almac.co.uk> wrote:
> 
<snip stuff about resolving names>

> Any suggestions much welcomed!

#!/usr/bin/perl -w
use Socket;

my $is = inet_aton($ARGV[0]);
my ($address,$aliases,@stuff) = gethostbyaddr($is,AF_INET);

print $address,"\n";

/J\
-- 
"Of course I smoke pot, but I'm not in favour of legalizing it. The
working classes do little enough as it is..." - Jonathan Aitken


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

Date: Tue, 06 Jul 1999 14:50:53 GMT
From: davidq@NOSPAMpost.almac.co.uk (David Quinton)
Subject: Re: gethostbyname problem
Message-Id: <3783170b.272402661@news.almac.co.uk>

On 6 Jul 1999 15:01:21 +0100, Jonathan Stowe <gellyfish@gellyfish.com>
wrote:

>David Quinton <davidq@NOSPAMpost.almac.co.uk> wrote:
>> 
><snip stuff about resolving names>
>
>> Any suggestions much welcomed!
>
>#!/usr/bin/perl -w
>use Socket;
>
>my $is = inet_aton($ARGV[0]);
>my ($address,$aliases,@stuff) = gethostbyaddr($is,AF_INET);
>
>print $address,"\n";
Thanks, Jonathon - I'd seen the "use Socket" in other people's coding
- but only when they wanted their *own* addy.

However it's not *my* addy that I want translated - rather it's one
from a log file.

Would it still work with out the "my" s?
-- 
I'm currently reading:
<http://www.amazon.co.uk/exec/obidos/ASIN/0436201305/bizorginternetse>
FREE Personal Numbers: 0709 119 1500
<http://www.ThisBritain.com/personalnos.htm>


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

Date: 6 Jul 1999 16:13:17 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: gethostbyname problem
Message-Id: <37821d0d@newsread3.dircon.co.uk>

David Quinton <davidq@NOSPAMpost.almac.co.uk> wrote:
> On 6 Jul 1999 15:01:21 +0100, Jonathan Stowe <gellyfish@gellyfish.com>
> wrote:
> 
>>David Quinton <davidq@NOSPAMpost.almac.co.uk> wrote:
>>> 
>><snip stuff about resolving names>
>>
>>> Any suggestions much welcomed!
>>
>>#!/usr/bin/perl -w
>>use Socket;
>>
>>my $is = inet_aton($ARGV[0]);
>>my ($address,$aliases,@stuff) = gethostbyaddr($is,AF_INET);
>>
>>print $address,"\n";
> Thanks, Jonathon - I'd seen the "use Socket" in other people's coding
> - but only when they wanted their *own* addy.
> 
> However it's not *my* addy that I want translated - rather it's one
> from a log file.
> 

What do you think the ARGV[0] is about ?  Is there anything in this code
that would indicate that it is getting the address of localhost ?

> Would it still work with out the "my" s?

Why would you want to take them out - are you running on Perl 4 ? - if that
is the case then you wont be able to use the Socket module either.

Of course you *could* take them out but what good do you think that will do.

Put this code in a file.  Make it executable. run it passing an IP address
as an argument:

    bash$ lookup.pl 194.112.33.226
    desktop83.dircon.net

Then go D'oh !

/J\
-- 
"Doctors, psychologists and animators have been called in to investigate"
- Channel 4 News


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

Date: Tue, 06 Jul 1999 16:07:02 GMT
From: davidq@NOSPAMpost.almac.co.uk (David Quinton)
Subject: Re: gethostbyname problem
Message-Id: <37892993.277146951@news.almac.co.uk>

On 6 Jul 1999 16:13:17 +0100, Jonathan Stowe <gellyfish@gellyfish.com>
wrote:
[snip]
>Then go D'oh !
Yes, yes - many thanks!
-- 
I'm currently reading:
<http://www.amazon.co.uk/exec/obidos/ASIN/0436201305/bizorginternetse>
FREE Personal Numbers: 0709 119 1500
<http://www.ThisBritain.com/personalnos.htm>


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

Date: Tue, 06 Jul 1999 16:12:50 GMT
From: davidq@NOSPAMpost.almac.co.uk (David Quinton)
Subject: Re: gethostbyname problem
Message-Id: <378a2aef.277495074@news.almac.co.uk>

On 6 Jul 1999 16:13:17 +0100, Jonathan Stowe <gellyfish@gellyfish.com>
wrote:

>Then go D'oh !
 ... and it works!

Many thanks
-- 
I'm currently reading:
<http://www.amazon.co.uk/exec/obidos/ASIN/0436201305/bizorginternetse>
FREE Personal Numbers: 0709 119 1500
<http://www.ThisBritain.com/personalnos.htm>


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

Date: Sun, 04 Jul 1999 21:44:05 +0100
From: Robin Bowes <robin.bowes@i.am>
Subject: getpwent and getpwuid interaction problem
Message-Id: <377FC795.E3549363@i.am>

Hi,

Using perl 5.005_02 (just upgraded to 5.005_3 - same result)

I'm using a script that loops over passwd file entries.  Here's the
relevant part that causes the problem:

# Start loading up each user from the passwd file.
while (($user, $passwd, $accountuid, $accountgid, $quota, $comment,
$gcos, $home, $shell) = getpwent())
{
    # OK, lets stat the users home directory...
    my ($mode, $uid, $gid) = (stat ($home))[2,4,5];

    if ($accountuid != $uid)
    {
        # Get the other owners information.
        my $owner = (getpwuid($uid))[0];

        # The users home directory is owned by another account.
        print "The user's <$user> home directory <$home> is owned by
<$owner> ($uid).\n";
    }
    else
    {
        # Everything seems to OK.
        print "The account <$user> seems to be OK.\n";
    }
}


Here's some sample output:

The account <root> seems to be OK.
The user's <bin> home directory </bin> is owned by <root> (0).
The account <root> seems to be OK.
The user's <bin> home directory </bin> is owned by <root> (0).
The account <root> seems to be OK.
The user's <bin> home directory </bin> is owned by <root> (0).
The account <root> seems to be OK.
The user's <bin> home directory </bin> is owned by <root> (0).
The account <root> seems to be OK.

If I remove the call to getpwuid, I get output like the following:

The account <root> seems to be OK.
The user's <bin> home directory </bin> is owned by <> (0).
The user's <daemon> home directory </sbin> is owned by <> (0).
The user's <adm> home directory </var/adm> is owned by <> ().
The user's <lp> home directory </var/spool/lpd> is owned by <> (0).
The user's <sync> home directory </sbin> is owned by <> (0).
The user's <shutdown> home directory </sbin> is owned by <> (0).
The user's <halt> home directory </sbin> is owned by <> (0).
The user's <mail> home directory </var/spool/mail> is owned by <> (0).
The account <news> seems to be OK.

What seems to be happening is that when getpwuid executes it interferes
with the position of the getpwent in the while loop causing oit to reset
to the beginning.

Is this normal behaviour and do I need to do something differently, or
is this a bug?

Thanks,

R.

-- 
Two rules to success in life: 
  1. Don't tell people everything you know.
     -- Sassan Tat


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

Date: 05 Jul 1999 03:51:10 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: getpwent and getpwuid interaction problem
Message-Id: <x7wvwfy1ox.fsf@home.sysarch.com>

>>>>> "RB" == Robin Bowes <robin.bowes@i.am> writes:

  RB> while (($user, $passwd, $accountuid, $accountgid, $quota, $comment,
  RB> $gcos, $home, $shell) = getpwent())
  RB> {
  RB>     my ($mode, $uid, $gid) = (stat ($home))[2,4,5];

  RB>     if ($accountuid != $uid)
  RB>     {
  RB>         # Get the other owners information.
  RB>         my $owner = (getpwuid($uid))[0];

  RB> The account <root> seems to be OK.
  RB> The user's <bin> home directory </bin> is owned by <root> (0).
  RB> The account <root> seems to be OK.

  RB> If I remove the call to getpwuid, I get output like the following:

  RB> The account <root> seems to be OK.
  RB> The user's <lp> home directory </var/spool/lpd> is owned by <> (0).
  RB> The user's <mail> home directory </var/spool/mail> is owned by <> (0).
  RB> The account <news> seems to be OK.

  RB> What seems to be happening is that when getpwuid executes it interferes
  RB> with the position of the getpwent in the while loop causing oit to reset
  RB> to the beginning.

  RB> Is this normal behaviour and do I need to do something differently, or
  RB> is this a bug?

it is an undocumented side effect. the unix lib calls which perl calls,
use a static buffer for the pw entries that all the pw routines
use. read the unix man pages on getpwnam and family. even there it is
not stated that you should not mix calls between getpwent and
getpw{uid,nam}. 

the solution is pretty simple. build a list of pw hashes with all the
info. then loop over all of the hashes like you loop above. also make a
hash of uid => names so you don't need to call anything after you slurp
in the pw file. then your code will be simpler and it won't have to deal
with static buffers.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: 5 Jul 1999 09:08:44 -0700
From: gerg@shell.ncal.verio.com (Greg Andrews)
Subject: Re: getpwent and getpwuid interaction problem
Message-Id: <7lqlac$n3a$1@shell1.ncal.verio.com>

robin.bowes@i.am writes:
>Hi,
>
>Using perl 5.005_02 (just upgraded to 5.005_3 - same result)
>
>I'm using a script that loops over passwd file entries.
>

Yeah, I ran into that when I wrote a similar script.  I solved it
the way Uri suggested, by building a hash of uid-to-login name
mappings.

Here are some other suggestions:

  Check that the user's home directory is not empty in
  the password entry before using stat().

  Check the user's home directory exists before retrieving the
  uid.  Otherwise, your code will return undef for the uid, your
  code will interpret it as being owned by uid 0, and mistakenly
  say root owns the directory.  In fact, re-use the stat buffer
  created by the -e operator to check that the home directory
  is a directory, as well as who owns it.

  Skip accounts with uids less than 100 and the "nobody" accounts
  (usually 65534, but also 60000 and 60001 on Solaris 2.x).
  Their home dirs are known to be owned by another uid (root), so
  your script shouldn't bother checking them.


  -Greg


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 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.  

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 V9 Issue 28
************************************


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