[26167] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8356 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 25 11:05:29 2005

Date: Thu, 25 Aug 2005 08:05:07 -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, 25 Aug 2005     Volume: 10 Number: 8356

Today's topics:
    Re: A simple question using SPLIT <aman.lalla@sympatico.ca>
    Re: Can a Perl Programmer Pick up PHP quickly? <nomail@hursley.ibm.com>
        can't rebind placehodler - Blob, ODBC, SQL Server, DBI, <eric@afaik.us>
        Field matching <mail@nomail.no.com>
    Re: Field matching <noreply@gunnar.cc>
    Re: Field matching <mail@nomail.no.com>
        Is there any performance benefit to... <nomail@hursley.ibm.com>
    Re: Is there any performance benefit to... <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: Is there any performance benefit to... <nomail@hursley.ibm.com>
    Re: Is there any performance benefit to... <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: Is there any performance benefit to... <sisyphus1@nomail.afraid.org>
        Making Datatypes Constant and Emulating Const Correctne <vtatila@mail.student.oulu.fi>
    Re: Making Datatypes Constant and Emulating Const Corre <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: move information from HTTP::Request to CGI.pm - Sol <miroslav@suchy.cz>
        need help with list of lists ( multi dimensional array) <not_valid2@yahoo.com>
    Re: Obtaining verbose info for http transfers. <kuujinbo@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 25 Aug 2005 13:23:51 GMT
From: Aman <aman.lalla@sympatico.ca>
Subject: Re: A simple question using SPLIT
Message-Id: <79EF1A86-156B-11DA-80EB-000D935B0FEC%aman.lalla@sympatico.ca>

Toni Erdmann <for-spammers-only@web.de> wrote:
 
> Aman wrote:
> 
>> Hello everyone,
>> 
>> I am new to perl and I am trying to split a line but can't seem to get 
>> it to work. Basically, the line is made up of multiple whitespaces.
>> An example of a line is as follows and I want to split it into 
>> variables.
>> 
>> 1  1 808748 1081461   0   0   0   1    3   0 744 1190 850  0  1 98  1
>> 
>> I tried using the following 
>> 
>> 	($r,$b,$avm)=split(/\s/,$line);
>> 
>> to split the first 3 rows but it does not work. Any ideas on how to 
>> accomplish this ? Ideally I would like to split each col. into a 
>> variable. Any help will be appreciated. Thanks
>> 
>> Aman
>> 
> 
> ($r,$b,$avm) = split( /\s+/, $line );
>                           ^
> 
> Toni
> 
> 

Thanks Toni, really appreciated. I will give this a shot.



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

Date: Thu, 25 Aug 2005 14:50:31 +0100
From: Derek Fountain <nomail@hursley.ibm.com>
Subject: Re: Can a Perl Programmer Pick up PHP quickly?
Message-Id: <430dccbe$0$17939$892e7fe2@authen.white.readfreenews.net>

Mike wrote:
> I have a lot of experience with Perl and a good paying job has come up
> that requires someone to update and maintain a website written in PHP.
> 
> Can a Perl programmer pick up PHP easily? Are there similarities?

PHP should present no problems to an experienced Perl guy. What does 
take some learning is the integration with the web server, http, and 
other technologies. If you can't, for example, explain in some detail 
how a session cookie works, and what security implications you might 
want to consider for an application of one, you might struggle with even 
a modest PHP program.

You may have some relevant Perl experience, depending on what you've 
been doing with Perl, but don't assume that because the language looks 
fairly simple to pick up that you'll know how to implement robust 
solutions with it.


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

Date: Thu, 25 Aug 2005 10:47:30 -0400
From: Eric Anderson <eric@afaik.us>
Subject: can't rebind placehodler - Blob, ODBC, SQL Server, DBI, Win32
Message-Id: <1124981258.f6eec5730bb9f7dee0452caeaf7a4b63@teranews>

I have been banging my head against the wall for a while now trying to 
figure out why I can't upload a some blob data to a SQL Server database 
via DBI. I think I had it working a while back but I cannot be sure and 
obviously I am missing something here. The basic code is:

$sql = 'UPDATE "File" SET Data = ? WHERE FileID = ?';
$stmt = $self->storage()->prepare( $sql );
$stmt->trace('5', 'C:\trace.log');
$stmt->bind_param(1, $self->data(), {TYPE=>SQL_LONGVARBINARY});
$stmt->bind_param(2, $self->id());
$stmt->execute();
$stmt->trace('0');

I've tried many variations of the above but I always get the same basic 
results. The above variations is what I understand as the "correct" 
method based on the documentation. This code is inside an object so 
$self->data() returns the blob data as a scalar and $self->id() returns 
the id of the record we are updating. The whole thing is in the context 
of a CGI application (Mason actually) that is doing a file upload. My 
test file is a PDF file (but I have tried many different files of 
various sizes and types). $self->storage() returns a database handler to 
the SQL server and I generally haven't had any problems storing other 
types of data. It will return a brand new handler (new connection) so 
there is not an issue of a previous execution getting in the way.

My error message I get is:

Can't rebind placeholder 1 at /Program Files/Apache 
Group/Apache2/sites/cordata/singlesignon/sso/app/models//Data/File.pm 
line 36.

Line 36 is the execute() statement. To try to debug this I enabled 
tracing (as you can see from the code). I have pasted the trace at the 
end of this message. I would be very thankful for any insight that could 
be provided. The two things that jump out to me in the trace are:

SQLDescribeParam failed reverting to default type for this parameter: 
HY010 [Microsoft][ODBC Driver Manager] Function sequence error

and

_rebind_ph/SQLBindParameter error -1 recorded: [Microsoft][ODBC SQL 
Server Driver]Invalid precision value (SQL-HY104)(DBD: 
_rebind_ph/SQLBindParameter err=-1)

but I don't know enough about what is going on to determine what I need 
to do to fix the problem. Again thank you for any help you can provide.

Eric

############# TRACE FILE ############


     DBI::st=HASH(0x234d2ac) trace level set to 0x5/0 (DBI @ Ox0/0) in 
DBI 1.42-ithread (pid 3704)
     -> bind_param for DBD::ODBC::st (DBI::st=HASH(0x234e404)~0x234d2ac 
1 '%PDF-1.2
%âãÏÓ

773 0 obj
<<
/Linearized 1
/O 775
/H [ 1488 1484 ]
/L 470565
/E 25965
/N 112
/T 454986
 >>
endobj
                                                    xref
773 54
0000000016 00000 n
0000001431 00000 n
0000002972 00000 n
0000003206 00000 n
0000003336 00000 n
0000003359 00000 n
0000005511 00000 n
0000005786 00000 n
0000005943 00000 n
0000006149 00000 n
000000638...' HASH(0x23507f0)) thr#2243ec
bind 1 <== '%PDF-1.2
%âãÏÓ

773 0 obj
<<
/Linearized 1
/O 775
/H [ 1488 1484 ]
/L 470565
/E 25965
/N 112
/T 454986
 >>
endobj
                                                    xref
773 54
0000000016 000' (attribs: HASH(0x23507f0)), type 0
SQLDescribeParam idx = 1.
SQLDescribeParam failed reverting to default type for this parameter: 
HY010 [Microsoft][ODBC Driver Manager] Function sequence error
     <- bind_param= 1 at /Program Files/Apache 
Group/Apache2/sites/cordata/singlesignon/sso/app/models//Data/File.pm 
line 34 via \Program Files\Apache 
Group\Apache2\sites\cordata\singlesignon\sso\tmp\obj\app\controllers\file\edit.html 
line 115
     -> bind_param for DBD::ODBC::st (DBI::st=HASH(0x234e404)~0x234d2ac 
2 '41') thr#2243ec
bind 2 <== '41' (attribs: ), type 0
SQLDescribeParam idx = 2.
SQLDescribeParam failed reverting to default type for this parameter: 
HY010 [Microsoft][ODBC Driver Manager] Function sequence error
     <- bind_param= 1 at /Program Files/Apache 
Group/Apache2/sites/cordata/singlesignon/sso/app/models//Data/File.pm 
line 35 via \Program Files\Apache 
Group\Apache2\sites\cordata\singlesignon\sso\tmp\obj\app\controllers\file\edit.html 
line 115
     -> execute for DBD::ODBC::st (DBI::st=HASH(0x234e404)~0x234d2ac) 
thr#2243ec
     dbd_st_execute (outparams = 0)...
bind 1 <== '%PDF-1.2
%âãÏÓ

773 0 obj
<<
/Linearized 1
/O 775
/H [ 1488 1484 ]
/L 470565
/E 25965
/N 112
/T 454986
 >>
endobj
                                                    xref
773 54
0000000016 00000 n
0000001431 00000 n
0000002972 00000 n
0000003206 00000 n
0000003336 00000 n
0000003359 00000 n
0000005511 00000 n
0000005786 00000 n
0000005943 00000 n
0000006149 00000 n
000000638...' (size 470565/470566/0, ptype 4, otype 1, sqltype 12)
bind 1 <== '%PDF-1.2
%âãÏÓ

773 0 obj
<<
/Linearized 1
/O 775
/H [ 1488 1484 ]
/L 470565
/E 25965
/N 112
' (len 470565/470565, null 0)
     bind 1: CTy=1, STy=VARCHAR, CD=470565, Sc=0, VM=470565.
     SQLBindParameter: idx = 1: fParamType=1, name=1, fCtype=1, SQL_Type 
= 12, cbColDef=470565, scale=32767, rgbValue = 234b374, 
cbValueMax=470565, cbValue = -470665
     Param value = 
dbd_error: err_rc=-1 rc=0 s/d/e: 38869944/38867784/38867616
dbd_error: SQL-HY104 (native 0): [Microsoft][ODBC SQL Server 
Driver]Invalid precision value (SQL-HY104)
dbd_error: err_rc=-1 rc=0 s/d/e: 0/38867784/38867616
dbd_error: err_rc=-1 rc=0 s/d/e: 0/0/38867616
_rebind_ph/SQLBindParameter error -1 recorded: [Microsoft][ODBC SQL 
Server Driver]Invalid precision value (SQL-HY104)(DBD: 
_rebind_ph/SQLBindParameter err=-1)
!   -> DESTROY for DBD::ODBC::st (DBI::st=HASH(0x234d2ac)~INNER) thr#2243ec
        ERROR: -1 '[Microsoft][ODBC SQL Server Driver]Invalid precision 
value (SQL-HY104)(DBD: _rebind_ph/SQLBindParameter err=-1)' (err#0)
!   <- DESTROY= undef during global destruction


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

Date: Thu, 25 Aug 2005 14:43:34 +0100
From: Geezer From The Freezer <mail@nomail.no.com>
Subject: Field matching
Message-Id: <430DCB06.82BC1BA9@nomail.no.com>

Whats the best way at using field manipulation in perl (much like 
awk where you can use: awk '$2 == 3 && $3 == 9{print}'  )

Assume I don't know how many fields are in each line of the input file too


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

Date: Thu, 25 Aug 2005 16:13:53 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Field matching
Message-Id: <3n61vpF1jq1U1@individual.net>

Geezer From The Freezer wrote:
> Whats the best way at using field manipulation in perl (much like 
> awk where you can use: awk '$2 == 3 && $3 == 9{print}'  )
> 
> Assume I don't know how many fields are in each line of the input file too

Which ways are you considering?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 25 Aug 2005 15:59:29 +0100
From: Geezer From The Freezer <mail@nomail.no.com>
Subject: Re: Field matching
Message-Id: <430DDCD1.B806BAA@nomail.no.com>



Gunnar Hjalmarsson wrote:
> 
> Geezer From The Freezer wrote:
> > Whats the best way at using field manipulation in perl (much like
> > awk where you can use: awk '$2 == 3 && $3 == 9{print}'  )
> >
> > Assume I don't know how many fields are in each line of the input file too
> 
> Which ways are you considering?
> 

I was considering sticking the whole file in an array and using a foreach $line
(@array)
then splitting the $line and then trying to compare the fields, but it seems
sloppy.
Just wondered if there was a simpler approach.


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

Date: Thu, 25 Aug 2005 14:24:52 +0100
From: Derek Fountain <nomail@hursley.ibm.com>
Subject: Is there any performance benefit to...
Message-Id: <430dc6bb$0$64033$892e7fe2@authen.white.readfreenews.net>

I've inherited a piece of code that does something like this:

sub func {
   my %hash = ();

   ...lots of code that populates and uses the hash

   %hash = ();
}

There are hundreds of these functions and they are called millions of 
times in a procedure which takes hours, sometimes days, to complete. The 
guy who wrote it was obviously concerned about performance.

The question pertains to that resetting of the hash at the end of 
function. Does it do anything that exiting the function doesn't do? In 
Java-land I've seen things like that to force the garbage collector to 
jump in, but in Perl-land won't it just get optimised away? The hash 
doesn't get that big, as far as I can see, and there's nothing unusual 
in any of the hash processing code.

Normally I'd just remove the line (or ignore it) but since it appears in 
every one of these functions, and since removing a useful optimisation 
might add an hour or two to my runtime, I thought I'd ask.


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

Date: Thu, 25 Aug 2005 15:35:34 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Is there any performance benefit to...
Message-Id: <Xns96BD9E9E0662Delhber1lidotechnet@62.89.127.66>

Derek Fountain <nomail@hursley.ibm.com> wrote:

> I've inherited a piece of code that does something like this:
> 
> sub func {
>    my %hash = ();
> 
>    ...lots of code that populates and uses the hash
> 
>    %hash = ();
> }

[...]

> Normally I'd just remove the line (or ignore it) but since it
> appears in every one of these functions, and since removing a
> useful optimisation might add an hour or two to my runtime, I
> thought I'd ask. 


Why don't you try running it without the line and seeing if there's a 
benefit? Sheesh.


-- 
Cheers,
Bernard


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

Date: Thu, 25 Aug 2005 14:43:09 +0100
From: Derek Fountain <nomail@hursley.ibm.com>
Subject: Re: Is there any performance benefit to...
Message-Id: <430dcb03$0$41250$892e7fe2@authen.white.readfreenews.net>

Bernard El-Hagin wrote:
> Derek Fountain <nomail@hursley.ibm.com> wrote:
> 
>>I've inherited a piece of code that does something like this:
>>
>>sub func {
>>   my %hash = ();
>>
>>   ...lots of code that populates and uses the hash
>>
>>   %hash = ();
>>}
> 
> [...]
> 
>>Normally I'd just remove the line (or ignore it) but since it
>>appears in every one of these functions, and since removing a
>>useful optimisation might add an hour or two to my runtime, I
>>thought I'd ask. 
> 
> 
> Why don't you try running it without the line and seeing if there's a 
> benefit? Sheesh.

Because, as I said in the part you conveniently chopped out of the quote 
above, this code takes many hours - maybe days - to run.

Sheesh.


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

Date: Thu, 25 Aug 2005 15:52:14 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Is there any performance benefit to...
Message-Id: <Xns96BDA1716A0EDelhber1lidotechnet@62.89.127.66>

Derek Fountain <nomail@hursley.ibm.com> wrote:

> Bernard El-Hagin wrote:
>> Derek Fountain <nomail@hursley.ibm.com> wrote:
>> 
>>>I've inherited a piece of code that does something like this:
>>>
>>>sub func {
>>>   my %hash = ();
>>>
>>>   ...lots of code that populates and uses the hash
>>>
>>>   %hash = ();
>>>}
>> 
>> [...]
>> 
>>>Normally I'd just remove the line (or ignore it) but since it
>>>appears in every one of these functions, and since removing a
>>>useful optimisation might add an hour or two to my runtime, I
>>>thought I'd ask. 
>> 
>> 
>> Why don't you try running it without the line and seeing if
>> there's a benefit? Sheesh.
> 
> Because, as I said in the part you conveniently chopped out of the
> quote above, this code takes many hours - maybe days - to run.


So?


-- 
Cheers,
Bernard


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

Date: Fri, 26 Aug 2005 00:27:30 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Is there any performance benefit to...
Message-Id: <430dd581$0$22808$afc38c87@news.optusnet.com.au>


"Derek Fountain" <nomail@hursley.ibm.com> wrote in message
news:430dcb03$0$41250$892e7fe2@authen.white.readfreenews.net...
> Bernard El-Hagin wrote:
> > Derek Fountain <nomail@hursley.ibm.com> wrote:
> >
> >>I've inherited a piece of code that does something like this:
> >>
> >>sub func {
> >>   my %hash = ();
> >>
> >>   ...lots of code that populates and uses the hash
> >>
> >>   %hash = ();
> >>}
> >
> > [...]
> >
> >>Normally I'd just remove the line (or ignore it) but since it
> >>appears in every one of these functions, and since removing a
> >>useful optimisation might add an hour or two to my runtime, I
> >>thought I'd ask.
> >
> >
> > Why don't you try running it without the line and seeing if there's a
> > benefit? Sheesh.
>
> Because, as I said in the part you conveniently chopped out of the quote
> above, this code takes many hours - maybe days - to run.
>
> Sheesh.

Weeeeeeeelllllllllllll .... let's put it this way .... take a chance .... be
bold .... and do as Bernard suggested :-)

You'll have to make allowances for me as I've had a little more bourbon than
is generally agreed to be "healthy" .... but I would have re-phrased
Bernard's (rhetorical) question  as "Why don't you try running it without
the line and seeing if there's *not* a
benefit? Sheesh."

Weeeeeeeelllllllllllll .... in truth, I'm far too much of a snag to ever be
guilty of using the word "Sheesh". Instead, let me just say that what you
considered might be a "useful optimisation" is neither useful, nor an
optimisation :-)

The only question that now remains to be answered is "Just how much Bourbon
have I, in fact, consumed ?" I don't know the answer .... though I know very
well that the last few sentences have taken an inordinately long time to
type.

Cheers,
Rob





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

Date: Thu, 25 Aug 2005 15:35:10 +0300
From: "Veli-Pekka Tätilä" <vtatila@mail.student.oulu.fi>
Subject: Making Datatypes Constant and Emulating Const Correctness
Message-Id: <dekdub$lbc$1@news.oulu.fi>

Hi,
Being relatively new to Perl with Java and bits of C under my belt, the 
newbie questions of a form how do I do or emulate thing T in Perl seem to be 
pretty common, and here's yet another one in the same generic spirit as my 
earlier thread about interfaces and type safety. If newbie questions like 
this have been answered a zillion times already, feel free to point me to 
any relevant documents or posts (via Google).

A lengthy intro follos:
I'm new to C+++, too, but remember a number of uses for the const keyword 
though the quirky syntax escapes me right now. The first use is telling the 
compiler that a pointer passed to a function is const and thus may not be 
modified. Put another way, you canot make it point to something else inside 
the function and are reminded of any modding attempts at compile time. The 
other kind of constness is making the object methods constant and is about 
denying the use of methods and operators that would change the state of the 
object being passed. You do need to flag the methods const manually but once 
this is done all attempts to call any non-const methods are caught right 
away. Things like this are called const correctness in the CPP FAQ at:

http://www.parashift.com/c++-faq-lite/const-correctness.html

The first form of constness seems useful in guarding against accidentally 
changing a pointer when you, say, ment to dereference it first. This doesn't 
appear to be as big an issue as it can be in C. As another example, passing 
an array to some analizer function as a constant strongly signals that no 
modification of the passed argument should be needed.

A good example of const methods on the OOP side, in my view, is not having 
to make a separate String class that cannot be modified. Because Java has no 
const methods, there are separate classes for Strings that are constant and 
the ones that you can actually modify (excluding the + operator for Strings 
as it's not relevant here).

As to what kind of questions these const uses translate to in Perl the 
following come to mind.
Is there a way of making:
a. a scalar,
b. an array
c. a hash
d. some reference (e,g. a blessed hash reference)
e. A method
constant inside a function or method?

Some partial solutions of which I'm aware so far:

a to c. you could always pass the parameters by value making it virtually 
impossible to modify the originals.  However, I'm worried about performance 
when huge strings or lists need to be copied around. I reckon I should do 
some benchmarks, then.

a and d. Regarding scalars, another approach I've seen involves a reference 
to a scalar constant as in:

use strict;
my $goldenRatio = \1.618;
$$goldenRatio *= 2; # Trying to modify a constant.

However, you can still sure modify the reference and I haven't found any 
good ways around that, because passing references by value doesn't really 
affect matters. You've still got a valid reference to some thingy.

c. The Hash::Util package has got some great functions that let you lock the 
key set or the hash as a whole, for example. The functions work very well 
but as they aren't built into Perl, there's no way to indicate the constness 
of a hash in a prototype, is there. Still locking the hash manually before a 
call is quite sufficient, I'm not complaining.

b. Arrays seme like a tough problem as far as constness goes , too. One way 
might be to turn the array into a hash and then use the above mentioned hash 
utilities to lock it. The PHP style would be numerical indeces denoting the 
insertion order as keys and the real array elements as values. Is turning an 
array to a locked hash a big performance hit?

Some code follows;

use strict;
use warnings;
use Hash::Util;
my @array = 1 .. 100;
my %hash;
for(my $i = 0; $i < @array; ++$i)
{ # Map array elements to a hash.
 $hash{$i} = $array[$i];
} # for

undef @array;
Hash::Util::lock_hash(%hash);

foreach(sort keys %hash)
{ # Try setting all hash values to one.
 $hash{$_} = 1; # Fails cleanly.
} # foreach

The problem with this approach is that the values don't retain there order, 
unless you use our fake array as a full blown hash and sort the keys. Is 
there a better way of doing constant arrays preferrably without lots of 
copying involved?

e. I have no idea how to make methods const and guard in some function that 
non-const methods are not called. The Java way is to make some sort of 
wrapper class that doesn't have any methods that could modify the data in 
question. But is there a more elegant solution in object oriented Perl, 
perhaps based on dynamic typing?

With kind regards Veli-Pekka Tätilä (vtatila@mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/ 




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

Date: Thu, 25 Aug 2005 15:00:54 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Making Datatypes Constant and Emulating Const Correctness
Message-Id: <430dc0ea$0$997$8fcfb975@news.wanadoo.fr>

Veli-Pekka Tätilä wrote:

> 
> As to what kind of questions these const uses translate to in Perl the 
> following come to mind.
> Is there a way of making:
> a. a scalar,
> b. an array
> c. a hash
> d. some reference (e,g. a blessed hash reference)
> e. A method
> constant inside a function or method?
<snip>

eg

use constant TEST1 => 42;
use constant TEST2 => ( 12, 34 );
use constant TEST3 => { item1 => 23 };
use constant TEST4 => sub { return 56 };

print TEST1."\n";
print join " ",TEST2,"\n";
print TEST3->{item1}."\n";
print TEST4->()."\n";

You could build these dynamically at runtime using eval, though this 
probably wouldn't gain you anything.

not sure about e. though.

Mark


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

Date: Thu, 25 Aug 2005 12:14:11 +0200
From: Miroslav Suchy <miroslav@suchy.cz>
Subject: Re: move information from HTTP::Request to CGI.pm - Solved
Message-Id: <dek5r4$9dl$1@mrazik2.dkm.cz>

Hello again,
I solved my problem. For archive purpose:
If you want to read STDIN again with CGI you must undef @CGI::QUERY_PARAM (Yeah, 
that one with comment "Other globals that you shouldn't worry about." in CGI.pm :) )

Miroslav Suchy


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

Date: Thu, 25 Aug 2005 07:29:56 -0500
From: "news-acct" <not_valid2@yahoo.com>
Subject: need help with list of lists ( multi dimensional array)
Message-Id: <430db9e5$0$63623$8046368a@newsreader.iphouse.net>

Hi -  looking for pointers or links to resources ...

I am reading in a text file - lines are
      prod_id         cost    sn
    Prod1                1000     123
    Product1        1000     124
    Product1        2000    456
    Prod1                2000    457
    Product2        1000     323
    Prod2             1000     324
    Product2        2000    556
    Prod2            2000    557
    Product3        1000     223
    Prod3             1000     224
    Product3        2000    756

I need to count how many of each product,  and how many of each product AND 
cost.
    Count of Product1 - 1000:    2
    Count of Product1 - 2000:    2
    Total count of Product1:    4

    Count of Product2 - 1000:    2
    Count of Product2 - 2000:    2
    Total count of Product2:    4

    Count of Produc3 - 1000:    2
    Count of Product3 - 2000:    1
    Total count of Product3:    3

Total count of all products:  11

It seems to be that an array would work great here, but I am not successful 
at doing it.
    would like to have an array   - 
array_cnt[Product_id][cost_value][count]
    where I could just increment the [count] value.
Thanks. 




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

Date: Thu, 25 Aug 2005 21:44:23 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Obtaining verbose info for http transfers.
Message-Id: <dekef8$ag4$1@pin3.tky.plala.or.jp>

Anno Siegel wrote:
> ko  <kuujinbo@hotmail.com> wrote in comp.lang.perl.misc:
> 
>>Eric Schwartz wrote:

[snip]

> Huh?  I don't get it.  How does one force you to use recursion and
> the other doesn't?
> 
>     sub foo {
>         my @urls = shift;
>         while ( my $url = shift @urls ) {
>             # do something
>         }
>     }
> 
>     sub bar {
>         my $url = shift;
>         # do something
>     }
> 
> 
> These do the same thing, except that foo() is unnecessarily roundabout.

I understood that they accomplish the same thing. The roundabout part, I 
obviously did not :)

> Minor differences may result from "# do something" being enclosed in a
> block in foo(), but not in bar(), but how foo() would avoid recursion
> needed in bar() is beyond me.

Sorry, mistaken/sloppy terminology. I've always associated the word 
recursion with a subroutine *explicitly* calling itself:

sub bar {
   # do stuff and sometime later..
   bar()
}

Rather than the sub's *depth*. For whatever reason when I started 
programming it just didn't look right to have a sub call itself, and the 
habit has stuck with me...

Thanks - keith


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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