[17448] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4868 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 11 09:05:35 2000

Date: Sat, 11 Nov 2000 06:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973951507-v9-i4868@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 11 Nov 2000     Volume: 9 Number: 4868

Today's topics:
        [Perl] How to find the Perl FAQ <rootbeer&pfaq*finding*@redcat.com>
        Command-line arguments <kdl@softhome.net>
        Crypt-Decrypt pscola@tiscalinet.it
    Re: Crypt-Decrypt (Clay Irving)
        missing lines parsing an accesslog <ebenezer@mosi.is>
    Re: New to Perl. How do you do a shell command? (Colin Watson)
        Pattern matching question (Andy Smith)
    Re: Pushing a hash on to a stack... (Christopher Burke)
    Re: Random Array with Sort? <iltzu@sci.invalid>
    Re: Returning an array from C to Perl <vidulats@yahoo.co.uk>
    Re: Returning an array from C to Perl <joe+usenet@sunstarsys.com>
    Re: Self-modifying code in Perl (Martien Verbruggen)
    Re: Self-modifying code in Perl (Martien Verbruggen)
    Re: Self-modifying code in Perl <joe+usenet@sunstarsys.com>
    Re: Self-modifying code in Perl <bart.lateur@skynet.be>
    Re: Self-modifying code in Perl (Martien Verbruggen)
        switching the user in perl <patiln@dresdnerkb.com>
    Re: switching the user in perl (Martien Verbruggen)
        use-ing .pm file from different dir <dvoon@my-deja.com>
    Re: use-ing .pm file from different dir (DoC)
    Re: Using POST and POST/ACTION on the same page - I fig (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 11 Nov 2000 11:21:53 GMT
From: Tom Phoenix <rootbeer&pfaq*finding*@redcat.com>
Subject: [Perl] How to find the Perl FAQ
Message-Id: <pfaqmessage973941841.19838@news.teleport.com>

Archive-name: perl-faq/finding-perl-faq
Posting-Frequency: weekly
Last-modified: 29 Apr 2000

[ That "Last-modified:" date above refers to this document, not to the
Perl FAQ itself! The last _major_ update of the Perl FAQ was in Summer
of 1998; of course, ongoing updates are made as needed. ]

For most people, this URL should be all you need in order to find Perl's
Frequently Asked Questions (and answers).

    http://www.cpan.org/doc/FAQs/

Please look over (but never overlook!) the FAQ and related docs before
posting anything to the comp.lang.perl.* family of newsgroups.

For an alternative way to get answers, check out the Perlfaq website.

    http://www.perlfaq.com/

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

Beginning with Perl version 5.004, the Perl distribution itself includes
the Perl FAQ. If everything is pro-Perl-y installed on your system, the
FAQ will be stored alongside the rest of Perl's documentation, and one
of these commands (or your local equivalents) should let you read the FAQ.

    perldoc perlfaq
    man perlfaq

If a recent version of Perl is not properly installed on your system,
you should ask your system administrator or local expert to help. If you
find that a recent Perl distribution is lacking the FAQ or other important
documentation, be sure to complain to that distribution's author.

If you have a web connection, the first and foremost source for all things
Perl, including the FAQ, is the Comprehensive Perl Archive Network (CPAN).
CPAN also includes the Perl source code, pre-compiled binaries for many
platforms, and a large collection of freely usable modules, among its
560_986_526 bytes (give or take a little) of super-cool (give or take
a little) Perl resources.

    http://www.cpan.org/
    http://www.perl.com/CPAN/
    http://www.cpan.org/doc/FAQs/FAQ/html/
    http://www.perl.com/CPAN/doc/FAQs/FAQ/html/

You may wish or need to access CPAN via anonymous FTP. (Within CPAN,
you will find the FAQ in the /doc/FAQs/FAQ directory. If none of these
selected FTP sites is especially good for you, a full list of CPAN sites
is in the SITES file within CPAN.)

    California     ftp://ftp.cdrom.com/pub/perl/CPAN/
    Texas          ftp://ftp.metronet.com/pub/perl/
    South Africa   ftp://ftp.is.co.za/programming/perl/CPAN/
    Japan          ftp://ftp.dti.ad.jp/pub/lang/CPAN/
    Australia      ftp://cpan.topend.com.au/pub/CPAN/
    Netherlands    ftp://ftp.cs.ruu.nl/pub/PERL/CPAN/
    Switzerland    ftp://sunsite.cnlab-switch.ch/mirror/CPAN/
    Chile          ftp://ftp.ing.puc.cl/pub/unix/perl/CPAN/

If you have no connection to the Internet at all (so sad!) you may wish
to purchase one of the commercial Perl distributions on CD-Rom or other
media. Your local bookstore should be able to help you to find one.

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

Comments and suggestions on the contents of this document
are always welcome. Please send them to the author at
<pfaq&finding*comments*@redcat.com>. Of course, comments on
the docs and FAQs mentioned here should go to their respective
maintainers.

Have fun with Perl!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/


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

Date: Sat, 11 Nov 2000 15:09:34 +0200
From: "Denys Kotseba" <kdl@softhome.net>
Subject: Command-line arguments
Message-Id: <8ujg7l$10ka$1@app0.visti.net>

Hello,

I have just upgraded to ActivePerl 618 and found out that I can't pass
command line arguments any more. The simple one-liner shown below produces
no output. Am I missing something? Please help.

Code sample:

print shift(@ARGV);

Regards,

Denys Kotseba.




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

Date: Sat, 11 Nov 2000 13:35:23 GMT
From: pscola@tiscalinet.it
Subject: Crypt-Decrypt
Message-Id: <3a0d4b1a.6249903@news.tiscalinet.it>

Hi everybody,

I would know if does exist some "standard" functions 
useful to crypt/decrypt informations and if so,
in which module/package they are.

Thanks in advance for you help,
kind regards.

Paolo



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

Date: 11 Nov 2000 13:59:24 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Crypt-Decrypt
Message-Id: <slrn90qk5s.7vj.clay@panix6.panix.com>

On Sat, 11 Nov 2000 13:35:23 GMT, pscola@tiscalinet.it wrote:

>I would know if does exist some "standard" functions 
>useful to crypt/decrypt informations and if so,
>in which module/package they are.

  http://www.perl.com/reference/query.cgi?security

-- 
Clay Irving <clay@panix.com>
If you're not part of the solution, you're part of the precipitate.
- Steven Wright 


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

Date: Sat, 11 Nov 2000 10:44:54 -0000
From: "Ebenezer Bodvarsson" <ebenezer@mosi.is>
Subject: missing lines parsing an accesslog
Message-Id: <3a0d964f.0@news.isholf.is>

Hi I'm parsing an acces log file and somehow it does not parse all the lines
and I cannot see any pattern of which lines it skips.

open(LOGFILE,"foo");
while (<LOGFILE>){
my ($ip, $id, $auth, $day, $tzone, $meth, $url, $protoc, $status, $bytes,
$refer)= split(/\s+/,<VISITS>, 11);

    #visited pages
    if ($Visit{$url})
      {
   $Visit{$url}++;
      }else{
   $Visit{$url}=1;
      }
}
close (LOGFILE);

Does anyone know what may cause this script to skip some lines in the acces
log?
It does not matter if I have only 10 lines in the file, only appr 6 get
parsed.
Perhaps the answer is staring me in the face but I just don't get it this
time.
thank's in advance

E.B.




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

Date: 11 Nov 2000 11:23:24 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: New to Perl. How do you do a shell command?
Message-Id: <8uja7c$s72$1@riva.ucam.org>

Angela Duane <angela.duane@storigen.com> wrote:
>I found about 1/2 page in one of my Perl books that describes how to do
>Shell things. I can't believe that this is such an uncommon thing to
>do.

No, it isn't. 'perldoc -f system'.

  system 'dd', 'if=/dev/zero', "of=$filename", 'bs=512k', "count=$blocks";

 ... is one way. As far as your code with the Shell module goes:

>use Shell qw(dd);     #list shell commands script will be using
>dd ("if=/dev/zero", "of=$FileName", "bs=512k", "size=$SizeOfFile");

There's no size= option to dd, at least not the version of it I have
(Debian GNU/Linux). bs= gives the block size, and count= gives the
number of blocks.

>It looks in the book that arguments need to have commas between each
>argument and "" and that flags need "", but should not have commas
>between them.

They're just ordinary string arguments to a function. Nothing special.
Surround them with '' or "" (either will do, but the different quotes
have different behaviour - "" interpolates variables like $FileName
above), and see 'perldoc perlop', the section on 'Quote and Quote-like
Operators'. Put commas between them, and see 'perldoc perlsub'.

>I can get the code to compile, but when the second line is executed I
>get a message something like:
>
>dd:  dd if=/dev/zero of=$FileName bs=512k size=$SizeOfFile: file
>doesn't exist. (something like that)

Please, *please* cut and paste the error message rather than "something
like". There are several things that this could be, depending on what
the error message is:

  * dd (usually /bin/dd) isn't on your $PATH for some strange reason.
  * dd is actually complaining about the size= option not existing.
  * You haven't set the $FileName or $SizeOfFile variables before trying
    to use them.

By the way, see 'perldoc perlstyle' for variable naming:

       o   While short identifiers like $gotit are probably ok,
           use underscores to separate words.  It is generally
           easier to read $var_names_like_this than
           $VarNamesLikeThis, especially for non-native speakers
           of English. It's also a simple rule that works
           consistently with VAR_NAMES_LIKE_THIS.

>Am I missing something for the syntax? I have tried very simple things
>like trying to cat a file or ls and I get similar results. Help me?!

Show us the exact errors if you still have problems. With the fixes I
mentioned, your code above works fine for me.

-- 
Colin Watson                                     [cjw44@flatline.org.uk]
"O brother man, fold to thy heart thy brother; Where pity dwells, the
 peace of God is there! To worship rightly is to love each other; Each
 smile a hymn, each kindly deed a prayer." - John Greenleaf Whittier


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

Date: Sat, 11 Nov 2000 13:51:38 GMT
From: asmith@hsonline.net (Andy Smith)
Subject: Pattern matching question
Message-Id: <3a0d4d4c$0$1510$7bbe8f7d@news.hsonline.net>

Hi,
If I have an array filled with strings and run through a foreach :

	foreach (@array) {
		if($_ =~ /^{S+HOWTO}\.html/) {
			print "$_\n";
		}
	}

Well, that is a piece of my code. What I really wanted to know is if
the pattern above should print the string "Foo-HOWTO.html" and not
print the string "Foo-HOWTO-1.html" providing they are both present in
the array. Just a curious question.

Andy 


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

Date: Sat, 11 Nov 2000 13:28:08 GMT
From: craznar@hotmail.com (Christopher Burke)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <8FE9E3A27Craznar@24.192.1.17>

ren.maddox@tivoli.com (Ren Maddox) wrote in
<m366lvjwx8.fsf@dhcp11-177.support.tivoli.com>: 

>> >  push @fulldata, \%hash;     # but do not reuse the same %hash
>> 
>> That one doesn't work ... because, even with creating new %hash each
>> loop. 
>
>Looks like you might not have finished this thought.  It seems that
>you started to say why this wouldn't work, but didn't actually say it.
>

No - I don't know why it doesn't work. When I tried it - it just didn't 
work.
-- 
---
/* Christopher Burke - Spam Mail to craznar@hotmail.com
|* www.craznar.com - International Internet Writing Experiment
\* Real mail to cburke(at)craznar(dot)com


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

Date: 11 Nov 2000 10:15:54 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Random Array with Sort?
Message-Id: <973937192.3210@itz.pp.sci.fi>

In article <8uhub7$q98$1@nnrp1.deja.com>, Quantum Mechanic wrote:
>
>However, I started thinking about the Fisher/Yates Shuffle, and wondered
>if its running time could be improved but still be unbiased (each
>permutation is equally likely). Fisher/Yates is O(n^2), while quicksort
>is O(n.log(n)).

Fisher-Yates is O(n).  You can't improve on that if you want to
shuffle the whole array.

Of course, if you only need a partial shuffle you can save some extra
work by doing only as many iterations of Fisher-Yates as you need.  In
fact, you can even do the shuffle incrementally if you don't know in
advance how many items will be needed.


I just hacked together the OO implementation below.  You pass the list
to be shuffled to the constructor, then call next() to pull the items
out in random order one by one.  When you reach the end, it'll start
over from the beginning with a new permutation.

  package Perm;
  use strict;

  sub new {
      my $class = shift;
      my $self = { pos => 0, buf => [@_] };
      bless $self, ref($class) || $class;
  }

  sub next {
      my $self = shift;
      my ($pos, $buf) = @$self{'pos','buf'};
      $self->{pos} = $pos < $#$buf && $pos+1;
      my $rand = $pos + int rand(@$buf - $pos);
      (@$buf[$pos, $rand] = @$buf[$rand, $pos])[0];
  }

  "That's all, folks!";	
  __END__

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post
 something, we discuss its implications.  If the discussion happens to
 answer a question you've asked, that's incidental." -- nobull in clpm



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

Date: Sat, 11 Nov 2000 10:30:02 -0000
From: <vidulats@yahoo.co.uk>
Subject: Re: Returning an array from C to Perl
Message-Id: <t0q7tabnvd5o9f@corp.supernews.com>

Hello,

I gone through all of these (perlxs, perlxstut, perlguts, perlapi) 
documents. 
Even I read all the FAQ's related to this topic.

But, couldn't make out from that.

Will anyone help me.

Vidula



Anno Siegel wrote:
> 
> 
>  <vidulats@yahoo.co.uk> wrote in comp.lang.perl.misc:
> >Hi Perl Experts,
> >
> >    I am writing my own C++ extension and I need to return an array 
from 
> >C++ to Perl.  Is this possible?
> >
> >If Yes, then Will anyone please help me out.
> >If No,  then What's the alternative to that.
> 
> You will want to study the following documents (not necessarily in
> that sequence): perlxs, perlxstut, perlguts, perlapi.
> 
> In particular, perlguts describes the procedure to return multiple
> values to perl.  Perhaps a little surprisingly, this is found in the
> chapter "Subroutines".
> 
> Anno


--
Posted via CNET Help.com
http://www.help.com/


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

Date: 11 Nov 2000 05:58:47 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Returning an array from C to Perl
Message-Id: <m3r94i7p20.fsf@mumonkan.sunstarsys.com>

<vidulats@yahoo.co.uk> writes:

> I gone through all of these (perlxs, perlxstut, perlguts, perlapi) 
> documents. 
> Even I read all the FAQ's related to this topic.
> 
> But, couldn't make out from that.

Here's a beautifully written series of articles by 
Steven McDougall on XS

http://www.perlmonth.com/columns/modules/modules.html?issue=6

HTH.
-- 
Joe Schaefer


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

Date: Sat, 11 Nov 2000 21:42:03 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Self-modifying code in Perl
Message-Id: <slrn90q8jr.gs3.mgjv@martien.heliotrope.home>

On 11 Nov 2000 07:15:31 GMT,
	Alan Barclay <gorilla@elaine.furryape.com> wrote:
> In article <slrn90pib1.gs3.mgjv@martien.heliotrope.home>,
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>>On 11 Nov 2000 00:07:54 GMT,
>>	Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>>> [A complimentary Cc of this posting was sent to Anno Siegel
>>><anno4000@lublin.zrz.tu-berlin.de>],
>>> who wrote in article <8ugpbb$57f$1@lublin.zrz.tu-berlin.de>:
>>>> An alternative I like to bring up at this point:
>>>> 
>>>>    read CODE, $_, -s CODE;
>>> 
>>> This assumes some relationship between what -s CODE returns and the
>>> amount of characters read from CODE.  There should be none given some
>>> translations may be performed behind the scene.
>>
>>If you hadn't pointed that oiut, I probably would have. pedantically
>>speaking, that is of course true, however...
>>
>>On the other hand, the only thing possible is that '-s CODE' is larger
>>than the buffer needed to actually read it. What you end up with is a
>>LENGTH argument to read() that is not going to be too small. You'll read
> 
> Is it not possible that in record orientated files, on OS's which support
> them, may have no end of line characters on disk, but do contain them
> when read through a stream?

Hmmm. I'm trying really hard to imagine how that would be possible.
Somewhere, somehow, the end-of-record would have to be indicated.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | You can't have everything, where
Commercial Dynamics Pty. Ltd.   | would you put it?
NSW, Australia                  | 


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

Date: Sat, 11 Nov 2000 21:45:17 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Self-modifying code in Perl
Message-Id: <slrn90q8pt.gs3.mgjv@martien.heliotrope.home>

On 11 Nov 2000 07:25:57 GMT,
	Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> [A complimentary Cc of this posting was NOT sent to Martien Verbruggen
><mgjv@tradingpost.com.au>],
> who wrote in article <slrn90pib1.gs3.mgjv@martien.heliotrope.home>:
>> > This assumes some relationship between what -s CODE returns and the
>> > amount of characters read from CODE.  There should be none given some
>> > translations may be performed behind the scene.
> 
>> On the other hand, the only thing possible is that '-s CODE' is larger
>> than the buffer needed to actually read it
> 
> ... on the systems we know...

Any example, even hypothetical, where the indicated size of a file would
be less than the contents of the file, or where the size of a file does
not include the end-of-line markers? 

>> It's an idiom which is often enough used in C
> 
> ... but C code is infinitely less portable than Perl code.  Let's keep
> it so.  Do not use such suspicious code in Perl...

No, it isn't. ANSI C is portable to any platform that an ANSI compiler
is available for, just as Perl is portable to any platform a Perl
interpreter runs on. I am willing to bet that you'll find more platforms
with ANSI/ISO C compilers than with Perl interpreters. And yes, fread is
part of ANSI/ISO C.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I'm just very selective about what I
Commercial Dynamics Pty. Ltd.   | accept as reality - Calvin
NSW, Australia                  | 


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

Date: 11 Nov 2000 07:47:51 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Self-modifying code in Perl
Message-Id: <m3aeb63caw.fsf@mumonkan.sunstarsys.com>

This is a repost- Gnus crashed during the original transmission :)

mgjv@tradingpost.com.au (Martien Verbruggen) writes:

> On 11 Nov 2000 07:25:57 GMT,
> 	Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> > [A complimentary Cc of this posting was NOT sent to Martien Verbruggen
> ><mgjv@tradingpost.com.au>],
> > who wrote in article <slrn90pib1.gs3.mgjv@martien.heliotrope.home>:
> >> > This assumes some relationship between what -s CODE returns and the
> >> > amount of characters read from CODE.  There should be none given some
> >> > translations may be performed behind the scene.
> > 
> >> On the other hand, the only thing possible is that '-s CODE' is larger
> >> than the buffer needed to actually read it
> > 
> > ... on the systems we know...
> 
> Any example, even hypothetical, where the indicated size of a file would
> be less than the contents of the file, or where the size of a file does
> not include the end-of-line markers? 
> 

Could you be more specific? I don't understand what you're asking for
here. If you're asking 

1) Does

$bufsize == read(FILE, $bufffer, $bufsize); # ??? (-s FILE > $bufsize here)

IME the answer is ("usually yes, but in certain situations, no").
I'm pretty sure I can drum up a counterexample with Apache's help;
also note that tied filehandles allow you to redefine the behavior
of read - a royal PITA when you're "read"ing via mod_perl :)

If you're asking 

2) Does 

local $/ = undef, $_ = <FILE>;
-s FILE == length $_; # ???

It's very easy to find counterexamples here:

% cat myscript.pl

#!/usr/bin/perl -wT
print "SIZE=", -s STDIN, "\n";
local $/ = undef, $_ = <STDIN>;
print "LENGTH=", length $_, "\n";
__END__

% wc bigfile
   2216    7691   90613 bigfile

% cat bigfile | myscript.pl
SIZE=4096
LENGTH=90613

Any FIFO in your filesystem will behave similarly to STDIN
in this case.  As to a "real" file, I'm not sure how the
output of myscript.pl could report different SIZE and LENGTH
numbers (I'd probably consider it a bug in such a case).

-- 
Joe Schaefer


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

Date: Sat, 11 Nov 2000 13:16:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Self-modifying code in Perl
Message-Id: <3kgq0t43qeqtm1maccsg05tsoshg9betck@4ax.com>

Tarael200 wrote:

>Yes, this is very rudimentary. It can not be considered a quine because it
>'cheats' by reading it's code off of the disk..
>
>Hey, I'm 14. Cut me some slack:-)
>
>----------------------------------------------------------
>#!/usr/bin/perl
>
>$Gen = 241;
>print $Gen . "\n";
>
>&modify_code;
>exec("perl selfmod.pl");
>
>sub modify_code {
>        open CODE, "<$0" or die "Can't open for reading: $!";
>        @filetext = <CODE>;
>        close CODE;
>
>        $_ = join("", @filetext);
>
>        ($ext) = /\$Gen = (\d+)/;
>        $ext++;
>        s/\$Gen = \d+/\$Gen = $ext/;
>
>        open OUTP, ">$0" or die "Can't open for writing: $!";
>        print OUTP $_;
>        close OUTP;
>}
>---------------------------------------------------------
>
>Comments? And don't tell me to use -w and use strict. I know that already.
>I'm just lazy ;-)

You can open the file with read and write access at once.

  sub modify_code {
	local $/;
	local *CODE;
        open CODE, "+<$0" or die "Can't open for r/w: $!";
	$_ = <CODE>;
  ...
	seek CODE, 0, 0;
	truncate CODE, 0;
	print CODE;
  }

Further comment: you assume that the first occurrence of the string
'$Gen' is the one you want to change. You could make this assumpion a
bit safer, by adding the '^' anchor and the /m modifier.

And you can do the match and the modification in one line.

	s/^(\$Gen = )(\d+)/$1 . (1+$2)/me;

Oh, a small bug:

>exec("perl selfmod.pl");

That ought to be

	exec("perl $0") 
or
	exec('perl', $0);

Personally, I added a condition:

	exec('perl', $0) if $Gen < 500;


Finally, Perl has a neat way of allowing self-modiying code without
saving to a file. You can create a stirng of  code, and eval it. For
example:

	*foo = eval 'sub {  print "Hello, $_[0]!\n" }';
	foo('world');

Other methods include

	eval 'sub foo {  print "Hello, $_[0]!\n" }';

and, if you want only to bake fixed values (variables) into you sub,
there are closures:

	sub greet {
	    my $greet = shift;
	    return sub { my $name = shift; print "$greet, $name!\n" }
	}
	*hi = greet("Hi");
	*yo = greet("Yo");

	hi('Mike');
	yo('Hannes');

-- 
	Bart.


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

Date: Sun, 12 Nov 2000 00:54:33 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Self-modifying code in Perl
Message-Id: <slrn90qjsp.gs3.mgjv@martien.heliotrope.home>

On 11 Nov 2000 07:47:51 -0500,
	Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> This is a repost- Gnus crashed during the original transmission :)
> 
> mgjv@tradingpost.com.au (Martien Verbruggen) writes:
> 
>> On 11 Nov 2000 07:25:57 GMT,
>> 	Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>> > [A complimentary Cc of this posting was NOT sent to Martien Verbruggen
>> ><mgjv@tradingpost.com.au>],
>> > who wrote in article <slrn90pib1.gs3.mgjv@martien.heliotrope.home>:
>> >> > This assumes some relationship between what -s CODE returns and the
>> >> > amount of characters read from CODE.  There should be none given some
>> >> > translations may be performed behind the scene.
>> > 
>> >> On the other hand, the only thing possible is that '-s CODE' is larger
>> >> than the buffer needed to actually read it
>> > 
>> > ... on the systems we know...
>> 
>> Any example, even hypothetical, where the indicated size of a file would
>> be less than the contents of the file, or where the size of a file does
>> not include the end-of-line markers? 
>> 
> 
> Could you be more specific? I don't understand what you're asking for
> here. If you're asking 

Do you know of any system, or could you imagine a system, where the size
of a file, as reported by the OS, would be smaller than the actual
number of bytes that the internal representation in a Perl string would
use.

IOW. 

open(FILE, 'some_file) or die $!;
$/ = undef;
$file_contents = <FILE>;

if (-s FILE < length $file_contents)
{
	# Does this ever happen? Can it? Could it?
}

> 1) Does
> 
> $bufsize == read(FILE, $bufffer, $bufsize); # ??? (-s FILE > $bufsize here)

Not what I meant, unless $bufsize is larger than length $file_contents.

> 2) Does 
> 
> local $/ = undef, $_ = <FILE>;
> -s FILE == length $_; # ???

I should have read ahead instead of clarifying my question first. Yes,
this is what I mean, almost. But I actually meant

-s FILE < length $_;

And my question was whether that would, could ever happen. I know of no
system where that could happen, and can't think of one, even a
hypothetical one (with the minimal requirement that it is sane), that
would end up in a situation where that would be the case. The closest I
can come is some system that is record based, and where all record
information is kept outside the file. 

This is line1This is line2This is line3

meta-info:
rec1: 0
rec2: 13
rec3: 26
eof: 39

In this case the file would take 38 characters on disk, but once read
into a scalar, it would need 41 characters. I'd hope however that a sane
system would include the size of the meta-information structure in the
file size. If there is at least one system where that doesn't happen,
then I'll retract my statement. I'll retract it if anyone can convince
me that there exists at leat one hypothetical _sane_ implementation of a
file/record system like this.

> It's very easy to find counterexamples here:
> 
> % cat myscript.pl
> 
> #!/usr/bin/perl -wT
> print "SIZE=", -s STDIN, "\n";
> local $/ = undef, $_ = <STDIN>;
> print "LENGTH=", length $_, "\n";
> __END__
> 
> % wc bigfile
>    2216    7691   90613 bigfile
>
> % cat bigfile | myscript.pl
> SIZE=4096
> LENGTH=90613
> 
> Any FIFO in your filesystem will behave similarly to STDIN
> in this case.  As to a "real" file, I'm not sure how the
> output of myscript.pl could report different SIZE and LENGTH
> numbers (I'd probably consider it a bug in such a case).

-s can only be used on real files. Scrap that. -s _should_ only ever be
used on real files. The results are meaningless otherwise, as you have
just shown. It gets its information from stat. And yes, when the
filehandle does not point to a regular file, I'm happy to concede that
what -s returns doesn't match what actually will be read, necessarily.

So, my question stays, but gets one little thing added:

 ... when the file handle is opened to a regular file.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | You can't have everything, where
Commercial Dynamics Pty. Ltd.   | would you put it?
NSW, Australia                  | 


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

Date: Thu, 9 Nov 2000 13:52:29 -0000 
From: "Dresdner Kleinwort Benson" <patiln@dresdnerkb.com>
Subject: switching the user in perl
Message-Id: <88BD1F0859C6D211BFAE0008C7A4BE1501A3AAD4@drkblonc0008-bkup.gb.dresdnerkb.com>

Hi,
I got your name from customer's comment for "perl for system admins".

I am facing following problem:
We are using Netscape site server with sun 5.7. We have web server login
name as 'nescape'. But netscape user is having limited rights, hence we
decided to change the user as root. Now root has some password & we need to
invoke through 'netscape'. We fill some container may be required but don't
know how to do this exactly. can you please suggest something please

Thanks in advance,

Narayan




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

Date: Sat, 11 Nov 2000 23:12:23 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: switching the user in perl
Message-Id: <slrn90qdt7.gs3.mgjv@martien.heliotrope.home>

On Thu, 9 Nov 2000 13:52:29 -0000 ,
	Dresdner Kleinwort Benson <patiln@dresdnerkb.com> wrote:
> Hi,
> I got your name from customer's comment for "perl for system admins".

My name? Gosh, I'm flattered.

> I am facing following problem:
> We are using Netscape site server with sun 5.7. We have web server login

You shouldn't assume that people are familiar with Netscape site server.
I am assuming that it's a new name for the Netscape HTTP server?

> name as 'nescape'. But netscape user is having limited rights, hence we
> decided to change the user as root. Now root has some password & we need to
> invoke through 'netscape'. We fill some container may be required but don't
> know how to do this exactly. can you please suggest something please

And your perl question is what exactly?

I am not being facetious. you simply have no question about Perl. I
would suggest that you go over to one of the groups in
comp.infosystems.www.* and ask there, but try to phrase your question a
little bit better. It's hard to exactly figure out what you are saying,
and what you are asking.

Or maybe you need to ask in a unix or Solaris specific group about what
you want. It's a bit hard to tell what that is exactly.

If you're looking at how to safely do suid stuff with perl, read the
perlsec documentation. And even that doesn't make it safe. You'll still
need to understand what is going on.

\begin{offtopic}

They'll probably tell you over there to never run your web server as
root. Netscape servers generally start up as root, and do a setuid to
a uid with less privileges, like nobody, www, or in your case, netscape.
There are very, very good reasons for that.

let me find my crystal ball, and blow the dust off it. I think I see
that you might be asking how to execute things as root, when you are
really a user with lower priorities. My first reaction is: Do NOT do it.
If you have to ask how to do it, you shouldn't be doing it. Instead, pay
someone who knows what they're doing to do it for you. If you value your
machine, and your data, don't mess around with this sort of stuff. it's
much better to redesign your needs so that you don't have to have root
permissions anymore.

If you are still willing to have a go at it yourself, look into sudo
(which has nothing to do with Perl, but at least it won't require you to
pas sin root passwords. Never do that. You might need Expect.pm or
something like that to interact with sudo, if that's possible at all. I
don't know. I've never considered doing this myself. I wouldn't do it. I
would find a way around the need to become root at all.

Also, look into setuid programs. But DO READ THE perlsec DOCUMENTATION.
It's important. Read it. I mean it. Do. And try to redesign your needs
so you don't need to be root.

Did I already mention I don't think you should do it? And that I think
you should probably review whether you really need to be root?

\end{offtopic}

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Freudian slip: when you say one thing
Commercial Dynamics Pty. Ltd.   | but mean your mother.
NSW, Australia                  | 


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

Date: Sat, 11 Nov 2000 10:47:32 GMT
From: dVoon <dvoon@my-deja.com>
Subject: use-ing .pm file from different dir
Message-Id: <8uj844$os2$1@nnrp1.deja.com>

Hi all,

If I have a user-defined 'myfunc.pm' file in ~/cgi-bin/sharefunc/ , how
do I 'use' it from other different directories?

I have tried putting the full path like:

  use /home/httpd/cgi-bin/sharefunc/myfunc;
or
  use "/home/httpd/cgi-bin/sharefunc/myfunc";

all have failed to even compile :(

I appreciate any help. Thanks.

Daniel


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 11 Nov 2000 13:09:35 GMT
From: doc@CONSORTIUM.RedBrick.DCU.IE (DoC)
Subject: Re: use-ing .pm file from different dir
Message-Id: <slrn90qdhc.1pcj.doc@Enigma.RedBrick.DCU.IE>

dVoon said this: 
>Hi all,
>
>If I have a user-defined 'myfunc.pm' file in ~/cgi-bin/sharefunc/ , how
>do I 'use' it from other different directories?
>
>I have tried putting the full path like:
>
>  use /home/httpd/cgi-bin/sharefunc/myfunc;
>or
>  use "/home/httpd/cgi-bin/sharefunc/myfunc";
>
>all have failed to even compile :(
>
If it's just a bunch of useful methods in a file as opposed to an actual
OO perl module, then you can just go

require '/home/httpd/cgi-bin/sharefunc/myfunc.pm'

If not, you could try invoking perl and telling it to look in this directory
in your scripts. I.e. instead of the first line of scripts being

#!/usr/bin/perl

Change it to:

#!/usr/bin/perl -I/home/httpd/cgi-bin/sharefunc

Then you could just go

use myfunc;

in your perl script, and It'll look in that directory.

Hope this helps.

	- DoC


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

Date: Sat, 11 Nov 2000 21:48:51 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Using POST and POST/ACTION on the same page - I figured it out
Message-Id: <slrn90q90j.gs3.mgjv@martien.heliotrope.home>

On Fri, 10 Nov 2000 23:55:38 -0800,
	Dragonia Radar Freedom, C.S. <radar@jetstream.net> wrote:
> I figured out my problem 10 minutes after posting this...
> a </form> is always a good thing :)

it's wonderful that you found your problem. And fixed it.

Now, please, for the next time, if you're still reading this, try to
figure out before you post whether your problem could possibly be
something else than a Perl problem. In this case, it was most definitely
not a Perl problem, and you could have known that immediately. You were
talking about forms, and what you wanted to display in browsers. Those
things are _never_ a Perl problem. HTML or browser problems, yes. Not
Perl.

The comp.infosystems.www.* hierarchy exists for HTML, WWW and general
problems related to CGI and Web programming. consider posting there
unless you know for certain that you have a problem with Perl, the
language.

Thank you for your cooperation,
Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I'm just very selective about what I
Commercial Dynamics Pty. Ltd.   | accept as reality - Calvin
NSW, Australia                  | 


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

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


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