[6964] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 589 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 8 22:07:10 1997

Date: Sun, 8 Jun 97 19:00:24 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 8 Jun 1997     Volume: 8 Number: 589

Today's topics:
     Beginner Question: Recursive File Copy? (Marc Haber)
     Re: Bizarre error (Gene Johannsen)
     call "c" from "perl"? (Jun Zhuang)
     Re: call perl script from c program? ()
     Re: Comparing large files. <merlyn@stonehenge.com>
     Re: Error in openning a file ... (Marco T Vazquez)
     Re: Error in openning a file ... (Marco T Vazquez)
     Extracting data from log file? <doc@widomaker.com>
     Re: Extracting data from log file? (Chipmunk)
     filehandle/seek/sysread??? (Masked due to spammers)
     Get your source code here.. <chizl@cyberdude.com>
     HOW-DO-I: Server Side Java with IIS 2.0 (Bear)
     Re: inconsistent opendir behaviour in Perl for win32 (Simon Oosthoek)
     Re: localtime(time) yelds year 97, not 1997. In all rea (Abigail)
     Multiple Accepts/Sockets kessler@dfacades.com
     Newbie: How do I write to an existing file. (Dick Hardcastle)
     Re: Parsing Comma Delemited Text DataBase (Clay Irving)
     passwd command and perl data? (Eric Harley)
     Re: Printing Prime Numbers <merlyn@stonehenge.com>
     Re: Printing Prime Numbers (Abigail)
     Problems Getting Perl for Win32 5.003 build 6 Running (Shelle)
     Re: Segmentation fault from multiple mkdirs in Perl scr <bruno@prior.ftech.co.uk>
     Re: sockets select() problem (Andrew M. Langmead)
     Re: UUencoding between UNIX and PC - newlines (Andrew M. Langmead)
     Re: Wheres the best online Perl tutorial? (Clay Irving)
     Re: Windows 3.1 / Perl 4 or 5 <harv@isd.net>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sun, 08 Jun 1997 23:22:05 GMT
From: s_haber@ira.uka.de (Marc Haber)
Subject: Beginner Question: Recursive File Copy?
Message-Id: <5nfeoe$sof$2@nz12.rz.uni-karlsruhe.de>

Hi!

I am just trying to learn perl. My first task is writing a Windows NT
login script in perl. From my programming experience I know that the
best way for me to learn a new language is modifying an example.

Does anybody have a perl program that does a recursive copy of a
directory tree (like cp -r or xcopy /s)? Calling an external copy
program is no option because I'll have to do some processing on the
files. I'd like to have a program that takes advantage of the copy
package.

Any hints will be appreciated.

Greetings
Marc

-- 
-------------------------------------- !! No courtesy copies, please !! -----
Marc Haber          |   " Questions are the         | s_haber@ira.uka.de
Karlsruhe, Germany  |     Beginning of Wisdom "     | Fon: *49 721 966 32 15
Nordisch by Nature  | Lt. Worf, TNG "Rightful Heir" | Fax: *49 721 966 31 29


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

Date: 8 Jun 1997 21:30:24 GMT
From: gej@spamalot.mfg.sgi.com (Gene Johannsen)
Subject: Re: Bizarre error
Message-Id: <5nf89g$353$1@murrow.corp.sgi.com>

tadmc@flash.net (Tad McClellan) writes:

| Gene Johannsen (gej@spamalot.mfg.sgi.com) wrote:
| : Hey:
| 
| : I got this error from a script:
| 
| :     Bizarre copy of CODE in leavesub at /usr/asrs/mack.pl line 514
| 
| : Line 514 of mack.pl looks like this:
| 
| :     return unless get_crane_status( &INBOUND_FULL ) == &YES;
| 
| : Can anyone explain this to me?
| 
| 
| You mean beyond the explanation of the error message that is given
| in the perldiag man page?

	You mean this:

        Bizarre copy of %s in %s
              (P) Perl detected an attempt to copy an internal value
              that is not copiable.

	Which brings me back to the question:  What does this mean?

gene

| 
| 
| --
|     Tad McClellan                          SGML Consulting
|     Tag And Document Consulting            Perl programming
|     tadmc@flash.net


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

Date: 9 Jun 1997 01:43:32 GMT
From: jzhuang@ringer.cs.utsa.edu (Jun Zhuang)
Subject: call "c" from "perl"?
Message-Id: <5nfn44$vf@ringer.cs.utsa.edu>
Keywords: perl and C



Need help to understand how to call "C" from Perl.

I tried call a "C" executable from perl script?
i.e. a simple "S" program is:
       int  main(int argc, char *argv[])
           {
             int sum;
             int a = atoi(argv[1]);
             int b = atoi(argv[2]);
             sum = a+b;
             return sum;
           }
  It was compiled and name as "sum".

 In the Perl script, I tried to call this program by using execvp:
        $x = 5;
        $y = 10;
        $return_value = execvp ("sum $x $y");
And I got errror:
Undefined subroutine &main::execl called
 
How do I call "c" from perl?
Thanks in advance.
-
-
Jun Zhuang                         |Jun Zhuang 
Department of Computer Science     |Department of Pharmacology
University of Texas                |UT Health Science Center
San Antonio, Texas                 |San Antonio, Texas
Email: jzhuang@ringer.utsa.edu     |Email: zhuang@arwen.uthscsa.edu



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

Date: 8 Jun 1997 17:54:40 GMT
From: suisum@freenet.edmonton.ab.ca ()
Subject: Re: call perl script from c program?
Message-Id: <5nerl0$jv8$2@news.sas.ab.ca>

How to call common shell scripts from C?

Bob Wilkinson (b.wilkinson@pindar.co.uk) wrote:
: In article <3397000A.517A@bayfront.org>, xuc@bayfront.org wrote:

: > I have two cgi programs, one written in c, another in perl.  Now, the C
: > program needs to use a subroutine in the perl script.  Is it possible to
: > call the perl script in the c program?    
: > 
: > Thanks a lot.
: > 
: > --Chun Xu

: Hello,

:       Type 'perldoc perlembed' at your prompt for instruction.

: Bob

: -- 
: I have become death, destroyer of the worlds.

--
Best regards,


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

Date: 08 Jun 1997 18:29:45 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Peter Kennis <pkennis@inetnow.net>
Subject: Re: Comparing large files.
Message-Id: <8chgf85zsm.fsf@gadget.cscaper.com>

>>>>> "Peter" == Peter Kennis <pkennis@inetnow.net> writes:

Peter> Two files containing 30.000 or more lines, I would like to 
Peter> find all lines from file1 that do not exist in file2.
Peter> I know there are a lot of ways to do this but I'd like to find 
Peter> one that is not to CPU intensive....
Peter> Both files are sorted alike so record 1 from file 1 should also 
Peter> be record 1 in file 2

Peter> File 1 example: aaaaaaa
Peter>                 bbbbbbb
Peter>                 ccccccc
Peter>                 ddddddd

Peter> File 2 example: aaaaaaa
Peter>                 ccccccc

Peter> Output should be : aaaaaaa
Peter>                    ddddddd

Peter> Any suggestions?

Well, this seems to be a perfect job for comm(1), but since this is
a Perl newsgroup:

	#!/usr/bin/perl
	exec "comm","-23","file1","file2";
	die "Trouble in paradise: $!";

:-)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 449 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 8 Jun 1997 23:11:59 GMT
From: vazq0017@maroon.tc.umn.edu (Marco T Vazquez)
Subject: Re: Error in openning a file ...
Message-Id: <5nfe7v$73p@epx.cis.umn.edu>

Daneshjoo (eermmb@engunx.unl.edu) wrote:
: Hi :

: 	I have a script which reads a random line from a file.  It works
: fine, except for one file.  Here is how the file looks like :


: #************ File : quotes_friends   *****************************

: Man is the only animal that can remain on friendly terms with the victims he intends to eat until he eats them.    -Samuel Butler 1835-1902
: We do not inherit the land, we borrow it from our children.  -Native American saying
: Man is a complex thing: he makes deserts bloom and lakes die.   -Gil Stern
: If we keep doing what we are doing, we are going to keep getting what we are getting.   -Stephen Covey, First Things First
: Everyone thinks of changing the world, but no one thinks of changing himself.   -Tolstoy

: #*******************************************************************


: (note : the file should look as if the end of each line is missing)

: The reason I wrote it this way, was that I didn't know how to write a
: script to choose random paragraphs, but random lines are easy.  The
: problem accurs when I run the script :


: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
: ////////////////////////////////////////////////////////////////////

: #!/usr/local/bin/perl  -w

: open (Quotes, "quotes_friends") || die $!; 
: @QUOTES = <Quotes>;
: srand;
: $QUOTE = rand @QUOTES;

: system "cat /$QUOTES[$QUOTE]  >  /quote.txt";

: /////////////////////////////////////////////////////////////////
: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

: It gives me the error message "can't open /[Here is prints one of the
: lines of the file by random]".  Could it be because of the "wide lines" or
: is it some thing else?  Could some one please help me? TIA


: 				Daneshjoo


: 			



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

Date: 8 Jun 1997 23:28:17 GMT
From: vazq0017@maroon.tc.umn.edu (Marco T Vazquez)
Subject: Re: Error in openning a file ...
Message-Id: <5nff6h$73p@epx.cis.umn.edu>

Daneshjoo (eermmb@engunx.unl.edu) wrote:
: Hi :

: 	I have a script which reads a random line from a file.  It works

: #!/usr/local/bin/perl  -w

: open (Quotes, "quotes_friends") || die $!; 
: @QUOTES = <Quotes>;
: srand;
: $QUOTE = rand @QUOTES;

: system "cat /$QUOTES[$QUOTE]  >  /quote.txt";
          ^^^ ^               ^  ^ ^

	If what you are trying to do is to redirect the quote to 
quote.txt you should use "echo" instead of "cat".  Also, you need to 
quote the quote so the complete line is redirected.  I don't know what 
the purpose of the slashes (/) is and I wouldn't use more spaces then 
necessary when invoking the shell.  Try something like this:

	system "echo \"$QUOTES[$QUOTE]\" > quote.txt";

 
/////////////////////////////////////////////////////////////////
: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

: It gives me the error message "can't open /[Here is prints one of the
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

	It does that because "cat" is expecting a file, not a string or 
line of text.  Check the man

: lines of the file by random]".  Could it be because of the "wide lines" or
: is it some thing else?  Could some one please help me? TIA


: 				Daneshjoo


: 			



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

Date: 8 Jun 1997 21:58:40 GMT
From: "Doc" <doc@widomaker.com>
Subject: Extracting data from log file?
Message-Id: <01bc7457$106284c0$aa9aa1ce@doc.Virginia.EDU>

What is the best way to assign variables to data in a log file?  

Example:
 	If I wanted to extract the IP address for the latest log-on of a user
from the pm.log file in /var/log to use to compare it to another IP
address, how would I instruct perl to find the IP address for that user at
that time in that log file?

I've tried pattern recognition, but can't get it to work properly.

Any assistance would be appreciated.

Doc



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

Date: 8 Jun 1997 23:57:17 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Extracting data from log file?
Message-Id: <5nfgst$prf$1@dartvax.dartmouth.edu>

In article <01bc7457$106284c0$aa9aa1ce@doc.Virginia.EDU>
"Doc" <doc@widomaker.com> writes:

>         If I wanted to extract the IP address for the latest log-on of a user
> from the pm.log file in /var/log to use to compare it to another IP
> address, how would I instruct perl to find the IP address for that user at
> that time in that log file?
> 
> I've tried pattern recognition, but can't get it to work properly.

I think pattern recognition is the way to go here.  Provide some
examples of your data and we can suggest some regexps.

Chipmunk


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

Date: Sun, 08 Jun 1997 21:19:47 GMT
From: nobody@nowhere.com, abuse@aol.com (Masked due to spammers)
Subject: filehandle/seek/sysread???
Message-Id: <339b1efb.8652361@nntp.idsonline.com>


I'm trying to write my own perl script to handle searching a '\n'
delimited textfile.  The database consists of 170,000 records, each
record is between 9 and 25 fields long.  Each field is on it's own
line in the file, and each record is seperated by a line-character
(\n).  

With 5,000 records, this is pretty fast, but with 170,000 records it's
too slow to be useful.

I've expiremented with seek() and tell() which return a line at
incredible speeds, even towards the end of the file.  The only problem
is I don't know how to go about indexing this file so that I can
determine each line's starting byte.  I can easily change the format
of the file to where each record is on a single line, if that makes
indexing any easier... but how do I go about indexing?  If it's
possible, it would be easy to look for the \n and then store the next
byte as the start of a new record.... how would I do that?


This is what I used to test seek() and tell() against a 33Mb
datafile.......

($position, $filename) = @ARGV;

open (FILE, $filename);
seek(FILE, $position, 0);
$trash = <FILE>;
$realpos = tell(FILE);
$nextline = <FILE>;
print "The next line of $filename is $nextline\n";
print "It actually starts at $realpos\n\n";
close (FILE);


even the last line of the file comes out pretty fast, which is much
better than 

open (FILE, "filename")
	while (<FILE>)
	{
	 next unless $_ =~ /$match_string/
	print $_;
	}

which would have to go through all 1.7 million lines of the text file,
comparing each line to $match_string.


If I could build a second "index" text file that had simply the text
being searched and the byte position in the data file, the search time
would be reduced a lot, as best I can tell.  

Any ideas how to go about doing an index that way?


Thanks in advance for any help with this,

Please reply to bobhenry@cymedia.com, not the address in the header of
this message (I've changed it to avoid spam)




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

Date: 8 Jun 1997 22:57:11 GMT
From: "Chizl" <chizl@cyberdude.com>
Subject: Get your source code here..
Message-Id: <01bc745e$7244f180$5e9112cf@default>

All the source code you will ever need.   Add your source code here for
others to use and learn..
http://www.sourcesite.simplenet.com/

-- 
L8r,
Chiz
chizl@cyberdude.com
chizl@sourcesite.simplenet.com
The Source Site
http://www.sourcesite.simplenet.com/
The ONLY site for All platforms and all language source code in one place.
Take code and give code for FREE!


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

Date: Sun, 08 Jun 1997 15:20:36 GMT
From: clary@cruzio.com (Bear)
Subject: HOW-DO-I: Server Side Java with IIS 2.0
Message-Id: <339acdb2.1239061@news.ucsc.edu>

Hi, I'm tryinng to set up my web server (IIS 2.0) to run server side
Java.  Since I have Perl set up fine, I figure that I would go through
similar steps to set of Java.  So, I went to:
	HKEY_LOCAL_MACHINE -> System -> Current Control Set -> 
	Services -> W3SVC -> Parameters -> Script Map
and added the key:
	.class : REG_SZ : c:\jdk1.1.1\bin\java.exe
Next, I added c:\jdk1.1.1\bin\ to my path in Control Panel -> System.
All directories are set for execute permissions.  Now, everything is
set, and should work... except for one obvious problem.  When the
server is requested a .class, let's say test.class, it runs java like:
	java test.class
This won't work because java gives me an error (as expected).  Al java
wants is:
	java test
Now, even with that being an obvious error I should still be able to
get the error message from the browser, right?  Instead I just get
Netscape trying to get me to save test.class to my harddisk as
test.exe. ??????  Anyone got any suggestions?  I'm stuck.

Thanks for any help.
       Aran

P.S. PLEASE Respond via E-Mail


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

Date: 8 Jun 1997 21:15:29 GMT
From: s.oosthoek@student.utwente.nl (Simon Oosthoek)
Subject: Re: inconsistent opendir behaviour in Perl for win32
Message-Id: <5nf7dh$ea0@pandora.cs.utwente.nl>

In a previous article Wm <wm_n00@tarrcity.demon.co.uk> says...

>>why doesn't it test 'c:/tmp/'?
>>I bet that gives the same result as 'c:/'
>
>Not here.
>
>>it seems to be the '/' at the end that is causing the problem....


Hmm, I tested this _after_ I posted it (stupid, I know) and it did work 
in a way...

Here are some other results that summarize the problem quite nicely:

Checking on 'd:/'
  -d says true
  opendir can't open it: No such file or directory

--> it is a directory, but opendir doesn't think so...

Checking on 'd:/tmp/'
  -d says false!
  opendir can open it
  and it has 15 items in it.

--> it is a directory according to opendir, but -d doesn't see it that 
way...

Checking on 'd:/tmp'
  -d says true
  opendir can open it
  and it has 15 items in it.

--> the same dir and now both -d and opendir agree

>Hence my thought that its the behaviour at root vs subdirs that is 
>inconsistent.

I agree.

>I agree.  What I wasn't sure about was if opendir and -d were *meant* to 
>behave differently in some circumstances.  Anyway, if Tom thinks its a
>bug that'll do for me.

I'd love to hear some arguments for that kind of behaviour ;-)
>
>On which point you've saved me the embarrassment of having to say that I 
>don't have perlbug and can't find any documentation that I can see from 
>Activeware saying how I should go about reporting one.  Could you help 
>me out by saying what the procedure, format, etc is for future 
>reference or point me to where I might find this information.  I will
>also ask in the Win32 mailing list. TIA.

Right, perlbug seems to be "forgotten" in the winperl release...
Anyway, I just sent the output of Tom's script to the address listed in 
the readme file. I included a small comment that I thought it was a bug 
and that was it.

We'll see what happens.....

Simon.



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

Date: Mon, 9 Jun 1997 01:09:29 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: localtime(time) yelds year 97, not 1997. In all realizations?
Message-Id: <EBHHvt.37t@nonexistent.com>

Alexander Petrosyan (PAF) (paf@i-connect.ru) wrote on 1377 September 1993
in <URL: news:01bc742c$5279d370$08c8c8c8@paf>:
++ That's true for 5.001NT port, and, as far as I've heard for 5.004 unix.
++ 
++ Why?

Because it's defined to return year - 1900. That happens to be 97
around this date.

++ What whould be when in 2000?

2000 - 1900, what would that be? "Saturday" of course!



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$=new Math::BigInt+qq;$$783$[$%9889$47$|88768$596577669$%$5$3364$[$$$|838747$[8889739$%$|$673$%$98$76777$=56;;$=$]*(q.25..($=@))=>do{print+chr$%$;$/=$}while$!=$'


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

Date: Sun, 08 Jun 1997 16:51:58 -0600
From: kessler@dfacades.com
Subject: Multiple Accepts/Sockets
Message-Id: <865806202.1799@dejanews.com>

Calling all Perl Socket Gurus!

I have a server/client setup based on Camel p350.  I fork lots of
children; they all inherit the parent's socket.  However, if they all
do an "accept" on that socket, they seem to collide (esp under
Solaris), and hang.

In the Camel example, the server doesn't fork until an accept returns;
but this way, your children are spawned to handle one connection and
then expected to exit.  I'd like them to stay around and handle more
connections, so that a surge in access is quickly dealt with.

Apache can do it in C... can I do it in perl?

Thanks for any advice/pointers.

Will Kessler
DigitalFacades Corporation
www.dfacades.com
kessler@dfacades.com

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Mon, 09 Jun 1997 04:42:57 GMT
From: dik9@desire.force9.net (Dick Hardcastle)
Subject: Newbie: How do I write to an existing file.
Message-Id: <5nfghp$ai1@newsfeed2.force9.net>

Hi.

I'm writing a CGI in Perl which collects data via an HTML form. I want
to insert this data into the file at a specific piont which will be
marked with something like <!--Insertion Piont--> or a similar marker.
My problem is that I don't know how to search a file or how to write
to a specific piont in a file using Perl.



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

Date: 8 Jun 1997 20:36:40 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Parsing Comma Delemited Text DataBase
Message-Id: <5nfj6o$1ar@panix.com>

In <339AC84F.3832@worldnet.att.net> Nasser Al-Zawawi <nzawawi@worldnet.att.net> writes:

>I trying to figure out how to parse a Text DataBase that is Comma
>delimeted and has "" Double quotes for its strings fields.  My problem
>is withen these string fields you could have a comma that should not be
>parsed.
>Meaning
>1,"Hello, World",6,"hi"
>Should be parsed into 4 fields
>1. 1
>2. "Hello, World"
>3. 6
>4. "hi"

>Not 5 fields
>1. 1
>2. "hello
>3. World"
>4. 6
>5. "hi"

>I can't figure out the regulare expression that could do that for me.
>I tried to tackle this problem with both AWK and PERL with no luck.
>I would appreciate any feed back about this.

I'd be inclined to use the Text::CSV module:

NAME
    Text::CSV - comma-separated values manipulation routines

SYNOPSIS
     use Text::CSV;

     $version = Text::CSV->version();      # get the module version

     $csv = Text::CSV->new();              # create a new object

     $status = $csv->combine(@columns);    # combine columns into a string
     $line = $csv->string();               # get the combined string

     $status = $csv->parse($line);         # parse a CSV string into fields
     @columns = $csv->fields();            # get the parsed fields

     $status = $csv->status();             # get the most recent status
     $bad_argument = $csv->error_input();  # get the most recent bad argument


DESCRIPTION
    Text::CSV provides facilities for the composition and
    decomposition of comma-separated values. An instance of the
    Text::CSV class can combine fields into a CSV string and parse a
    CSV string into fields.

 ...

EXAMPLE
      require Text::CSV;

      my $csv = Text::CSV->new;

      my $column = '';
      my $sample_input_string = '"I said, ""Hi!""",Yes,"",2.34,,"1.09"';
      if ($csv->parse($sample_input_string)) {
        my @field = $csv->fields;
        my $count = 0;
        for $column (@field) {
          print ++$count, " => ", $column, "\n";
        }
        print "\n";
      } else {
        my $err = $csv->error_input;
        print "parse() failed on argument: ", $err, "\n";
      }

      my @sample_input_fields = ('You said, "Hello!"',
                                 5.67,
                                 'Surely',
                                 '',
                                 '3.14159');
      if ($csv->combine(@sample_input_fields)) {
        my $string = $csv->string;
        print $string, "\n";
      } else {
        my $err = $csv->error_input;
        print "combine() failed on argument: ", $err, "\n";
      }

-- 
Clay Irving                                        See the happy moron,
clay@panix.com                                     He doesn't give a damn,
http://www.panix.com/~clay                         I wish I were a moron,
                                                   My God! Perhaps I am!


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

Date: Sun, 08 Jun 1997 18:08:16 -0700
From: erich@powerwareintl.com (Eric Harley)
Subject: passwd command and perl data?
Message-Id: <erich-0806971808170001@ppp-207-104-16-23.snrf01.pacbell.net>

How would I pipe data into the passwd(1) command on a BSD box?

Do i just open it like a file handle?

open PAS, "| passwd $user";

print PAS "$oldpass";
print PAS "$newpass";
print PAS "$secondpass";

Thanks!
-Eric Harley
erich@powerwareintl.com


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

Date: 08 Jun 1997 14:31:57 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Darryl Caldwell <darrylc@eznet.com>
Subject: Re: Printing Prime Numbers
Message-Id: <8c3eqs93xu.fsf@gadget.cscaper.com>

>>>>> "Darryl" == Darryl Caldwell <darrylc@eznet.com> writes:

Darryl> It took me a night to think about it to get it to work. I'm
Darryl> curious if there are more efficient approaches. I am really
Darryl> interested in algorithms -- one of my weaker areas. I wouldn't
Darryl> have been able to come up with anything on the spot. I would
Darryl> appreciate any comments. Thanks.

Well, here's a way that scales nicely as the data size gets larger,
thanks to some help from string-ish ops:

    my $max = 50000;
    my $primes = "\xff" x $max; # initially, they're all possibly prime
    print "primes:";
    for my $guess (2..$max) {
      next unless vec($primes, $guess - 1, 8);
      print " $guess"; # found one!
      my $mask = ("\xff" x ($guess - 1))."\x00";
      $mask .= $mask while length($mask) < length($primes);
      $primes &= $mask; # remove multiples
    }
    print "\n";

Took a minute to find primes under 50,000 on my sparc.  Scale as
necessary.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 449 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Mon, 9 Jun 1997 01:04:07 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Printing Prime Numbers
Message-Id: <EBHHMv.2Ft@nonexistent.com>

Randal Schwartz (merlyn@stonehenge.com) wrote on 1377 September 1993 in
<URL: news:8c3eqs93xu.fsf@gadget.cscaper.com>:
++ >>>>> "Darryl" == Darryl Caldwell <darrylc@eznet.com> writes:
++ 
++ Well, here's a way that scales nicely as the data size gets larger,
++ thanks to some help from string-ish ops:
++ 
++     my $max = 50000;
++     my $primes = "\xff" x $max; # initially, they're all possibly prime
++     print "primes:";
++     for my $guess (2..$max) {
++       next unless vec($primes, $guess - 1, 8);
++       print " $guess"; # found one!
++       my $mask = ("\xff" x ($guess - 1))."\x00";
++       $mask .= $mask while length($mask) < length($primes);
++       $primes &= $mask; # remove multiples
++     }
++     print "\n";
++ 
++ Took a minute to find primes under 50,000 on my sparc.  Scale as
++ necessary.

Uhm, it took 63s on my sparc, vs 17s for my list implementation.

Simple analysis shows your solution is real bad, and doesn't scale
well at all. [1]

The mask you are building for each prime has length O (n). Hence &=
with the mask takes time O (n). Since there are O (n / ln n) primes <= n
[2, p. 110], your solution takes O (n^2 / log n).

The traditional list implementation [3] however takes O (n * sum (1/p_i)),
1 <= i <= pi(sqrt (n)), p_i being the ith prime. Clearly,

   pi(sqrt(n)) 1      sqrt(n)  1
       sum     --  <=   sum    -  <= ln sqrt(n) + 1.  [2, p. 262]
       i=i     p        j=1    j
                i

Hence, the traditional sieve takes O (n log n).

Even the naieve method of "try to divide every number with numbers up
to its square root" scales better, as that takes only O (n sqrt n).
(Add an extra log n if you think division can't be done in constant time).


[1] Using $max = 500000, your solution took 75m 1s, vs 3m 35 for the
    traditional sieve.
[2] Ronald L. Graham, Donald E. Knuth and Oran Patashnik:
    "Concrete Mathematics". Addison-Wesley, 1988.
    ISBN 0-201-14236-8.
[3] See for instance: <URL:news:EBEB4r.Jn7@nonexistent.com>


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$=new Math::BigInt+qq;$$783$[$%9889$47$|88768$596577669$%$5$3364$[$$$|838747$[8889739$%$|$673$%$98$76777$=56;;$=$]*(q.25..($=@))=>do{print+chr$%$;$/=$}while$!=$'


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

Date: Sun, 08 Jun 1997 22:44:03 GMT
From: shelle@interaccess.com (Shelle)
Subject: Problems Getting Perl for Win32 5.003 build 6 Running
Message-Id: <5nfcjj$1d0_002@interaccess.interaccess.com>

My system=Windows95 Pentium 200MMX running Windows95 rev b

Since Friday I've been searching every FAQ (Including the on put out by 
"Evangelo Prodromou") on every site, every newsgroup (Including Deja New 
archives), and every page I could find with ANY information listed on, and 
still cannot solve this problem.

When I try to run from the command line I either get blank lines or syntax 
errors for calling out to file locations or using switches.  When I try to 
access a simple script via a web page I get "Server Error 500" and a message 
something like "Failed to initiate CGI..."

I have made the changes to the registry as suggested in the documentation - 
What am I missing?

TIA


Michelle ----,-'-(@

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Michelle Feigen      ----,-'-(@      shelle@interaccess.com
                     MEAN PEOPLE SUCK!    
          http://homepage.interaccess.com/~shelle/
       http://homepage.interaccess.com/~shelle/grafx/       
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: Mon, 09 Jun 1997 01:26:30 +0100
From: Bruno Prior <bruno@prior.ftech.co.uk>
Subject: Re: Segmentation fault from multiple mkdirs in Perl script - Help!
Message-Id: <339B4DB6.59BB@prior.ftech.co.uk>

I've just RTFM (I've slapped my own wrists for not doing this before
posting) and the camel book points out that "if you are creating a long
list of subdirectories....it will be more efficient to call the mkdir
program yourself with the list of directories to avoid starting zillions
of subprocesses". I've changed the script accordingly, and sure enough,
it now works. Silly me!

Incidentally, as the only suggestion I received (from a variety of
sources) was to upgrade to Perl 5, I would just like to comment that I
had a go a while back at upgrading, but the dbmopens in my scripts (of
which there are several hundred) stopped working. The 2nd edition of the
camel book says that dbmopen was retained for backwards compatibility,
but it didn't work for me, and I couldn't be bothered to try and chnge
my scripts to use the new tie command, which is why I am still using
version 4. Does anyone have any idea why dbmopen won't work under Perl 5
for me. Could it be because I have version 5.001? Was this backwards
compatibility added in later versions (i.e. 5.004)?

Cheers,


Bruno Prior			bruno@prior.ftech.co.uk


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

Date: Sun, 8 Jun 1997 14:25:30 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: sockets select() problem
Message-Id: <EBGo2J.24E@world.std.com>

etruben@ci.ua.pt (Ruben Mendes) writes:

>I am trying to translate a C program I made to Perl. I have only one
>problem (not bad considering its my first Perl hack :). Here's what I do:

>I call select() to block until one of two socket descritors is ready for
>_reading_ . In C it works fine because it returns as soon as there is
>one byte to be read.
>It seems that in Perl the select() returns only when some buffer is full.

This is not the case. There are two gotchas in using select with perl:

1. The writer needs to turn off the default buffering. Unlike C, you
don't have the choice between fully buffered, line buffered or
unbuffered. In perl, you have "default buffering" (whatever STDIO
would pick for you. Usually fully buffered or line buffered depending
where the output is going.) or "command buffered" (each output
statement like print() or write() will not finish until all its output
is written.) See the autoflush method in the FileHandle module or the
$| variable in perlvar man page.

2. select() is returning based on any data available to be read. The
<> and read() operators buffer data and try to return full read
requests. You may need to use sysread() so that each time select()
returns that data can be read, that you get all of the data. (select()
returns if data is available to be read by your process from the
kernel. It doesn't know about data buffered within your process, nor
does it know if the data would be a "full" buffered read request.)
-- 
Andrew Langmead


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

Date: Sun, 8 Jun 1997 20:12:39 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: UUencoding between UNIX and PC - newlines
Message-Id: <EBH453.AKp@world.std.com>

danew@enterprise.net (Matthew Burnham) writes:

>I have a script that uuencodes a file and emails it off somewhere,
>unfortunately the output is mangled so that the newlines aren't right.
>How can I make it work!

>This is an extract from the script:

>if (-e $filename)
>{
>	open(FILE, "<$filename");

You probably want to say "binmode(FILE)" here. See
<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq4/How_do_I_handle_binary_data_cor.html>
for details.



>	while(<FILE>)

Less importantly, you might want to either read chunks of data with
read() and uuencode them separately, (choosing the amount to read to
match uuencoding character, byte boundries correctly, and line
boundries correctly. A multiple of 60 would be good.) or to slurp the
file in one chunk. (With a very large read() or undef()ing $/).
Reading on newline boundries make little sense with binary files.
-- 
Andrew Langmead


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

Date: 8 Jun 1997 20:27:06 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Wheres the best online Perl tutorial?
Message-Id: <5nfikq$sv4@panix.com>

In <5na3c8$1fms@uni.library.ucla.edu> "John L. Stein" <stein@seas.ucla.edu> writes:

>Wheres the best online Perl tutorial?

>I've searched Perl.net an Orielly thoroughly but could'nt
>find a really good tutorial.

Well, you could try the "Tutorial" section of Perl Reference:
http://www.panix.com/~clay/perl/

-- 
Clay Irving                                        See the happy moron,
clay@panix.com                                     He doesn't give a damn,
http://www.panix.com/~clay                         I wish I were a moron,
                                                   My God! Perhaps I am!


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

Date: Sun, 08 Jun 1997 18:37:31 -0700
From: EH <harv@isd.net>
Subject: Re: Windows 3.1 / Perl 4 or 5
Message-Id: <339B5E5B.2499@isd.net>

Zac wrote:
> 
> I have read a mountain of information regarding Perl but nothing seems
> to address my confusion. I am a 486 / Windows 3.11 user, and have
> never seen a Unix Operating System.

See if you can get unix access, you don't really need it, but it's cool.
:)
Plus, if you have shell access, you can upload your perl programs onto
your ISP's 
server and run them to make sure they work.

> I understand that I can write a perl script in pure text (in Windows,
> Notepad for example) and upload it to a CGI directory, and it would
> run.

Yup, just make sure you upload it with your ftp program set to ascii,
not binary.
  
> Other information (book: "60 Minute Guide to CGI programming with Perl
> 5" by Robert Farrell) seems to suggest that Even though I am a windows
> 3.11 user, I will still need to download a programme called Perl 5.
>
> If Perl is a pure text language, why do I need a Programme which I
> presume is a compiler of some sort. If I then find this programme and
> am able to run it on my Windows 3.11 operating system, will it still
> run on my Service Providers Unix Platform.

You don't unless you want to run your programs on your local machine,
which doesn't work nicely in dos/windows anyway.
With windows 3.11 you need a port of Perl if you want to run your
programs. So, you don't really need it. you can ports for windows and
alot of other platforms in the CPAN archives.


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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 V8 Issue 589
*************************************

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