[8858] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2475 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 1 20:05:33 1998

Date: Fri, 1 May 98 17:00:29 -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           Fri, 1 May 1998     Volume: 8 Number: 2475

Today's topics:
    Re: 1701 days hath September (was: Re: rename funciton) (John Stanley)
    Re: \D fails when [^0-9] doesn't <rootbeer@teleport.com>
    Re: ANSI Colour in Perl <Rosie@dozyrosy.demon.co.uk>
    Re: Any Ideas on netgroup editing? <rootbeer@teleport.com>
    Re: Bizarre copy of HASH in debugger <jdf@pobox.com>
    Re: Bizarre copy of HASH in debugger <jflood@qsun.ho.att.com>
    Re: Defending Perl (Alan Barclay)
    Re: Defending Perl <Rosie@dozyrosy.demon.co.uk>
    Re: email attachments <zenin@archive.rhps.org>
    Re: HELP ON FILE LOCKING (John Armsby)
    Re: How to Schedule Program Execution <rootbeer@teleport.com>
    Re: Man...I really need to get 'The Camel Book' this we (Kevin Reid)
    Re: Man...I really need to get 'The Camel Book' this we <ahdiii@webspan.net>
    Re: Man...I really need to get 'The Camel Book' this we <ahdiii@webspan.net>
    Re: need help with hashtable size/memory <zenin@archive.rhps.org>
    Re: Perl for VMS <rootbeer@teleport.com>
    Re: Perl web server.... (Kevin Reid)
        Problem evaluating scalars <nikitins@infoservriga.lv>
    Re: Problem evaluating scalars <jdf@pobox.com>
        Randomly sorting an array (BurninUrGe)
    Re: Randomly sorting an array (John Porter)
    Re: Randomly sorting an array <rootbeer@teleport.com>
        Redirection <bdwornick@usa.net>
    Re: Splitting a variable ??? (Alan Barclay)
    Re: strictly speaking.. <rootbeer@teleport.com>
    Re: Test httpd server status <quentin@shaddam.amd.com>
    Re: Test httpd server status <joneil@cks.ssd.k12.wa.us>
        Warning Message Incorrectly Says File Handle Variable U (Greg Teets)
    Re: Warning Message Incorrectly Says File Handle Variab <rootbeer@teleport.com>
    Re: web_store.cgi error in the browser <rootbeer@teleport.com>
    Re: Win32 reading in passwords <igor.k@usa.net>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 1 May 1998 23:33:38 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: 1701 days hath September (was: Re: rename funciton)
Message-Id: <6idm4i$1j7$1@news.NERO.NET>

In article <6id50h$jbi$1@ns1.arlut.utexas.edu>,
Stuart McDow <smcdow@arlut.utexas.edu> wrote:
>stanley@skyking.OCE.ORST.EDU (John Stanley) writes:
>> A "group moderating itself" is the definition of "unmoderated
>> newsgroup". "A select few moderating the rest" is how a moderated
>> group works.
>
>I think it's a matter of accepting certian logistics and a paradigm
>with a certian goal in mind. 

Logistics and paradigms don't have anything to do with it. In an
unmoderated group, the group moderates itself. In a moderated group, a
few people moderate what everyone can read. That's how USENET works.
Goals have nothing to do with this.

>clp.misc isn't going away. If the idea of moderated newsgroups makes
>you bristly, 

I know it isn't going away, and I am at a loss to know where you get
this "bristly" nonsense. I pointed out that moderated groups were
certainly not "a group moderating itself", that's all. I didn't make any
statements about that being good or bad or if I liked that or didn't
like it. 

>I'm not intending to be
>incendiary here; I'm just trying to point out that it's a matter of
>individual priorities. 

No, it is a matter of understanding how USENET groups work. All this
touchy-feely stuff about people living in gated communitities and stuff
is very nice, but it doesn't change how a moderated newsgroup works.



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

Date: Fri, 01 May 1998 21:26:41 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Terrence Brannon <brannon@lnc.usc.edu>
Subject: Re: \D fails when [^0-9] doesn't
Message-Id: <Pine.GSO.3.96.980501142543.2859O-100000@user2.teleport.com>

On 1 May 1998, Terrence Brannon wrote:

> #$ignore_header_re="^[^0-9]+";  #           THIS DOES NOT!!!!!!
> $ignore_header_re="^\D+";       # <-------- THIS FAILS!!!!!!!!!

Have you tried examining those strings? I don't think that the second one
contains what you think it does. Hope this helps!

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



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

Date: Fri, 1 May 1998 22:31:25 +0100
From: Rosemary I H Powell <Rosie@dozyrosy.demon.co.uk>
Subject: Re: ANSI Colour in Perl
Message-Id: <oA1d4UAt8jS1EwIa@dozyrosy.demon.co.uk>

In article <893874119.982509@thrush.omix.com>, Zenin
<zenin@archive.rhps.org> writes
>Shawn <sweiner@usa.net> wrote:
>: There is at least 1 module in CPAN that I know of, located I believe
>: in the user interfaces area.
>: The name of the module is: ANSIColor-1_01.tar.gz
>
>       Term::ANSIColor actually.  If one scans for either 'ANSI' or
>       the correct spelling of "color" on the WAIT it should be at
>       the top of the list.
ICK!! You mean the AMERICAN spelling - the correct way in this country
is coloUr.

Rosemary

Just Another Micro$oft Idiot
-------------------------------------------------------------------
| Rosemary I.H.Powell  EMail: Home: rosemary@dozyrosy.demon.co.uk |     
|                             Work: r.i.h.powell@rl.ac.uk         |
|                       http://www.netlink.co.uk/users/dozyrosy/  |
|                       http://www.dozyrosy.demon.co.uk/          | 
-------------------------------------------------------------------


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

Date: Fri, 01 May 1998 21:41:29 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Charudatta Deodas <charudatta@hotmail.com>
Subject: Re: Any Ideas on netgroup editing?
Message-Id: <Pine.GSO.3.96.980501144047.2859Q-100000@user2.teleport.com>

On Fri, 1 May 1998, Charudatta Deodas wrote:

> Is there any way to know the string length of the string? 

Are you asking for the length function? (I'm not sure; your question was
buried so deeply in other text!) Hope this helps!

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



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

Date: 01 May 1998 17:14:47 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: jerryflood@att.com
Subject: Re: Bizarre copy of HASH in debugger
Message-Id: <n2d1r63s.fsf@mailhost.panix.com>

Jerry Flood <jflood@qsun.ho.att.com> writes:

> my %hash;
> $hash{key} = value;

That's a suspect use of a bareword, there.  Is that pseudo-code, or is
that really the code you're running?

> $hashref = \%hash;
> print "${%$hashref}{key}\n";

You mean either

   $hashref->{key}

or

   ${$hashref}{key}

You'll want to check out perlref, perllol, and perldsc.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY


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

Date: Fri, 01 May 1998 17:19:18 -0400
From: Jerry Flood <jflood@qsun.ho.att.com>
Subject: Re: Bizarre copy of HASH in debugger
Message-Id: <354A3C56.D8A9193E@qsun.ho.att.com>

Well I changed this:

print "${%$hashref}{key}\n";

to this:
print "$hashref->{key}\n";

and it appears to work in both cases. Are these equivelent ???

THanks
Jerry
jerryflood@att.com


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

Date: 1 May 1998 22:53:26 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: Defending Perl
Message-Id: <894063193.43237@elaine.drink.com>

In article <6i7u4i$gnd$1@mathserv.mps.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Mike Lacey
><lacey_michael_j/swby@swby.cgo.Cargill.Com>],
>who wrote in article <6i71ik$hrh@wind.cargill.com>:
>> Hmmm
>> 
>> Something tells me that Ilya works with, and has always worked with, fairly
>> modern, fairly standard, kit.
>
>No, it is Warp 3 with fixpak 17.  This is two or three years obsolete,
>the current level of Warp 3 is fixpak 36, and of Warp 4 is fixpak 6.

I'd consider that still pretty modern & standard. About 3 years ago
I was installing perl4 on a system that was basically a V7 Unix with
Wollogong networking hacked in. That is a system that would be state of
the art in about 1980 or so - about 15 years old.



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

Date: Fri, 1 May 1998 22:12:03 +0100
From: Rosemary I H Powell <Rosie@dozyrosy.demon.co.uk>
Subject: Re: Defending Perl
Message-Id: <$gGYAQAjqjS1EwJ$@dozyrosy.demon.co.uk>

In article <354801CB.57C95063@spider.herston.uq.edu.au>, Jaime Metcher
<metcher@spider.herston.uq.edu.au> writes
>Win32 - download binary distribution - type one command - agree to
>everything - toast Sarathy in fine Cabernet Sauvignon - back to work.
>Jaime Metcher (extremely un-guru-like, but productive nonetheless)

Well said! Even a win-dozy old woman like me managed this without any
problems. I would give him a gold medal too.

Rosemary
Just Another Micr$soft Idiot
-------------------------------------------------------------------
| Rosemary I.H.Powell  EMail: Home: rosemary@dozyrosy.demon.co.uk |     
|                             Work: r.i.h.powell@rl.ac.uk         |
|                       http://www.netlink.co.uk/users/dozyrosy/  |
|                       http://www.dozyrosy.demon.co.uk/          | 
-------------------------------------------------------------------


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

Date: 1 May 1998 23:23:21 GMT
From: Zenin <zenin@archive.rhps.org>
Subject: Re: email attachments
Message-Id: <894065454.29479@thrush.omix.com>

Brian Mathis <brianm@kodak.com> wrote:
: You really should be using Net::SMTP to send your messages.  It's much
: safer.

	You assume (danger!) that an SMTP server is available.	Some
	systems do not have incoming mail and therefor have no sendmail or
	other mail daemon running ever except to send out qued mail. 
	Calling sendmail on such systems is your only "safe" method.  -Yes,
	you could try to decode the address and talk SMTP directly to the
	remote machine but what if it's not available? Are you ready to
	start your own mail que system?

	SMTP is not portable.  Don't use it if you want to be portable.

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: Fri, 01 May 1998 23:51:22 GMT
From: jaws@atl.mindspring.com (John Armsby)
Subject: Re: HELP ON FILE LOCKING
Message-Id: <6idn8r$e2l$1@camel20.mindspring.com>




I have exactly the same question!  I am locking a file (see example
below) which locks the file for writing.  I think that I am having
problems with people reading the file while the web daemon is writing
to it.  the subsequent write of a bad read corrupts the file...  What
I want to do is to modify my little test script (below) in my
applicaiton to lock both read and write while the processess is
writing the file. this little script works great to prevent anyone
writing the file while it is being written....  In unix you can open
two windows and run the same script and only one window can write
tothe file at the time.  Unfortunately that is not enough as I have
sadly found out.  I need the read lock too.

help!

John Armsby@mindspring.com

#!usr/local/bin/perl


use Fcntl;
open(MYFILE,">>testfile.txt") or die "can't open textfile.txt";
my($arg)=pack("s s 11 i",&F_WRLCK,0,0,0,$$);
fcntl(MYFILE,&F_SETLK,$arg) or die" can't lock\n";


for($i=0;$i<1000000;$i++)
	{

	print MYFILE ("$i\n");
	}
print MYFILE ("END of write\n");
close;




Tom Phoenix <rootbeer@teleport.com> wrote:

>On 1 May 1998, DAVID CHEW wrote:

>> Subject: HELP ON FILE LOCKING

>Please check out this helpful information on choosing good subject
>lines. It will be a big help to you in making it more likely that your
>requests will be answered.

>    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

>> If A is writing on a fileX, and locks the fileX and someone else B
>> starts reading the fileX, Would B be able to read fileX correctly if
>> fileX is locked for writing by A. 

>What do you mean by "correctly"? If another process is writing to the
>file, it can be tricky to ensure that your process reads the data
>correctly. 

>> Should B test for locking before reading fileX

>Almost certainly, B should obtain a lock on the file before reading.

>Of course, this applies whether your code is written in Perl or in any
>other language. If you have more questions about file locking which
>aren't answered in your system's documentation, you should ask in a
>newsgroup about your system. Hope this helps!

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





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

Date: Fri, 01 May 1998 21:24:57 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Rick Alber <ralber@ix.netcom.com>
Subject: Re: How to Schedule Program Execution
Message-Id: <Pine.GSO.3.96.980501142102.2859N-100000@user2.teleport.com>

On Fri, 1 May 1998, Rick Alber wrote:

> The script is triggered by a crontab program running on my ISP's Apache
> server. Unfortunately, I soon won't be able to use a crontab program and
> would like to figure out a way to trigger the program each night using
> PERL

Why can't you still use cron? Your system administrator may have a valid
reason for not wanting you to run programs at odd times, in which case you
should probably not try to evade that restriction. Or, your system
administrator may have a foolish reason, in which case you should probably
find a new system administrator! :-)  But any other method (such as making
your own program which does cron's job) will be more load on your system,
and your system administrator can't want that, right? 

In sum, the only real solution is to find a system administrator who lets
you run cron, or the equivalent. Hope this helps!

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



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

Date: Fri, 1 May 1998 18:02:08 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Man...I really need to get 'The Camel Book' this weekend.
Message-Id: <1d8czo5.1ubexj1e4et9qN@slip-32-100-246-5.ny.us.ibm.net>

Arthur Dardia <ahdiii@webspan.net> wrote:

> Here is my code:
> 
<snip>
> 
> okay...this is the first version of my first program.  It's supposed to
> output the first 3 numbers in the 2nd multiplication table (2,4,6).
> But, it just prints out:
> 
> C:\Program Files\Perl\eg>perl hank
> Multiplcation Tables in Perl.
>      1      2      3
> 2   0      0      0
> 
> C:\Program Files\Perl\eg>
> 
> How do I make it print out numbers instead of 0?  Am I defining the
> variables wrong?

While other people have pointed out the individual problems, I will give
you a fixed version of your code:

print "Multiplication Tables in Perl.\n"; # ()s unnecessary

$m1 = 2;

$ma = $m1*1;
$mb = $m1*2;
$mc = $m1*3;

print("     1      2      3\n");
print("$m1    $ma      $mb      $mc\n");


And you can use printf to make the print statements neater:

printf "%5s %5d %5d %5d\n", "", 1, 2, 3;
printf "%5d %5d %5d %5d\n", $m1, $ma, $mb, $mc;


Here is a complete multiplication table program:

#!perl -w

$amax = 20; # number of rows
$bmax = 3; # number of columns

$format = '%5d ' x $bmax . "\n"; # construct printf format

@bs = 1 .. $bmax; # make array consisting of numbers 1 through $bmax

for ($a = 1; $a <= $amax; $a++) {    # for loop from 1 to $amax
  printf $format, map {$a * $_} @bs; # print line
}

# The map operator multiplies each element of @bs by $a and returns
# the results, which are then formatted and printed.

__END__

-- 
  Kevin Reid.      |         Macintosh.
   "I'm me."       |      Think different.


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

Date: Fri, 01 May 1998 19:14:25 -0400
From: Arthur Dardia <ahdiii@webspan.net>
Subject: Re: Man...I really need to get 'The Camel Book' this weekend.
Message-Id: <354A5751.9F63E044@webspan.net>

Thank to all who answered.  Next time my problem won't be newbie.  But
semi-newbie is a maybe.  :)

Hank

Kevin Reid wrote:

> Arthur Dardia <ahdiii@webspan.net> wrote:
>
> > Here is my code:
> >
> <snip>
> >
> > okay...this is the first version of my first program.  It's supposed to
> > output the first 3 numbers in the 2nd multiplication table (2,4,6).
> > But, it just prints out:
> >
> > C:\Program Files\Perl\eg>perl hank
> > Multiplcation Tables in Perl.
> >      1      2      3
> > 2   0      0      0
> >
> > C:\Program Files\Perl\eg>
> >
> > How do I make it print out numbers instead of 0?  Am I defining the
> > variables wrong?
>
> While other people have pointed out the individual problems, I will give
> you a fixed version of your code:
>
> print "Multiplication Tables in Perl.\n"; # ()s unnecessary
>
> $m1 = 2;
>
> $ma = $m1*1;
> $mb = $m1*2;
> $mc = $m1*3;
>
> print("     1      2      3\n");
> print("$m1    $ma      $mb      $mc\n");
>
> And you can use printf to make the print statements neater:
>
> printf "%5s %5d %5d %5d\n", "", 1, 2, 3;
> printf "%5d %5d %5d %5d\n", $m1, $ma, $mb, $mc;
>
> Here is a complete multiplication table program:
>
> #!perl -w
>
> $amax = 20; # number of rows
> $bmax = 3; # number of columns
>
> $format = '%5d ' x $bmax . "\n"; # construct printf format
>
> @bs = 1 .. $bmax; # make array consisting of numbers 1 through $bmax
>
> for ($a = 1; $a <= $amax; $a++) {    # for loop from 1 to $amax
>   printf $format, map {$a * $_} @bs; # print line
> }
>
> # The map operator multiplies each element of @bs by $a and returns
> # the results, which are then formatted and printed.
>
> __END__
>
> --
>   Kevin Reid.      |         Macintosh.
>    "I'm me."       |      Think different.



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

Date: Fri, 01 May 1998 19:19:37 -0400
From: Arthur Dardia <ahdiii@webspan.net>
Subject: Re: Man...I really need to get 'The Camel Book' this weekend.
Message-Id: <354A5888.5E5BA735@webspan.net>

Say I wanted to be able to set $amax and $bmax from the command line.  Would
I use @ARGV?  Is there an @ARGV2?

Hank

PS - I guess my next question WAS a newbie one.  :(

Kevin Reid wrote:

> Arthur Dardia <ahdiii@webspan.net> wrote:
>
> > Here is my code:
> >
> <snip>
> >
> > okay...this is the first version of my first program.  It's supposed to
> > output the first 3 numbers in the 2nd multiplication table (2,4,6).
> > But, it just prints out:
> >
> > C:\Program Files\Perl\eg>perl hank
> > Multiplcation Tables in Perl.
> >      1      2      3
> > 2   0      0      0
> >
> > C:\Program Files\Perl\eg>
> >
> > How do I make it print out numbers instead of 0?  Am I defining the
> > variables wrong?
>
> While other people have pointed out the individual problems, I will give
> you a fixed version of your code:
>
> print "Multiplication Tables in Perl.\n"; # ()s unnecessary
>
> $m1 = 2;
>
> $ma = $m1*1;
> $mb = $m1*2;
> $mc = $m1*3;
>
> print("     1      2      3\n");
> print("$m1    $ma      $mb      $mc\n");
>
> And you can use printf to make the print statements neater:
>
> printf "%5s %5d %5d %5d\n", "", 1, 2, 3;
> printf "%5d %5d %5d %5d\n", $m1, $ma, $mb, $mc;
>
> Here is a complete multiplication table program:
>
> #!perl -w
>
> $amax = 20; # number of rows
> $bmax = 3; # number of columns
>
> $format = '%5d ' x $bmax . "\n"; # construct printf format
>
> @bs = 1 .. $bmax; # make array consisting of numbers 1 through $bmax
>
> for ($a = 1; $a <= $amax; $a++) {    # for loop from 1 to $amax
>   printf $format, map {$a * $_} @bs; # print line
> }
>
> # The map operator multiplies each element of @bs by $a and returns
> # the results, which are then formatted and printed.
>
> __END__
>
> --
>   Kevin Reid.      |         Macintosh.
>    "I'm me."       |      Think different.



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

Date: 1 May 1998 23:00:25 GMT
From: Zenin <zenin@archive.rhps.org>
Subject: Re: need help with hashtable size/memory
Message-Id: <894064078.254149@thrush.omix.com>

Caroline Hadley <hadley@globin.bio.warwick.ac.uk> wrote:
: I'm creating 3 hashtables in my program, 2 of which have about 450,000
: 'keys' and associated values. The other one is smaller. I'm having huge
: problems with the size of the program - most of the time it just crashes
: after reaching about 120+Mb. I can't understand why it's getting this
: big when the hashtables aren't that large.

	The size of the hashtable isn't simply the total of the data it
	contains, but the overhead of storing data as perl scalar values
	as well as the extra data that the hashtree needs.  A 5 char long
	string is not going to take just 5 bytes of memory, it's going to
	be double that at least. -I forget exactly, it's been a couple
	months since I looked at the structs of SV and friends.

	You might want to consider using a DBM file even if only as a
	temp file.  You can use the tied DBM file as you would a normal
	hash, but when you read and set values it will go to disk so you
	won't have to keep it all in memory at any one time.  Just don't
	use things like keys() or values() but instead try to use a
	while loop with each() or you'll eat the memory up again.

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: Fri, 01 May 1998 21:39:21 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: "Teresa J. Feck" <feck@fre.fsu.umd.edu>
Subject: Re: Perl for VMS
Message-Id: <Pine.GSO.3.96.980501143854.2859P-100000@user2.teleport.com>

On Fri, 1 May 1998, Teresa J. Feck wrote:

> Does any one know of a source to for VMS Perl version 5.003?

Why do you want an old version? But whatever there is should be on CPAN.
Hope this helps!

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



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

Date: Fri, 1 May 1998 18:02:06 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Perl web server....
Message-Id: <1d8cp03.kx4pvpx7st2jN@slip-32-100-246-5.ny.us.ibm.net>

<otis@POPULUS.net> wrote:

> > Some time ago I saw a webserver written in perl.. I have searched .
> > engines.DejaNews etc and stilll cannot find it ,... any pointers as to
> > where on the web it may live are appreciated...

(Sorry for not replying to the original message, but my news server
doesn't have it.)

Well, here's one that I wrote (based on the one in the documentation for
HTTP::Daemon). I wrote it for the Macintosh, you may need to modify it
for other platforms. I have indicated places that are likely to need
changing.

#!perl -w

use HTTP::Daemon;
use HTTP::Status;
use Mac::FancyStatus;

$WebDir = "Apps & Data:Web Shared Folder"; # change this
$| = 1;

$srv = new HTTP::Daemon(LocalPort => 80);

while ($con = $srv->accept) {
  $req = $con->get_request;
  if ($req) {
    $path = $WebDir . $req->url->path;
    $path =~ s!/!:!g;                    # change this
    setmsg($req->method, $path);
    if ($req->method eq "GET") {
      if (-d $path) {
        $con->send_file_response($path . "index.html");
      } else {
        $con->send_file_response($path);
      }
    } else {
      $con->send_error(RC_FORBIDDEN);
    }
  }
  $con = undef;
}

sub setmsg ($$) {
  my ($method, $file) = @_;
  printf "%-20s %-5s %s\n", scalar localtime, $method, $file;
}


-- 
  Kevin Reid.      |         Macintosh.
   "I'm me."       |      Think different.


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

Date: Sat, 02 May 1998 01:07:27 +0300
From: Mihails Nikitins <nikitins@infoservriga.lv>
Subject: Problem evaluating scalars
Message-Id: <354A479E.816FA85C@infoservriga.lv>

Hello PERL experts,

I have a stupid problem evaluating strings being read from a text file.

I'd like to substitute scalar names with its values for some pattern
text file looking like:
Some preformatted text $some $good $values

Imagine a simple text file containing one string:
$name is cool

Here are 4 lines of code:
*********************
$name = "PERL";
open( IN, "text.txt" );
$string = <IN>;
print $string;
*********************
The program prints out
$name is cool
instead of the desired
PERL is cool

How can I force PERL to substitute $name with its value in a very simple
manner? Function eval tries to evaluate 'is' and 'cool'. It works
correctly only if $name is the only word in the string.

If there is no file reading, everything works as desired:

$name = "PERL";
$string = "$name is cool!";
print "$string\n";

results in

PERL is cool

Thank you in advance!

Regards,
Mihails Nikitins




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

Date: 01 May 1998 18:24:37 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Mihails Nikitins <nikitins@infoservriga.lv>
Subject: Re: Problem evaluating scalars
Message-Id: <90ola822.fsf@mailhost.panix.com>

Mihails Nikitins <nikitins@infoservriga.lv> writes:

> I'd like to substitute scalar names with its values for some pattern

This is a FAQ.  See perlfaq4, "How can I expand variables in text
strings?"

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY


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

Date: 01 May 1998 21:11:59 GMT
From: burninurge@aol.com (BurninUrGe)
Subject: Randomly sorting an array
Message-Id: <1998050121115900.RAA01735@ladder03.news.aol.com>

I have an array of student's names in alphabetical order which I would like to
put in random order. Could someone please help me figure out why my approach
isn't working. I'm not a very experienced Perl programmer, but understand most
of the concepts. Please e-mail me any reply as you never know when the news
server will go down (again).

Here's my code so far:

open(MYFILE, "shirt.txt");

$count = 0;
srand();
$_ = <MYFILE>;
open(OUTFILE, ">newshirt.txt");

while ($line = <MYFILE>) {
	@students[$count] = $line;
	
	$count++;
 }

@mine;
$count = 0;

foreach(@students) {
	$i = int(rand(342));
	while (@mine[i]) {
		print @mine[i];
	}
	@newstudents[$count] = @students[$i];
	@mine[i] = $count;
	$count++;
}

foreach(@newstudents) {
	print OUTFILE $_;
}

exit(0);


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

Date: Fri, 01 May 1998 21:45:37 GMT
From: jdporter@min.net (John Porter)
Subject: Re: Randomly sorting an array
Message-Id: <MPG.fb40e12b5e54d5698969c@news.min.net>

On 01 May 1998 21:11:59 GMT,
in article <1998050121115900.RAA01735@ladder03.news.aol.com>,
burninurge@aol.com (BurninUrGe) wrote:
> I have an array of student's names in alphabetical order which I would like to

What you have is way too many errors.
Run perl with the -w switch, and correct the errors it tells you about.
Then post your syntactically corrected program again, and
we'll take a look.

John Porter


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

Date: Fri, 01 May 1998 22:11:20 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: BurninUrGe <burninurge@aol.com>
Subject: Re: Randomly sorting an array
Message-Id: <Pine.GSO.3.96.980501144215.2859R-100000@user2.teleport.com>

On 1 May 1998, BurninUrGe wrote:

> open(MYFILE, "shirt.txt");

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.

> $count = 0;
> srand();
> $_ = <MYFILE>;

That reads one line and stores it into $_, but you never do anything with
it. That's odd.

> open(OUTFILE, ">newshirt.txt");
> 
> while ($line = <MYFILE>) {
> 	@students[$count] = $line;

When you're having trouble getting your code to work, be sure to ask Perl
to give you warnings about anything suspicious. That's the -w invocation
option (see perlrun). In this case, it would point out that you shouldn't
use @students[$count] when you mean $students[$count] , since those are
very different things.

> 	$count++;
>  }

The more common way to write that loop in Perl is something like this. 
(Not that there's anything necessarily wrong about doing it another way;
the Perl Motto is There's More Than One Way To Do It. But a method tends
to be the more common way to do a task if it's quicker to write, easier to
comprehend, and faster to debug.) 

    while (<MYFILE>) {
	push @students, $_;
    }

> @mine;

Perl should warn you about this line, too. 

> $count = 0;
> 
> foreach(@students) {
> 	$i = int(rand(342));

Where did 342 come from? If you want the total number of @students, you
could simply use that:

	$i = int(rand(@students));	# Random index into @students

> 	while (@mine[i]) {

I'm sure Perl warned you about this!

> 		print @mine[i];
> 	}

But I don't know what you're trying to do with that loop. It sure looks
like you're trying to make an infinite loop, though.

> 	@newstudents[$count] = @students[$i];
> 	@mine[i] = $count;
> 	$count++;
> }

I don't know what @mine is supposed to be. Is it a list of indices?

> foreach(@newstudents) {
> 	print OUTFILE $_;
> }

Of course, if you simply wish to shuffle some items, this sub may be
all you need. (You may need to alter this code somewhat if you're
running it on an old version of Perl, prior to 5.004.)

    sub shuffle {
	# returns a random shuffle of a given list
	my @list = @_;			# private copy
	for my $i (1..$#list) {		# Yes, start at 1!
	    my $j = rand($i+1);		# pick one at or before $i
	    @list[$i,$j] = @list[$j,$i];  # swap
	}
	@list;
    }

Proving that this does in fact shuffle fairly is left as an exercise.
:-)  Hope this helps!

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



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

Date: Fri, 01 May 1998 23:26:59 GMT
From: Brian Dwornick <bdwornick@usa.net>
Subject: Redirection
Message-Id: <354A5955.2004FEB@usa.net>

Hello,

I am having a problem with a script redirect a user to a page depending
on what they type in.

I have a form (index.cgi) that takes in $username and $password
it then verifys it to an encrypted file
then I want to redirect it to admin.cgi with just $username and a new
variable $session

Both admin.cgi and index.cgi work doing what they are suposed to do but
I can't get variables from one to the other

print "Location: admin.cgi?username=$username&session=$session";

is how i have been trying to do it
is there special characters i have to use?

i want it to use "Location: file.name";

Help

Brian




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

Date: 1 May 1998 23:03:11 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: Splitting a variable ???
Message-Id: <894063788.700117@elaine.drink.com>

In article <6i6m8q$i3f@hplntx.hpl.hp.com>, Larry Rosler <lr@hpl.hp.com> wrote:
>Martien Verbruggen wrote in message
><6i5p9v$lck$2@comdyn.comdyn.com.au>...
>>In article <wxxd8e1r432.fsf@refil.ifi.uio.no>,
>> Terje Kvernes <terjekv@ifi.uio.no> writes:
>>> "Igor Krivokon" <igor.k@usa.net> writes:
>>>
>>>> $string = "042498a";
>>>> ($a, $b, $c, $d ) = $string =~ /(\d\d)(\d\d)(\d\d)(\w)/;
>>>
>>> why not \d{2} instead of \d\d? Hm...
>>
>>Because \d\d is 4 characters, and \d{2} 5? :)
>
>
>Because \d\d is a bit faster! :)

The substr solution seems a bit faster still:


#!/usr/local/bin/perl -w
use strict;
use Benchmark;

use vars qw( $string );
$string = '042498a';

timethese (100000, {
    'looped' => q{
 my ($a, $b, $c, $d) = $string =~ /(\d{2})(\d{2})(\d{2})(\w)/;
    },
    'unrolled' => q{
 my ($a, $b, $c, $d) = $string =~ /(\d\d)(\d\d)(\d\d)(\w)/;
    },
   'substr' => q{
	my($a,$b,$c,$d) = (
		substr($string,0,2),
		substr($string,3,2),
		substr($string,5,2),
		substr($string,6),
	)
   },
} );

Benchmark: timing 100000 iterations of looped, substr, unrolled...
    looped:  6 secs ( 5.17 usr  0.00 sys =  5.17 cpu)
    substr:  3 secs ( 1.98 usr  0.00 sys =  1.98 cpu)
  unrolled:  5 secs ( 4.72 usr  0.00 sys =  4.72 cpu)


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

Date: Fri, 01 May 1998 21:17:14 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: strictly speaking..
Message-Id: <Pine.GSO.3.96.980501135624.2859L-100000@user2.teleport.com>

On Fri, 1 May 1998, it was written:

> Basically, my question is whether strict actually changes the way the 
> compiler interprets a script, or if it just gives the compiler more 
> things to do as it's parsing.

There are currently three strictures. (By default, use strict invokes all
three.) Although we should examine them one at a time, I'll use parallel
prose to describe parallel features; please forgive the repetitiveness of
these three paragraphs! :-) 

use strict 'subs' has an effect at compile time only. If you use an
unknown bareword which might be intended to be a subroutine call, it
complains. If you don't do that, this pragma requires nothing more of
perl. (Of course, perl has to check to see whether you're doing this
anyway; in the absence of this pragma, it simply compiles the bareword as
a literal string.) 

use strict 'vars' also has an effect at compile time only. If you use an
undeclared unqualified global variable, it complains. If you don't do
that, this pragma requires nothing more of perl. (Of course, perl has to
check to see whether you're doing this anyway; in the absence of this
pragma, it simply compiles in code to reference a new global.)

use strict 'refs' is the only current stricture which affects runtime at
all. If you use a string as a reference, it complains. If you don't do
that, this pragma requires nothing more of perl. (Of course, perl has to
check to see whether you're doing this anyway; in the absence of this
pragma, it simply uses the string as a symbolic reference.)

In sum, the strictures don't ask perl to do any extra work, only to
complain if you've violated the rules. 

> PS. anyone know the origins of the variable name $sememe in strict?

There's a definition of sememe in the online dictionary at this URL, but a
good book on linguistics may be helpful.

    http://www.m-w.com/dictionary

It may help to know that Larry Wall is a linguist. :-)  Hope this helps! 

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



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

Date: 01 May 1998 16:12:16 -0500
From: Quentin  Fennessy <quentin@shaddam.amd.com>
Subject: Re: Test httpd server status
Message-Id: <xim67jpy9u7.fsf@shaddam.amd.com>


Robert- I suggest you check out libwww-perl.  The modules
included make your program almost trivial to write.  Here is
some code from lwpcook(1) (libwww-perl cookbook).

from lwpcook(1):

     It is very easy to use this library to just fetch documents
     from the net.  The LWP::Simple module provides the get()
     function that return the document specified by its URL
     argument:

       use LWP::Simple;
       $doc = get 'http://www.sn.no/libwww-perl/';

You can find this on CPAN.

-- 
Quentin Fennessy			AMD, Austin Texas
Secret hacker rule #11 - hackers read manuals


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

Date: Fri, 01 May 1998 14:31:41 -0700
From: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
To: Robert Watkins <r-watkins@worldnet.att.net>
Subject: Re: Test httpd server status
Message-Id: <354A3F3D.ED3CA454@cks.ssd.k12.wa.us>

Robert Watkins wrote:

> Okay, I'm stuck on this one.
>
> I want to write a Perl script that telnets to port 80 of an httpd server,
> sends the command "HEAD / HTTP/1.0\n\n" and loads the output to a variable.
> The idea behind this is to then read that variable to see which http response
> is contained in the line beginning HTTP: if it is 200, great, if not, I will
> have an e-mail sent to me so that I know something is up. We have, you see, 6
> web servers running on various boxes under various flavors of Unix, and I want
> to make this a cron job so that I don't have to worry about checking the
> server status manually. This is the plan: if there's an easier way to ge the
> same result, I'ld be quite happy to hear it.
>

Anything 'webbish' should use LWP.

#!/bin/perl -w
use strict;
use LWP; # ******BIG HINT*******
my(@servers) = qw{server1 server2 server3};
my($ua) = new LWP::UserAgent;
foreach(@servers)
{
    my($url) = new URI::URL "http://$_";
    my($request) = new HTTP::Request HEAD => $url;
    my($response) = $ua->request($request);
    if($response->is_error)
    {
        # you know what to do
    }
}

Jerome O'Neil



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

Date: Fri, 01 May 1998 22:48:41 GMT
From: teetshd@email.uc.edu (Greg Teets)
Subject: Warning Message Incorrectly Says File Handle Variable Used Only Once
Message-Id: <354a50ed.79666808@news.ececs.uc.edu>

The following code, which works fine, produces the warning error
reproduced below.  Please explain what causes the error message.

for ($x = 0; $x < $num_dups; $x++)
   {
   open (DUPS_OUT, ">>dup_records");
   select ("DUPS_OUT");
   $| = 1;
   printf DUPS_OUT ("duplicate $x\n");
   $search1 = substr($dup_data[$x], 24, 12);
   $search2 = substr($dup_data[$x], 41, 11);
   $search = sprintf("$search1$search2");

   $CSA = substr($dup_data[$x], 0, 4);

   $SID = &get_sid($CSA);
      }


Identifier "main::DUPS_OUT" used only once: possible typo at
search_dups.pl  line 20.

Thanks
Greg Teets
Cincinnati, OH




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

Date: Fri, 01 May 1998 23:38:44 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Greg Teets <teetshd@email.uc.edu>
Subject: Re: Warning Message Incorrectly Says File Handle Variable Used Only Once
Message-Id: <Pine.GSO.3.96.980501163140.2859X-100000@user2.teleport.com>

On Fri, 1 May 1998, Greg Teets wrote:

> The following code, which works fine, produces the warning error
> reproduced below.  Please explain what causes the error message.
> 
> for ($x = 0; $x < $num_dups; $x++)
>    {
>    open (DUPS_OUT, ">>dup_records");

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.

>    select ("DUPS_OUT");

I don't think you want or need the quote marks there, although that's not
causing an error message (by itself, at least). 

>    $| = 1;
>    printf DUPS_OUT ("duplicate $x\n");
>    $search1 = substr($dup_data[$x], 24, 12);
>    $search2 = substr($dup_data[$x], 41, 11);
>    $search = sprintf("$search1$search2");
> 
>    $CSA = substr($dup_data[$x], 0, 4);
> 
>    $SID = &get_sid($CSA);
>       }
> 
> 
> Identifier "main::DUPS_OUT" used only once: possible typo at
> search_dups.pl  line 20.

None of these 15 lines seems to be line 20 on my machine. Running
5.004_04, I can generate other warnings, but not this one. (Are you using
an old version of Perl?) See if you can cut your code down to half a dozen
lines or fewer, and if you still haven't exterminated the bug, then post
the actual code. Thanks! 

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



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

Date: Fri, 01 May 1998 21:20:23 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: tiles@pyramidtile.com
Subject: Re: web_store.cgi error in the browser
Message-Id: <Pine.GSO.3.96.980501141956.2859M-100000@user2.teleport.com>

On Fri, 1 May 1998 tiles@pyramidtile.com wrote:

> But when I type:
> http://www.pyramidtile.com/web_store/Web_store/web_store.cgi
> 
> it comes up error, any suggestions would greatly be apprectiated

When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to solving
such problems. It's available on CPAN.

   http://www.perl.com/CPAN/
   http://www.perl.org/CPAN/
   http://www.perl.org/CPAN/doc/FAQs/cgi/idiots-guide.html
   http://www.perl.org/CPAN/doc/manual/html/pod/

Hope this helps!

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



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

Date: Fri, 1 May 1998 15:37:16 -0700
From: "Igor Krivokon" <igor.k@usa.net>
Subject: Re: Win32 reading in passwords
Message-Id: <6idikp$dhk$1@news.ncal.verio.com>

scott@softbase.com wrote in message <6icd7m$rsv$1@mainsrv.main.nc.us>...
>Neil Freetly (nfreetly@ibm.net) wrote:
>> How can I accept input from the keyboard without displaying it to the
>> screen?
>
>> For instance, I want to prompt for a password in my WIN32 Perl program,
>> but I don't want to echo to the screen what the user types in.  Any
>> Ideas?
>
>First thing's first: the Win32 model of security is based on the idea
>that once the user logs in, the user is authenticated and has full

>control over the system. On NT, this is definitely true. On Windows


No, it's not true. 
Read any book on NT administration. Keywords: "user rights".

>95, "security" is totally irrelevant. Prompting the user for a
>password is bad design, since once the user logs in the user is
>going to expect to be validated already.

The fact that user is logged in means the following:
user has *certain* rights to access *certain* system resources, 
related to this machine. 

Every time you request additional rights and/or 
new resouces (say, on other machines), 
you are validated (typically). For example:
1) access to shared network resources
2) ftp access to other machines
3) well, any application-specific validation - 
source code control systems, online library access, 
electronic commerce, and etc., etc.

Do you really think that prompting the user for a password 
in such situations is "bad design"?

>In Perl under Windows, there is probably no way at all to stop keyboard
>echo.  To do this, you would have to use the console API, which I do
>not believe is supported in Perl in any way.


Portable solution: Term::ReadKey 
Win32 - specific: Win32::Console

Regards, 

Igor Krivokon
<igor.k@usa.net>







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

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

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