[6257] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 879 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 1 13:07:12 1997

Date: Sat, 1 Feb 97 10:00:20 -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           Sat, 1 Feb 1997     Volume: 7 Number: 879

Today's topics:
     Re: -f $file == $x gives warning under -w <rootbeer@teleport.com>
     Re: Bug? Passing Empty Array To Subroutine <rootbeer@teleport.com>
     Re: Can anyone help? (Tad McClellan)
     Re: flock() Function Question <rootbeer@teleport.com>
     Re: HELP! Difficult regexp matter! <rootbeer@teleport.com>
     Re: Locking files and/or databases <rootbeer@teleport.com>
     Malformed Header (KeFKa)
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: Sat, 1 Feb 1997 08:59:36 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Steven W McDougall <swmcd@world.std.com>
Subject: Re: -f $file == $x gives warning under -w
Message-Id: <Pine.GSO.3.95.970201085824.19573O-100000@linda.teleport.com>

On Fri, 31 Jan 1997, Steven W McDougall wrote:

> maui:~>perl -we '-e "x"==0 and print "OK\n"'
> Use of uninitialized value at -e line 1.
> OK
> 
> I want to make this warning go away.

perl -we 'unless (-e "x") { print "OK\n" }'

Does that do what you want? Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Sat, 1 Feb 1997 08:53:56 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Paul Baleme - PCD ~ <pbaleme@pcocd2.intel.com>
Subject: Re: Bug? Passing Empty Array To Subroutine
Message-Id: <Pine.GSO.3.95.970201083103.19573N-100000@linda.teleport.com>

On 1 Feb 1997, Paul Baleme - PCD ~ wrote:

> When passing the 0'th element of a non-existent array, perl5 seems
> to create an entry in the array.  

It's not a bug; parameters are lvalues. (Surprise! :-)

The elements of @_ within a sub are actually aliases to the actual
parameters. This allows you to write subs that modify their parameters in
place, like this.

    sub strip_whitespace {
        for (@_) {
            s/^\s+|\s+$//g;
        }
    }

Of course, you can't get away with that if your parameter is not a valid
lvalue; in that case, Perl makes the parameter read-only. 

This leads us to the solution. If you wish to pass the value if it exists
but not to create it if it doesn't, just make sure it's not a valid
lvalue. 

    &foo(0+$array[0]);	# if it's a number
    &foo("$array[0]");	# if it's a string

Alas, these cause complaints under -w that you're using an undefined value
(which you are). Such is the life of a programmer.

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Sat, 1 Feb 1997 10:15:02 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Can anyone help?
Message-Id: <66qvc5.r81.ln@localhost>

Glenn Johnson (ng19@dial.pipex.com) wrote:
: I am new to the perl programming environment, so I have a few questions..

: 1.  How is perl script activated?  Is it a compiled, or an interpreted 
: language?

It can be argued either way ;-)

Most consider it interpreted.

I think "a compile and go" language is more accurate.

It appears interpreted, since it appears to execute directly from
the source code.

In reality, it scans the _entire script_ (interpreters go line by line),
and does a form of compilation to execute from.


: 2.  What method is used to send data from a web browser to a perl script? 

This is a browser issue not a perl issue. Perl is a general purpose
programming language. It is used for such things as: WWW CGI (this is
what you are asking about), system administration, data reduction,
text processing, and myriad other uses.

Fortunately, there is another Usenet newsgroup specifically for
discussing CGI issues:  comp.infosystems.www.authoring.cgi

You should probably ask your question there. You are more likely to
find people who know about the vagaries of CGI programming in the
CGI newsgroup.


:   I can't seem to understand the data importing process (i.e. there is 
: obviously an input string.  Normally this would be filled by a file, 
: opened from a disk and redirected to the input string, but how does this 
: compare to opening a direct string created from a web browser.  Where is 
: the interfacing?)

: Thanks in advance for your time.  I'm sure these questions are relatively 
: stupid, 

Not stupid at all. Just not posted to the most appropriate newsgroup ;-)


: but your comments would be gratefully appreciated.


You might also (in addition to reposting to the CGI newsgroup above)
want to have a look at "The Idiot's Guide to Solving Perl CGI Problems":

http://www.perl.com/perl/faq/idiots-guide.html

Don't be put off by the demeaning title. It has information likely to
be of great help in figuring out how to do what it is you want to do.


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


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

Date: Sat, 1 Feb 1997 09:39:47 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Ralph Freshour <rfresh@mail.idt.net>
Subject: Re: flock() Function Question
Message-Id: <Pine.GSO.3.95.970201091946.19573R-100000@linda.teleport.com>

On Sat, 1 Feb 1997, Ralph Freshour wrote:

> In my perl code I'm not sure my flock() is working correctly.  

Here's a q&d test of flock.

    #!/usr/bin/perl

    # Test flock

    $how_many = 3;	# How many subprocesses to use at once
    $|=1;	# Flush as we go
    FORK:
	while (@kids<$how_many) {
	    unless (defined ($pid = fork)) {
		sleep 1;
		redo FORK;
	    }
	    unless ($pid) {
		# Child process here.
		$id = "Child #" . scalar @kids;
		open FILE, "+< $0" or die "$id: Can't open my own script!";
		print "($id) About to lock file...";
		flock FILE, 2;
		print "($id) flocked...";
		sleep 5;
		print "($id) done!\n";
		exit;
	    }
	    # Parent process here
	    push @kids, $pid;
	}
    # Now we wait for them
    for $kid (@kids) {
	last if -1 == waitpid($kid, 0);
    }
    exit;

On this system, here's what you see:

(Child #0) About to lock file...(Child #0) flocked...(Child #1) About to
lock file...(Child #2) About to lock file...(Child #0) done!
(Child #1) flocked...(Child #1) done!
(Child #2) flocked...(Child #2) done!

In other words, no process prints "flocked" until the previous one is
done. Does that happen on your system? Hope this helps! 

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Sat, 1 Feb 1997 09:12:56 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Oussik Oganessian <oganessi@informatik.hu-berlin.de>
Subject: Re: HELP! Difficult regexp matter!
Message-Id: <Pine.GSO.3.95.970201090753.19573Q-100000@linda.teleport.com>

On 31 Jan 1997, Oussik Oganessian wrote:

> I have faced a non-trivial problem, when trying to convert some files to
> LaTeX format.  There are a number of chars which must be replaced with
> expressions respectivelly.  E.g.: 
> $ -> \$
> \ -> $\backslash$
> and so on...
> 
> Previously I used to translate these with s/// sequentially, but the
> above example hampers that, since $ or \ on the right side of the first
> substitution will be replaced by the second substitution. 

To do a series of substitutions in parallel, you may need to split your
input data into chunks then look up each chunk in a translation table.
Alternatively, you could use intermediate values (but I _think_ this would
be slower).

   s/\$/<dollar sign>/g;
   s/\\/<backslash>/g
   s/<dollar sign>/\$/g;
   s/<backslash>/\\/g;

Of course, this could be done more efficiently with a hash table lookup.
Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Sat, 1 Feb 1997 08:18:45 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: iguana@one.net
Subject: Re: Locking files and/or databases
Message-Id: <Pine.GSO.3.95.970201081739.19573L-100000@linda.teleport.com>

On Fri, 31 Jan 1997 iguana@one.net wrote:

>      Can anybody give me a clue as to how to lock a file so that no one
> else (any other process) can access it 

I think you could use the methods in Randal's fourth Web Techniques
column, which explains how to use flock() to avoid problems when multiple
processes need to modify one file. Hope this helps! 

   http://www.stonehenge.com/merlyn/WebTechniques/

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Sat, 01 Feb 97 04:52:20 GMT
From: kefka@sound.net (KeFKa)
Subject: Malformed Header
Message-Id: <5culvv$snp@guitar.sound.net>

What is the malformed header mean, and what part of the script is the header?
please e-mail response


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

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

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 V7 Issue 879
*************************************

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