[22920] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5140 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 26 14:06:42 2003

Date: Thu, 26 Jun 2003 11:05:13 -0700 (PDT)
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, 26 Jun 2003     Volume: 10 Number: 5140

Today's topics:
    Re: Altering values by reference (Tad McClellan)
    Re: Altering values by reference (Tad McClellan)
    Re: Array dereferencing (Jan Fure)
    Re: Array dereferencing <mbudash@sonic.net>
    Re: array question (Tad McClellan)
    Re: array question (Tad McClellan)
    Re: Execute shell script from a perl script <glex_nospam@qwest.net>
    Re: Execute shell script from a perl script <glex_nospam@qwest.net>
    Re: Execute shell script from a perl script (Glenn Jackman)
    Re: Execute shell script from a perl script (Helgi Briem)
    Re: Execute shell script from a perl script <glex_nospam@qwest.net>
    Re: Hide source, compiling, whatever! (Mike)
    Re: how to convert all invalid UTF-8 sequences to numer <flavell@mail.cern.ch>
        need assistance understanding multilevel hashes. <allen.wooden@educate.invalid>
    Re: need assistance understanding multilevel hashes. <usenet@dwall.fastmail.fm>
    Re: Offer tips, comments on this code (generates html t (Tad McClellan)
    Re: Offer tips, comments on this code (generates html t <spamblock@junkmail.com>
        PERL - problems with use <alan.vowles@virgin.net>
    Re: Perl 5.6 and Perl 5.8 (Tad McClellan)
    Re: Perl Forking Server Problems (Bryan Castillo)
    Re: Please help with a script, knoledge needed! <estrunk @ home.nl>
    Re: Please help with a script, knoledge needed! <mbudash@sonic.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 26 Jun 2003 08:47:58 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Altering values by reference
Message-Id: <slrnbfluce.6sf.tadmc@magna.augustmail.com>

Dela Lovecraft <dlovecraft@remove.this.to.emai.lme.breathe.com> wrote:

> Is there a way of altering a variable sent as a reference 
> to a subroutine in Perl *without* using a return value? 


Yes.

In fact, you can alter a variable even if it is NOT a reference.

(as long as it IS an "lvalue".)


[snip: call-by-value vs. call-by-reference]


> Is such a thing possible in Perl?


Yes.


> Suppose I had a sub 


Then you would surely read the docs for subroutines (perlsub.pod)
and come across this:

   Because the assignment copies the values, this also has the effect
   of turning call-by-reference into call-by-value.  Otherwise a
   function is free to do in-place modifications of C<@_> and change
   its caller's values.

and you would have already known the answer to your question.  :-)



To get call-by-reference (the default) in Perl:

   by_ref($x);
   sub by_ref { $_[0] += 10 }

To get (the effect of) call-by-value in Perl:

   by_val($x);
   sub by_val { my $num = $_[0]; $num += 10 } # make copy, operate on copy


Neither of them use what is termed a "reference" in Perl (ie. perlref.pod).


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 26 Jun 2003 10:32:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Altering values by reference
Message-Id: <slrnbfm4h1.76a.tadmc@magna.augustmail.com>

Thens <thens@nospam.com> wrote:

>   are both these same
> 
> sub doSomething{
>   my ($arg1, $arg2) = @_;
>   ..
> }
> 
> sub doSomething{
>   my $arg1 = shift;
>   my $arg2 = shift;
>   ..
> }


Yes, with regard to call-by-value vs. call-by-reference.

No, with respect to their effects on the contents of @_.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 26 Jun 2003 09:52:39 -0700
From: jan_may2002_fure@attbi.com (Jan Fure)
Subject: Re: Array dereferencing
Message-Id: <e47a84bf.0306260852.5fb00476@posting.google.com>

tiltonj@erols.com (Jay Tilton) wrote in message news:<3efa1fdf.338871560@news.erols.com>...
> Could you phrase that in the form of a question?  It's not clear what
> you are misunderstanding.

Given data of the form:

1 2 4
1 2 5
1 3 4.5
2 2 6
2 3 7

How can I order it like:
([1,(2 2 3), (4 5 4.5)], [2, (2 3), (6 7)])

In verbal form, I want to group the values from columns 2 to n by
those corresponding to the same value in column 1, for further
processing for the purpose of finding mean, median, standard deviation
etc.

The ultimate goal is to get an output file like:

1 2.333 4.5
2 2.5 6.5

for the data above in the case of mean/average. To get this, I need to
have some array to loop through, and calculate the statistics for each
row.

In my first post, I showed the code which generated a data structure
with multiple data pairs with the same key, but I am stuck at that
point, as my understanding of referencing is too poor to properly
access the data.
Data::Dumper showed me that the data appears to be properly ordered.

Jan Fure


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

Date: Thu, 26 Jun 2003 17:51:29 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Array dereferencing
Message-Id: <mbudash-E88692.10513126062003@typhoon.sonic.net>

In article <e47a84bf.0306260852.5fb00476@posting.google.com>,
 jan_may2002_fure@attbi.com (Jan Fure) wrote:

> tiltonj@erols.com (Jay Tilton) wrote in message 
> news:<3efa1fdf.338871560@news.erols.com>...
> > Could you phrase that in the form of a question?  It's not clear what
> > you are misunderstanding.
> 
> Given data of the form:
> 
> 1 2 4
> 1 2 5
> 1 3 4.5
> 2 2 6
> 2 3 7
> 
> How can I order it like:
> ([1,(2 2 3), (4 5 4.5)], [2, (2 3), (6 7)])
> 
> In verbal form, I want to group the values from columns 2 to n by
> those corresponding to the same value in column 1, for further
> processing for the purpose of finding mean, median, standard deviation
> etc.
> 
> The ultimate goal is to get an output file like:
> 
> 1 2.333 4.5
> 2 2.5 6.5
> 
> for the data above in the case of mean/average. To get this, I need to
> have some array to loop through, and calculate the statistics for each
> row.
> 
> In my first post, I showed the code which generated a data structure
> with multiple data pairs with the same key, but I am stuck at that
> point, as my understanding of referencing is too poor to properly
> access the data.
> Data::Dumper showed me that the data appears to be properly ordered.
> 
> Jan Fure

one way:

#---------------------------------------------------
use strict;
use Data::Dumper;

my @data = ("1 2 4",
"1 2 5",
"1 3 4.5",
"2 2 6",
"2 3 7",
);

my %hash;
foreach (@data) {
  my @values = split /\s+/;
  foreach my $i (1..$#values) {
    push @{$hash{$values[0]}->[$i-1]}, $values[$i];
  }
}

my @final;
foreach (sort keys %hash) {
  push @final, [ $_, @{$hash{$_}} ];
}

print Dumper(@final);
#---------------------------------------------------

yields:

$VAR1 = [
          '1',
          [
            '2',
            '2',
            '3'
          ],
          [
            '4',
            '5',
            '4.5'
          ]
        ];
$VAR2 = [
          '2',
          [
            '2',
            '3'
          ],
          [
            '6',
            '7'
          ]
        ];

-- 
Michael Budash


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

Date: Thu, 26 Jun 2003 09:30:46 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: array question
Message-Id: <slrnbfm0sm.6sf.tadmc@magna.augustmail.com>

Math55 <magelord@t-online.de> wrote:

> 	while(<READFILTEREDLIST>) {	
> 	
> 		@filterArray=<READFILTEREDLIST>;


The while() reads the first line into the $_ variable, then
you never do anything with that first line...


> 		($size, $realPath)=split('\s', $pfad);


A pattern match should *look like* a pattern match.

Space characters are not a scarce resource. Feel free to use as
many as you like to make your code easier to read and understand:


   ($size, $realPath) = split( /\s/, $pfad );


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 26 Jun 2003 10:27:38 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: array question
Message-Id: <slrnbfm47a.76a.tadmc@magna.augustmail.com>

Alan J. Flavell <flavell@mail.cern.ch> wrote:
> On Thu, Jun 26, by accident I became aware that Graham Wood
> had caused the following to appear:

>> This is balderdash.  Ignore me.
> 
> Usenet postings with attachments normally get ignored by
> my newsreader.


By mine too.

Sometimes I think my scorefile is prescient.   :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 26 Jun 2003 10:05:37 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: Execute shell script from a perl script
Message-Id: <HYDKa.11$j4.22272@news.uswest.net>

kderaedt wrote:
> Hi,
> 
>     How can I executed a Unix shell script from a Perl script.
> The shell script is a dump of a oracle table to a file.  The perl script is
> for the reformat of this output file.
perldoc -f system



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

Date: Thu, 26 Jun 2003 10:24:01 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: Execute shell script from a perl script
Message-Id: <XdEKa.13$j4.23788@news.uswest.net>

J. Gleixner wrote:
> kderaedt wrote:
> 
>> Hi,
>>
>>     How can I executed a Unix shell script from a Perl script.
>> The shell script is a dump of a oracle table to a file.  The perl 
>> script is
>> for the reformat of this output file.
> 
> perldoc -f system
> 

Or if your perl script takes input from STDIN, and you modified your 
shell script to echo to STDOUT, no need to call system, it'd simply be:

script.pl < script.sh > formatted.out



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

Date: 26 Jun 2003 15:40:21 GMT
From: xx087@freenet.carleton.ca (Glenn Jackman)
Subject: Re: Execute shell script from a perl script
Message-Id: <slrnbfm4v4.b1l.xx087@freenet10.carleton.ca>

J. Gleixner <glex_nospam@qwest.net> wrote:
> Or if your perl script takes input from STDIN, and you modified your 
> shell script to echo to STDOUT, no need to call system, it'd simply be:
> 
> script.pl < script.sh > formatted.out

You mean:
    script.sh | script.pl > formatted.out


-- 
Glenn Jackman


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

Date: Thu, 26 Jun 2003 16:10:31 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Execute shell script from a perl script
Message-Id: <3efb1a10.283981703@news.cis.dfn.de>

On Thu, 26 Jun 2003 15:54:22 +0200, "kderaedt" <kderaedt@hotmail.com>
wrote:

>How can I executed a Unix shell script from a Perl script.

system($script) == 0 or die "Cannot run $script:$?\n";

or better yet:

my $output = qx/$script/ or die "Cannot run $script:$!\n";

>The shell script is a dump of a oracle table to a file.  
>The perl script is for the reformat of this output file.

Why don't you use Perl to dump the Oracle table
to a file?  You'd use the DBI and DBD::Oracle modules.


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

Date: Thu, 26 Jun 2003 12:46:54 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: Execute shell script from a perl script
Message-Id: <fkGKa.31$j4.36317@news.uswest.net>

Glenn Jackman wrote:
> J. Gleixner <glex_nospam@qwest.net> wrote:
> 
>>Or if your perl script takes input from STDIN, and you modified your 
>>shell script to echo to STDOUT, no need to call system, it'd simply be:
>>
>>script.pl < script.sh > formatted.out
> 
> 
> You mean:
>     script.sh | script.pl > formatted.out
Yep.  That's what I meant.  Two thoughts wrongly combined into one. I 
was going to say to send the output to script.pl, then I thought well 
easier yet would be to just send the output from the initial script..

Thanks




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

Date: 26 Jun 2003 10:37:20 -0700
From: csdude@hotmail.com (Mike)
Subject: Re: Hide source, compiling, whatever!
Message-Id: <46cdc619.0306260937.66f0f47@posting.google.com>

> This is a FAQ.  Read all about it in:
> 
> perldoc -q hide
> 
> Short answer, can't be done.

Thanks to all of you for the advice. I didn't realize it was that
commonly asked, I guess it was a matter of searching for the wrong
terms. Everything I found was from 1999 and 2000, and I was hoping
that something more recent was available.

I apologize again for the "troll-like" question, I certainly didn't
mean for it to be.


> The PAR module (available from CPAN) does the
> same thing and is free.

I really think that this will work, I appreciate the tip! It won't be
perfect, but probably close enough.


> I doubt very much that your programs are so super
> duper that it will be worth his while to steal them.

LOL you might be surprised! I've had it happen no less than 3 other
times (by this guy and another).

Thanks for the PAR tip,

Mike


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

Date: Thu, 26 Jun 2003 16:51:59 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: how to convert all invalid UTF-8 sequences to numeric equivalent?
Message-Id: <Pine.LNX.4.53.0306261645200.6298@lxplus090.cern.ch>

On Thu, Jun 26, Shambo inscribed on the eternal scroll:

> > Your mental model is way adrift, I'm afraid.  This talk of "non utf-8
> > valid sequences" strikes me as a bit like counting what you've been
> > told is a stack of pound notes and then being surprised that the stack
> > doesn't contain US dollars.
>
> You're sort of correct. I am believing what I'm being told. After
> checking the converted XML against the Xerces parser, it reports
> errors as "invalid utf-8 sequence".

You must have either told it, or at least implied, that it was to
expect utf-8 on input.

> When I look at the character it's
> referring to, it's something along the lines of £.

As I said, you're not correctly describing the input that you're
giving it.

> > You have the choice of either delivering utf-8 as XML likes it as
> > default, or telling XML that it's getting iso-8859-1.  Nothing to do
> > with Perl there, though.
>
> It has everything to do with Perl since I'm using Perl to convert the
> text files to XML.

Oh dear, clearly you are a stranger around here.  Normally that kind
of response would set you up for a plonk.  I say again, the fact that
you are supplying your processor with iso-8859-1 when it expects utf-8
has nothing to do with Perl.

The key to solving a complex problem is to break it down into
manageable pieces and to understand what is and isn't relevant to each
of the pieces.  And the piece where you are handing your data over to
your XML processor is all about XML and that processor, and nothing to
do with Perl, no matter that Perl was involved somewhere else in your
processing chain.

> I will take your advice and figure out how to tell Perl to write the
> proper encoiding on output.

Looks like a good choice.  Have fun.



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

Date: Thu, 26 Jun 2003 16:41:55 GMT
From: Allen Wooden <allen.wooden@educate.invalid>
Subject: need assistance understanding multilevel hashes.
Message-Id: <ke6mfv0pdcb6shkth2rfkc8khr6h17gid2@4ax.com>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

After reading the FAQ
(http://www.perldoc.com/perl5.6/pod/perlfaq7.html#How-can-I-use-a-variable-as-a-variable-name-)
about multilevel hashes I'm still having a tough time understanding
how to use them in the context of the program I'm trying to write.  

My program get one or more args from commandline. One of those
arguments is an 'customer' name.  (ie: ./prog customer).

within the program it load a configuration file which has a bunch of
hashes that coincide with the customer name.   It then runs and
generates output using data from the customer's hash name.
what I'm having trouble is getting the customer name argument to pull
the data from the correct hash without using symbolic references. I
hope I made sense with that.

- From the way I read the FAQ, multilevel hashes are what I should use
as opposed to turning off strict refs and doing thing symbolically.

I also ran into the same brick wall reading p. 279 of the Camel book.

Thanks





-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0 - not licensed for commercial use: www.pgp.com

iQA/AwUBPvsh7zfNlJlmhaSWEQKZ4QCgweeDrxQ/wRLoO4hveHfg2KP/uq8AoJvC
LdDthGjP0Nna4ZP7OK+OxeJI
=VAfz
-----END PGP SIGNATURE-----

Replace invalid with com to reply via email.
PGP key available @ keyserver.pgp.com


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

Date: Thu, 26 Jun 2003 18:02:11 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: need assistance understanding multilevel hashes.
Message-Id: <Xns93A68EC8AA871dkwwashere@216.168.3.30>

Allen Wooden <allen.wooden@educate.invalid> wrote:

> - From the way I read the FAQ, multilevel hashes are what I should
> use as opposed to turning off strict refs and doing thing
> symbolically. 

Yes.

> 
> I also ran into the same brick wall reading p. 279 of the Camel
> book. 

Have you looked at 'perldoc perldsc' ?  It's the 'Perl Data Structures 
Cookbook', and has examples of the kind of thing you want to do.


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

Date: Thu, 26 Jun 2003 10:01:22 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Offer tips, comments on this code (generates html to index image files)
Message-Id: <slrnbfm2m2.6sf.tadmc@magna.augustmail.com>

David Oswald <spamblock@junkmail.com> wrote:

> Please offer suggestions, comments, and tips on the following perl code.

> I
> "overwrote" it to make it easy to modify in the future. 


> # --- Declarations ---
> 
> my ($outfile)="index.html";  # declare the output html file's name.


You should limit the scope of variables as much as possible, so
consider declaring them near their first use instead of way up
here at the top of the program.

Put spaces around operators, as suggested in:

   perldoc perlstyle

   my $outfile = "index.html";


Over-commenting *increases* maintenance time, since you say the
same thing twice, once in code and once in a comment.

   my() already means "declare"

   $outfile already implies what it is, due to the well-chosen variable name



>  openhtmlfile($outfile);    #open the output html file.


Thatsureisahardtoreadchoiceofname:

   open_html_file($outfile);


> sub getdir() {    #Opens the current directory and gets all image filenames
> into an array.


But it does not return that array.

It returns a list (as all subroutines do).

See this Perl FAQ:

   What is the difference between a list and an array?


>  while (defined ( $file = readdir(CURRENTDIR))) {
>   if ($file =~ /.*\.((jpe?g)|(tiff?)|(bmp)|(gif))$/i) {
>    push (@entries,$file);
>   }
>  }


You can use grep() to replace that whole while loop (untested):

   my @entries = 
      grep { /.*\.((jpe?g)|(tiff?)|(bmp)|(gif))$/i } readdir CURRENTDIR;



>  return sort(@entries);


Returns a "list", not an "array".


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 26 Jun 2003 10:48:29 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Re: Offer tips, comments on this code (generates html to index image files)
Message-Id: <vfmcm1lhpqp8ee@corp.supernews.com>

Thanks, all your comments make sense.

Dave


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbfm2m2.6sf.tadmc@magna.augustmail.com...


<snipped for brevity>




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

Date: Thu, 26 Jun 2003 18:44:42 +0100
From: "Alan Vowles" <alan.vowles@virgin.net>
Subject: PERL - problems with use
Message-Id: <HfGKa.1626$QA2.248804@newsfep2-win.server.ntli.net>

Hello,

I have written a simple PERL script for use with my website, and even
through the script runs perfectly on my own computer using the Apache
webserving software, i am having problems making the script online.

The server i am using does support the use of PERL and i have even double
checked the path to PERL for the '#!' line.  The server simply produces an
"Access Denied - You are not allowed to view this page" error.

Can anyone help?

Thanks.




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

Date: Thu, 26 Jun 2003 10:02:41 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl 5.6 and Perl 5.8
Message-Id: <slrnbfm2oh.6sf.tadmc@magna.augustmail.com>

Alvise Valsecchi <alvise@hochfeiler.it> wrote:

> Hi, I am new to this newsgroup, hence you might have discussed this
> topic in the past.


   http://groups.google.com/advanced_group_search


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 26 Jun 2003 09:15:47 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: Perl Forking Server Problems
Message-Id: <1bff1830.0306260815.7820126b@posting.google.com>

littleretsam@yahoo.com (Jeff Chinnock) wrote in message news:<49fcf7a7.0306251728.1a1a4160@posting.google.com>...
> Hello!
> Perl newbie having a problem with a forking perl server that needs to
> receive information from a socket, format it, and send it on to
> another local socket.  At this point, I am unable to determine where
> the problem exists and have gone through many iterations and am unable
> to determine why it 1) seems to hammer the CPU - i don't think this
> should be happening, but I'm not sure where the true problem is 2)
> believe that there is a problem with the interaction between parent
> and child with the $connection variable, but again, don't know why.
> 
> Any insight into my problem would be greatly appreciated.
> Jeff
> 
> #!/usr/bin/perl -w
> #
> #
> # AUTHOR: 	Jeff Chinnock - contrib: Jacque Bussey, Joe Burton, Mike
> Winter
> # NAME:		nco_logreader.pl
> # CREATE DATE:	2003.3.1
> # ABSTRACT:	Probe for taking data from a logfile and sending to
> multiple socketprobes
> #
> # USAGE:	nco_logreader -config <Config File Path & Name>
> #
> # REVISION HISTORY:
> 
> ##############################
> ## Define Modules and Options
> use strict;
> use POSIX qw(:sys_wait_h);
> use IO::File;
> use IO::Socket;
> 
> ##############################
> ## Define Variables and Arrays
> 
> my $config = "/tmp/EACO.conf";		## Default location for configfile.
> User must enter other value on command line
> my $debug = 0;				## 0 = NONE, 1 = DEBUG - Change in configfile
> my $delimiter = "\;";			## Default delimiter for records.  Change in
> configfile
> my $rulesheader = "DCO_RAW_FEED";	## Default header for all records. 
> MUST change in configfile.
> my ($debugfile,$headerlength,$recordlength);
> my ($listenSocket,$n,$serverIP,$serverPort) = '';
> my ($spSock,$name,$spHost,$spPort) = '';
> 
> # Take input from the command line if necessary
> while (@ARGV) {
>     $config = $ARGV[1] if ($ARGV[0] =~ /-config/);
>     help_menu() if($ARGV[0] =~ /-help/);
>     shift;
> }
> # Read configuration file - please ask Jeff Chinnock if you want to
> change this file
> read_configfile($config);
> 
> 
> $listenSocket = IO::Socket::INET-> new (LocalPort	=> $serverPort,
> 					   LocalAddr	=> $serverIP,
> 					   Listen	=> 2000,
> 					   Proto	=> 'tcp',
> 					   Reuse	=> 1,
> 					  );
> 
> fatal_error("Cant create a listening socket: $@") unless
> $listenSocket;
> log_message("INFO: Listening socket ready on $serverIP:$serverPort")
> if($debug);
> 
> $spSock = IO::Socket::INET-> new (PeerPort	=> $spPort,
> 	 			       PeerAddr	=> $spHost,
> 				       Proto	=> 'tcp',
> 				       );
> 
> fatal_error("Cant create a connection to socket probe socket: $@")
> unless $spSock;
> log_message("INFO: Socket probe socket ready on $spHost:$spPort")
> if($debug);
> 
> $SIG{CHLD} = \&reaper;
> #$SIG{CHLD} = 'IGNORE';
> 
> while(1) {
> 
>     # Accept child connection
>     next unless my $connection = $listenSocket->accept;
> 
>     # Set up $data and $origdata variables for use in substr
>     my ($data,$origdata);
> 
>     defined (my $child = fork()) or fatal_error("Can't fork child:
> $!");
>     # If I am a child process, work on data coming in
>     if ($child == 0) {
> 
> 	# my ($count,@events,$header); MOVED BELOW FOR SECTION WHERE NEEDED
> 
> 	print $connection "OK\n";
> 
> 	# Close child copy of listen socket, we will not take any more data
> here
> 	$listenSocket->close;
> 
> 	# Take incoming information and put into variables $data and
> $origdata for processing
> 	while (<$connection>) {
> 	    $data = $_;
> 	    $origdata = $_;
> 
> 	    if ($data) { last; }
> 	}
> 
> 	my ($count,@events,$header);



This looks like an infinite loop to me.
Once data is true you will enter the loop and you never
modify data in the body of this loop to be untrue.

> 	for($count=0; $data; $count++) {

put a log_message here and check to see if this loop just gets
executed over and over again.


> 	    if ($count == 0) {
> 		# If i am first piece of data, take out length of header based on
> value from configfile
> 		$header = substr($data,0,$headerlength,''); }
> 	    else { 
> 		# In the meat of the processing section, parse each piece of data
> into a unique record
> 		$events[$count-1] = substr($data,0,$recordlength,'');
> 		# We have moved the following line from below to here so it doesn't
> have to reprocess the event again
> 		print $spSock "$rulesheader$delimiter$header$delimiter$events[$count-1]\n";
> 	    }
> 	}
>     
> 	exit 0;
> 	}
>    # Close connection to mainframe process
>    $connection->close; 
> }
> 
> ##############################
> ### Define subroutines
> 
> sub log_message {
>     ####### WARNING, THIS SUBROUTINE ACCESSES A GLOBAL VARIABLE
>     # This sub takes a message and dumps it to the log file.
> 
>     my $message = $_[0];	# Message to send to the logfile
>     $message =~ s/\n//;		# Remove Newlines, keep log tidy	
> 
>     # Open log file
>     sysopen(LOG,$debugfile,O_WRONLY|O_APPEND|O_CREAT) or die("Unable
> to open log file: $debugfile: $!");
> 
>     # Send the message to the log, prepend a timestamp.
>     print LOG scalar(localtime) .": $message\n";
>     close(LOG);
> 
>     # Roll logfile over when greater than 100000 bytes
>     if (-s $debugfile > 100000) {
>       rename($debugfile,"$debugfile\_old") or fatal_error("ERROR:
> Unable to rename $debugfile to $debugfile\_old.");
>       log_message("INFO: $debugfile has grown larger than 100000
> bytes, and has been backed up.") if($debug);
>     }
> }
> sub fatal_error {
>     my $error = $_[0];				# Passed in error.
>     log_message("ERROR: $error") if($debug);	# Send the message to the
> log
>     print STDERR $error;			# Display the error to stderr
>     exit(1);					# Exit script
> }
> sub reaper {
>     1 until (-1 == waitpid(-1,WNOHANG));
>     $SIG{CHLD} = \&reaper
> }


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

Date: Thu, 26 Jun 2003 19:45:11 +0200
From: "Eric Strunk" <estrunk @ home.nl>
Subject: Re: Please help with a script, knoledge needed!
Message-Id: <bdfbeq$orj$1@news4.tilbu1.nb.home.nl>


"Eric Strunk" <estrunk @ home.nl> schreef in bericht
news:kmfhfv8bvtd5sg33thua4rm8pqvop8h09a@4ax.com...
> On Tue, 24 Jun 2003 20:24:55 GMT, Michael Budash <mbudash@sonic.net>
> wrote:
>
> <snip>
>
> >> How do i get it to print it once for a file, but only if found
> >> something in the file.
> >
> >while (<F>) {
> >   my $hdrprinted;
> >   if ( /$zoek/i ) {
> >      $hits++;
> >      unless ($hdrprinted) {
> >         # print the header here
> >         $hdrprinted++;
> >      }
> >      print "<pre>$_\n<br></PRE>\n";
> >   }
> >}
> >
> >hth-
>
> It didn't work out still have all the headers i had before, put all
> the code down here again.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use CGI;
> use CGI::Carp ("fatalsToBrowser");
> my $q = CGI->new;
> my $zoek = $q->param("zoek");
> chdir "/xxx/xxx.xxx.xx/xxxxx";
> my @data_files = glob "*.*";
>
> print CGI::header();
> print CGI::start_html("genealogische zoekmachine");
>
> print <<EOT;
> <P><UL><BR><FONT SIZE=+1><B><I>Legenda:</I></B></FONT><P>
> 1 = Recordnummer<BR>
> 2 = Geslacht<BR>
> 3 = Naam en voornamen<BR>
> 4 = Geboorteplaats<BR>
> 5 = Geboortedatum<BR>
> 6 = Overlijdensdatum<BR>
> 7 = Recordnummer vader<BR>
> 8 = Recordnummer moeder<BR></UL><P><HR WIDTH=33% ALIGN=LEFT>
> EOT
>
>
> my $hits = 0;
> foreach my $file ( @data_files ) {
>     if ( !open F, "<$file" ) {
>         warn "Could not open $file ($!)\n";
>         next;
>     }
>     my $found = 0;
>     while (<F>) {
>     my $hdrprinted;
>         if ( /$zoek/i ) {
>             $hits++;
>             unless ($hdrprinted) {
>    print "<pre> test </pre>\n";
>
> print"<pre><b>Bestandsnaam</b><br>\n<i>$file</i></PRE><br>\n";
>                 print "<pre>  1  </pre>" ; \
>     $hdrprinted++;
> }
> print "<pre>$_\n<br></PRE>";
>         }
>
>     }
>     close F;
> }
>
> print "<h3>", $hits ? $hits : "Geen", " bestanden gevonden</H3>";
>
> ------------------------------------------------------------------------
> It still prints everything between unless [$hdrprinted ] and
> $hdrprinted every hitt, does something be declared???
>
> Thanks for the last answer you did give.
> I'm verry glad you posted it.
>
> Kind regards
> Eric.

The solving answer came throug E-mail by last sender,
Thanks again.

Kind regards.
Eric.




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

Date: Thu, 26 Jun 2003 17:54:00 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Please help with a script, knoledge needed!
Message-Id: <mbudash-E48946.10540126062003@typhoon.sonic.net>

In article <bdfbeq$orj$1@news4.tilbu1.nb.home.nl>,
 "Eric Strunk" <estrunk @ home.nl> wrote:

> "Eric Strunk" <estrunk @ home.nl> schreef in bericht
> news:kmfhfv8bvtd5sg33thua4rm8pqvop8h09a@4ax.com...
> > On Tue, 24 Jun 2003 20:24:55 GMT, Michael Budash <mbudash@sonic.net>
> > wrote:
> >
> > <snip>
> >
> > >> How do i get it to print it once for a file, but only if found
> > >> something in the file.
> > >
> > >while (<F>) {
> > >   my $hdrprinted;
> > >   if ( /$zoek/i ) {
> > >      $hits++;
> > >      unless ($hdrprinted) {
> > >         # print the header here
> > >         $hdrprinted++;
> > >      }
> > >      print "<pre>$_\n<br></PRE>\n";
> > >   }
> > >}
> > >
> > >hth-
> >
> > It didn't work out still have all the headers i had before, put all
> > the code down here again.
> >
> > #!/usr/bin/perl
> >
> > use strict;
> > use warnings;
> > use CGI;
> > use CGI::Carp ("fatalsToBrowser");
> > my $q = CGI->new;
> > my $zoek = $q->param("zoek");
> > chdir "/xxx/xxx.xxx.xx/xxxxx";
> > my @data_files = glob "*.*";
> >
> > print CGI::header();
> > print CGI::start_html("genealogische zoekmachine");
> >
> > print <<EOT;
> > <P><UL><BR><FONT SIZE=+1><B><I>Legenda:</I></B></FONT><P>
> > 1 = Recordnummer<BR>
> > 2 = Geslacht<BR>
> > 3 = Naam en voornamen<BR>
> > 4 = Geboorteplaats<BR>
> > 5 = Geboortedatum<BR>
> > 6 = Overlijdensdatum<BR>
> > 7 = Recordnummer vader<BR>
> > 8 = Recordnummer moeder<BR></UL><P><HR WIDTH=33% ALIGN=LEFT>
> > EOT
> >
> >
> > my $hits = 0;
> > foreach my $file ( @data_files ) {
> >     if ( !open F, "<$file" ) {
> >         warn "Could not open $file ($!)\n";
> >         next;
> >     }
> >     my $found = 0;
> >     while (<F>) {
> >     my $hdrprinted;
> >         if ( /$zoek/i ) {
> >             $hits++;
> >             unless ($hdrprinted) {
> >    print "<pre> test </pre>\n";
> >
> > print"<pre><b>Bestandsnaam</b><br>\n<i>$file</i></PRE><br>\n";
> >                 print "<pre>  1  </pre>" ; \
> >     $hdrprinted++;
> > }
> > print "<pre>$_\n<br></PRE>";
> >         }
> >
> >     }
> >     close F;
> > }
> >
> > print "<h3>", $hits ? $hits : "Geen", " bestanden gevonden</H3>";
> >
> > ------------------------------------------------------------------------
> > It still prints everything between unless [$hdrprinted ] and
> > $hdrprinted every hitt, does something be declared???
> >
> > Thanks for the last answer you did give.
> > I'm verry glad you posted it.
> >
> > Kind regards
> > Eric.
> 
> The solving answer came throug E-mail by last sender,
> Thanks again.
> 
> Kind regards.
> Eric.
> 
> 

which was, fyi:

change:

     while (<F>) {
     my $hdrprinted;

to:

     my $hdrprinted;
     while (<F>) {


-- 
Michael Budash


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

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

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 V10 Issue 5140
***************************************


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