[10673] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4265 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 20 15:07:19 1998

Date: Fri, 20 Nov 98 12:00:21 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 20 Nov 1998     Volume: 8 Number: 4265

Today's topics:
    Re: Aggregate (Patrick Timmins)
    Re: ascending <baliga@synopsys.com>
    Re: ascending <r28629@email.sps.mot.com>
        defining DSN in UNIX <mislam@mindspring.net>
        Extending a scalar's reserved memory (Matt Knecht)
    Re: FAQ? <perlguy@technologist.com>
    Re: FAQ? (Joergen W. Lang)
        Finding Win32 NTFS File Owner <randy.omeara@lmco.com>
    Re: Hashed array printing ? <uri@sysarch.com>
    Re: Hashed array printing ? <dkoleary@tako.wwa.com>
        Help - popup window option <dales@enhanced-performance.com>
        help: can't find HTTP_COOKIE. my cookies don't go <muriarte@nextel.es>
    Re: HELP: how to prompt for input from command line? <mblase@ncsa.uiuc.edu>
    Re: How do you pass parameters to Perl script from HTML <delonad@netdoor.com>
        How secured my flat database could be using cgi? <proband@cam.org>
        Newbie 'sys/socket.ph' question (was Re: Raw Sockets) (P8r Versteegen)
        NT perl and mail mcnay@my-dejanews.com
        Perl CGI on NT error <mkshanx@uxmail.ust.hk>
    Re: puzzler (Sean McAfee)
    Re: puzzler (Joergen W. Lang)
    Re: reset one variable? <r28629@email.sps.mot.com>
        Stdin <mfoley@richmond.net>
    Re: Strange days have found me! <ckuskie@cadence.com>
    Re: Sum by group (Peter J. Kernan)
    Re: Sum by group (Claes Bjorklund)
    Re: Sum by group <r28629@email.sps.mot.com>
    Re: Sum by group (Patrick Timmins)
        undef VB 6.0 COM object crash <jscarpaci@gpu.com>
    Re: Win32::TieRegistry and EventLog (Tye McQueen)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Fri, 20 Nov 1998 19:35:27 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: Aggregate
Message-Id: <734g9u$5a0$1@nnrp1.dejanews.com>

In article <73439k$p5f$1@nnrp1.dejanews.com>,
  c_b9209@my-dejanews.com wrote:

> Hello!
>
> Have a data file where the first coulmn has group data and the other have
> values and I want to clculate the sum and counts by groups and the data file
> is realy huge have found I can use hash variabels but I can't get the values
> in a array. How I do to calculate the sum for each column by group in the
> data file? has anyone a solution of this, please help me this problem make me
> crazy here is my script for a small data file

Hard to guess what you want without seeing your actual data structure,
but guessing from your description, something like:

while (<DATA>) {
   @temp = split/\s+/;
   for ($i=1; $i<@temp; $i++) {
      push @{$group{$temp[0]}{$i}}, $temp[$i];
   }
}

foreach $grp (sort keys %group) {
   foreach $clmn (sort keys %{ $group{$grp} } ) {
      $sum = 0;         # reset this each time through the loop
      $cnt = @{ $group{$grp}{$clmn} };
      for ($i=0; $i<@{ $group{$grp}{$clmn} }; $i++) {
         $sum += $group{$grp}{$clmn}[$i];
      }
      print "Group $grp column $clmn: sum = $sum, n = $cnt\n";
   }
}
__DATA__
setA 1 2 3 4
setB 5 6 7 8
setA 9 10 11 12
setB 13 14 15 16

Will print out:

Group setA column 1: sum = 10, n = 2
Group setA column 2: sum = 12, n = 2
Group setA column 3: sum = 14, n = 2
Group setA column 4: sum = 16, n = 2
Group setB column 1: sum = 18, n = 2
Group setB column 2: sum = 20, n = 2
Group setB column 3: sum = 22, n = 2
Group setB column 4: sum = 24, n = 2

Hope that helps

Patrick Timmins
$monger{Omaha}[0]

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 20 Nov 1998 10:16:03 -0800
From: Yogish Baliga <baliga@synopsys.com>
To: Casema <ours@casema.net>
Subject: Re: ascending
Message-Id: <3655B1E2.EE78F64@synopsys.com>

This is not a perl related question. This is related to SQL language.

If you want to do the ordering on some field, the answer is,
  "SELECT * from news ORDER by <column name> DESC/ASC .... "

-- Baliga

Casema wrote:

> Hi group,
>
> $SQL = "SELECT * FROM news";
> what would be a valid statement to get the output ascending /
> descending?????
> Oh, by the way, I am using WIN32::ODBC, so this is Perl Related
>
> Thanks,
>
> michel



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

Date: Fri, 20 Nov 1998 12:58:24 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Casema <ours@casema.net>
Subject: Re: ascending
Message-Id: <3655BBD0.690B153D@email.sps.mot.com>

[posted to c.l.p.m and copy emailed]

Casema wrote:
> 
> Hi group,
> 
> $SQL = "SELECT * FROM news";
> what would be a valid statement to get the output ascending /
> descending?????
> Oh, by the way, I am using WIN32::ODBC, so this is Perl Related

NO, this is an SQL question (SQL command 'ORDER BY'). Again, using a
perl module does _not_ always make it perl-related. 

If you insist, my guess is that you next question will be "how to
specified selection criteria?" (SQL command 'WHERE'), get the point?

Have I said the same thing before????

-TK


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

Date: Fri, 20 Nov 1998 19:58:58 +0000
From: Mir S Islam <mislam@mindspring.net>
Subject: defining DSN in UNIX
Message-Id: <3655CA02.A7AB4F56@mindspring.net>

Hi, where do I setup the DSN on UNIX (linux and DEC-OSF1) and what is
the format ? I have installed the DBI::ODBC on the system with iodbc
driver. Now, I understand that I have to put odbc.ini file somewhere in
the system or user directory so that I can call the DSN from perl
script. Right ? I am unable to find any example on CPAN site on how to
define/write the ODBC.ini file.

Thanks.
-- 
Mir S Islam
Software Engineer
Product Development
Mindspring Enterprise : MSPG
(404)815-0770 x2633


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

Date: Fri, 20 Nov 1998 19:45:51 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Extending a scalar's reserved memory
Message-Id: <PFj52.32993$%X2.7790843@news3.voicenet.com>

A good way to trim a bit of time off building a large array would be to
pre-extend the array.  Something like:

$array[5_000] = '';

That way, Perl will fetch all the memory it thinks it should need to
fill in array elements 0 .. 4_999 at once.


Is there a similar trick for scalars?

-- 
Matt Knecht - <hex@voicenet.com>


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

Date: Fri, 20 Nov 1998 17:07:06 GMT
From: Brent Michalski <perlguy@technologist.com>
Subject: Re: FAQ?
Message-Id: <3655A1BA.9D7C9AAA@technologist.com>

F Rodriguez wrote:
> 
> Can someone direct me to the Perl FAQ?
> Many tx.
> 
> MagicFab@bigfoot.com

Sure, go straight for three blocks, take a left at the 7-11, ... :-)

Go to:
 http://www.perl.com and click on the link that says "FAQs"

Brent
-- 
Java? I've heard of it, it is what I drink when I am hacking Perl. -me
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$            Brent Michalski             $
$         -- Perl Evangelist --          $
$    E-Mail: perlguy@technologist.com    $
$ Resume: http://www.inlink.com/~perlguy $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$


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

Date: Fri, 20 Nov 1998 20:45:47 +0100
From: jwl@worldmusic.de (Joergen W. Lang)
Subject: Re: FAQ?
Message-Id: <1dit2o2.4accbs1pqvu9hN@host029-210.seicom.net>

F Rodriguez <magicfab@hotmail.com> wrote:

> Can someone direct me to the Perl FAQ?
> Many tx.
> 
> MagicFab@bigfoot.com

    % perldoc perlfaq

or on the web:

    http://language.perl.com/faq/index.html

hth,

Joergen
-- 
-------------------------------------------------------------------
   "Everything is possible - even sometimes the impossible"
             HOELDERLIN EXPRESS - "Touch the void"
-------------------------------------------------------------------


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

Date: Fri, 20 Nov 1998 10:39:43 -0800
From: "Randy O'Meara" <randy.omeara@lmco.com>
Subject: Finding Win32 NTFS File Owner
Message-Id: <734d24$hcf$1@lscruz.scf.lmms.lmco.com>

Is there a way to find the owner of a file on a Win32 NTFS file system?
I'm using Win32 RK with Perl 5.005.

Thanks,
Randy O'Meara





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

Date: 20 Nov 1998 12:05:53 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Hashed array printing ?
Message-Id: <x7k90q2t1q.fsf@sysarch.com>

>>>>> "DKO" == Douglas K O'Leary <dkoleary@tako.wwa.com> writes:


  DKO> However, when I throw in a newline to try & keep the code 
  DKO> readable, I get the array pointer on one of the variables only...

  DKO> printf ("%-18s %-5s %5d %5d\n",$disk,\
  DKO> $Disks{$disk}[0],$Disks{$disk}[1],$Disks{$disk}[2]);

  DKO> 	results in:

  DKO> [[display snipped]]
  DKO> /dev/dsk/c7t2d7    SCALAR(0x40060b2c)  4384    16
  DKO> /dev/dsk/c8t3d0    SCALAR(0x40060b68)  4384   288
  DKO> [[display snipped]]

  DKO> 1.   Why does it work on one line and not on two?

you don't need the \ to continue lines in per;l. statements can be as
long as they want. so you are actually applying thr reference operator \
to the next value so you print its reference and not its value. just
delete the \ and you will be back to the original output.

hth,

uri

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


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

Date: 20 Nov 1998 19:40:57 GMT
From: "Douglas K. O'Leary" <dkoleary@tako.wwa.com>
Subject: Re: Hashed array printing ?
Message-Id: <734gk9$iv6$1@hirame.wwa.com>

Uri Guttman <uri@sysarch.com> wrote:
: you don't need the \ to continue lines in per;l. 

And, so it turns out that it was a dumb newbie question after all.
Thank you for help; that was the answer.

Doug

-- 
    
--------------------
Douglas K. O'Leary
Senior System Admin
dkoleary@mayspeh.com
dkoleary@wwa.com
--------------------


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

Date: Fri, 20 Nov 1998 11:04:42 -0800
From: Dale Sutcliffe <dales@enhanced-performance.com>
Subject: Help - popup window option
Message-Id: <3655BD49.7F8141C6@enhanced-performance.com>

based on which radio button selected is it possible to display results in a new window and/or in the
same window, below the form?
How?



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

Date: Fri, 20 Nov 1998 18:25:08 +0100
From: mikel <muriarte@nextel.es>
Subject: help: can't find HTTP_COOKIE. my cookies don't go
Message-Id: <3655A5F4.58A40F6C@nextel.es>

my cookies don't go (no javascript, no perl-CGI)

CGI_perl: when i print the ENV array: the HTTP_COOKIE doesn't exist

have i to create it?

The server is Netscape Fastrack server: does it matter?

the cookies.txt file of my PC have no entry from this server:
troubleshooting?

regards in advance

mikel



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

Date: Fri, 20 Nov 1998 11:29:15 -0600
From: Marty Blase <mblase@ncsa.uiuc.edu>
Subject: Re: HELP: how to prompt for input from command line?
Message-Id: <3655A6EB.FC30D876@ncsa.uiuc.edu>

Okay, I got what I needed. Thanks! (The Camel book doesn't have an index
listing for "prompt". Looking up "STDIN", of course, told me exactly what
you guys just did.)

FFR, here's a generic sample of the UNIX code I needed:

while() {                     # infinite loop
	print "Enter some text, or nothing to quit: ->";
	$text = <STDIN>; 
	chomp $text;          # strip the linefeed
	last unless $text;    # quits if the user just hit "enter"
	$text =~ <some modifications>;
	print "Modified text is: $text\n";
}


- Marty


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

Date: Fri, 20 Nov 1998 11:04:19 -0600
From: Aaron Delong <delonad@netdoor.com>
Subject: Re: How do you pass parameters to Perl script from HTML #exec statement?
Message-Id: <Pine.GSO.4.05.9811201103370.19882-100000@lance.netdoor.com>

Have you tried adding your arguments like this:

<!--#exec cgi="/cgi-shell/my_script.pl?arg1=one&arg2=two&arg3=three"-->


On Fri, 20 Nov 1998, Bill Morgan wrote:

> I am running the Netscape Enterprise v3.5 web server on an NT 4.0 platform.  I 
> am calling a Perl script from an HTML file using the #exec statement.
> For example, <!--#exec cgi="/cgi-shell/my_script.pl" -->
> 
> I need to pass a parameter to the Perl script from the #exec line, but I 
> cannot figure out how to do it!  I need to know the proper syntax for passing 
> parameters from #exec, as well as how to capture the parameter name and value 
> in the Perl script.
> I would be very happy if someone could share the secret with me.  Please email 
> any replies as well as posting to this group.  Thanks very much!
> 
> ---------------------------------------------------------------------------
> William E. Morgan       NAVAL SURFACE WARFARE CENTER
> Code N84                     email: wmorgan@nswc.navy.mil
> 17320 Dahlgren Rd.     phone: (540)653-6088
> Dahlgren, VA  22448   fax: (540)653-1810
> 
> 
> 



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

Date: Fri, 20 Nov 1998 14:30:17 -0500
From: Sylvain Lavigne <proband@cam.org>
Subject: How secured my flat database could be using cgi?
Message-Id: <3655C349.F9D0839A@cam.org>

Hi!

I'm using cgi to make flat file databases on my home directory.
So, I'm a bit anxious about security. 2 Questions:

1.
>From my script I give read access to my database and I put
a chmod 744 database.dat permission.  So, far it is ok.  If
my database is readable, can someone else read the file by
bypassing the cgi script and have access to private data?
How can I prevent that?

2.
>From my script I give write access to my database and I put
a chmod 742 database.dat permission.  So, far it is ok.  If
my database is writable, can someone else write in the file by
bypassing the cgi script and corrupt my private data?
How can I prevent that?

All suggestions will be appreciated.

Thank for helping.

Sylvain.





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

Date: 20 Nov 1998 12:19:28 -0500
From: pverst1@umbc.edu (P8r Versteegen)
Subject: Newbie 'sys/socket.ph' question (was Re: Raw Sockets)
Message-Id: <7348b0$8od@alumni.umbc.edu>

Once upon a time, someone write:
>>
>> Here is some code for a 'server' / 'client' using sockets:
>>
>> ---------- Server ----------
>>
>> $line = "Test\n"; #Data to send
>>
>>
>> $port = 5000;
>>
>> ($d1, $d2, $prototype) = getprotobyname("tcp");
>> ($d1, $d2, $d3, $d4, $client) = gethostbyname (`hostname`);
>> ($d1, $d2, $d3, $d4, $server) = gethostbyname ("your hostname defined in the
>> server code");
>>
>> $clientaddr = pack ("Sna4x8", 2, 0, $client);
>> $serveraddr = pack ("Sna4x8", 2, $port, $server);
>>
>> socket (SOCKET, 2, 1, $prototype) || die ("No socket");
>> bind (SOCKET, $clientaddr) || die ("Can't bind");
>> connect (SOCKET, $serveraddr);
>>
>> $line = <SOCKET>;
>> print ("$line\n");
>> close (SOCKET);
>>

    I'm trying to learn perl and its socket API's, but my
"require 'sys/socket.ph';" call give this error:

Illegal expression (COND_EXPR) as lvalue in file /usr/lib/perl/sys/socket.ph at line 98, next 2 tokens ") )"

    My naive guess is that I need to "require" more files.  Correct?
If so, whch ones?  aTdHvAaNnKcSe

    L8r, P8r.
    pverst1@alumni.umbc.edu

=;)

"History's the course, and life's the test."  -- Cool Moe Dee



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

Date: Fri, 20 Nov 1998 18:03:16 GMT
From: mcnay@my-dejanews.com
Subject: NT perl and mail
Message-Id: <734aso$j7$1@nnrp1.dejanews.com>

I know how to do mail from unix perl scripts. (sendmail)

Is there a way, or module to do mail from NT perl scripts.  If so, sample
please, and what needs to be set up on the machine running the perl.

I have a script that is looking at database issues and needs to notify a
person if there is problems, since they won't take the time to read the log
on the machine.

Thanks

ruth

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Sat, 21 Nov 1998 02:21:18 +0800
From: Ron <mkshanx@uxmail.ust.hk>
Subject: Perl CGI on NT error
Message-Id: <Pine.GSO.3.95L.981121021937.6271B-100000@uststf1>

HI, 


My simple program : 

#!/usr/local/bin/perl  
# hello.pl - my first perl script!  

use CGI;  
print "Hello, world!\n";	



which i copied from my book is giving the following problem: 
"
%1 is not a valid Windows NT application. 
"


Is it something to do with the #! user/... part? 
Since that sounds like UNIX? 

If yes, then what should I do for having it work in UNIX?

Thanks,
Ron




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

Date: Fri, 20 Nov 1998 17:48:12 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: puzzler
Message-Id: <wXh52.784$CY1.3041863@news.itd.umich.edu>

In article <733v23$l9i$1@nnrp1.dejanews.com>,
 <jschueler@detroit.usweb.com> wrote:
>Is there a good trick for transposing a two dimensional array?	That is,
>combine a two dimensional array into a one dimensional array columnwise: 1st
>element/1st row followed by 1st element/2nd row, etc.  There must be some way
>to streamline what I wrote.

>my @LOL = (
>        [ "fred", "barney" ],
>        [ "george", "judy", "elroy" ],
>        [ "homer", "lisa", "bart" ],
>        ) ;

Here's what I came up with:

$i = 0;
@Result = ( );
do {
	$n = @Result;
	do { push @Result, $$_[$i] if $i < @$_ } foreach @LOL;
	$i++;
} while ($n < @Result);

-- 
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


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

Date: Fri, 20 Nov 1998 20:45:55 +0100
From: jwl@worldmusic.de (Joergen W. Lang)
Subject: Re: puzzler
Message-Id: <1dit6ei.enksjw90z37aN@host029-210.seicom.net>

<jschueler@detroit.usweb.com> wrote:

> Is there a good trick for transposing a two dimensional array?    That is,
> combine a two dimensional array into a one dimensional array columnwise: 1st
> element/1st row followed by 1st element/2nd row, etc.  There must be some way
> to streamline what I wrote.
> 
> The following code prints out:
> 
> fred
> george
> homer
> barney
> judy
> lisa
> elroy
> bart
> 
> ------------------ begin code --------------------
> #! /usr/bin/perl5
> 
> my @LOL = (
>         [ "fred", "barney" ],
>         [ "george", "judy", "elroy" ],
>         [ "homer", "lisa", "bart" ],
>         ) ;
> 
> my $IDX ;
> my @RETVAL = () ;
> 
> while ( @LOL ) {
>         shift @LOL while ( @LOL && ! @{ $LOL[0] } ) ;
>         for ( $IDX = 0 ; @LOL && @{ $LOL[$IDX] } ; $IDX++ ) {
>                 push( @RETVAL, shift @{ $LOL[$IDX] } ) ;
>                 }
>         }
> 
> print join "\n", @RETVAL ;
> print "\n" ;

How 'bout this:

#!/usr/bin/perl -w

@LOL = (
        [ "fred", "barney" ],
        [ "george", "judy", "elroy" ],
        [ "homer", "lisa", "bart" ],
        ) ;

# Just in case you don't know the number of elements in
# the longest array of @LOL.

$longest = 0;
foreach $index (0..$#LOL) { 
    $longest = @{ $LOL[$index] } if ( @{ $LOL[$index] } > $longest);
}

# Collect

foreach $n (0..$longest) {
    foreach $m (0..$#LOL) {
        push @colum_wise, "$LOL[$m][$n]\n" if defined ($LOL[$m][$n]);
    }
}

print @colum_wise;

__END__

hth,

Joergen
-- 
-------------------------------------------------------------------
   "Everything is possible - even sometimes the impossible"
             HOELDERLIN EXPRESS - "Touch the void"
-------------------------------------------------------------------


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

Date: Fri, 20 Nov 1998 13:01:49 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: dropzone@mail.utexas.edu
Subject: Re: reset one variable?
Message-Id: <3655BC9D.8B97E43C@email.sps.mot.com>

[posed to c.l.p.m and copy emailed]

forrest reynolds wrote:
> 
> Hello,
>              I'm looking in the Camel book at "reset".... it doesn't
> mention resetting
> just one variable. Is this possible without using:
> 
>               $var = "" ;
> 

reset a variable? do you mean

$var = undef ,or, undef $var ,or, ....


-TK


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

Date: Thu, 19 Nov 1998 14:47:04 -0500
From: "Matthew Foley" <mfoley@richmond.net>
Subject: Stdin
Message-Id: <TEj52.626$Oa2.3526@news12.ispnews.com>

How do i read info from stdin in and parse it as a varible.  Thanks




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

Date: Fri, 20 Nov 1998 09:03:56 -0800
From: Colin Kuskie <ckuskie@cadence.com>
Subject: Re: Strange days have found me!
Message-Id: <Pine.GSO.3.96.981120090220.6649A-100000@pdxue150.cadence.com>

On Thu, 19 Nov 1998, Rusty Williamson wrote:

> I'm having problems with the following code.  When ypwhich works I get a
> zero, if it fails I get 256.  This is backwards!

You're right!  Someone should document this in the perlfunc manpage!

> Does anyone see something I don't see?

Yes.  I see the entry in the perlfunc manpage:

             The return value is the exit status of the program
             as returned by the wait() call.  To get the actual
             exit value divide by 256.  See also the exec entry
             elsewhere in this document.

Read your friendly local perl manpages.
Colin



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

Date: 20 Nov 1998 18:46:36 GMT
From: pete@theory2.phys.cwru.edu (Peter J. Kernan)
Subject: Re: Sum by group
Message-Id: <734dec$e62$1@alexander.INS.CWRU.Edu>

In article <73442a$q21$1@nnrp1.dejanews.com>,
	c_b9209@my-dejanews.com writes:
> Hi
> 
> I want to sum by group in a data file were the first column has 
> groups values
> and other has regular values. The data file is really huge
> here is a script for small file but it doesn't works for a big one,
> please can
[...snip...]
> foreach $key  (sort(keys %sum0)) {
probably you are running out of memory, buy more or see
perldoc -f each
-- 
	Perl is an Elegant and Recursive Language
open SIG, "<$ENV{HOME}/.sig"         or die       "sigless!     $!"; 
$sig = do {local $/; <SIG>};         close SIG && print<<"$sig SIG";
        Pete Kernan  CWRU Physics and Statistics Depts
        http://theory2.phys.cwru.edu/~pete
$sig SIG


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

Date: Fri, 20 Nov 1998 20:04:39 +0100
From: claes_no_spam@canit.se (Claes Bjorklund)
Subject: Re: Sum by group
Message-Id: <claes_no_spam-2011982004400001@p31.one.canit.se>

In article <734dec$e62$1@alexander.INS.CWRU.Edu>,
pete@theory2.phys.cwru.edu (Peter J. Kernan) wrote:

>In article <73442a$q21$1@nnrp1.dejanews.com>,
>        c_b9209@my-dejanews.com writes:
>> Hi
>> 
>> I want to sum by group in a data file were the first column has 
>> groups values
>> and other has regular values. The data file is really huge
>> here is a script for small file but it doesn't works for a big one,
>> please can
>[...snip...]
>> foreach $key  (sort(keys %sum0)) {
>probably you are running out of memory, buy more or see
>perldoc -f each
May be I were unclear, the problem is, I have lot of fields/columns 
and the script will be too long with my solution
\Claes
>-- 
>        Perl is an Elegant and Recursive Language
>open SIG, "<$ENV{HOME}/.sig"         or die       "sigless!     $!"; 
>$sig = do {local $/; <SIG>};         close SIG && print<<"$sig SIG";
>        Pete Kernan  CWRU Physics and Statistics Depts
>        http://theory2.phys.cwru.edu/~pete
>$sig SIG


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

Date: Fri, 20 Nov 1998 13:09:01 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: c_b9209@my-dejanews.com
Subject: Re: Sum by group
Message-Id: <3655BE4D.BDE0FADD@email.sps.mot.com>

[posted to c.l.pm and copy emailed]

c_b9209@my-dejanews.com wrote:
> 
> Hi
> 
> I want to sum by group in a data file were the first column has groups values
> and other has regular values. The data file is really huge
> here is a script for small file but it doesn't works for a big one,please can
> anyone help me this problem make me crazy
> 
> \Claes
> 
> sub test{
> open IN, "$utdata\\tabel.dat" or die "can't open in: $!";
> while (<IN>){
> ($var,@DATS)=split(" ",$_);
>    $suml{$var}  = [  @DATS ];
>    $sum0{$var}+= $DATS[0];
>    $sum1{$var}+= $DATS[1];
>    $sum2{$var}+= $DATS[2];
>    $sum3{$var}+= $DATS[3];
>    $sum4{$var}+= $DATS[4];
>    $ant{$var}+=1;
> }
> foreach $key  (sort(keys %sum0)) {
>     print "$key =  $ant{$key} $sum0{$key} $sum1{$key} $sum2{$key}  $sum3{$key}
> $sum4{$key}\n";
> 
> }
> 
> }

posting multiple copy of the same question doesn't make it quicker, you
are just congesting this already congested ng.

You did not supply a small sample of you data file, so your code isn't
helpful enough, though it looked 'normal' to me. You also didn't
describe axactly what your problem was. BTW, what did you mean by "it
doesn't works for a big one"?

-TK


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

Date: Fri, 20 Nov 1998 19:39:48 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: Sum by group
Message-Id: <734gi1$5io$1@nnrp1.dejanews.com>

In article <73442a$q21$1@nnrp1.dejanews.com>,
  c_b9209@my-dejanews.com wrote:

> Hi
>
> I want to sum by group in a data file were the first column has groups values
> and other has regular values. The data file is really huge
> here is a script for small file but it doesn't works for a big one,please can
> anyone help me this problem make me crazy

You posted this question once before under a different subject header
 ... why?

Again:

while (<DATA>) {
   @temp = split/\s+/;
   for ($i=1; $i<@temp; $i++) {
      push @{$group{$temp[0]}{$i}}, $temp[$i];
   }
}

foreach $grp (sort keys %group) {
   foreach $clmn (sort keys %{ $group{$grp} } ) {
      $sum = 0;    # have to reset this each time through the loop
      $cnt = @{ $group{$grp}{$clmn} };
      for ($i=0; $i<@{ $group{$grp}{$clmn} }; $i++) {
         $sum += $group{$grp}{$clmn}[$i];
      }
      print "Group $grp column $clmn: sum = $sum, n = $cnt\n";
   }
}
__DATA__
setA 1 2 3 4
setB 5 6 7 8
setA 9 10 11 12
setB 13 14 15 16

will print out:

Group setA column 1: sum = 10, n = 2
Group setA column 2: sum = 12, n = 2
Group setA column 3: sum = 14, n = 2
Group setA column 4: sum = 16, n = 2
Group setB column 1: sum = 18, n = 2
Group setB column 2: sum = 20, n = 2
Group setB column 3: sum = 22, n = 2
Group setB column 4: sum = 24, n = 2

Patrick Timmins
$monger{Omaha}[0]

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 20 Nov 1998 13:22:40 -0500
From: John Scarpaci <jscarpaci@gpu.com>
Subject: undef VB 6.0 COM object crash
Message-Id: <3655B36F.65578B9F@gpu.com>

I am encountering problems using the ActivePerl distribution to create
COM objects written in VB 6.0 and then undefing them.  Below is a
description I sent to ActiveState.  Is anyone encountering this?

Thanks in advance,
John Scarpaci
GPU Energy -- Reading, PA 19612


A COM object written in VB 6.0 causes perl.exe to trap.
Steps to produce the crash :
1. The COM object is instantiated with Win32::OLE->new("SayHello.Hello",
$obj).
2. The object is then undefed.
3. The script then crashes.

The undef crashes according to the debugger at :
Win32::OLE::Tie::FETCH(D:\Perl\site\lib/Win32/OLE.pm:190):
190:        $self->Fetch($key, !($^H & 0x200));

The expectation is the script ends without a dialog box stating the
following :

The instruction at "0x66001b81" referenced memory at "0x66001b81".  The
memory could not be "read".

Click on OK to terminate the application
Click on CANCEL to debug the application

The problem occurs 9 out of 10 times when running the script in the
"Sample Code" section.  The COM object is local.  The problem does not
seem to occur with COM objects written in Visual J++6.0.  The ActivePerl
build 506 distribution is
being used.  VB 6.0 is being used for the COM object.


Sample_Code====================================================

# the perl code
use strict;
use Win32::OLE;

my $obj;
$obj = Win32::OLE->new("SayHello.Hello", $obj) || die "CreateObject:
$!";
undef $obj;

' the VB 6.0 code for a COM DLL
Public m_hello As String

Public Function Say()
   Say = m_hello
End Function




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

Date: 20 Nov 1998 12:31:46 -0600
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: Win32::TieRegistry and EventLog
Message-Id: <734cii$kkv@fohnix.metronet.com>

keydet89@yahoo.com writes:
) Does anyone have working examples of scripts that use
) Win32::TieRegistry?  I have NT 4.0 w/ ActivePerl build 506.

The documentation is full of examples.  I also have some simple
scripts that use it but I don't think they would be more informative
than the examples in the docs.

The documentation is contained in TieRegistry.pm using POD, which
means you can just read it directly or you can use tools like
perldoc or pod2html to translate the simple X<> formatting tags
away.

If you have something you are trying that isn't working, perhaps
you should post a small example of the code, a description of what
you wanted the code to do, and a description of what it does and
doesn't do that you don't like.

If there is something about the documentation that you would like
improved, suggestions are welcome.
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: 12 Jul 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 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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