[7773] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1398 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 1 18:07:21 1997

Date: Mon, 1 Dec 97 15:00:23 -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, 1 Dec 1997     Volume: 8 Number: 1398

Today's topics:
     Alphanumeric Ranges Using .. and ++ <mrs@cae091.ed.ray.com>
     Re: camel vs llama (Tad McClellan)
     Re: Creating Calling Trees (Joel Wilf)
     Re: each() does not work?! <mortensi@idt.ntnu.no>
     Re: each() does not work?! <rootbeer@teleport.com>
     Re: each() does not work?! (brian d foy)
     Re: getopts on NT? <rmook@us.oracle.com>
     Is the contant function in Fcntl.pm an undocumented per (Mark A. Lehmann)
     Mirror PUT program <bill@tssun7.dsccc.com>
     negative lookahead help in HTML entity substitution (Eric Litman)
     Re: open and whitespace <rootbeer@teleport.com>
     Re: open and whitespace (John Moreno)
     Re: open and whitespace (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
     PerlShop "invalid transmission" (Dave Reed)
     Re: problem using eval with array of file test operator (Andrew M. Langmead)
     Re: Q: alternative to Perl? (kuehne)
     Re: Q: Learning perl with no progr. experience (Rodger Donaldson)
     Re: Random numbers, perl and win95 :( (Daryn Brightblade)
     Re: Random numbers, perl and win95 :( (Jim Michael)
     Re: readdir() and Win32 Perl <mikeo@gsd.state.nm.us>
     Re: Safe use of flock() -- was Re: giving up on flock (Tad McClellan)
     Scoring A Group of Arrays Part II (Daniel G. Drumm)
     Re: Trimming space <Matthew.Rice@ftlsol.com>
     Re: Win32::internet <ebohlman@netcom.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 01 Dec 1997 15:21:31 -0500
From: Mark Stallard <mrs@cae091.ed.ray.com>
Subject: Alphanumeric Ranges Using .. and ++
Message-Id: <34831C4B.50CA@cae091.ed.ray.com>

I'm writing a module which must generate sequences of alphanumeric
strings.  For example, the module might be asked to issue the first
3 "numbers" between 1715A51882 and 1715A51932, and it would return
the list ( 1715A51882, 1715A51883, 1715A51884 ).  The next request
would begin where the previous request left off.

Other functions would include boolean test for whether or not a
value lies in a given range, and a count of values not yet issued
from a given range.

I can't rely on .. and ++ alone to generate these lists.  Those
operators will work only if all of the alphabetical characters
precede all of the digits. For example, the perlop man page shows
this:

	print ++($foo = 'a0');      # prints 'a1'
	print ++($foo = 'Az');      # prints 'Ba'
 	print ++($foo = 'zz');      # prints 'aaa'

That won't work if I intermingle alphabetical with numeric:

	print ++($foo = "1a0");      	# prints '2'; "1a0" == 1
	print ++($foo = "A1z");      	# prints '1'; "A1z" == 0
	print ++($foo = "1715A51882");	# prints '1716'

The .. operator shares these restrictions with ++.

Can anyone show me a succinct, straightforward method of generating
these lists as I've described?

  -----------------------------------------------------------------
  Mark Stallard                         Raytheon Electronic Systems
  mrs@cae091.ed.ray.com                 Sudbury, Massachusetts (US)
  -----------------------------------------------------------------


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

Date: Mon, 1 Dec 1997 14:17:43 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: camel vs llama
Message-Id: <716v56.ki2.ln@localhost>

Joe Keyes (c-keyes@mail.dec.com) wrote:
: I have seen mention made on this group of the
: llama book being for programming newbies, and

I would not agree with that.

Llama is good for programmers who are newbies to perl.

Learning how to program _and_ learning Perl at the same time
is going to be harder, of course.

The Llama would for sure be helpful, but I don't know that it would be
enough to learn how to program from (I already knew programming, so
I cannot assess that aspect of it)


: camel book being for programmers' reference in
: learning perl.

: Is that asessment accurate?

For the Camel, yes.

For the Llama, maybe sorta kinda.


: Isn't the camel only up to 5.003? 

Yes.



The most accurate and up-to-date documentation that exists for Perl
is shipped with the perl distribution itself...

 
--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 1 Dec 1997 22:16:26 GMT
From: jwilf@darepc.jpl.nasa.gov (Joel Wilf)
Subject: Re: Creating Calling Trees
Message-Id: <slrn686dpe.so6.jwilf@darepc.jpl.nasa.gov>

In article <879875446.6680@dejanews.com>,
pverdret@sonovision-itep.fr (philippe Verdret) posted his excellent
Devel::CallTree.pm and Tree.pm packages.

Thank you, Philippe.  I'm finding these to be excellent for tracing
program/function execution.



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

Date: 1 Dec 1997 20:51:52 GMT
From: Morten Simonsen <mortensi@idt.ntnu.no>
Subject: Re: each() does not work?!
Message-Id: <65v818$30d$1@due.unit.no>

Tom Phoenix <rootbeer@teleport.com> wrote:
: On 1 Dec 1997, Morten Simonsen wrote:

: > I have used each() many times before, and it has worked fine, but now
: > it seems like something is wrong. I have a database at 1000 entries.
: > When I tries to list the entries, only some of the entries are found
: > by running each() on the DB. If I try to print the entry by
: > 
: > print $DB{$key}
: > 
: > I find all the entries that are not listed by using each(). The problem
: > seems to arise when there are more than 350 entries. 

: It could be a bug in the database code, or it could be that you're
: altering the hash while you're iterating over it with each(). Without some
: code, it's impossible to be sure.

I do not alter anything during the each-loop. (I have done that error
before:) (A little question anyway: Does it affect the each()-iterator
if you alter the value of a given key, or is it just when you add a new key
that things start to get messy?)

: > I use perl Perl for Win32 Build 306 version 5.003_07

: There are much newer versions available. Do you still have problems with a
: newer version? Good luck!

I tried the same program on a UNIX-machine, running perl 5.003 with EMBED,
and the error did NOT occur there. So i guess I must have found a bug
in the database code? I will try to get a newer version and see if that
helps.

Morten Simonsen


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

Date: Mon, 1 Dec 1997 13:22:35 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Morten Simonsen <mortensi@idt.ntnu.no>
Subject: Re: each() does not work?!
Message-Id: <Pine.GSO.3.96.971201131813.28036V-100000@usertest.teleport.com>

On 1 Dec 1997, Morten Simonsen wrote:

> Does it affect the each()-iterator if you alter the value of a given
> key,

No, because you can't. :-)  You can't change a key in a hash of any kind. 
(You could delete an element and create a new one with a different key,
but that's not the same thing as altering a key. And of course, that would
be altering the hash.) You could change the variable which holds a copy of
the key, but that shouldn't cause anything unexpected to happen. 

> I tried the same program on a UNIX-machine, running perl 5.003 with
> EMBED, and the error did NOT occur there. So i guess I must have found a
> bug in the database code?

Sounds likely. If the database code is using library routines on your
machine, you may have found a bug in those. In that case, you'd need to
get replacements for those library routines, of course. Good luck! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Mon, 01 Dec 1997 16:56:47 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: each() does not work?!
Message-Id: <comdog-ya02408000R0112971656470001@news.panix.com>

In article <Pine.GSO.3.96.971201131813.28036V-100000@usertest.teleport.com>, Tom Phoenix <rootbeer@teleport.com> wrote:

>On 1 Dec 1997, Morten Simonsen wrote:
>
>> Does it affect the each()-iterator if you alter the value of a given
>> key,
>
>No, because you can't. :-)  You can't change a key in a hash of any kind. 

he was talking about the value, not the key, i think :)

you can change the value without affecting each(), as in this example:

   #!/usr/bin/perl
   
   foreach (0..9) { $hash{$_} = $_*$_ };  #build a hash of squares
   
   while( ($key, $value) = each %hash )
      {
      $hash{$key} += 1;
      }
      
   foreach ( sort {$a <=> $b} keys %hash ) { print "$_: $hash{$_}\n" }
   
   __END__
   
   0: 1
   1: 2
   2: 5
   3: 10
   4: 17
   5: 26
   6: 37
   7: 50
   8: 65
   9: 82

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Mon, 01 Dec 1997 16:46:26 -0500
From: Bob Mook <rmook@us.oracle.com>
Subject: Re: getopts on NT?
Message-Id: <34833032.5EE1@us.oracle.com>

Jeff Kehoe wrote:
> 
> Lokisdog (see.my.sig@nospam.com) wrote:
> : Jeff Kehoe wrote:
> : >
> : > Is there something special I need to do to use getopts() for perl on NT?
> : >
> 
> : < snipped>
> 
> : This works on NT:
> 
> : ++++++++++++++  Start Code Snippet  ++++++++++++++
> 
> : require "getopt.pl" || die "No getopt.pl";
> 
> : # =============> Extract the command line switch arguments
> 
> : &Getopt (se);
> :
> : $start = $opt_s;
> : $end = $opt_e;
> :
> : # ============> Print them out to test
> 
> : print "Start is $start\n";
> : print "End is $end\n";
> 
> : +++++++++++++++++++  End Code Snippet +++++++++++++++
> 
> : The output looks like this:
> 
> : D:\PerlScripts>opts.pl -s dog -e cat
> : Start is dog
> : End is cat
> 
> Eric,
> 
> I discovered that your solution doesn't work if I invoke the script
> directy as you have shown.  If I type
> 
> D:\PerlScripts>perl opts.pl -s dog -e cat
> 
> it will work.  So something is wrong with my association or launching
> of perl scripts.  Any ideas?
> 
> Thanks for your help,
> Jeff

Yes, I've seen the same thing.  I think whats happening is that you are
running under control of the shell (cmd.exe) in the case that works,
which can pass parameters to your program (perl.exe) and script.  When
launched by the association, your script can't be passed parameters by
the shell since it isn't being run - only perl.exe is being run.  You
could probably setup a shortcut that could have its properties setup to
take in parameters.

bob


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

Date: 01 Dec 1997 16:02:57 -0600
From: mlehmann@prismnet.com (Mark A. Lehmann)
Subject: Is the contant function in Fcntl.pm an undocumented perl function?
Message-Id: <5bd8jgu3fy.fsf@smokey.prismnet.com>

I have been attempting to determine why:

use Fcntl;
use NDBM_File;

package change_name_space;

tie(%candidate, "NDBM_File", '/tmp/candidate_list', 
    Fcntl::O_RDWR, 0666);

fails when the Fcntl is missing in the constant.  I tried Fcntl::O_RDWR and
Fcntl::O_RDWR().  I then searched through the Fcntl.pm file in my
$PERLLIBDIR/$OPERATING_SYSTEM/$PERLVERSION directory
(/usr/local/lib/perl5/aix/5.00401 on my system).  I found this curious grouping
of lines in the code:

  sub AUTOLOAD {
      my($constname);
      ($constname = $AUTOLOAD) =~ s/.*:://;
      my $val = constant($constname, @_ ? $_[0] : 0);

I did not find the "constant" function defined anywhere in the part of the
code written in perl.  Is this an undefined function that returns predefined
constants when provided a constant string name?

Could this simply be a function defined in the shared object library that I
missed or is this a magical function that I can use to truely provide
constants?

-- 
Mark Lehmann.


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

Date: Mon, 01 Dec 1997 14:29:36 -0600
From: Bill Petersen <bill@tssun7.dsccc.com>
Subject: Mirror PUT program
Message-Id: <34831E30.6C2922C1@tssun7.dsccc.com>

I have a mirror program written in perl which works great!
But it does a pull (you tell it what site to mirror, and it
does ftp gets to pull the data down).

But what I need is a similar program that does a push (put).
I want a 'master' site to control the distribution of the
data.  When something gets updated, an admin can 'push'
the data out to the replica sites.  I like the 'mirror' concept
because I want to have files deleted from the replicas when they
are removed from the master, etc.

The program must work using ftp so things like rdist or nfs won't work.

Does anyone have such a program?

Regards,

Bill

------------------------------------------------------------------------
Bill Petersen                                       email: brp@dsccc.com
UNIX System, Web, Firewall, and Email Admin         voice: 972-519-4249
Technical Services, DSC Communications Corp, Plano, Texas
------------------------------------------------------------------------
Communication, its one of those things we take for granted...
------------------------------------------------------------------------





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

Date: 1 Dec 1997 20:10:14 GMT
From: elitman@viaduct.com (Eric Litman)
Subject: negative lookahead help in HTML entity substitution
Message-Id: <65v5j6$2m$1@news2.digex.net>

I have a document parser which needs to be able to look through a text
document and find any ampersands which are not part of either an HTML entity
or a double ampersand (&&).

It seems to me that this should work:

$match =~ s/&+?(?![^&][a-zA-Z0-9#]{2,5};)/\&amp\;/go;

However, it doesn't. Any thoughts?

--
Eric A. Litman           Viaduct Technologies, Inc.            Bethesda, MD
CEO                        http://www.viaduct.com            (301) 493-0220
            digital cellular (PCS) info: http://www.celltalk.com


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

Date: Mon, 1 Dec 1997 13:27:29 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Niall O Broin <nobroin@esoc.esa.de>
Subject: Re: open and whitespace
Message-Id: <Pine.GSO.3.96.971201132304.28036W-100000@usertest.teleport.com>

On Mon, 1 Dec 1997, Niall O Broin wrote:

> I need to process files generated by Macintosh users who quite often use
> filenames with leading spaces (deliberately because space sorts to the
> top of a Finder file list) and trailing spaces (probably accidentally). 

> Does anyone know why open strips leading and trailing whitespace ? 

IMHO, you've given a good reason why MacPerl shouldn't strip leading and
trailing whitespace in open(). Maybe you should report this as a bug in
MacPerl, and try to get it fixed. :-) 

Good luck! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Mon, 1 Dec 1997 16:29:27 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: open and whitespace
Message-Id: <1d0l73v.1kumqkd1ep9268N@roxboro-163.interpath.net>

Niall O Broin <nobroin@esoc.esa.de> wrote:

> On page 194 in Camel II it says
> 
> But we've never actually seen anyone use that in a script...
> 
> Well, of course, someone had to use it :-) 
> 
> I need to process files generated by Macintosh users who quite often use
> filenames with leading spaces (deliberately because space sorts to the
> top of a Finder file list) and trailing spaces (probably accidentally).
> I was trapping for this as suggested in the Camel and it was working,
> but I've now encountered other problems where code I didn't write opens
> these files. I don't really want to have to modify the filenames
> everywhere I might need to.
> 
> Does anyone know why open strips leading and trailing whitespace ? After
> all, if a space is a legal character in a filename (as it is in most
> modern Unices, if a little hard to deal with via most shells), why
> shouldn't it be used ? I don't see it as a portability issue - if your
> OS doen't support spaces in filenames, don't use them. I have looked at
> do_open in doio.c so I know how the space stripping is done, and I could
> easily change it it's a two liner), but would I break anything else ? I
> really don't see how, but I'm not Larry :-)

A alternative is to use sysopen.  But this is covered in the faq -
although I haven't had much luck with the solutions using MacPerl.

-- 
John Moreno


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

Date: Mon, 01 Dec 97 16:33:54 -0500
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: open and whitespace
Message-Id: <34832e93$3$ofn$mr2ice@speaker>

In <EKJ0oG.4oG@world.std.com>, on 12/01/97 at 07:55 PM,
   aml@world.std.com (Andrew M. Langmead) said:
+-----
| Niall O Broin <nobroin@esoc.esa.de> writes:
| >Does anyone know why open strips leading and trailing whitespace ? After
| >all, if a space is a legal character in a filename (as it is in most
| >modern Unices, if a little hard to deal with via most shells), why
| >shouldn't it be used ?
| Here's my guess.
| A lot of perl, especially a lot of early perl, was written to read text
| files, munge the data, and output the results.
+--->8

Actually, the reason is consistency:  otherwise, open() would have to treat
the argument differently depending on whether it's a filename, a file with
mode information in shell-redirection format (spaces are ignored by the shell,
so open() is consistent with that usage), or a pipeline (which is passed to
the shell, which ignores the spaces).  As it is, open() always acts the same
way a shell would act when faced with the same file specifier, at least for
those cases understood by both.

It's worth remembering that Perl was originally designed as a system
administration scripting language combining the syntax and semantics of
existing Unix tools, very much including shells.

-- 
brandon s. allbery           [Team OS/2][Linux][JAPH]        bsa@void.apk.net
cleveland, ohio              mr/2 ice's "rfc guru" :-)                  KF8NH
"Never piss off a bard, for they are not at all subtle and your name scans to
 `Greensleeves'."  ---unknown, quoted by Janet D. Miles in alt.callahans



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

Date: Mon, 01 Dec 1997 16:02:45 -0500
From: daveSTOP*SPAMreed@webshowplace.com (Dave Reed)
Subject: PerlShop "invalid transmission"
Message-Id: <daveSTOP*SPAMreed-0112971602450001@d86.b70.cmb.ma.ultra.net>

I'm trying for the first time to install and use PerlShop.cgi in a virtual
hosting situation where the script is located at

www.mydomain.com/cgi-bin/TheStore/PerlShop.cgi  

but  when referred to with a web browser the format must be (according to
my virtual host)  

www.mydomain.com/cgi-bin/vr?TheStore/PerlShop.cgi

When I use Netscape 4.03 and try to enter the store from the entry page
with a form posting to  

www.mydomain.com/cgi-bin/vr?TheStore/PerlShop.cgi

PerlShop.cgi executes but gives me "transmission error #1" or #3.

The relevant code in the script appears to be:

if (lc $use_cookies eq 'yes')
   {
   &create_cookie('orderid', $unique_id, $cookie_expire_days);
   print "\n";    }
   }
   else
         {&Transmission_error(1);}
}

generating transmission error #1 most of the time, regardless of whether I
have the $use_cookies option set for 'yes' or 'no',  and then occasionally

if (($unique_id eq '!ORDERID!') || ( $unique_id !~ /\d{$id_length}?/ ))
      {&Transmission_error(3);}

generating transmission error #3.

The problem seems to be related to creating the unique ID.

Any ideas what is causing the transmission error messages?

Thanks.

-Dave Reed . . . . . . . . . . . . . davereed@webshowplace.com

WEBSHOWPLACE, Box 819, Assonet, MA 02702 . . . ph 508-763-8050

Award-winning Website Design . . Online Shopping Cart Commerce

http://www.webshowplace.com


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

Date: Mon, 1 Dec 1997 21:07:22 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: problem using eval with array of file test operators
Message-Id: <EKJ40B.MpI@world.std.com>

Curtis Hrischuk <ceh@sunspot.sce.carleton.ca> writes:

>Hi.  I am trying to write a method which prints out the status of a
>file using the file test operators.  The code is shown below.  I am
>having a problem trying to figure out how to set up the command text
>string and using eval. 

When you print out the text you are about to eval, it should look
exactly like a script you would want to execute. Which probably means
interpolating $ftest, and not interpolating the variable names.

    $command =     
    "if ( $ftest \$fname ) {
      \$qualifier = "";
    } else {
      \$qualifier = "not";
    }";
    print "Command is $command\n";  
    eval $command ;

but instead of the eval, how about a couple of other options? If you
make the tests subroutine references instead of strings, you could
skip the eval.

my @test  = (
		 [sub {-r $_[0]}, "File is %sreadable by effective uid\n" ],
# and the rest of the file tests.

foreach $ratest (@test) {
  if(&{$ratest->[0]}($fname)) {
    $qualifier = '';
  }
  else {
    $qualifier = 'not ';
  }
  printf $ratest->[1], $qualifier;
}
 
Also, most of the file mode tests are taken from the result of the
stat() command. You might just want to run stat() and pick apart the
results yourself.

-- 
Andrew Langmead


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

Date: 1 Dec 1997 15:07:52 -0600
From: kuehne@ccwf.cc.utexas.edu (kuehne)
Subject: Re: Q: alternative to Perl?
Message-Id: <65v8v8$dfs@piglet.cc.utexas.edu>

You need TECO. Forget that regexp stuff. Say hello to Q-registers.
Text AND a number! This is best done on a DecWriter II, where you can
enjoy that olde happy thump-n-buzz.


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

Date: 1 Dec 1997 19:36:30 GMT
From: rodgerd@orwell.rm.gen.nz (Rodger Donaldson)
Subject: Re: Q: Learning perl with no progr. experience
Message-Id: <slrn6864ds.lve.rodgerd@orwell.rm.gen.nz>

On 1 Dec 1997 13:15:16 GMT, ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au> wrote:

>In <347FFD0C.42B2@xs4all.nl> av3@xs4all.nl writes:
>
>>i wanna start learning perl. The thing is: i have no programming
>>experience whatsoever

>The first thing you should do is learn how to program.  I would suggest a
>languge like pascal or scheme to do this.
>
>Perl is not a good lannguge to learn programing on IMHO.

I beg to differ.  Perl is a naturalistic languange that allows one to do
useful things quickly.  It ay not straitjacket the learner into doing things
correctly as much as pascal does, but it won't straightjacket the user into
being able to do next to nothing useful, either.  Perl has a happy knack of
encouraging the beginner to keep going.

(All in my opinion and experience, of course).

-- 
Rodger Donaldson		rodgerd@ihug.co.nz
The Pinguin Patrol


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

Date: Tue, 02 Dec 1997 06:32:51 GMT
From: daryn@solamnia.demon.co.uk (Daryn Brightblade)
Subject: Re: Random numbers, perl and win95 :(
Message-Id: <881015540.25556.0.nnrp-03.c2de12b5@news.demon.co.uk>

oh s**t
sorry
meant the code to be..:
$file=int(rand(100000));
print $file;

dammit
sorry

thanks anyway...

Daryn Brightblade
Comrades in Arms, Brothers in Peace, the Clan Brightblade
http://www.solamnia.demon.co.uk/



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

Date: Mon, 1 Dec 1997 22:43:39 GMT
From: genepool@netcom.com (Jim Michael)
Subject: Re: Random numbers, perl and win95 :(
Message-Id: <genepoolEKJ8Gr.5Du@netcom.com>

Daryn Brightblade (daryn@solamnia.demon.co.uk) wrote:
: piece of code looking like

: $file=int(rand(100000));
: print $filename;

What is being assigned to $filename? Anyway, assuming that was a typo, try

srand; #initialize the RNG
$file=int(rand(100000));
print $file;

Cheers,

Jim


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

Date: Mon, 01 Dec 1997 13:35:03 -0700
From: Michael Owens <mikeo@gsd.state.nm.us>
Subject: Re: readdir() and Win32 Perl
Message-Id: <34831F77.8C838231@gsd.state.nm.us>

Scott McGee wrote:
> 
> Hi all,
> 
> I have looked in the FAQ's and checked over the messages here, and
> don't see an answer to a problem I am having.
> 
> I am used to working in a UNIX (normally Solaris 2.4) environment, but
> have just installed the Win32 version of Perl on my Win 95 box and
> gotten it working with CGI and my Personal Web Server. One script I
> wanted to use reads a directory and manipulates the filenames it finds.
> The code, which works fine on Solaris 2.4 but not at all one Win 32
> looks something like this:
> 
> opendir(DIR, "$dirpath\\$dirname") || print "Cannot open $dirname\n";
> @files = grep(!/^\.\.?$/, readdir(DIR));
> closedir(DIR);
> 
> while (<@files>) {

  ^^^^^^^^^^^^^^^^
The problem is with the while() construct. @files is an array, but
you're using it as if it where a filehandle.  Use foreach instead, like
so:
  foreach (@files) {

>    print "$_ \n";
> }

Seems to me this should fail on Solaris also; are you by chance using 
<*> to get the directory listing on Solaris?

Mike Owens
mowens@state.nm.us


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

Date: Mon, 1 Dec 1997 16:04:58 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Safe use of flock() -- was Re: giving up on flock
Message-Id: <aacv56.pv2.ln@localhost>

Keith Willis (keith_willis.junk@non-hp-unitedkingdom-om1.om.hp.com) wrote:
: On 23 Nov 1997 17:14:49 -0500, Mark Mielke <markm@nortel.ca> wrote:

: >Any ideas people? _SHOULD_ i be checking the return code of close() in
: >C + perl scripts?Let's just say i wrote my code like this:
: >
: >--- CUT HERE ---
: >use Fcntl qw(:flock);
: >use IO::File;
: >
: >sub log
: >{
: >    my($path, $message) = @_;
: >    my $handle = new IO::File($path, "a") ||
: >        die "open of $path failed: $!\n";


Another process might get a time slice right here, and tack 
some more stuff onto the end of the file. The 'new' end of file
position is not in $handle.


: >    flock($handle, LOCK_EX) ||
: >        die "lock could not be obtained for $path: $!\n";
: >
: >    seek($handle, 0, SEEK_END) ||
: >        die "seek-to-eof failed for $path: $!\n";


All fixed, $handle now knows where the real end of file is.


: I am probably missing something here 
: (and this is not related to the
: subject of flock), 


Oh but it is related to flock().  _That_ is what you are missing  ;-)


: but if you open the file with a type of "a", why
: would you need to do a SEEK_END as well?


Because, after getting the file handle (open seeks to end of file), 
and before getting the lock, the 'end of file' position may have
moved  ;-)


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 1 Dec 1997 22:09:34 GMT
From: dgd@nebula.is.rpslmc.edu (Daniel G. Drumm)
Subject: Scoring A Group of Arrays Part II
Message-Id: <65vciv$esi$1@tepe.tezcat.com>

I've taken some example code I received from Chipmunk, and tried to come up
with a reduced program for debugging purposes.

What I am trying to do is this:

1. Create 6 arrays, @a to @f.
2. Roll a dice 10 times and put the results in each array, such that each
array contains 10 results.
3. Go through each array, and find out how many times each number was
rolled in TOTAL, across all 6 arrays.

Here's the code to create the array and then try to "score" how many times
the number came up. Part A works fine, but Part B is clearly not right.
I also think the nesting of two loops inside a third is not very efficient.

#!/usr/local/bin/perl

srand(time|$$);

# Part A

for ($arr = 'a'; $arr le 'f'; $arr++) {
    for ($iteration = 1; $iteration < 10; $iteration++) {
        $number = int(rand(6)) + 1;
        push (@$arr, $number);
    }
}

# Part B

for ($arr = 'a'; $arr le 'f'; $arr++) {
    foreach (@$arr) {
      $temp{$_}++;
    }
    foreach (keys %temp) {
      $scores{$_}++;
    }
    %temp = ();
}

print $scores{1};
print "\n";
print $scores{2};
print "\n";
print $scores{3};
print "\n";
print $scores{4};
print "\n";
print $scores{5};
print "\n";
print $scores{6};
print "\n";
print "--------";
print "\n";
print @a;
print "\n";
print @b;
print "\n";
print @c;
print "\n";
print @d;
print "\n";
print @e;
print "\n";
print @f;
print "\n";



--
--
Daniel G. Drumm - ddrumm@rush.edu
Rush Presbyterian St. Luke's Medical Center - Chicago, IL
Network Division - Information Services


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

Date: 01 Dec 1997 17:12:19 -0500
From: Matthew Rice <Matthew.Rice@ftlsol.com>
Subject: Re: Trimming space
Message-Id: <m3vhx867cs.fsf@hudson.ftlsol.com>

bart.mediamind@tornado.be (Bart Lateur) writes:

> >I want to ask how to trimming left and right space of a string.
> >For example : $str = "   this is a test.      " to "this is a test."
> 
> Easy, but it's a two step process.
> 
> 	$str =~ s/^\s+//;	#trim leading blanks
> 	$str =~s/\s+$//;	#trim trailing blanks
> 
> Note that will not only remove dangling spaces, but also tabs and
> newlines.

I like this one better:
        $str =~ s/^\s+|\s+$//g;

-- 
Matthew Rice                             e-mail: matthew.rice@ftlsol.com


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

Date: Mon, 1 Dec 1997 21:57:38 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Win32::internet
Message-Id: <ebohlmanEKJ6C2.171@netcom.com>

Mark E. Owen <meo@enterprise.net> wrote:

: Is there any web pages about that has some useful examples on how to
: use the Win32::internet (internet.pm) module?

: I'm specifically looking to be able to download various GIF/JPEG files
: from web sites (eg. http://host/foo.jpg)

Actually, your best bet would be to use the LWP::Simple module for this, 
as it will make it absolutely trivial:

use LWP::Simple;
my $url='http://host/foo.jpg';
my $fname='bar.jpg';
getstore($url,$fname);



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

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

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