[12392] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5992 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 14 16:07:19 1999

Date: Mon, 14 Jun 99 13:00:21 -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           Mon, 14 Jun 1999     Volume: 8 Number: 5992

Today's topics:
    Re: a thread on threads <uri@sysarch.com>
    Re: a thread on threads <gbartels@xli.com>
    Re: can i variably name an array? (Greg Bacon)
        can't send large-ish udp packets? <nmarino@home.com>
        examples <hernal@champint.com>
        Extracting PIDs from a 'ps aux' <jjones@paracom.com>
        file read olmert@netvision.net.il
    Re: file rename script for WinNT (Jerome O'Neil)
    Re: file rename script for WinNT <mike@buckeye.shs.ohio-state.edu>
    Re: file rename script for WinNT <mike@buckeye.shs.ohio-state.edu>
        Find and replace in a file within a while loop ramverma@my-deja.com
    Re: Find and replace in a file within a while loop <craig@mathworks.com>
    Re: Form Redirection <davidf@gaylordusa.com>
        how do I get the total space used in a directory <robrien99@yahoo.com>
    Re: Linus Torvalds and Carmen Electra? (Greg Bacon)
    Re: perl cgi and apache <rdsys@inficad.com>
    Re: Perl class and constructor (Andrew Allen)
        Sorting Arrays of Arrays, Thanks! (Completed script inc (Marc Bissonnette)
    Re: Verifying date data (Andrew Allen)
    Re: Which .gz file to download for Net::Cmd.pm ? (Andrew Allen)
    Re: Which .gz file to download for Net::Cmd.pm ? (Andrew Allen)
    Re: Which .gz file to download for Net::Cmd.pm ? <cassell@mail.cor.epa.gov>
    Re: Which .gz file to download for Net::Cmd.pm ? (I R A Aggie)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 14 Jun 1999 15:01:55 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: a thread on threads
Message-Id: <x7ogiihaho.fsf@home.sysarch.com>

>>>>> "GB" == Greg Bartels <gbartels@xli.com> writes:

  GB> the module simulates parallel hardware components in perl.
  GB> it does so by describing each component as a subroutine.
  GB> all the neccessary subroutines are scheduled to be executed 
  GB> at a given "simulation time". 

  GB> the only way I can think of doing this is that every subroutine 
  GB> is executed in a separate thread. when a Delay(n) is encountered, 
  GB> that thread stops, and schedules itself to continue at a later 
  GB> time. All data is shared between threads, since in this 
  GB> application, they are, by design, guaranteed not to step on one 
  GB> another.

this can be done in forked processes very easily. as tom has said,
threads are overhyped and prone to bugginess. forks are simpler and just
require some clear thinking about the IPC. 

  GB> all I need, basically, is a means to stop and start execution of
  GB> a subroutine call. and this will be handled by the scheduler
  GB> whenever a Delay(n) is called. Delay(n) will cause its own thread 
  GB> to stop, and schedule the thread to restart at some point in the 
  GB> future, restarting whereever it left off.

just have a master parent process which controls scheduling communicate
with all the parallel children. when a child needs to delay, it sends a
message to the parent and waits for a reply. the child is just a
read message/process/write message loop. the parent keeps track of the
children and who is running/delayed. the IPC needs to be designed to
handle the messages that trigger various subs in the children. that can
be done with pipes, shared memory and sempahores, signals, etc. you
might even be able to use RPC if all you want is a call and reply
method, but i like to roll my own so i get finer control over what
happens. the parent will need to use some form of 4 arg select to manage
multiple pipes and children but that is not difficult.

threads are never needed, only desired by those who think they are a
winner. redmond has pushed more threads onto the world by making fork
disappear and all the kiddies think that is the only way to do it
now. having a separate data space is usually a win and it requires you
you to make a better IPC than you would with threads. also multiple
processes (not necessarily forked) scale over multiple boxes (think
seti, des cracking, etc.) whereas threads don't.

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Mon, 14 Jun 1999 14:34:18 -0400
From: Greg Bartels <gbartels@xli.com>
Subject: Re: a thread on threads
Message-Id: <37654B2A.7EEC8755@xli.com>

the requirements are:

1) simultaneous subroutine execution control
(multiple subroutines executing at same time
 and being able to start stop subroutines via subroutine call.)

2) completely shared data
(all threads uses exactly the same data space)

3) low overhead, I'll be doing lots of forking or threading,
	or whatever I end up using.

4) win32 compatibility would be nice, since half the machines
here at work run NT. Not my decision, but I'm stuck with it.

an example would be:

# shared data
my $a;

sub first_sub
{
	$string .= "Abott";
	MySleep(5);
	$string .= "costello \n";
}

sub second_sub
{
	MySleep(1);	#make sure first_sub actually goes first
	$string .= " and ";
	MySleep(20);
	print $a ;
}


$a = '';
Schedule(\&first_sub, 'now');
Schedule(\&second_sub, 'now');
EventHandler();	# executes all schedule events, 
	# wont return until all events are finished.

#####################

Schedule causes a fork or a process or a thread to be created
	It sets up the thread to call the subroutine 
	but nothing is executed.

EventHandler causes all processes to execute.

MySleep causes its process to stop execution and schedule
	restart at some point  in the future.


I dont know how to do this with fork in a clean manner.
I also read that fork has a lot of overhead, and I'll 
be doing a _LOT_ of forking for a hardware simulator.
every piece of hardware will simulate with its own process.

All I need is execution control, all the data is shared.

threads were supposed to be "lightweight" which implied
low overhead, so I can have a lot of threads without sucking
up resources, etc.

Greg


Uri Guttman wrote:
> 
> >>>>> "GB" == Greg Bartels <gbartels@xli.com> writes:
> 
>   GB> the module simulates parallel hardware components in perl.
>   GB> it does so by describing each component as a subroutine.
>   GB> all the neccessary subroutines are scheduled to be executed
>   GB> at a given "simulation time".
> 
>   GB> the only way I can think of doing this is that every subroutine
>   GB> is executed in a separate thread. when a Delay(n) is encountered,
>   GB> that thread stops, and schedules itself to continue at a later
>   GB> time. All data is shared between threads, since in this
>   GB> application, they are, by design, guaranteed not to step on one
>   GB> another.
> 
> this can be done in forked processes very easily. as tom has said,
> threads are overhyped and prone to bugginess. forks are simpler and just
> require some clear thinking about the IPC.
> 
>   GB> all I need, basically, is a means to stop and start execution of
>   GB> a subroutine call. and this will be handled by the scheduler
>   GB> whenever a Delay(n) is called. Delay(n) will cause its own thread
>   GB> to stop, and schedule the thread to restart at some point in the
>   GB> future, restarting whereever it left off.
> 
> just have a master parent process which controls scheduling communicate
> with all the parallel children. when a child needs to delay, it sends a
> message to the parent and waits for a reply. the child is just a
> read message/process/write message loop. the parent keeps track of the
> children and who is running/delayed. the IPC needs to be designed to
> handle the messages that trigger various subs in the children. that can
> be done with pipes, shared memory and sempahores, signals, etc. you
> might even be able to use RPC if all you want is a call and reply
> method, but i like to roll my own so i get finer control over what
> happens. the parent will need to use some form of 4 arg select to manage
> multiple pipes and children but that is not difficult.
> 
> threads are never needed, only desired by those who think they are a
> winner. redmond has pushed more threads onto the world by making fork
> disappear and all the kiddies think that is the only way to do it
> now. having a separate data space is usually a win and it requires you
> you to make a better IPC than you would with threads. also multiple
> processes (not necessarily forked) scale over multiple boxes (think
> seti, des cracking, etc.) whereas threads don't.
> 
> uri
> 
> --
> Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
> uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
> Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
> The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 14 Jun 1999 19:15:29 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: can i variably name an array?
Message-Id: <7k3kch$h1i$6@info2.uah.edu>

In article <375f8211.1380814@news.skynet.be>,
	bart.lateur@skynet.be (Bart Lateur) writes:
: Tom Christiansen wrote:
: >Script kiddies don't have real programming backgrounds.
: 
: So programming in Perl isn't "real" programming?

You're affirming the consequent.

Greg
-- 
I prefer dark chocolate, especially with nuts, but that doesn't mean I should
legislate that you have to eat it. 
    -- Bjarne Stroustrup


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

Date: Mon, 14 Jun 1999 19:50:24 GMT
From: "Nicholas Marino" <nmarino@home.com>
Subject: can't send large-ish udp packets?
Message-Id: <42d93.2471$Mp5.1237@news.rdc1.pa.home.com>

My perl script can't seem to send udp packets beyond a certain size.

For example, in the following code:

        $fpicname = "image.gif";
        open(FPIC, $fpicname);
        binmode(FPIC);
        $bytesread = read(FPIC, $picdata, 8192);
        close(FPIC);
        $rc = send(TTMD, $picdata, 0, $ipaddr);

If image.gif is 648 bytes, the packet is received fine at the other end.
However when I attempt to send a 2236 byte image, the other end
never sees the packet.

I've tried calling setsockopt(SOCK, SOL_SOCK, SO_SNDBUF, 8192)
thinking a larger send buffer might help, but it doesn't.

Is there a limit on UDP packet size? I'm running RedHat Linux, v 5.2.






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

Date: Mon, 14 Jun 1999 14:36:28 -0400
From: "Lucas Hernandez" <hernal@champint.com>
Subject: examples
Message-Id: <7k3hrt$7m1$1@sneezy.strategicit.net>

Is it there an example source of cgi code for windows platform..?
I'm trying to find out how to create a html code able to call a pearl script
under windows platform.. any help or hints will be appreciated.

Lucas




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

Date: Mon, 14 Jun 1999 14:35:41 -0500
From: "John Jones" <jjones@paracom.com>
Subject: Extracting PIDs from a 'ps aux'
Message-Id: <iPc93.167$eW3.649@newsfeed.slurp.net>

I am needing to create a script in UNIX that can be run from a cron job.
What this needs to do is:

    >  ps aux | grep radius

Which should generate this sort of output:

   root     16099  0.0  0.1    404   192   p5  S     9:02AM    0:17.82
radiusd
   root     16101  0.0  1.5  3936 3772  p5  S     9:02AM    0:24.63 radiusd

What I need to do is generate a 'kill -9 XXXXX' command to the command line,
where XXXXX is the pid of the processes running, which in the output is the
second field (16099 and 16101).

I have tried a few approaches, the most recent being something along the
lines of:

   @grep = 'ps aux | grep radius';

   @line1 = $grep[0];
   @line2 = $grep[1];      # these two lines work, verified by a 'print
@line1' and such.

The problem I am running into, is that when using backquotes, multiple line
output is assigned an array as one line per element.  What do I need to do
to then extract the pids (second 'word' in each 'element') into an array
called @pids?

I can then do a:

     > kill 9, @pids;

at the end of the script.


Input, thoughts, and any comments are welcome, although you will have to
remove the NOSPAM string from my email addresses to respond.



John Jones
Systems Administrator
Paracom Technologies/Feist Internet
Wichita, KS

jjones@NOSPAMparacom.com
postmaster@NOSPAMfn.net
postmaster@NOSPAMfeist.com





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

Date: Mon, 14 Jun 1999 18:02:41 GMT
From: olmert@netvision.net.il
Subject: file read
Message-Id: <7k3g3q$v81$1@nnrp1.deja.com>

Hello
Can any body help me with this: I want to create a perl script that
opens a file for reading, prints it's content to the user's screen, and
then timesout for 2 seconds. after two seconds it checks if the file was
updated, and if so- prints the content from the place it stopped the
previous time.
any ideas?
please reply to olmert@netvision.net.il

THANKS!!!


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 14 Jun 1999 18:49:46 GMT
From: jeromeo@atrieva.com (Jerome O'Neil)
To: plemmons.1@osu.edu (Mike Plemmons)
Subject: Re: file rename script for WinNT
Message-Id: <7k3isa$htg$1@brokaw.wa.com>

[Posted and mailed]

In article <plemmons.1-1406991314400001@mac15.shs.ohio-state.edu>,
	plemmons.1@osu.edu (Mike Plemmons) writes:
> to wonder that it is not possible.  I know the script works to the point
> where I can see what file is being looked at.  It seems that the
> rename($was,$_) is not working.
> 

Are you trying to rename accross filesystems?



-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: Mon, 14 Jun 1999 15:11:44 -0400
From: Mike Plemmons <mike@buckeye.shs.ohio-state.edu>
To: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: file rename script for WinNT
Message-Id: <Pine.LNX.4.05.9906141510440.20682-100000@buckeye.shs.ohio-state.edu>

I am not trying to rename across filesystems.  I am running the script on
WinNT Server 4.0 with SP3 and all the files are on the same system.

Thanks,

Mike Plemmons - GO BUCKS!!
(H/W) plemmons.1@osu.edu
(W) mike@buckeye.shs.ohio-state.edu
http://buckeye.shs.ohio-state.edu/~mike

On Mon, 14 Jun 1999, Jerome O'Neil wrote:

> Are you trying to rename accross filesystems?
> 
> -- 
> Jerome O'Neil, Operations and Information Services
> Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
> jeromeo@atrieva.com - Voice:206/749-2947 
> The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com
> 



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

Date: Mon, 14 Jun 1999 15:46:48 -0400
From: Mike Plemmons <mike@buckeye.shs.ohio-state.edu>
To: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: file rename script for WinNT
Message-Id: <Pine.LNX.4.05.9906141545430.20698-100000@buckeye.shs.ohio-state.edu>

I would like to end this post now by saying that I found my problem.  I
was using the internal perl rename function wrong and (stupid me) and I
using = when I should have been using =~ to do regex.

Thanks for the help,

Mike Plemmons - GO BUCKS!!
(H/W) plemmons.1@osu.edu
(W) mike@buckeye.shs.ohio-state.edu
http://buckeye.shs.ohio-state.edu/~mike

On Mon, 14 Jun 1999, Jerome O'Neil wrote:

> [Posted and mailed]
> 
> In article <plemmons.1-1406991314400001@mac15.shs.ohio-state.edu>,
> 	plemmons.1@osu.edu (Mike Plemmons) writes:
> > to wonder that it is not possible.  I know the script works to the point
> > where I can see what file is being looked at.  It seems that the
> > rename($was,$_) is not working.
> > 
> 
> Are you trying to rename accross filesystems?
> 
> 
> 
> -- 
> Jerome O'Neil, Operations and Information Services
> Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
> jeromeo@atrieva.com - Voice:206/749-2947 
> The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com
> 



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

Date: Mon, 14 Jun 1999 17:59:59 GMT
From: ramverma@my-deja.com
Subject: Find and replace in a file within a while loop
Message-Id: <7k3fuo$v51$1@nnrp1.deja.com>

This is the scenario:
1. Loopup.txt
   This file contains Tokens and Values like the follOwing"
   TOKEN=SOME_VALUE.
   TOKEN=SOME_VALUE.
   There may be many lines of Tokens and values.

2. Replace file. This file will contain the tokens (contained in
   lookup.txt).

   I have to loop through the first file(lookup.txt) read a line token
   then loop through the relace file, search if token exists and
   replace it with the value. Exit out of the inner loop and get the
   second line of token and loop again through the replace file again.
   This goes on till the entire loopup.txt file is looped through.

   So far everything is fine. But the problem is, it doesn't replace
   the tokens in the replace file(pattern matching), even though it
   finds it.

   Can any one help.

   Thanks,
   Ram.




Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Mon, 14 Jun 1999 15:21:43 -0400
From: Craig Ciquera <craig@mathworks.com>
Subject: Re: Find and replace in a file within a while loop
Message-Id: <37655647.B6F25CE8@mathworks.com>

A small example would help here.  Its a little confusing as to which file
is being written too and exactly where your problem is occuring.

Craig

ramverma@my-deja.com wrote:

> This is the scenario:
> 1. Loopup.txt
>    This file contains Tokens and Values like the follOwing"
>    TOKEN=SOME_VALUE.
>    TOKEN=SOME_VALUE.
>    There may be many lines of Tokens and values.
>
> 2. Replace file. This file will contain the tokens (contained in
>    lookup.txt).
>
>    I have to loop through the first file(lookup.txt) read a line token
>    then loop through the relace file, search if token exists and
>    replace it with the value. Exit out of the inner loop and get the
>    second line of token and loop again through the replace file again.
>    This goes on till the entire loopup.txt file is looped through.
>
>    So far everything is fine. But the problem is, it doesn't replace
>    the tokens in the replace file(pattern matching), even though it
>    finds it.
>
>    Can any one help.
>
>    Thanks,
>    Ram.
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.



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

Date: Mon, 14 Jun 1999 12:37:31 -0700
From: David <davidf@gaylordusa.com>
Subject: Re: Form Redirection
Message-Id: <376559FB.E682CD09@gaylordusa.com>

Ok, well what I want to do is have the side bar on my frames pop out the
list box, then when I click on a state I want it to appear in the main
frame to the right.  See...http://www.gaylordusa.com/gaylordw3.html for
viewing.  

Right now, it is listing the contents inside of the left frame which
obviously is not what I want.  I need either a perl script or a
javascript that can send the URL to a frame target (TARGET=main in this
case).  I'm not really familiar with either language (though I plan on
learning perl this summer), and would appreciate any help possible
greatly.  Thank You.


"Ethan H. Poole" wrote:
> 
> [Posted and Emailed]  In article <37651A1C.B7701D62@gaylordusa.com>,
> davidf@gaylordusa.com says...
> >
> >Thanks, I like that javascript better than the form and it works with
> >both browsers.  I added a </FORM> (whoops) but that didn't make a
> >difference with IE.  It still didn't work.  Javascript works though and
> >it's a little smoother.  Thanks for help.
> 
> JavaScript is a rather poor solution if you are looking for a solution that
> works with all browsers.  Many browsers do not support JavaScript.  Many
> browsers that do support JavaScript have JavaScript disabled because there
> are many poor JavaScript programmers out there who ruin an otherwise workable
> site if JavaScript is left enabled, and occassionally JavaScript itself still
> has some internal bugs that will crash a browser.
> 
> --
> Ethan H. Poole              | Website Design and Hosting,
>                             | CGI Programming (Perl & C)..
> ========Personal=========== | ============================
> * ehpoole @ ingress . com * | --Interact2Day, Inc.--
>                             | http://www.interact2day.com/


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

Date: Mon, 14 Jun 1999 20:33:01 +0100
From: Robert O'Brien <robrien99@yahoo.com>
Subject: how do I get the total space used in a directory
Message-Id: <376558ED.121BD1DA@yahoo.com>

Newbie question:
I am trying to run this script on a Solaris box.  Basically trying to
emulate du(1).  None of the fields I get or simple math on them work eg
(nblks / blksize) give the same size as
du -sk /dir1
------------------------
while( $line = <DIRS_TO_CHECK> )
{
        $line =~ chomp $line;
        print "\$dir = $dir\n";
        @file_info = stat( $line );
        $blk_size = (stat( $line )) [12];
        $mtime = (stat( $liner )) [9];
        print "blk size = $blk_size\n";
        foreach ( @file_info )
        {
                print "\t$_\n";
        }
        print "blk size = $blk_size\n";
        printf "mtime = %s \n", scalar localtime($mtime);
}
close( DIRS_TO_CHECK );
------------------------
Is there a better / smarter way to do this?  Can do this in various
shells using du, but am trying to learn Perl.
Will also want to specify regexps in the file I'm reading
e.g
input file:
/dir[1-3]
<EOF>
or du /dir[1-3]
TIA
-Rob-



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

Date: 14 Jun 1999 19:39:51 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Linus Torvalds and Carmen Electra?
Message-Id: <7k3lq7$h1i$7@info2.uah.edu>

In article <7jrd6c$6vc$1@gaddy.interpath.net>,
	"John Bjorgen" <john.bjorgen@cplc.com> writes:
: I apologize...I'm a newbie and didn't realize I was committing such a
: grave error.  Forgive my impropriety.  Just trying to get some
: attention to get my questions answered.  Will never do it again

If you want answers to your questions, take the advice offered in

    <URL:http://www.plover.com/~mjd/perl/Questions.html>

Greg
-- 
Conservatives are not necessarily stupid, but most stupid people are
conservatives. 
    -- John Stuart Mill


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

Date: Mon, 14 Jun 1999 18:34:50 GMT
From: "Ray A. Lopez" <rdsys@inficad.com>
Subject: Re: perl cgi and apache
Message-Id: <37654B49.D647E83C@inficad.com>

fezzzza wrote:

> Please help I cant seem to get my perl script running on apache on red
> hat 6.0 I get a server error
>
> on looking at the error logs I get a [error[ (2) no such file or
> directory :exec of /home/httpd/cgi-bin/hello.cgi failed
>
> I have set all the directorys and and to chmod 777 and inable the suid
> bit flag on perl.
>
> in the script the firslt line is !#/usr/bin/perl I have tried moving
> the perl file to the cgi-bin and chaing it to !#perl
>

Try #!/usr/bin/perl -w

> still the same error message I have swtiched on indexes and includes
> and FollowSysmlinks and ExecCGI in the access.conf and set up both
> a  AddHandler cgi-script .cgi and Addtype application/x-httpd-cgi .cgi
>
> or set them up as one or the other.
>
> I am a complete loss of what the probmlem might be
>
> Oh if I run on the command line
>
> perl /home/httpd/cgi-bin/hello.cgi it works fine
>
> As anyone got any ideas ???
>
> Thanks in advance





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

Date: 14 Jun 1999 18:54:33 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Perl class and constructor
Message-Id: <7k3j59$ip6$2@fcnews.fc.hp.com>

Songtao Chen (@cisco.com) wrote:
: Hi everyone,

<snip a good question about OO encapsulation>

Read "The Parable of the Broken Capsule":

  http://www.deja.com/getdoc.xp?AN=476805299

Andrew


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

Date: Mon, 14 Jun 1999 19:16:56 GMT
From: dragnet@internalysis.com (Marc Bissonnette)
Subject: Sorting Arrays of Arrays, Thanks! (Completed script included)
Message-Id: <Iyc93.10501$ga.12520@news21.bellglobal.com>

Hey folks, 

Just wanted to say thanks to everyone who helped with my sorting and indexing 
problems. (2 threads: "Where did I go wrong?" and "Separating array into 
alphabetical array of arrays")

For anyone who's interested, the completed script follows. 

What it does: Reads in from a text file pipe-separated data, sorts 
alphabetically based on last name, prints an html file for each letter of the 
alphabet in a simple table format.

Thanks again for everyone's help. I now know a *ton* more about sorting and 
array/hash referances than before :) :) :)

#!/usr/bin/perl5
require 'cgi-lib.pl';
$indata="icd.txt";
open (DATA, $indata) || &CgiError("Unable to open database for reading 
$indata");
my (%data, @names, $hash, $line, $data, @printed, $temp, $blarg);

while (<DATA>) {
		chop $_;
		my @line = split /\|/;
		$blarg="$line[1]"."$line[0]";
		$data{$blarg} = {
			fname     => $line[0],
			lname     => $line[1],
			title     => $line[2],
			company   => $line[3],
			address1  => $line[4],
			address2  => $line[5],
			city      => $line[6],
			province  => $line[7],
			postal    => $line[8],
			country   => $line[9],
			work_phone=> $line[10],
			work_fax  => $line[11],
			email     => $line[12],
		};
		
		push @names, $blarg;

}

my ($last_letter, @printed, $temp);

$last_letter eq 'a';

foreach (@names) {
	$temp=(substr $_, 0, 1);
	$temp=~ tr/A-Z/a-z/;
	if ($temp ne $last_letter) {
		$last_letter = $temp;
		push @$temp, $_;
		
	} else {
		push @$temp, $_;
	}
}

@printed = 
('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t
','u','v','w','x','y','z');

foreach (@printed) {
	$writefile="../members/"."$_".".htm";
	open (WPUBLISH, ">>$writefile") || die "Couldnt open ";
print WPUBLISH<<EOF;
<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">
<html>
<head>

(bunch of HTML header stuff here)

<TABLE BORDER=\"0\" CELLSPACING=\"3\" CELLPADDING=\"0\">
EOF

	foreach (@$_) {
print WPUBLISH<<EOF;
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>First Name</TD>   
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{fname}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Last Name</TD>    
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>$data{$_}{lname}</B></TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Title</TD>        
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{title}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Company</TD>      
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{company}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Address 1</TD>    
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{address1}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Address2</TD>     
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{address2}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>City</TD>         
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{city}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Province</TD>     
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{province}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Postal Code</TD>  
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{postal}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Country</TD>      
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{country}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Work Phone</TD>   
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{work_phone}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Work Fax</TD>     
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\">$data{$_}{work_fax}</TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><B>Email</TD>        
<TD><FONT FACE=\"ARIAL\" SIZE=\"2\"><A 
HREF=\"mailto:$data{$_}{email}\">$data{$_}{email}</A></TD></TR>
<TR><TD><FONT FACE=\"ARIAL\" SIZE=\"2\">&nbsp;</TD></TR>
EOF
	}
	print WPUBLISH "</TABLE>\n</BODY>\n</HTML>";
}
$test="test.txt";
print &PrintHeader;
print "Done!\n";


-- 
----------------------------
Marc Bissonnette
InternAlysis
Corporate Internet Research and Results!
http://www.internalysis.com



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

Date: 14 Jun 1999 18:48:01 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Verifying date data
Message-Id: <7k3ip1$ip6$1@fcnews.fc.hp.com>

Skip Hollowell (thollowe@opentext.com) wrote:
: Have you ever tried to get authorization to install unofficial code onto a
: governement production installation?

You don't have to. You don't have to install modules anywhere
"official":

use lib qw(.);

: Please give me a a break and realize that the whole world can't always bend
: the beauracracy to their wills every time.

So you bend to theirs.

: I don't know who pays your salary, but in my world, the customer is always
: right.

Only in the money-paying sense. Saying "the customer is always right"
is sometimes an excuse for only providing them what they ask for, and
not what they really want. The customer is frequently wrong on
technical issues.

: Abigail wrote in message ...
: >
: >So you distribute them as part of your product.
: >
: >What would you do if the customer said they haven't computers and
: >are unwilling to buy them?





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

Date: 14 Jun 1999 18:58:04 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Which .gz file to download for Net::Cmd.pm ?
Message-Id: <7k3jbs$ip6$3@fcnews.fc.hp.com>

David Cassell (cassell@mail.cor.epa.gov) wrote:
: I R A Aggie wrote:
: > 
: > On Fri, 11 Jun 1999 19:21:05 GMT, dwang999@my-deja.com
: > <dwang999@my-deja.com>, in <7jrniq$nnd$1@nnrp1.deja.com> wrote:
: > 
: > + I try to download the Net::Cmd.pm from CPAN but could not find which
: > + .tar.gz file to download. Any help is appreciated.
: > 
: > I was about to guess[*]. But I realized that I could be lazy and accurate.
: > If you don't have the CPAN module installed, get it. Install it. Use
: > it.

: Or you could be even lazier, like me.  Examining his page
: source shows:

:    X-Http-User-Agent: Mozilla/4.5 [en] (WinNT; I)

: So we probably ought to be directing him to ActiveState's
: ppm package repository.

: > % perl -MCPAN -e shell
: > 
: > cpan shell -- CPAN exploration and modules installation (v1.50)
: > ReadLine support enabled
: > 
: > cpan> i /Net::Cmd/
: > [blahblahblah]
: >     CPAN_VERSION 2.12
: >     CPAN_FILE    GBARR/libnet-1.0606.tar.gz
: > [blahblahblah]
: > 
: > Answer: it's in libnet...
: > 
: > James
: > 
: > [*] libnet was my guess...

: so he can go to his command prompt and type:

:    ppm install libnet

: and go on to others things...

: BTW, why am I proud to be so darn lazy?

: David
: -- 
: David Cassell, OAO                     cassell@mail.cor.epa.gov
: Senior computing specialist
: mathematical statistician


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

Date: 14 Jun 1999 18:58:46 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Which .gz file to download for Net::Cmd.pm ?
Message-Id: <7k3jd6$ip6$4@fcnews.fc.hp.com>

David Cassell (cassell@mail.cor.epa.gov) wrote:
: BTW, why am I proud to be so darn lazy?

Now _that's_ hubris :)

Andrew


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

Date: Mon, 14 Jun 1999 12:13:23 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Which .gz file to download for Net::Cmd.pm ?
Message-Id: <37655453.44AE34FC@mail.cor.epa.gov>

Clayton L. Scott wrote:
> 
> : I R A Aggie wrote:
> : >
> 
> : Or you could be even lazier, like me.  Examining his page
> : source shows:
> 
> :    X-Http-User-Agent: Mozilla/4.5 [en] (WinNT; I)
> 
> : So we probably ought to be directing him to ActiveState's
> : ppm package repository.
> 
>         That's a silly assumption. Many people use a windows client but do
>  most of their perl programming on/for another platform.

Hey Clayton, you managed to make it appear that James amde this
statement, when in fact I did [you messed up the attribution].
And it isn't necessarily a silly assumption.  Lots of people
use more than one platform for Perl programming.  Some of us
even write one type of code on win boxes and another type on
Solaris and a third on...

And a win32 user needs to know about using ppm.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 14 Jun 1999 19:23:07 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Which .gz file to download for Net::Cmd.pm ?
Message-Id: <slrn7malr5.lbq.fl_aggie@thepentagon.com>

On Mon, 14 Jun 1999 12:13:23 -0700, David Cassell
<cassell@mail.cor.epa.gov>, in <37655453.44AE34FC@mail.cor.epa.gov>
wrote:

+ And a win32 user needs to know about using ppm.

While that's true, a win32 user is not likely to be asking about
a tarball... :)

James


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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