Re: Good God. I'm going to pull my hair out.

2002-03-07 Thread Derrick Wippler

Why did I say CGI? I meant DBI.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Good God. I'm going to pull my hair out.

2002-03-07 Thread Randal L. Schwartz

> "Derrick" == Derrick Wippler <[EMAIL PROTECTED]> writes:

Derrick> The thing that puzzles me is, that CGI is supposed to return a reference.

s/CGI/DBI/, right?

Derrick> So..

Derrick> $rec = $st->fetchrow_arrayref ;

Derrick> Should return a Reference to an array.

But it's always the *same* array, for efficiency.  So you'll need to
copy it.  It says that in the doco's somewhere, although I couldn't
find that in the two minutes I had to type this reply. :)

If you're just going to accumulate the whole thing, why not
call one of the "return the whole shebang" calls anyway,
like ->fetchall_arrayref?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Good God. I'm going to pull my hair out.

2002-03-07 Thread Derrick Wippler

Nice Article, explains alot of questions I've had about addressing and 
references.

The thing that puzzles me is, that CGI is supposed to return a reference.
So..

$rec = $st->fetchrow_arrayref ;

Should return a Reference to an array.
This Reference to an array is then placed in an array.
I shouldn't place a reference to a reference in an array should I ?

$rec = $st->fetchrow_arrayref;
push @recs, [$rec];
print "$rec[0][0]->[1] \n";


Unless CGI is not doing what it's supposed to be.
Which might be the case, because if I use

$rec = $st->fetchrow_hashref ;
push @recs, $rec;
print "$recs[0]->{field_name};

It works fine.

Unless I'm totally lost, which means what I thought I understand I really 
don't and not understanding what you thought you understood is confusing.
Isn't it ?

( Laughed the hole way through the camel book. I love Perl humor )

At 12:25 PM 3/6/02 -0800, you wrote:
> > "Derrick" == Derrick Wippler <[EMAIL PROTECTED]> writes:
>
>Derrick> Can anyone tell me why " print $rec->[4] " prints
>Derrick> but print "$recs[0]->[4] does not print a thing ?
>
>Ah yes, another candidate to read my "deep copy" article...
>
>
>
>--
>Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
><[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
>Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
>See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Good God. I'm going to pull my hair out.

2002-03-06 Thread Nikola Janceski

Good article, luckily I try to avoid too many references just for that
reason, but then my programs sometimes get bigger when run. Sanity for
memory... sometimes you don't have a choice and need to keep an eye on
things.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 06, 2002 3:25 PM
To: [EMAIL PROTECTED]
Subject: Re: Good God. I'm going to pull my hair out.


>>>>> "Derrick" == Derrick Wippler <[EMAIL PROTECTED]> writes:

Derrick> Can anyone tell me why " print $rec->[4] " prints
Derrick> but print "$recs[0]->[4] does not print a thing ?

Ah yes, another candidate to read my "deep copy" article...

<http://www.stonehenge.com/merlyn/UnixReview/col30.html>

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Good God. I'm going to pull my hair out.

2002-03-06 Thread Randal L. Schwartz

> "Derrick" == Derrick Wippler <[EMAIL PROTECTED]> writes:

Derrick> Can anyone tell me why " print $rec->[4] " prints
Derrick> but print "$recs[0]->[4] does not print a thing ?

Ah yes, another candidate to read my "deep copy" article...



-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Fwd: Re: Good God. I'm going to pull my hair out.

2002-03-06 Thread Derrick Wippler


>ok. I'm sorry. I posted my code incorrectly.
I'm using $rec[0]->[4] to try and access the data.
( I was just trying anything to get it to do something, and I didn't change 
my code back before I posted )

It's a standard multidimensional array. ( yes ? )

I've written many before. I have an exact copy of this code that returns a 
hashref. instead of an
arrayref, the hash version works flawlessly. but darned if i can fig out 
why I can't
get it to work here. Some one suggested it was a scoping issue, but I doubt 
that sense "my" will scope rec and recs to the while loop block and back.

I've already scraped this code from a function to just placing rec in my 
main code.
( because I have to get this running today ) but when I go back and clean 
things up latter I'm still gonna have this prob.
PS: This is the first Multidimensional array I've built sense upgrading to 
Perl 5.6.1
Anything change that I don't know about ?



>At 05:11 PM 3/6/02 +0100, you wrote:
>>Derrick Wippler wrote:
>> >
>> > Can anyone tell me why " print $rec->[4] " prints
>> > but print "$recs[0]->[4] does not print a thing ?
>> >
>> > I've confimed the data, the first row in the fourth column is an "F"
>> > $rec->[4] prints it, but $recs[0]->[4] does not !!! ARG 
>> @#@!#!!!@@!!@!!
>> > PS: I'm using DBI, my DBI object is $db
>> >
>> > my @recs;
>> >  my $sql = shift;
>> >  my $st = $db->prepare($sql);
>> >  my $rc = $st->execute(@_);
>> >  my $rec;
>> >
>> >  while ($rec = $st->fetchrow_arrayref)
>> >  {
>> >  print @$rec,"\n";
>> >  print "|$rec->[4]|\n";
>> >  push @recs, $rec;
>> >  }
>> >
>> >  $st->finish;
>> > print " Ref: $recs->[0][4]\n";
>>
>>have you tried $recs[0]->[4] ?
>>/jon
>>
>> >
>> > --
>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>> > For additional commands, e-mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Good God. I'm going to pull my hair out.

2002-03-06 Thread Jon Molin

Derrick Wippler wrote:
> 
> Can anyone tell me why " print $rec->[4] " prints
> but print "$recs[0]->[4] does not print a thing ?
> 
> I've confimed the data, the first row in the fourth column is an "F"
> $rec->[4] prints it, but $recs[0]->[4] does not !!! ARG @#@!#!!!@@!!@!!
> PS: I'm using DBI, my DBI object is $db
> 
> my @recs;
>  my $sql = shift;
>  my $st = $db->prepare($sql);
>  my $rc = $st->execute(@_);
>  my $rec;
> 
>  while ($rec = $st->fetchrow_arrayref)
>  {
>  print @$rec,"\n";
>  print "|$rec->[4]|\n";
>  push @recs, $rec;
>  }
> 
>  $st->finish;
> print " Ref: $recs->[0][4]\n";

have you tried $recs[0]->[4] ?
/jon

> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Good God. I'm going to pull my hair out.

2002-03-06 Thread Jeff 'japhy' Pinyan

On Mar 6, Derrick Wippler said:

>Can anyone tell me why " print $rec->[4] " prints
>but print "$recs[0]->[4] does not print a thing ?

This is a scoping issue.

>  my @recs;
>  my $sql = shift;
>  my $st = $db->prepare($sql);
>  my $rc = $st->execute(@_);
>  my $rec;
>
>  while ($rec = $st->fetchrow_arrayref) {

Here you are SETTING the $rec variable each time.  This while loop is
going to end when $st->fetchrow_arrayref returns false (probably undef),
so at that point, $rec will be undef.

>print @$rec,"\n";
>print "|$rec->[4]|\n";
>push @recs, $rec;

You are pushing $rec to the array, but $rec is not SCOPED TO THIS BLOCK,
it is scoped to the outer block.  When you change it outside the block,
the value you pushed to @recs changes too.  Since @recs holds $rec, which
is a reference, when $rec changes, so does what $recs[$i] refers to.

  $x = "japhy";
  $y = \$x;
  $x = "jeff";
  print $$y;  # jeff

Your solution is to remove the 'my $rec' from outside the while loop, and
place it in the conditional:

  while (my $rec = $st->fetchrow_arrayref) { ... }

or, in a slightly clunkier way, leave the 'my $rec' where it is and do:

  while ($rec = ...) {
push @recs, [ @$rec ];
  }

[ @$rec ] means "dereference the array reference in $rec, and then make an
anonymous array reference with its contents".  That copies (a
"shallow" copy) $rec.  But it's ugly, too, and doesn't work for
multidimensional structures.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Good God. I'm going to pull my hair out.

2002-03-06 Thread Tanton Gibbs

Your code is printing
$recs->[0][4]
NOT
$recs[0]->4

There is a big difference between the two (mainly the former is an arrayref
whereas the latter is an array).

Change your code to the latter and it should work.
- Original Message -
From: "Derrick Wippler" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 06, 2002 2:08 PM
Subject: Good God. I'm going to pull my hair out.


> Can anyone tell me why " print $rec->[4] " prints
> but print "$recs[0]->[4] does not print a thing ?
>
> I've confimed the data, the first row in the fourth column is an "F"
> $rec->[4] prints it, but $recs[0]->[4] does not !!! ARG
@#@!#!!!@@!!@!!
> PS: I'm using DBI, my DBI object is $db
>
> my @recs;
>  my $sql = shift;
>  my $st = $db->prepare($sql);
>  my $rc = $st->execute(@_);
>  my $rec;
>
>  while ($rec = $st->fetchrow_arrayref)
>  {
>  print @$rec,"\n";
>  print "|$rec->[4]|\n";
>  push @recs, $rec;
>  }
>
>  $st->finish;
> print " Ref: $recs->[0][4]\n";
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Good God. I'm going to pull my hair out.

2002-03-06 Thread Nikola Janceski

uh... don't you mean?
print $rec->[0 .. 4]; # element 0 through 4

or
print $rec->[0,4]; ## elements 0 and 4


-Original Message-
From: Derrick Wippler [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 06, 2002 2:08 PM
To: [EMAIL PROTECTED]
Subject: Good God. I'm going to pull my hair out.


Can anyone tell me why " print $rec->[4] " prints
but print "$recs[0]->[4] does not print a thing ?

I've confimed the data, the first row in the fourth column is an "F"
$rec->[4] prints it, but $recs[0]->[4] does not !!! ARG
@#@!#!!!@@!!@!!
PS: I'm using DBI, my DBI object is $db

my @recs;
 my $sql = shift;
 my $st = $db->prepare($sql);
 my $rc = $st->execute(@_);
 my $rec;

 while ($rec = $st->fetchrow_arrayref)
 {
 print @$rec,"\n";
 print "|$rec->[4]|\n";
 push @recs, $rec;
 }

 $st->finish;
print " Ref: $recs->[0][4]\n";


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Good God. I'm going to pull my hair out.

2002-03-06 Thread Derrick Wippler

Can anyone tell me why " print $rec->[4] " prints
but print "$recs[0]->[4] does not print a thing ?

I've confimed the data, the first row in the fourth column is an "F"
$rec->[4] prints it, but $recs[0]->[4] does not !!! ARG @#@!#!!!@@!!@!!
PS: I'm using DBI, my DBI object is $db

my @recs;
 my $sql = shift;
 my $st = $db->prepare($sql);
 my $rc = $st->execute(@_);
 my $rec;

 while ($rec = $st->fetchrow_arrayref)
 {
 print @$rec,"\n";
 print "|$rec->[4]|\n";
 push @recs, $rec;
 }

 $st->finish;
print " Ref: $recs->[0][4]\n";


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]