[7527] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1154 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 9 21:17:55 1997

Date: Thu, 9 Oct 97 18:00:32 -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           Thu, 9 Oct 1997     Volume: 8 Number: 1154

Today's topics:
     Re: #!/usr/bin/perl for NT ??? <dms0603@is2.nyu.edu>
     Re: can Perl do this? (Toutatis)
     Re: Can't open blah, blah, blah (brian d foy)
     Re: Coverting Flatfile *to* Excel <wghhicks@ix.netcom.com>
     Re: Emailing information from a Form which includes Lis <rootbeer@teleport.com>
     Re: glob in web script (brian d foy)
     Help with installation... <lyonsj@bgnet.bgsu.edu>
     Re: Help!  I need to delete multiple lines from an HTML <rootbeer@teleport.com>
     Re: Launch Applications from Macperl (Paul J. Schinder)
     Re: LLama book script (Faust Gertz)
     Re: LLama book script (brian d foy)
     Re: map in void context (was Re: $x = $y || $z - danger (Jahwan Kim)
     Re: mkdir problems <Barry@exclaim.demon.co.uk>
     Oraperl doc for Perl4? (Steve Leibel)
     Re: Out of memory error? <jong@mrc-lmb.cam.ac.uk>
     PERL and Access <chrisw@solarcomm.com>
     PERL and ACCESS <chrisw@solarcomm.com>
     Re: Perl5.003: Is it possible to alter the sort order f (Andrew M. Langmead)
     Posting to a Newsgroup with a Perl Script. <brandons@uidaho.edu>
     Re: Problems with flock <rootbeer@teleport.com>
     Re: Question: File locking <gjlee@uclink4.berkeley.edu>
     Re: Question: File locking (brian d foy)
     Re: Question: File locking <rootbeer@teleport.com>
     range of return values for rand function (Jim Sauer)
     Reading Variable Names from a file peo@sprintmail.com
     Re: regexp: matching at least n chars out of a string o <usenet-tag@qz.little-neck.ny.us>
     Re: regexp: matching at least n chars out of a string o (brian d foy)
     Re: regexp: matching at least n chars out of a string o (brian d foy)
     Re: striphtml <usenet-tag@qz.little-neck.ny.us>
     Win32::FileSecurity module - documentation? (Eric)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 10 Oct 1997 00:03:28 GMT
From: "Dawn Marie Hayes" <dms0603@is2.nyu.edu>
Subject: Re: #!/usr/bin/perl for NT ???
Message-Id: <01bcd50e$ee9c2440$5fed7a80@dawnmarie.nyu.edu>



Authorized User <matthew.kravitz@systecinc.com> wrote in article
<01bcd421$b71ef580$7cfce59b@matthewk.systecinc.com>...
> i know how to declare a perl script in unix, but how is this accomplished
> in NT? 
> i wanted to avoid typing  'perl <script_name> .

Associate the extension of the perl scripts (usually *.pl) with the perl
interperter. This can be done in File Manager in NT 3.51 or by double
clicking on a *.pl file in NT 4.0 and then browsing to the perl interp. EXE
in the resulting dialog.

HTH,

Joe Hayes


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

Date: 9 Oct 1997 23:39:35 GMT
From: toutatis@_SPAMTRAP_toutatis.net (Toutatis)
Subject: Re: can Perl do this?
Message-Id: <toutatis-ya023180001010970139310001@news.euro.net>

In article <343D67AE.41F9@wwdg.com>, Chris Kahrhoff <cck@wwdg.com> wrote:

> I'm am to learn perl in order to write a program that will collect data
> from a syslog of a terminal server and make a report of that data,
> including duration of connection, name of connection, etc.  Will perl do
> this?  How would I go about writing this program?  Does a similar
> program already exist?  Thanks for any help you can give me.  I prefer
> email responses.
> Chris Kahrhoff

Yes, Perl is the perfect tool for what you want. Now you just have to learn
it. It wouldn't hurt you. Being able to speak perl is treasure. And
O'Reilly will be your friend. :-]

-- 
Toutatis


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

Date: Thu, 09 Oct 1997 19:34:29 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Can't open blah, blah, blah
Message-Id: <comdog-ya02408000R0910971934290001@news.panix.com>

In article <01bcd5c0$f7d80da0$21653cd1@200cyrix.thegrid.net>, "Justin White" <whitek@thegrid.net> wrote:

>I'm a beginning CGI Scripter at an ISP and am having problems saving to a
>file.  I have a form that users fill out and submit.  When submitted, I
>told the perl script to send a few form variables ex.($FORM{'$name'}) to a
>couple of email boxes and some variables to a file, delimited by tildes
>(~).  All the mail stuff works fine, but when I try to print to the file on
>the BSDI server, I read in the error log - reason: Premature end of script
>headers.  Please tell me what this means.

"Premature end of script headers" means something came out of your
script before the HTTP headers did.  some error logs will include this
output in the error log directly above the server error message.

from your subject line i'm guessing that you tried to open a file for
writing and that the open was unsuccessful - probably because the
script process UID didn't have write permission to where it was trying to 
write.  at some point the script complained about this - hence the 
"Premature end of script headers".

are you by chance using die() in your script?  there have been recent
threads about how to recover gracefully from fatals in a CGI script, so
you might want to check DejaNews[1] for the subject "Die and the Web" in
this newsgroup.

good luck :)

[1]
<URL:http://www.dejanews.com>

-- 
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: Thu, 09 Oct 1997 23:06:43 -0400
From: Jerry Hicks <wghhicks@ix.netcom.com>
To: tim@pbisweb.com
Subject: Re: Coverting Flatfile *to* Excel
Message-Id: <343D9BC3.51ADF654@ix.netcom.com>

Timothy Lux wrote:
> 
> Hi:
> 
> Ive read the posts on how to get an Excel document into a flatfile database
> (simple way is to save it as a comma-delimited text file within Excel)... but
> I need to go the other way. I have a flatfile database where the 'admin' user
> can choose to convert the data to an Excel document. I can get the data to any
> format I need, but is the solution to:
>         1 - convert the data to comma delimited
>         2 - open Excel
>         3 - open the file
> 
> I don't want the user to have to do anything special... is there a way to open
> Excel and the file all from PERL?  Or would the solution be to send the comma
> delimited file via email, and hope they know how to do it from that point on?
> 
> Thanks in advance--
> 
> Tim

Win32::OLE is your friend


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

Date: Thu, 9 Oct 1997 17:48:40 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Gerrard Leach <grleach@achilles.net>
Subject: Re: Emailing information from a Form which includes List Boxes
Message-Id: <Pine.GSO.3.96.971009174630.5084F-100000@usertest.teleport.com>

On Thu, 9 Oct 1997, Gerrard Leach wrote:

>     # get the name/value pair strings
>     ($name, $value) = split(/=/, $contents);

You should really use a module like CGI.pm to do this for you. Not only
will that be easier...

>     # translate "+" to a space
>     $value =~ tr/+/ /;
> 
>     # decipher ASCI hexidecimal escaped characters, if any
>     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>     
>     # Associate key and value
>     #$contents{$name} .= "\0" if (defined($contents{$name})); # \0 is
> the multiple separator
>     #$contents{$name} .= $value;

 ...It'll also be correct. :-)

> in the case of scrollable boxes in which you can select multiple
> objects, I am unable to do get all the selections. 

CGI.pm will do that correctly as well. Good luck with it!

-- 
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: Thu, 09 Oct 1997 19:17:43 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: glob in web script
Message-Id: <comdog-ya02408000R0910971917430001@news.panix.com>

In article <343D4672.66EF@net1plus.com>, Mordkoff@ACM.org wrote:

>I have a web script (I guess it's a CGI script) that I just added a glob
>command to. It still works when I run it from the command line, but the
>glob fails (returns no filenames) when my web server runs it for me.

is the current working directory of the script what you think it is? 
remember that running it from the web server gives it a different
environment.  when the script needs to be in a certain directory,
affirmatively change the current working directory or use absolute
paths.

good luck :)

-- 
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: Thu, 9 Oct 1997 19:33:56 -0400
From: Jen Lyons <lyonsj@bgnet.bgsu.edu>
Subject: Help with installation...
Message-Id: <Pine.SGI.3.95.971009192759.6260B-100000@sigma.bgsu.edu>


I'm trying to install Perl 5.004_01 on a Linux machine (v2.1.42), but when
I run
sh Configure -Dcc=gcc
and it works fine, until I get to where it asks about cc.  The location of
gcc is /usr/bin/gcc, but it says "Whoa there!   Your gcc doesn't seem to
be working properly!  Let me know where it is!" and then stops.  I don't
have any library files; would this make a difference?

Thanks for your help
Jen Lyons
frustrated...

*********************************************************************
"The impossible often has a kind of integrity to it which the merely
 improbable lacks."
				--Douglas Adams
*********************************************************************



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

Date: Thu, 9 Oct 1997 17:45:36 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Robert Hahn <rwhahn@idirect.com>
Subject: Re: Help!  I need to delete multiple lines from an HTML page
Message-Id: <Pine.GSO.3.96.971009173613.5084E-100000@usertest.teleport.com>

On Thu, 9 Oct 1997, Robert Hahn wrote:

> I'm rather new at Perl, so I hope someone can help me.  I need to write
> a script that delets multiple lines from an HTML page. 

Make a script that deletes multiple lines from a text file, then use it on
your HTML file. :-)

> 1) given that the block of lines I want to delete are preceeded and
> followed by an identical comment: 
> 
> <HTML>
> ...
> <!--myComment.right.here and maybe a # will be found in here too-->
> ...
> <!--myComment.right.here and maybe a # will be found in here too-->
> ...
> </HTML>
> 
> 2) that a string value is passed to the perl script from an HTML form:
> 
> ...variable=<!--myComment.right.here-->&...
> 
> Why would this code not work?  

> # Get the input
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

Use CGI.pm, which will not only do this for you...

> # Split the name-value pairs
> @pairs = split(/&/, $buffer);
> 
> foreach $pair (@pairs) {
>    ($name, $value) = split(/=/, $pair);
> 
>    # Un-Webify plus signs and %-encoding
> 	$value =~ tr/+/ /;
> 	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> 	$value =~ s/(\W)/\\$1/g;
> 
>    $FORM{$name} = $value;
> }

It'll do it correctly. :-)

> # Begin the Editing of the Resale File
> open (FILE,"$resalereal") || die "Can't Open $resalereal: $!\n";
> @LINES=<FILE>;
> close(FILE);

Do you know what happens if more than one process tries to edit your
file at the same time? That could be bad. You should open for update, then
use flock.

> $SIZE=@LINES;

Why the ALL CAPS?

> $PVAL = "$FORM{address}";

The double quotes are merely misleading.

> # Open File for deleting a listing
> open (RESALE,">$resalereal") || die "Can't Open $resalereal: $!\n";
> 
> for ($i=0;$i<=$SIZE;$i++) {
>    $_=$LINES[$i];

This is better done in Perl like this:

    for (@LINES) {

>    if (/$PVAL.*?$PVAL/s) { 

$PVAL came from a form blank. If it has regexp metacharacters, it probably
won't do what you want. In fact, it might crash your script! Maybe you
want \Q in there, but I'm not sure. Why is it twice? Do you expect that
whatever it matches will appear twice on one line? If it is the string
'<!--myComment.right.here-->', the dots are metacharacters - but it's not
going to match the lines you quoted. 

> I've tried many things, but either I get no result (as per the perl code
> above) or I wipe the entire file.

You can use CGI.pm (or something similar) to help you write and debug your
script. With the Perl debugger, you can step through it and see what it's
doing.

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.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Thu, 09 Oct 1997 20:15:23 -0400
From: schinder@leprss.gsfc.nasa.gov (Paul J. Schinder)
Subject: Re: Launch Applications from Macperl
Message-Id: <schinder-0910972015240001@schinder.clark.net>

In article <343C63EA.3158@cinci.infi.net>, cmuth@enquirer.com wrote:

}  Hello,
}  
}  It would be greatly appreciated if someone could tell me how to simply
}  launch an application from MacPerl.  I tried:
}  
}          open(AFILE,"| ".$OpenThisFile) || die "couldn't do it";

Unless you're using the MPW tool and Toolserver, this doesn't have a
chance in hell of working.  Pipes don't work under MacOS.

The easiest way to launch another application is by using AppleScript:

MacPerl::DoAppleScript(<<END);
launch application "foobar"
END

}  
}  Running this (with a valid path name) gave no error (not even my
}  "couldn't do it" thing), but did nothing.
}  Also, I would love to know how to get MacPerl to quit after it is done
}  running a script.

At the beginning of your script, insert a "MacPerl::Quit(2);".  This sets
a flag that tells MacPerl to quit when your script reaches a real or
implied "exit".

You could find all of this out simply by using the MacPerl "Help" or "?"
menu (depending on which MacOS you're using).


}  If you have any ideas, please email me at cmuth@enquirer.com.
}  Thanks a lot.

-- 
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693, Greenbelt, MD 20771
schinder@leprss.gsfc.nasa.gov


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

Date: Thu, 09 Oct 1997 22:37:13 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: LLama book script
Message-Id: <343d57c9.453350@news.wwa.com>

On Thu, 09 Oct 1997 21:09:46 GMT, amacater@galactic.demon.co.uk
(Andrew Martin Adrian Cater [Andy]) wrote:

>Still having trouble with this one from page 10 of LLama book (2nd. ed).
>
>Here is the entire script

[snip]

>	$secretword = $words($name);	

should still be

	$secretword = $words{$name};	

There is a world of different between '(' and '{'.  Not to mention the
world of difference between ')' and '}'.  I know they look similar,
but the one you want to use has a little noise.  :-}  

>I don't understand it - it's so simple.

It is and it isn't.  :-)  It is for those of us who have read and
understood the chapter on hashes.  It isn't for you 'cause you don't
know enough to avoid those kinds of errors.  Hang in there.  If you
just can't get it to work, move on to the other chapters and go back
to it when you think you have discovered your error.


HTH

Faust Gertz
Philosopher at Large

"I wouldn't want to live in a world that had seen my genitalia.
You've got no trump card." -- Janeane Garofalo, on turning down a role
that required nudity. 


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

Date: Thu, 09 Oct 1997 19:43:38 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: LLama book script
Message-Id: <comdog-ya02408000R0910971943380001@news.panix.com>

In article <876431386.17553.0.nnrp-05.9e983fd9@news.demon.co.uk>, amacater@galactic.demon.co.uk (Andrew Martin Adrian Cater [Andy]) wrote:

>Still having trouble with this one from page 10 of LLama book (2nd. ed).
>
>Here is the entire script


>        $secretword = $words($name);    

you have the same error as before - those parentheses should be
curly braces like they are in the book.  sometimes the typography
obscures the difference, but if you look closely you'll se it as

   $secretword = $words{$name};

good luck :)

-- 
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: 9 Oct 1997 22:09:49 GMT
From: jahwan@supernova.math.lsa.umich.edu (Jahwan Kim)
Subject: Re: map in void context (was Re: $x = $y || $z - dangerous assumption?)
Message-Id: <slrn63qlhd.sl5.jahwan@supernova.math.lsa.umich.edu>

On 9 Oct 1997 17:57:48 GMT, Terry Michael Fletcher 
    - PCD ~ <tfletche@pcocd2.intel.com> wrote:
[snip]
> the innner map or for loop were remarkably the same.  this realization is
> explained by randal in that the C<for> loop has to dynamically create the
> variable $i, which takes a little overhead that the map doesnt have to do,
> and C<map> is only returning a one-value reference.  this block of code
> was executed in my script for every line of the file (about 2000!), which
> is a lot of local $i's.
[snip]

    You mean your program ended already after two thousand factorial lines?
:)

(sorry, couldn't resist)
Jahwan


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

Date: Thu, 09 Oct 1997 23:07:15 GMT
From: "Barry Neville" <Barry@exclaim.demon.co.uk>
Subject: Re: mkdir problems
Message-Id: <01bcd508$48a29340$7f6fdec2@exclaim.demon.co.uk>

Barry Neville <Barry@exclaim.demon.co.uk> wrote in article
<01bcd43b$0876e5a0$7f6fdec2@exclaim.demon.co.uk>...
> I'm getting some crazy results from the Perl mkdir function running on a
> Solaris 2.5 machine. The resulting permissions I'm getting seem almost
> random. Can anyone shed some light?
> 
> Thanks.
> 

Yup, lead 0 was my problem - strange one! Thanks to all.


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

Date: Thu, 09 Oct 1997 19:07:03 GMT
From: stevel@coastside.net (Steve Leibel)
Subject: Oraperl doc for Perl4?
Message-Id: <343d2abd.2980354@snews.zippo.com>

Hello,

Can anyone tell me where to find Oraperl documentation for Perl4?

email preferred, thanks much.

Steve Leibel
stevel@eci.net


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

Date: Fri, 10 Oct 1997 01:50:00 +0100
From: Jong <jong@mrc-lmb.cam.ac.uk>
To: brian shields <Brian_shields.0192063@nt.com>
Subject: Re: Out of memory error?
Message-Id: <343D7BB8.41C6@mrc-lmb.cam.ac.uk>

brian shields wrote:
> 
> Greetings,

Hi,

I ususally fill up our 1 GB memory 500mhz Dec Alpha
machine in the lab with a program which can use
only 10mb memory.

This happens when I use hashes without using
local or my (this means, I continuously
add keys and values making huge hashes while
I have to reset at a regular interval.)

The other way to do this is when it is not
easy to reset with local or my. I often
use soft reference and sometimes it is
difficult to restrict with my etc.

eg)  ${"hash_name"}{"$key"}=$value;

As the hash name changes continously, you can
create very large number of hashes etc.

Anyway, my guess is you are not restricting
your hashes or arrays. If you say push(@array, xx);
and do not dump @array at the right place, you
will get too big an array.

jong
>    I am running Perl version 5.001 on an HP-UX 712 9.05.  I am running a
> program to create an associative array of our internal e-mail
> addresses.  The array is keyed by employee id and it constructs a list
> for each id (dept number, first name, last name, and e-mail address).  I
> have set it up to have no more than 2 iterations of the e-mail address
> per employee (an employee can have more than one e-mail address).  The
> program runs out of memory.  I estimate there are about 60K records to
> be produced.  What I do not understand is why so much memory is used
> when the source file is only 1.5 MB?  My program is using a small
> portion of each record in this file(perhaps about 80 bytes of
> information).  Using the HP command 'top' to monitor memory usage, I can
> see the program went from initially using about 1 MB of memory to 80MB
> before it finally failed.  My system has 128MB RAM.  I would expect an
> internal file of less than 5 MB to be created.  So why is so much memory
> being consumed?  I am not running anything else at the same time either
> which would consume all available memory.  I would sure appreciate any
> suggestions on making full use of available memory without wasting it
> all somehow.  Any ideas?
> 
> Sincerely,
> 
> Brian

-- 
         #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
         #  Jong <-- My name.   Structural Studies,     #
         #  LMB, MRC Centre, Hills Road, Camb, CB22QH,  #
         #  UK, Tel: +44 01223 402479 (Lab)             #
         #  Email: jong@mrc-lmb.cam.ac.uk,              #
         #  http://www.mrc-lmb.cam.ac.uk/genomes        #
         #______________________________________________#


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

Date: Thu, 09 Oct 1997 17:29:26 -0500
From: Chris Wicklas <chrisw@solarcomm.com>
Subject: PERL and Access
Message-Id: <343D5AB8.2776@solarcomm.com>

Hi guys-

I'm stuck.  I'm just learning PERL and have a question.  The script that
I am using writes gathered information (ie. name, address, etc.) to a
pipe delimited ASCII text file.  I'm using Microsoft Access to read and
sort my text file into a database. 

The problem comes when I try to import this text file into Access. For
some reason, Access isn't recognizing the \n operator as a line break to
move on to the next entry.  I also tried using the \r operator as well
as the \r\n operators together.  No Dice!  The file imports fine into
Excel, but I can't use this file for two reasons: 1. Excel only allows
for 255 characters per cell; and 2. The guy that I'm doing this for
already has an existing database that is done in Access.

I'm not sure if this is a scripting problem on my part or if I'm just
missing something with Access. Does anybody out there have any ideas for
a fix or even a work-around? Any help that anybody could give me would
be greatly appreciated.

Thanks in advance-
Chris


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

Date: Thu, 09 Oct 1997 17:17:08 -0500
From: Chris Wicklas <chrisw@solarcomm.com>
Subject: PERL and ACCESS
Message-Id: <343D57D6.1E13@solarcomm.com>

Hi guys-

I'm stuck.  I'm just learning PERL and have a question.  The script that
I am using writes gathered information (ie. name, address, etc.) to a
pipe delimited ASCII text file.  I'm using Microsoft Access to read and
sort my text file into a database. 

The problem comes when I try to import this text file into Access. For
some reason, Access isn't recognizing the \n operator as a line break to
move on to the next entry.  I also tried using the \r operator as well
as the \r\n operators together.  No Dice!  The file imports fine into
Excel, but I can't use this file for two reasons: 1. Excel only allows
for 255 characters per cell; and 2. The guy that I'm doing this for
already has an existing database that is done in Access.

I'm not sure if this is a scripting problem on my part or if I'm just
missing something with Access. Does anybody out there have any ideas for
a fix or even a work-around? Any help that anybody could give me would
be greatly appreciated.

Thanks in advance-
Chris


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

Date: Thu, 9 Oct 1997 22:11:37 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Perl5.003: Is it possible to alter the sort order for a single sort?
Message-Id: <EHt1nD.HLK@world.std.com>

hunngai@fast.net (Gail Hunn) writes:
>I have a flat text file of some 350 records, each with 9 fields
>delimited by vertical bars.  The data in the fields is all uppercase.

>I want to sort on fields 0, 3, and 7.  So far so good.  However, the
>presence of empty fields seems to inject a certain amount of
>randomness into the output.  

I don't quite understand, a blank field should have a consistent sort
order. It is before any characters. I mean, when I say:

 perl -ne 'print "" cmp $_, "\n"' /usr/dict/words | less

I keep on getting "-1". (until I get bored and hit "q")

>I tried to remedy this by inserting a punctuation character into the
>empty fields (for example, a period or question mark).  However, the
>default sort order appears to place punctuation ahead of uppercase
>letters.  The question marks show up first, then all of the
>data-filled fields come up, in correct order, at the end.

Since all the comparison subroutine does is return -1,0, or 1 for less
than, equal to or greater than, you can do what you want to make the
determination of what "less","equal" or "greater" mean. 

OK, lets assume that your sorting by fields in the manner shown in the
FAQ. 

while(<>) {
  @field = split /\|/;
  push @primary, $field[0];
  push @secondary, $field[3];
  push @ternery, $field[7];
  push @record, $_;
}

print @record[ sort by_fields 0 .. $#record ];

If you want the blanks to appear after non-blanks, just test for them
explicitly.

sub by_fields {
  cmp_blanks_last($primary[$a],$primary[$b]) ||
  cmp_blanks_last($secondary[$a],$secondary[$b]) ||
  cmp_blanks_last($ternery[$a],$ternery[$b]);
}

sub cmp_blanks_last {
  my ($left,$right) = @_;
  # if either left or right is blank, it is sorted after the non-blank
  return 1 if $left eq '' and $right ne '';
  return -1 if $left ne '' and $right eq '';
  # otherwise, do the default comparison.
  return $left cmp $right;
}
-- 
Andrew Langmead


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

Date: Thu, 09 Oct 1997 16:56:21 -0700
From: Brandon Stirling <brandons@uidaho.edu>
Subject: Posting to a Newsgroup with a Perl Script.
Message-Id: <343D6F25.E875123D@uidaho.edu>

Posting to a Newsgroup with a Perl Script.

This should be an easy task, but I can only find a method to read
Newsgroups with a perl script.

Can anyone in Perl land give me a starting point for this process?

 
-- 
Brandon Stirling
Web Technologists
Computer Services
University of Idaho


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

Date: Thu, 9 Oct 1997 17:35:49 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Xavier Tarafa Mercader <xavi@teclata.es>
Subject: Re: Problems with flock
Message-Id: <Pine.GSO.3.96.971009173219.5084D-100000@usertest.teleport.com>

On Thu, 9 Oct 1997, Xavier Tarafa Mercader wrote:

> #Close table
> if(!close(TABLE)){
>         print STDERR "Could not close Table: $table_content file";
>         exit(0);
> }
> 
> #unlock table
> $valor=flock(TABLE,$LOCK_UN);

Closing the file automatically releases the lock, so unlocking isn't
needed. Just close, and everything will work. (Don't release the lock,
ever, unless you know enough to break this rule. :-)

In fact, the more common way to do what you've done with close looks
something like this. 

    close TABLE
	or die "Could not close Table: $table_content file: $!";

That's easier to write and read. Also, it puts a diagnostic message (like
"no more room on device", perhaps) into the message. It also exits with a
non-zero status. Hope this helps! 

-- 
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: Thu, 09 Oct 1997 15:46:42 -0700
From: "George J. Lee" <gjlee@uclink4.berkeley.edu>
Subject: Re: Question: File locking
Message-Id: <343D5ED2.D9BEAA3A@uclink4.berkeley.edu>

Tad McClellan wrote:

[snip]
 
> Anyway, questions concerning locking in Perl FAQ, part 5:
> 
>    "How can I lock a file?"
> 
>    "What can't I just open(FH, ">file.lock")?"
> 
>    "I still don't get locking.  I just want to increment
>     the number in the file.  How can I do this?"
> 
> Boy! That last one sounds just like what you described...
> 
> It gives code for doing that. One of the comments in there says:

[snip]

> Please read the newsgroup where you asked the question.

Sorry about that, and thanks for your reply. I guess I didn't state my
problem clearly enough. I am not actually writing to the file I lock; I
am only using it so two programs can't buy at the same time. The
database access has no direct relation to the file I'm locking. In fact,
the lockfile is 0 bytes. My question is: if I lock the file, is it still
possible for two instances to access the buy procedure? The program
still doesn't work right if I click on the submit button rapidly.

Thanks.

George Lee


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

Date: Thu, 09 Oct 1997 20:01:45 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Question: File locking
Message-Id: <comdog-ya02408000R0910972001450001@news.panix.com>

In article <343D5ED2.D9BEAA3A@uclink4.berkeley.edu>, "George J. Lee" <gjlee@uclink4.berkeley.edu> wrote:

>Tad McClellan wrote:

>> Anyway, questions concerning locking in Perl FAQ, part 5:
>> 
>>    "How can I lock a file?"
>> 
>>    "What can't I just open(FH, ">file.lock")?"
>> 
>>    "I still don't get locking.  I just want to increment
>>     the number in the file.  How can I do this?"


>Sorry about that, and thanks for your reply. I guess I didn't state my
>problem clearly enough. I am not actually writing to the file I lock; I
>am only using it so two programs can't buy at the same time. The
>database access has no direct relation to the file I'm locking. In fact,
>the lockfile is 0 bytes. My question is: if I lock the file, is it still
>possible for two instances to access the buy procedure? The program
>still doesn't work right if I click on the submit button rapidly.

you might consider writing some unique information to the lockfile so 
that processes can determine if they have the lock - perhaps writing the
PID to the file in your case.  if the process's PID is not in the lockfile,
then it doesn't get to access the buy procedure.  other than that, do as
Tad suggested.

good luck :)

-- 
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>
--code freeze is a terrible thing to waste


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

Date: Thu, 9 Oct 1997 17:53:15 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "George J. Lee" <gjlee@uclink4.berkeley.edu>
Subject: Re: Question: File locking
Message-Id: <Pine.GSO.3.96.971009175049.5084H-100000@usertest.teleport.com>

On Wed, 8 Oct 1997, George J. Lee wrote:

> I need help with file locking. I am designing a web site for investing
> (URL below) and it includes a stock simulation program. It uses a perl
> script as a cgi interface to a msql database to keep track of trades.
> Trouble is, if two people buy stock at precisely the same time, one of
> them won't got the stock because both instances of my perl script assign
> the same id # to it. Also, if one person clicks the submit button for
> the buy form multiple times, they can get more shares than they should
> be able to with their money. 

Good thing it's just a simulation. :-)

> I tried using file locking to prevent two instances from trying to buy
> at the same time, but with no success. I know flock works on the server
> because I have tested it using a test script, but I can still cheat by
> clicking the buy button rapidly. Here as a portion of the relevant code: 
> 
>       open(PURCHASE, ">>$LOCK_FILE")     or die "open $LOCK_FILE: $!\n";
>       flock(PURCHASE, 2);
>       &add_to_the_cart;
>       flock(PURCHASE, 8);
>       exit;

Ah, you're releasing the lock. Don't do that. :-)  If you lock as soon as
you open and close or exit as soon as you're all done, everything should
work for you. (Closing releases the lock, and exiting closes the file, so
you never need to (or should) explicitly release the lock.)

Hope this helps!

-- 
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: Thu, 9 Oct 1997 23:58:53 GMT
From: jim@theaction.com (Jim Sauer)
Subject: range of return values for rand function
Message-Id: <EHt6ws.4w6@nonexistent.com>

According to the camel book :
rand returns a value between 0 and 1 (including 0 and excluding 1).
rand EXPR returns a number between 0 and the value of EXPR.
Is that also (including 0 but excluding the value of EXPR)?
TIA
Jim Sauer
jsauer@adelphia.net



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

Date: Thu, 09 Oct 97 20:04:27
From: peo@sprintmail.com
Subject: Reading Variable Names from a file
Message-Id: <NEWTNews.876442787.32009.peo@eagle>


I have a file that has a list of variable references in it of the form:

MYPATH=$PATH:/HOME/MYDIR
NEWPATH=${MYPATH}

etc.

What I want to do is read in the file and process each line picking out all
the variable references (both types $VAR and ${VAR}) without having the
variables interpolated and after performing my own substitution on the
variable place them back into the string.  The problem I am having is pulling
the variable names out of the read line.  Is there an easy way of doing
this?

Thanks,
Paul Orman
peo@sprintmail.com



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

Date: 9 Oct 1997 22:22:30 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: regexp: matching at least n chars out of a string of length m
Message-Id: <eli$9710091814@qz.little-neck.ny.us>

Posted and mailed.

 <gtuckerkellogg@genetics.com> wrote:
> I have	a collection of strings which contain many occurances of the
> character ':'.	I'd like to know, for each string, all the substrings of
> length $window than contain $want colons.

You have tabs in the middle of your text. It looked fine until the
newsreader quoted it, thus pushing text to the next tabstop.

>   for (i=0;i<length($string)-$window; $i++) {
>     my $substring = substr($string,$i,$window);
>     if ($substring =~ /some_magical_regexp/) {

      if ( ($substring =~ tr/:/:/) >= $want ) {

> #            stuff the results into $result;
>             substr($result,$i,1) = "1";
>     }
> 
> but I can't seem to figure out the right regexp.  Am I barking up the
> wrong tree?

Don't use a regexp. I'm not an expert in perl efficiency issues (I've
got plenty of CPU time to burn for my tasks) but your looping looks 
inefficient. You might want to consider some other technique. 

Elijah
------
prechecking for zero colons in the whole thing might be useful


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

Date: Thu, 09 Oct 1997 19:15:47 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: regexp: matching at least n chars out of a string of length m
Message-Id: <comdog-ya02408000R0910971915470001@news.panix.com>

In article <eli$9710091814@qz.little-neck.ny.us>, Eli the Bearded <usenet-tag@qz.little-neck.ny.us> wrote:

>Elijah
>------
>prechecking for zero colons in the whole thing might be useful

i knew i was missing something - my script should have checked the 
portion of the string left after moving the window to see if there
were enough colons for a possible match.  this could save loads of
time in long strings but maybe increase the time for shorter string.

i had to read this after i sent mine :(

-- 
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>
--still wondering about alt.fan.e-t-b


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

Date: Thu, 09 Oct 1997 19:11:04 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: regexp: matching at least n chars out of a string of length m
Message-Id: <comdog-ya02408000R0910971911040001@news.panix.com>

In article <876416222.32513@dejanews.com>, gtuckerkellogg@genetics.com wrote:

>I have  a collection of strings which contain many occurances of the
>character ':'.  I'd like to know, for each string, all the substrings of
>length $window than contain $want colons.

i think i understand this problem, so let me explain it back to you and
you tell me if i got it wrong:  for a substring of length N, find all
substrings that have *at least* M :'s, but perhaps more.  the : can be 
anywhere in the substring.  the substring has to be of length N - it
can't be shorter or longer.

(i hope that is right)

given that, and knowing that using matching operators will be horribly
inefficient, i propose a solution which i think is close to linear in
length of the substring (my suspicion is that it is a little less than
linear for most cases).

the philosophy of the algorithm is to start at the beginning of the
string and check the substring of length N for the right number of
occurances of :.  if the right number are there, remember the offset
for that substring, then move the window along and check again, and
so on.

i haven't tested this extensively, so there might be quirks, but i
need to get back to the work i'm getting paid to do :)

#!/usr/bin/perl

#forgive me, i'm not a computer scientist...

my $string = 'asdF:asdf:safg:sg:saf:fsad::sfg:sdgfsdfg:::sdfg:sdfg:sfd';

my $window_size   = 15;
my $number_needed = 5;
my $offset        = 0;
my $length        = length $string;

while( ($length - $offset) >= $window_size )
   {  
   $current_window = substr($string, $offset, $window_size);
   
   $number_found = ($current_window =~ tr/:/:/);
   
   #if we found less than we needed, we can move the window
   #ahead by the number of extra finds needed since the intervening
   #substrings won't match.  e.g. if we found M-2, moving
   #the window one place will match *at most* M-1, so go ahead
   #and skip that one too.
   if( ($difference = ($number_needed - $number_found) ) > 0 )
      {
      $offset += $difference;
      }
   #if we found the exact number that is needed, remember this
   #starting position and advance the window by one place
   elsif( $difference == 0 )
      {
      push @offsets, $offset++;
      }
   #if we found more than that needed, skip ahead to the
   #next place where there might be a possible match
   # e.g. if we found M+2, then we can move the window
   #two places ahead since moving
   #the window by one place will find *at least* M+1, and
   #so on.  we just need to record the offsets
   elsif( $difference < 0 )
      {
      while( $difference < 0 )
         {
         push @offsets, $offset++;
         $difference++;
         }
      }
   }

print "There were $#offsets matches:\n" if scalar @offsets != 1;
print "There was 1 match:\n" if scalar @offsets == 1;

foreach( @offsets )
   {
   print substr($string, $_, $window_size), "\n";
   }
   
__END__

There were 5 matches:
g:sg:saf:fsad::
:sg:saf:fsad::s
:saf:fsad::sfg:
fg:::sdfg:sdfg:
g:::sdfg:sdfg:s
:::sdfg:sdfg:sf

-- 
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: 9 Oct 1997 22:28:57 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: striphtml
Message-Id: <eli$9710091821@qz.little-neck.ny.us>

In article <876419479.3983@dejanews.com>,  <gmichel@nais.com> wrote:
> s{<([^>'"]*|".*?"|'.*?')+>}{}gsx;
> 
> Specifically, the "+" appears to cause an error.  Anyone see similar
> behavior?

I'd guess that changing the first * to a + would fix things:

	s{<([^>'"]+|".*?"|'.*?')+>}{}gsx;

But that may introduce some subtle stripping problem. You might want
to s/<>//g immediately after it.

Elijah
------
just came up with a much different strip html solution for the procmail list


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

Date: Thu, 09 Oct 1997 22:41:05 GMT
From: eric@intiman.org_nospam (Eric)
Subject: Win32::FileSecurity module - documentation?
Message-Id: <343d5b8b.19215561@intXnt>

I was just getting build 310 of the Win32 version of Perl set up.  In the
update documentation it mentions a module FileSecurity that I can't find
anything for online or the docs that came with Perl.

Anyone have any idea how it works?  I could really use a module that can
change a directory or file permissions to write only.  So far the only way I
have come accross in NT 3.51 is with the file manager.

Cacls is the closest way I know of from the command line.  And even it will
not allow me to set the write access only.

Advise?  Thanks!


eric@intiman.org_nospam
Eric Kylstra
Computer Coordinator
Intiman Theatre

I have the nospam on the end of my email address for the obvious reason.
Remove it to email me directly.


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

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

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