[7896] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1521 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 22 08:17:29 1997

Date: Mon, 22 Dec 97 05:00:48 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 22 Dec 1997     Volume: 8 Number: 1521

Today's topics:
     Re: _SUBROUTINE_NAME_ variable? (brian d foy)
     Re: _SUBROUTINE_NAME_ variable? <Chris_Hill@mentorg.com>
     Re: Calling FTP from a Perl script being run by inetd (M.J.T. Guy)
     Re: Compilation error with Format <ebohlman@netcom.com>
     Re: does ne1 know... (brian d foy)
     Re: does ne1 know... <ebohlman@netcom.com>
     Re: Extensible File Handle Objects (M.J.T. Guy)
     Re: failed exec() (M.J.T. Guy)
     Re: HELP!  Bitwise XOR (^) doesn't work on strings? (Bart Lateur)
     help! package export variables <smiley@seds.lpl.arizona.edu>
     Re: help! package export variables (brian d foy)
     Re: Listing files on your server as scalar values. lineberry@cyberdude.com
     Re: Listing files on your server as scalar values. <ebohlman@netcom.com>
     Mail::Send <antony@fabric8.com>
     ORAPerl <jan.peyer@be.softlab.ch>
     Re: Poor Man's FLOCK (M.J.T. Guy)
     Re: Removing Files older than 14 days (M.J.T. Guy)
     Socket communication between Perl and C (Melchisedech Bernd)
     Stand-Alone Computer <eaarmour@cableinet.co.uk>
     Re: Stand-Alone Computer <ebohlman@netcom.com>
     Re: Teaching programing <rjc@liddell.cstr.ed.ac.uk>
     Re: text wrap (Michael Budash)
     Re: text wrap (brian d foy)
     Tricky Frames Problem <ashley@yeehaw.com>
     Re: Tricky Frames Problem (brian d foy)
     Re: Which language pays most 17457 -- C++ vs. Java? (Kurt Watzka)
     WWW database <sc1334@speedy.udg.es>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 22 Dec 1997 03:47:22 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: _SUBROUTINE_NAME_ variable?
Message-Id: <comdog-ya02408000R2212970347220001@news.panix.com>
Keywords: from just another new york perl hacker

In article <Pine.GSO.3.96.971220221326.4324N-100000@user2.teleport.com>, Tom Phoenix <rootbeer@teleport.com> wrote:

>On Sat, 20 Dec 1997, Tim Maher wrote:
>
>> To facilitate the printing of error messages from user-defined subs, I'm
>> wondering if there's a built-in variable that knows the name of its
>> local subroutine. 

>        my $name = (caller 0)[3];

caller can be hours of fun:

   #!/usr/bin/perl
   
   use subs qw(just another new york perl hacker);

   # a linked list of subroutine calls   
   my %hash = qw( just    another
                  another new
                  new     york
                  york    perl
                  perl    hacker
                  hacker  just
                 );
                 
   just; # the subroutine which calls all of the others
   
   sub just    { $_ = (caller 0)[3]; s/.*:://; &{$hash{$_}}; }
   sub another { $_ = (caller 0)[3]; s/.*:://; &{$hash{$_}}; }
   sub new     { $_ = (caller 0)[3]; s/.*:://; &{$hash{$_}}; }
   sub york    { $_ = (caller 0)[3]; s/.*:://; &{$hash{$_}}; }
   sub perl    { $_ = (caller 0)[3]; s/.*:://; &{$hash{$_}}; }
   
   #hacker walks down the stack, printing subroutine names as it
   #goes along
   sub hacker  
      { 
      foreach(0..5) 
         {
         $_ -= 5;
         my $name = (caller -$_)[3];
         $name    =~ s/.*::/ /;
         print $name; 
         } 
      }
   
   =head other fun things 
   print just another new york perl hacker;
   
   sub just    { $_ = (caller 0)[3]; s/.*:://;  $_ .= shift }
   sub another { $_ = (caller 0)[3]; s/.*::/ /; $_ .= shift }
   sub new     { $_ = (caller 0)[3]; s/.*::/ /; $_ .= shift }
   sub york    { $_ = (caller 0)[3]; s/.*::/ /; $_ .= shift }
   sub perl    { $_ = (caller 0)[3]; s/.*::/ /; $_ .= shift }
   sub hacker  { $_ = (caller 0)[3]; s/.*::/ /; $_ .= shift }
   =cut
   
   =head playing with $AUTOLOAD
   print just another new york perl hacker;
   
   sub AUTOLOAD { $AUTOLOAD =~ s/.*::/ /; $AUTOLOAD .= shift }
   =cut

   __END__

-- 
brian d foy                                  <comdog@computerdog.com>
Meta Meta FAQ <URL:http://computerdog.com/Meta_MetaFAQ.html>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Mon, 22 Dec 1997 10:11:22 +0000
From: Chris Hill <Chris_Hill@mentorg.com>
Subject: Re: _SUBROUTINE_NAME_ variable?
Message-Id: <349E3CCA.DE88932A@mentorg.com>

This information can be gleened from the return values of the
caller function.

:) Chris.


Tim Maher wrote:
> 
> To facilitate the printing of error messages from user-defined subs, I'm
> wondering
> if there's a built-in variable that knows the name of its local
> subroutine.
> 
> Judging from camel, lama, panther, and FAQ, I guess the answer's no,
> unless
> somebody out there knows more about this!
> 
> --
> ====================================================================
> |  Tim Maher, Ph.D.             Tel/Fax: (206)781-UNIX             |
> |  Head UNIX Guru, CONSULTIX    Email: tim@consultix.wa.com        |
> |  *The UNIX Training Experts*  http://www.consultix.wa.com/yumpy/ |
> ====================================================================


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

Date: 22 Dec 1997 10:31:05 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Calling FTP from a Perl script being run by inetd
Message-Id: <67lfh9$46r$1@lyra.csx.cam.ac.uk>

Derek Balling  <dballing@speedchoice.com> wrote:
>
>Background
>----------
>inetd calls in.fingerd
>in.fingerd calls client.pl
>client.pl calls /bin/ftp
>
>The problem lies in this piece of code:
>
># netrc = "~/.netrc"
>$FTP_COMMAND = "/bin/ftp"; $TEST_FTP_HOST = "my.hostname.com";
>open FTP, "$FTP_COMMAND $TEST_FTP_HOST |" || (die "Cannot execute
>command! : $!\n");
>while (<FTP>)
>{
>  $line = $_;
>  look_for_strings_in_output;
>}
>close FTP;
>
>If I call client.pl by itself I get the results I would expect. If I let
>in.fingerd call the client.pl script, then the while loop is never
>executed. The script doesn't 'die', but FTP appears to NOT return
>anything. FTP *DOES* appear to execute, although I haven't tested it for
>certain by actually trying to do something that'll leave a trace (like
>moving a file). 

This entry in perlfaq8 is probably relevant:

     Why doesn't open() return an error when a pipe open fails?


Mike Guy


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

Date: Mon, 22 Dec 1997 08:26:38 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Compilation error with Format
Message-Id: <ebohlmanELL0sE.L40@netcom.com>

Randy <randx@imagin.net> wrote:
: Thanks Tom, you were right on the money.

: I just logged back in to answer my own question, and you were 
: right. I did not have an end of line after the peiod, at the end 
: of the fille. Adding a return after the period fixed my problem.

: Lesson one. Remember that last CR at the end of the file, for 
: format statements and data, especially.

Corrolary to lesson one: because human-generated text files often leave 
out the newline on the last line, even though they're supposed to have 
it, make sure that any programs you write can deal with this when reading 
text files.  In particular, chop() is not reliable when used on lines 
from human-generated text files.  Use chomp() instead.



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

Date: Mon, 22 Dec 1997 03:03:25 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: does ne1 know...
Message-Id: <comdog-ya02408000R2212970303250001@news.panix.com>
Keywords: from just another new york perl hacker

In article <t65i76.nd3.ln@localhost>, tadmc@metronet.com (Tad McClellan) wrote:

>MrPc (tjbiuso@redrose.net) wrote:
>: where can i get source code for a keyword search engine?
>
>
>If you can come up with good keywords, you could enter those
>keywords into a search engine and likely find a keyword search engine.

i've only had a glimpse of such problems, and i swish there were wais
to do this... :)

-- 
brian d foy                                  <comdog@computerdog.com>
Meta Meta FAQ <URL:http://computerdog.com/Meta_MetaFAQ.html>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Mon, 22 Dec 1997 08:10:57 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: does ne1 know...
Message-Id: <ebohlmanELL029.K8M@netcom.com>

brian d foy <comdog@computerdog.com> wrote:
: In article <t65i76.nd3.ln@localhost>, tadmc@metronet.com (Tad McClellan) wrote:

: >MrPc (tjbiuso@redrose.net) wrote:
: >: where can i get source code for a keyword search engine?
: >
: >
: >If you can come up with good keywords, you could enter those
: >keywords into a search engine and likely find a keyword search engine.

: i've only had a glimpse of such problems, and i swish there were wais
: to do this... :)

Gopher it!



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

Date: 22 Dec 1997 09:52:14 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Extensible File Handle Objects
Message-Id: <67ld8e$35m$1@lyra.csx.cam.ac.uk>

RHS Linux User  <gale@int-gw.livelink.com> wrote:
>
>Why not let <$fh> call the getline or getlines method whenever $fh is
>any kind of blessed reference?  There are many obvious benefits.  If
>anyone else has tried to deal with IO handle base classes while at the
>same time trying to standardize how object variables are stored, they
>will know what I mean.  (I have some modules that are a good general
>workaround for this problem, if anyone is interested.)
>
>Is this hard to implement?  Is it / was it already done?

See the section "Tying FileHandles" in the perltie man page.


Mike Guy


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

Date: 22 Dec 1997 12:28:37 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: failed exec()
Message-Id: <67lmdl$7c7$1@lyra.csx.cam.ac.uk>

Justin Vallon <vallon@mindspring.com> wrote:
>M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
>> David Minsterman  <daminste@mailbox.syr.edu> wrote:
>> >What I am using is this:    exec "java $programname"
>> 
>> That is dangerous, if the $programname is somehow user supplied.
>> Consider what happens if the $programname were '; rm -rf /'
>> (or corresponding for non-unix systems).   Use the multi-argument form
>> of exec instead.   It's also more efficient.
>> 
>>        exec 'java', $programname or die "exec failed: $!"
>> 
>
>If exec "string" calls exec, that is not an issue, since you would
>require the shell to run multiple commands.  Remember, exec loads the
>program 'java', and gives it arguments (":", "rm", "-rf", "/"), which
>java would probably barf on.

But exec won't do that.   Since there's a shell metacharacter ";" present,
it'll call sh.    Hence my point about using the other form.
 
>I would worry about system("blah blah $user_arg").

The rule for whether or not to use the shell is exactly the same for
system as for exec.   You should worry equally about both cases.


Mike Guy


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

Date: Mon, 22 Dec 1997 09:06:52 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: HELP!  Bitwise XOR (^) doesn't work on strings?
Message-Id: <34a228cd.3500370@news.tornado.be>

>On Sat, 20 Dec 1997, Bart Lateur wrote, concerning bitwise string and
>numeric operations:
>
>> This doesn't make sense. We've always been told that "a scalar is a
>> scalar". 
>
>Then whoever told you that was lying to you. :-)  That's not necessarily a
>sin: I do that in my classes, but I tell everybody in advance that I'll
>lie a little in unimportant ways. 

>> From a programmer's viewpoint (as opposed an implementor's
>> viewpoint) we cannot distinguish between a string and a number. 
>
>Not so. You may not know what's in a particular scalar variable, but you
>can always force an expression to be seen as an integer or as a string.
>
>	0+$foo			# gotta be an integer
>	"$foo"			# sure, it's a string
>
>If there's any doubt at all, you should use one of these methods to force
>Perl to see things your way. 

Rubbish. I don't mean to say that what you say isn't correct, I'm saying
that the rule stinks.

Rules should be simple, and apply to everything there's supposed to
apply to.

Remember the '"0" is false' controversy? The PODs contain (or used to
contain) the phrase "A scalar is interpreted as TRUE if it is not the
null string or 0. There are actually two varieties of null string:
defined and undefined.".

Now, much to my suprise, { chop("12A0") } and { chr(48) } both are
considered to be FALSE, although they're neither the null string nor 0.

When I asked about this (in CLPM), Randal Schwartz replied that "You can
not distinguish between strings and numbers. Perl does, for efficiency
reasons, keep both a numeric and string interpretation internally, and
will only do the concversion from one to the other if needed. Therefore,
"0" is the same a 0. Thus "0" is FALSE." (something like this, anyway).
(The docs have changed since then, and Perl's warnings have been
extended, to warn about "0" as false.)

So now you're telling me that there are operators that do make this
distinction. This is very, VERY poor design. Either Perl should:

	- treat "0" as a string as not FALSE (FALSE is 0 if numeric and
'' if string, or if undefined)

or
	- make all operators and functions behave the same way with
regard to scalars of any type. I know of a 'scalar' context, or an
'array context'. A 'string context' or a 'numeric context' isn't part of
the Perl vocabulary.


I'm not saying that bitmanipulation dealing with strings isn't useful.
This concept may be extended to arithmetic with numbers of any bit
length (COBOL!). But I am saying that for this functionality you really
should have a different operator name.

	Bart.


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

Date: 22 Dec 1997 09:09:07 GMT
From: "Mr. Guy Smiley" <smiley@seds.lpl.arizona.edu>
Subject: help! package export variables
Message-Id: <67lanj$kva$1@news.ccit.arizona.edu>

I find it surprising that nowhere in the Programming Perl book, nor
anywhere in the online perldocs (perlmod, perlobj) does it explain how to
import an exported variable. This should be very simple. Consider this
example of the type of code I'm trying to do:


-------MyPackage.pm-----
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(@list);

@list = (A, B, C);


------Test.pl------
use MyPackage;

print $MyPackage::{list};
print *MyPackage::list;
# etc, etc. Nothing works! 

I just want to get a damn variable!!! WTF!

-- 
Mr. Guy Smiley   
--
e-mail:  ( smiley at seds dot org )     
website: ( double u double u double u dot seds dot org slash tilde smiley )
phone:   ( five two zero three two one one nine six four )


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

Date: Mon, 22 Dec 1997 05:18:54 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: help! package export variables
Message-Id: <comdog-ya02408000R2212970518540001@news.panix.com>
Keywords: from just another new york perl hacker

In article <67lanj$kva$1@news.ccit.arizona.edu>, "Mr. Guy Smiley" <smiley@seds.lpl.arizona.edu> wrote:

>I find it surprising that nowhere in the Programming Perl book, nor
>anywhere in the online perldocs (perlmod, perlobj) does it explain how to
>import an exported variable. This should be very simple. 

while looking for "Export" in the Programming Perl index i found
an entry for "Exporter".  on those pages such things are explained
and discussed.

you could also try

   perldoc Exporter

to see what that has to say.

if you are building modules, you might want to take a look at the 
h2xs manual page as well.


>-------MyPackage.pm-----
>require Exporter;
>@ISA = qw(Exporter);
>@EXPORT_OK = qw(@list);

aren't you missing the 
   
   package MyPackage;

in there?


>------Test.pl------
>use MyPackage;
>
>print $MyPackage::{list};
>print *MyPackage::list;
># etc, etc. Nothing works! 
>
>I just want to get a damn variable!!! WTF!

well, you have @EXPORT_OK defiend in the package, but those thingys
aren't imported unless you ask for them specifically, which you did
not.

they could be exported by default if you had used @EXPORT.

you also need to call an array an array:

   foreach( @MyPackage::list ) {print "$_\n"}

and so forth, like so:

   #!/usr/bin/perl
   
   package Foo;
   
   @list = qw(just another new york perl hacker);
   
   package main;
   
   foreach (@Foo::list) { print "$_ " }
   
   __END__
   
   just another new york perl hacker


good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
Meta Meta FAQ <URL:http://computerdog.com/Meta_MetaFAQ.html>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Mon, 22 Dec 1997 06:11:05 -0600
From: lineberry@cyberdude.com
To: comdog@computerdog.com (brian d foy)
Subject: Re: Listing files on your server as scalar values.
Message-Id: <882791949.29294598@dejanews.com>

In article <comdog-ya02408000R0912971543420001@news.panix.com>,
  comdog@computerdog.com (brian d foy) wrote:
>
> In article <881656967.30439@dejanews.com>, jerryl@connecti.com wrote:
>
> >Hi,  I want to set each file I have on my remote server as a scalar
> >value. I wrote the following script that will list all the files in my
> >directory (unix system) but the information is in a file not a scalar
> >variable.
>
> [snip `ls -l` approach]
>
> you might want to consider use of the directory reading family of
> functions: opendir, readdir, and so on, along with the file test
> operators.
>
> see the perlfunc and perlop manual pages for more information.
>
> good luck :)

Thanks,  Using the "directory functions" would be a better way of doing
my task. Here's the problem I encounter when using "opendir". Everything
works fine when I use the DIRHANDLE "THISDIR" but if I try to go one
directory up ".." some of the directories are not listed as directories.
And if I try to use the -f for "ascii text" files; they do not get
listed. However, all the remaining files and directories are printed as
BLAH:.

My results for the ROOT DIRHANDLE will look something like:
[...]
Directory: .
Directory: ..
BLAH: .profile
BLAH: .cshrc
BLAH: .plan
BLAH: .project
BLAH: .tin
BLAH: perl
BLAH: html
BLAH: mail
[...]


#!/usr/bin/perl -w

open(OUTPUT, ">dirp") or die "What's wrong with dirp? = : $!";

opendir THISDIR, "." or die "Major Problem #1: $!"; @allfiles = readdir
THISDIR; foreach $file (@allfiles) {if (-d "$file") {print OUTPUT
"Directory: $file\n"} else {print OUTPUT "BLAH: $file\n"}} closedir
THISDIR;

opendir ROOT, ".." or die "Something's wrong! = : $!"; @rootdir = readdir
ROOT; foreach $file (@rootdir) {if (-d "$file") {print OUTPUT "Directory:
$file\n"} elsif (-f "$file") {print OUTPUT "File: $file\n"} else {print
OUTPUT "BLAH: $file\n"}} closedir ROOT; close OUTPUT;


To be honest, I haven't tried using the -f filetest with the DIRHANDLE
"THISDIR". THISDIR prints all the results I originally wanted. I suppose
I can copy the script into other directories and run it there. But, I
want to learn how to do this right. So why doesn't the "ROOT" DIRHANDLE
work correctly?

Any suggestions?
-Jerry (Perl Rookie)

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


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

Date: Mon, 22 Dec 1997 12:49:30 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Listing files on your server as scalar values.
Message-Id: <ebohlmanELLCyI.85L@netcom.com>

lineberry@cyberdude.com wrote:
: Thanks,  Using the "directory functions" would be a better way of doing
: my task. Here's the problem I encounter when using "opendir". Everything
: works fine when I use the DIRHANDLE "THISDIR" but if I try to go one
: directory up ".." some of the directories are not listed as directories.
: And if I try to use the -f for "ascii text" files; they do not get
: listed. However, all the remaining files and directories are printed as
: BLAH:.

[snip]

[offending section of code reformatted for readability]

: opendir ROOT, ".." or die "Something's wrong! = : $!";
: @rootdir = readdir ROOT;
: foreach $file (@rootdir)

Let's pretend the first actual directory in your root is called /mydir, 
and that your foreach loop has come to it.

:  {if (-d "$file") 

$file will hold "mydir" (*not* "/mydir").  The -d operator will check to 
see if "mydir" is a subdirectory of *your working directory*, not of the 
root directory.  The test will fail unless you do have such a 
subdirectory in your working directory.

The lesson you need to learn is that readdir() returns *filenames*, *not* 
pathnames.  If you need to do something with a filename that came from 
readdir(), you need to prefix it with the appropriate path.

:    {print OUTPUT "Directory: $file\n"}
:   elsif (-f "$file") {print OUTPUT "File: $file\n"}
:   else {print OUTPUT "BLAH: $file\n"}
:  }
: closedir ROOT;
: close OUTPUT;


: To be honest, I haven't tried using the -f filetest with the DIRHANDLE
: "THISDIR". THISDIR prints all the results I originally wanted. I suppose

If you had tried it, it would have worked, because it would be testing 
files whose filenames were acceptable pathnames.



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

Date: Mon, 22 Dec 1997 01:58:38 -0800
From: antony quintal <antony@fabric8.com>
Subject: Mail::Send
Message-Id: <349E39CE.A9E9490A@fabric8.com>

hello.

i'm trying to use Mail::Send;


 ...but i notice there isn't a 'from' method. can i get a hint on how to
set it? 

i'm not doing anything too evil, i'd just like to use my virtual
hostname (unless, of course, vanity is evil).

bye.
antony

-- 
   8888
 888  888   
888    888  :::::::::::::::::::::::
 888  888   http://www.fabric8.com
   8888     san francisco
 888  888   415.487.9702
888    888  :::::::::::::::::::::::
 888  888   
   8888


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

Date: Mon, 22 Dec 1997 11:32:52 +0100
From: Jan Peyer <jan.peyer@be.softlab.ch>
Subject: ORAPerl
Message-Id: <349E41D4.772BD3C4@be.softlab.ch>

Hi Everyone

Does someone can tell me where i can find somethings about ORAPerl for
Perl V. 5.004

Thanks
Jan



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

Date: 22 Dec 1997 12:02:45 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Poor Man's FLOCK
Message-Id: <67lkt5$6mi$1@lyra.csx.cam.ac.uk>

In article <349ADAEA.5C74183F@aol.com>, Vik Rubenfeld  <VikR@aol.com> wrote:
>How about this approach, for times when FLOCK is unavailable:
>
> - the process checks for the existence of a lock file. If it
>   finds it it waits for it to go away. (After 20 seconds if
>   the lockfile is still there it deletes the lockfile and
>   proceeds.)
>   
> - the process creates a lock file, and writes to it an ID
>   number chosen randomly
>   
> - the process pauses 2 seconds, then reads the lock file
>   back in to see if it has the same ID put there
>   
> - if it is not the correct lock file, or if there is no lockfile, 
>   it restarts from the top
>   
>Here's how this should work:
>
>- process #1 checks for a lockfile, doesn't see it
>- process #2 checks for a lockfile, doesn't see it
>- process #1 writes out a lockfile, commences waiting 2 seconds
>- process #2 writes out a lockfile, commences waiting 2 seconds
>- process #1 finishes waiting 2 seconds, reads in the lockfile, realizes the
>lockfile belongs to somebody else, and restarts from the top.

But here's how it might work:
 - process #1 checks for a lockfile, doesn't see it
 - process #2 checks for a lockfile, doesn't see it
 - process #1 writes out a lockfile, commences waiting 2 seconds
 - process #1 finishes waiting 2 seconds, reads in the lockfile, decides
   that it has control and proceeds
 - process #2 writes out a lockfile, commences waiting 2 seconds
 - process #2 finishes waiting 2 seconds, reads in the lockfile, decides
   that it has control and proceeds

You can't afford to make any assumptions about the rate at which different
processes run.   The operating system can schedule them (and all the
other competing processes belonging to others) in an arbitrary order,
and can delay processes at whim.

Attempts at locking like this simply _don't work_.   Don't waste your
time on it.


Mike Guy


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

Date: 22 Dec 1997 10:54:01 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Removing Files older than 14 days
Message-Id: <67lgs9$4qu$1@lyra.csx.cam.ac.uk>

In article <348ef05f.1009849@news.wwa.com>, Faust Gertz <faust@wwa.com> wrote:
>Here is some untested code:

So I see.      :-)

>1>for (<*.ABC>) { 
>2>   undef $1;

That isn't doing what you think it does.   $1 is read-only, so you can't
unset it like that.   That statement is a no-op.   This is probably
a bug in Perl  -  it ought to fail on attempting to write to a read-only
variable, in the same way as

      $1 = undef;

does.

In your code, you'll need to use

      local $1;

instead.


Mike Guy


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

Date: 22 Dec 1997 10:47:41 +0100
From: melchi@kalium.HL.Siemens.DE (Melchisedech Bernd)
Subject: Socket communication between Perl and C
Message-Id: <67lcvt$1um@kalium.HL.Siemens.DE>


Hi everybody,

here's a probably silly IPC newbie question.

I want to establish a Client/server communication link via
Unix sockets. My hardware is a sparc 20 under SOLARIS 2.5.

The server is a C program while the client is written in perl.

The intended functionality is that the server reads strings
from stdin and sends them via the socket mechanism to the client
which simply prints to stdout the received strings.

The sequence is the following:

- Start the server
- In debugger, it ca be seen that the server 'waits' in the line
  where the 'accept' call is located
- After starting the client perl script, the server proceeds and asks for the
  string data.
- Strings are interactively entered. I checked the return value of the write
  statement. It was ok.(showing the actual length of the written string)
- Nothing happens in the client which semms to be waiting for lines to
  come in from <SOCK>. 
- If the server process is terminated by typing 'end', the client correctly terminates.

I read the perlipc man page and copied the client perl code from there.

The two sources are found below. 

Any help is welcome. In case the code is too weird or totally misleaded,
maybe somebody experienced in this topic could provide 
a short example of a sucessful Perl/C communication via
sockets.

Thanks in advance.


----- File sock1_client.pe -------------------------------

#!/usr/local/bin/perl5 -w

    use Socket;
    use strict;
    my $sockname = '/tmp/catsock';
    my $uaddr;
    my $line;

    
    $uaddr = sockaddr_un($sockname);

    socket(SOCK, PF_UNIX, SOCK_STREAM, 0)           || die "socket: $!";
    connect(SOCK, $uaddr)                           || die "connect: $!";

    

    while ($line = <SOCK>) {
        printf(STDOUT "%s\n",  $line);
    }
    exit;

----- Compile-command for sock1_server.c -----------------

cc -g sock1_server.c -lsocket

----- File sock1_server.c --------------------------------

#include <sys/types.h>
#include <sys/stream.h>   /* definition of queue_t, requd. in socknmod.h */
#include <tiuser.h>          /* definition of struct t_info */
#include <stropts.h>       /* struct strbuf */
#include <sys/sockmod.h>  /* includes socket.h */
#include <assert.h>

void main(int argc, char *argv[])
{
  int                 write_sock;
  struct sockaddr_un  socket_addr;
  int                 connect_ret_value = -1;
  int                 bind_ret_value = -1;
  int                 listen_ret_value = -1;
  int                 accept_ret_value = -1;
  int                 write_ret_value = -1;
  int                 i = 0;
  char                *socket_name = "/tmp/catsock";
  char                string[100];


  unlink(socket_name);

  write_sock = socket(AF_UNIX, SOCK_STREAM, 0);

  assert(write_sock != -1);

  socket_addr.sun_family = AF_UNIX;
  strcpy(socket_addr.sun_path, "/tmp/catsock");

  bind_ret_value = bind(write_sock, (struct sockaddr *) &socket_addr, sizeof (struct sockaddr_un));
 
  assert(bind_ret_value != -1);

  listen_ret_value = listen(write_sock, 1);

  assert(listen_ret_value != -1);

  printf("Server now started\n");

  /* probably wait loop needed as in debugger_init.c */
  /* works fine without */
  accept_ret_value = accept(write_sock, (struct sockaddr *) 0, (int *) 0);

  assert(accept_ret_value != -1);

  while (strcmp(string, "end") != 0)
    {
      printf("Please enter a string or 'end' to terminate>\n");
      scanf("%s",
            string);
      write_ret_value = write(write_sock, string, strlen(string));
    }
    
  close(write_sock);
    
}







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

Date: Mon, 22 Dec 1997 11:50:38 +0000
From: Eric Armour <eaarmour@cableinet.co.uk>
Subject: Stand-Alone Computer
Message-Id: <349E540E.1173@cableinet.co.uk>

All,

1. I am running Windows NT version 4.0, which is not connected to a
network. I want to run Perl scripts on the machine purely for my own
personal use and education. As I am a beginner I have no ideas how I can
achieve this.

2. I have been told that I need MS personal web server. Is this really
necessary? Is it available free?


Regards

Eric


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

Date: Mon, 22 Dec 1997 12:36:58 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Stand-Alone Computer
Message-Id: <ebohlmanELLCDM.7o0@netcom.com>

Eric Armour <eaarmour@cableinet.co.uk> wrote:
: All,

: 1. I am running Windows NT version 4.0, which is not connected to a
: network. I want to run Perl scripts on the machine purely for my own
: personal use and education. As I am a beginner I have no ideas how I can
: achieve this.

Easy.  You get one of the two Win32 ports of perl: either the ActiveState 
port or the "standard" port done by Gurusamy Sarathy.  I'd suggest the 
latter, but both ports have their good points.  Go over to www.perl.com 
where you should find the Sarathy port and a link to the ActiveState port.

: 2. I have been told that I need MS personal web server. Is this really
: necessary? Is it available free?

That depends on what you're going to do with Perl.  If you're going to be 
writing CGI scripts called from HTML pages, then you'll need some sort of 
Web server, and the MS product (which is free) will work, though it's not 
the only one you could use.  On the other hand, if the scripts you want 
to write aren't Web-related (and most Perl scripts aren't), you don't 
need any kind of Web software.


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

Date: 22 Dec 1997 08:59:32 +0000
From: Richard Caley <rjc@liddell.cstr.ed.ac.uk>
Subject: Re: Teaching programing
Message-Id: <eyhk9cxda8b.fsf@liddell.cstr.ed.ac.uk>

In article <47f9a72a44rhodri@wildebst.demon.co.uk>, Rhodri James (rj) writes:

rj> I'd still recommend starting with something like Pascal, however.  The
rj> rigid typing makes sure that when you are free and easy with another
rj> language, you at least know that you are breaking rules.

I always thought Pascal was a dreadful teaching language. It
encourages people to think that `program' is synonymous with `huge
text file it will take you a month to read'. No modularity. Also it
was always clear from lesson one that it was a toy language.

As of today, there seems to be an obvious choice. Java. Whatever you
think of it for real work, it has reasonable hygene (i.e. it makes it
natural to write reasonable code), it's fairly widespread and freely
available. Most importantly for a teaching tool, it's obvious from the
start that it can be used for both things the learners can enjoy
(silly applets) and has a likelyhood of future usefullness. There is
even the occasional job advert for Java programmers. 

The only real problem with it is that it's perhaps too solidly object
oriented -- not a good preparation for the real world where most
people are still dealing with non-OO languages and code. But for an
introductory course that probably doesn't matter.

-- 
rjc@cstr.ed.ac.uk			_O_
					 |<



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

Date: Mon, 22 Dec 1997 00:15:00 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: text wrap
Message-Id: <mbudash-2212970015010001@d222.pm6.sonic.net>

In article <672j27$gu2@bgtnsc01.worldnet.att.net>, comdog@computerdog.com
(brian d foy) wrote:

>> In article <mbudash-1412971602190001@d108.pm3.sonic.net>,
>> mbudash@sonic.net (Michael Budash) wrote:
>> 
>> > In article <344ae17f.262941158@news.west.net>, name@server.com (Mike
>> > Rambour) wrote:
>> > >> p.s. What I am trying to do is take text from a textarea and save it
>> > >> to a file but I need the output in 70 chars and it comes out as one
>> > >> big line.  From my searching of the web, what I think I need is
>> > >> text:::wrap.
>> 
>> Text::Wrap could do what you want.  you can get it at CPAN. [1]
>>  
>> > I've had good luck with this in the html, not some perl trick:
>> > 
>> > <textarea name="body" rows=10 cols=70 wrap="hard">
>> 
>> it only takes one client to mess up your data file.  never rely on the 
>> client to do anything. :)

what does that last comment mean?

-- 
Michael Budash, Owner * Michael Budash Consulting
mbudash@sonic.net * http://www.sonic.net/~mbudash
707-255-5371 * 707-258-7800 x7736


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

Date: Mon, 22 Dec 1997 04:01:15 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: text wrap
Message-Id: <comdog-ya02408000R2212970401150001@news.panix.com>
Keywords: from just another new york perl hacker

In article <mbudash-2212970015010001@d222.pm6.sonic.net>, mbudash@sonic.net (Michael Budash) wrote:

>In article <672j27$gu2@bgtnsc01.worldnet.att.net>, comdog@computerdog.com
>(brian d foy) wrote:

>> it only takes one client to mess up your data file.  never rely on the 
>> client to do anything. :)

>what does that last comment mean?

which part of it confuses you?  i don't see the ambiguity in either the
statement or the imperative.

-- 
brian d foy                                  <comdog@computerdog.com>
Meta Meta FAQ <URL:http://computerdog.com/Meta_MetaFAQ.html>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Mon, 22 Dec 1997 00:55:14 -0700
From: "Ashley M. Kirchner" <ashley@yeehaw.com>
Subject: Tricky Frames Problem
Message-Id: <349E1CE2.951BC075@yeehaw.com>

Case:

A couple of main frame windows as follows:

+-----------------------------------------------------+
|          |         B                   |            |
|          |          I                  |            |
|          |           G                 |            |
|S         |                             |            |
| M        |             I               |  C         |
|  A       |              C              |   A        |
|   L      |               O             |    P       |
|    L     |                N            |     T      |
|          +-----------------------------|      I     |
|     I    |  C O N T R O L  P A N E L   |       O    |
|      C   +-----------------------------+        N   |
|       O  |  S E A R C H   W I N D O W  |            |
|        N |     C G I   E N G I N E     |            |
+-----------------------------------------------------+

A SQL database in the back.

My problem:  From the search window, one will enter a parameter which
will then call a CGI script (which communicates with the SQL db) to get
the results based on the parameter entered.

I need to figure out a way to make the results from the search engine
(CGI script) to get displayed in the appropiate windows.

Let's say our search returned 9 items.  Each item returned is really a
combination of fields: icon.title, icon.location, icon.owner and
icon.caption.  Out of those, I'll start off by grabbing all the
icon.locations and generating a 'small-icon' html file which will be
displayed in the SMALL ICON window as thumbnails.

Then, I need to grab the amount of items returned (in this case 9) and
generate a 'control' page, which is really a javascript page that will
function as a slide show through buttons (play, stop).

As for the rest of the fields (icon.title, icon.owner and icon.caption),
those I can deal with afterwards.

My main problem right now is: How do I tell the CGI script to update
BOTH the 'SMALL ICON' window (by rewriting what's in there and
refreshing the frame) as well as the 'CONTROL PANEL' and refreshing that
frame as well.

Ideas anyone?

A



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

Date: Mon, 22 Dec 1997 04:04:14 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Tricky Frames Problem
Message-Id: <comdog-ya02408000R2212970404140001@news.panix.com>
Keywords: from just another new york perl hacker

In article <349E1CE2.951BC075@yeehaw.com>, ashley@photocraftlab.com wrote:

>A couple of main frame windows as follows:

no perl in that


>I need to figure out a way to make the results from the search engine
>(CGI script) to get displayed in the appropiate windows.

still nothing perl specific.

>My main problem right now is: How do I tell the CGI script to update
>BOTH the 'SMALL ICON' window (by rewriting what's in there and
>refreshing the frame) as well as the 'CONTROL PANEL' and refreshing that
>frame as well.

and still nothing perl specific.

sounds like you haven't read the CGI FAQ or the Frames documentation,
both of which are referenced in the CGI Meta FAQ.  if you still have
problems after RTFMing, you might want to post a newsgroup which 
discusses such matters.

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
Meta Meta FAQ <URL:http://computerdog.com/Meta_MetaFAQ.html>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 22 Dec 1997 07:59:16 GMT
From: watzka@stat.uni-muenchen.de (Kurt Watzka)
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <67l6kk$m7k$1@sparcserver.lrz-muenchen.de>

fred@genesis.demon.co.uk (Lawrence Kirby) writes:

>In article <67iipp$ktj$1@darla.visi.com>
>           seebs@plethora.net "Peter Seebach" writes:

>>In article <ObfZp4YD9GA.296@upnetnews02.moswest.msn.net>,
>>William J. Leary Jr. <Bill_Leary@msn.com> wrote:
>>>Not that I've ever noticed.  I frequently use C compilers to target embedded
>>>systems.
>>
>>Then you're using "freestanding environments", which are a separate language.
>>The library is, indeed, part of the hosted environment form of C.

>Aren't the standard library identifiers with external linkage reserved
>even in a freestandinhg environment?

How about "In a freestanding environment the name and type of the function
called at program startup are implementation-defined. There are otherwise
no reserved external identifiers". I read that as excluding the reservation
of external identifiers defined in the library clause in a freestanding 
environment. What am I missing?

Kurt

-- 
| Kurt Watzka                             Phone : +49-89-2178-2781
| watzka@stat.uni-muenchen.de


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

Date: Mon, 22 Dec 1997 13:14:02 +0100
From: Samuel Costa Bendicho <sc1334@speedy.udg.es>
Subject: WWW database
Message-Id: <349E598A.597A5F4D@speedy.udg.es>

Hi there!

I have to design a web with a little database accessible through CGI

I had in mind using Perl. Do you know what kind of database should I
use?
I'd like to know if there exist some kind of perl libraries to work with
some standard type of database.

Thank you in advance

Please, reply to Centollo@thevortex.com, too

        Sam



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

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

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