Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

finding out what is uninitialized
I have two arrays that I am printing to a file and I get the "Use of
uninitialized value..." warning.  But I get that for less than 100 of
3000+ lines.  Is there a way that I can log what data is uninitialized.
Here's the snippet of code I am using:

foreach $coded (@fund_array) {
printf (FILE "$coded\n");
}

where the @fund_array is defined by :
push(@fund_array,"$cat_key\|$title\|$url\|$code\|");

I can't for the life of my figure out why I am getting this error for
only a handful.

TIA,
Tim

--
Tim McGeary
Senior Library Systems Specialist
Lehigh University
610-758-4998
tim.mcgeary@lehigh.edu



Report this thread to moderator Post Follow-up to this message
Old Post
Tim McGeary
08-03-04 08:57 PM


Re: finding out what is uninitialized
Here is what I do for uninitialized  variables:

foreach $coded (@fund_array) {
if (defined($coded) {
printf (FILE "$coded\n");
}else{
printf(FILE,"\n");
}

}

or drop off the else statement if you don't want the blank line.

Rod,



On Aug 3, 2004, at 8:48 AM, Tim McGeary wrote:

> I have two arrays that I am printing to a file and I get the "Use of
> uninitialized value..." warning.  But I get that for less than 100 of
> 3000+ lines.  Is there a way that I can log what data is
> uninitialized.  Here's the snippet of code I am using:
>
> foreach $coded (@fund_array) {
>    printf (FILE "$coded\n");
> }
>
> where the @fund_array is defined by :
>    push(@fund_array,"$cat_key\|$title\|$url\|$code\|");
>
> I can't for the life of my figure out why I am getting this error for
> only a handful.
>
> TIA,
> Tim
>
> --
> Tim McGeary
> Senior Library Systems Specialist
> Lehigh University
> 610-758-4998
> tim.mcgeary@lehigh.edu
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
http://www.iowatelecom.net/~rodj/key.txt


Report this thread to moderator Post Follow-up to this message
Old Post
Script Monkey
08-03-04 08:57 PM


Re: finding out what is uninitialized
So if I don't have this, what is printed to my file?  Nothing?  Just an
error to the screen?

What I don't understand is that if the data wasn't there, I wouldn't
have pushed it to the array previously.  And I've gone over that code in
depth and everything is being set before it's push together into the
array.  This really bugs me.  (no pun intended)

Tim

Tim McGeary
Senior Library Systems Specialist
Lehigh University
610-758-4998
tim.mcgeary@lehigh.edu



Script Monkey wrote:
> Here is what I do for uninitialized  variables:
>
> foreach $coded (@fund_array) {
>     if (defined($coded) {
>         printf (FILE "$coded\n");
>     }else{
>         printf(FILE,"\n");
>     }
>
> }
>
> or drop off the else statement if you don't want the blank line.
>
> Rod,
>
>
>
> On Aug 3, 2004, at 8:48 AM, Tim McGeary wrote:
> 
> http://www.iowatelecom.net/~rodj/key.txt
>


Report this thread to moderator Post Follow-up to this message
Old Post
Tim McGeary
08-03-04 08:57 PM


Re: finding out what is uninitialized
Tim McGeary wrote:
> I have two arrays that I am printing to a file and I get the "Use
> of uninitialized value..." warning.  But I get that for less than
> 100 of 3000+ lines.  Is there a way that I can log what data is
> uninitialized. Here's the snippet of code I am using:
>
> foreach $coded (@fund_array) {
>    printf (FILE "$coded\n");
> }

Why are you using the printf() function? If you don't know, try
print() instead.

> where the @fund_array is defined by :
>    push(@fund_array,"$cat_key\|$title\|$url\|$code\|");

If that's the only way @fund_array gets populated, there is no way it
can contain undefined elements.

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

Report this thread to moderator Post Follow-up to this message
Old Post
Gunnar Hjalmarsson
08-03-04 08:57 PM


Re: finding out what is uninitialized
On Aug 3, 2004, at 9:12 AM, Gunnar Hjalmarsson wrote:
 
>
> If that's the only way @fund_array gets populated, there is no way it
> can contain undefined elements.

Is the warning pointing to the push() line though?  One of those
variables could be undef.

James


Report this thread to moderator Post Follow-up to this message
Old Post
James Edward Gray II
08-03-04 08:57 PM


Re: finding out what is uninitialized
Good point.

Tim,

how are $cat_key, $title, $url, and $code being populated?

SM



On Aug 3, 2004, at 9:14 AM, James Edward Gray II wrote:

> On Aug 3, 2004, at 9:12 AM, Gunnar Hjalmarsson wrote:
> 
>
> Is the warning pointing to the push() line though?  One of those
> variables could be undef.
>
> James
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
http://www.iowatelecom.net/~rodj/key.txt


Report this thread to moderator Post Follow-up to this message
Old Post
Script Monkey
08-03-04 08:57 PM


Re: finding out what is uninitialized
Tim McGeary wrote:
> Ok, here's the code that is pushing $cat_key, $title, $url, and
> $code into the @fund_array:

Before digging into it, and so we know which problem we are helping
you to solve: *Is* the warning referring to the push() statement?

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

Report this thread to moderator Post Follow-up to this message
Old Post
Gunnar Hjalmarsson
08-03-04 08:57 PM


Re: finding out what is uninitialized
No, the warning statement is when I'm printing to the file.  In both
case, it refers to the process of writing to a file from the
foreach $item (@fund_array) process.

Tim

Tim McGeary
Senior Library Systems Specialist
Lehigh University
610-758-4998
tim.mcgeary@lehigh.edu



Gunnar Hjalmarsson wrote:
> Tim McGeary wrote:
> 
>
>
> Before digging into it, and so we know which problem we are helping
> you to solve: *Is* the warning referring to the push() statement?
>




Report this thread to moderator Post Follow-up to this message
Old Post
Tim McGeary
08-03-04 08:57 PM


Re: finding out what is uninitialized
[ Please type your replies below the quoted part of the message you
respond to. Please only quote what's needed to give context. ]

Tim McGeary wrote:
> Gunnar Hjalmarsson wrote: 
>
> No, the warning statement is when I'm printing to the file.  In
> both case, it refers to the process of writing to a file from the
> foreach $item (@fund_array) process.

Well, in that case the reason for the warning is to be found anywhere
else in your code.

I would suggest that you write and post a *short* but *complete*
program, including sample data, that people can copy and run, and that
illustrates the problem you are encountering. When doing so, don't
forget to enable strictures and declare *all* variables you are using.

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

Report this thread to moderator Post Follow-up to this message
Old Post
Gunnar Hjalmarsson
08-03-04 08:57 PM


RE: finding out what is uninitialized
From: Tim McGeary <mailto:tmm8@Lehigh.EDU> wrote:

: Ok, here's the code that is pushing $cat_key, $title,
: $url, and $code into the @fund_array:
:
: @sirsi_array has a DB_key, a Title and "data" which
: is either a code or a URL, in such a manner:
:
: 101|Journal of Nature|PBIO|
: 101|Journal of Nature|http://www.nature.org/|
: 102|Journal of Crap|PBIO|
: 102|Journal of Crap|http://www.crap.org/|
: 102|Journal of Crap|http://www.jstor.org/crap/|
:
: Each of the above rows is what the @sirsi_array
: would have. Here's the pseudocode for the real code
: below:
:
: Split array element.
: Check to see if we have a new DB_key
: If yes, check to see if code matches allowed codes.
:     If yes, then set $code=$data and $titles=1.
:     Else, $titles=0, push to @reject_array and move on.
: If no, set $title
:     check for jstor or prola in $data
:       If yes, append (archive) to $title
:     set $url with $ezproxy prefix
:     set $cat_key with simple algorithm based on # of titles
:     push $cat_key, $title, $url, and $code to @fund_array
: increment $titles
:
: Real code:
:
: my $preCat = 0;
: my $titles = 0;
: my $title = '';
: my $code = '';
: my $url = '';
: my @fund_array;
: my @reject_array;


You have 'strict' turned off. Not a good idea. You'll
need to present a working example or more code (all of
it?). I added this, but there is still more missing.

my @sirsi_array = (
'101|Journal of Nature|PBIO|',
'101|Journal of Nature|http://www.nature.org/|',
'102|Journal of Crap|PBIO|',
'102|Journal of Crap|http://www.crap.org/|',
'102|Journal of Crap|http://www.jstor.org/crap/|',
);


This part of the code doesn't look like it has an
error, but with all those global variables running
around, we can't be sure. We'll need to see more code
to help you find the error you're getting.



HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328








Report this thread to moderator Post Follow-up to this message
Old Post
Charles K. Clarkson
08-03-04 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Pages (3): [1] 2 3 »
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:38 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.