Thanks Tom and the many others that responded.  It is much appreciated.

Travis Hervey 


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
Tom Phoenix
Sent: Friday, November 16, 2007 12:18 PM
To: Travis Hervey
Cc: beginners@perl.org
Subject: Re: Problem with Hashes

On 11/16/07, Travis Hervey <[EMAIL PROTECTED]> wrote:

> I have the below code that is reading in a csv file and writing an xml
> file.  The code as is will work fine if I remove the use strict line.
(
> I would prefer not to do this.)

All of us would prefer that you keep 'use strict'!

> However as it is now with the use
> strict it gives me a runtime error of: "Can't use string ("") as a
HASH
> ref while "strict refs" in use at C:\Code\EventXML\TestEventXML.pl
line
> 15, <EVENTCSV> line 1."  Line 15 is where it tries to assign a value
to
> an array of hashes. ($events[$cnt]{title} = $event_line[0];)

Well, the hash reference in that statement comes from $events[$cnt].
Did you put an empty string into that variable?

> my @event_line = "";

You're assigning a scalar value (an empty string) to an array. That
will give you an array of one element, and that one element is the
empty string. Is that really what you want?

> my @events = "";

Here it is again; you seem to have put an empty string in $events[0],
which would be what the message is complaining about. You probably
wanted both arrays to be empty, which is the default for new arrays:

  my(@event_line, @events);  # start out empty

The reason your program "worked" without "use strict" was that you
accidentally referred to a global variable instead of having a real
reference in $events[0], but you didn't re-use that global elsewhere
in your program. Of course, it would be easy to make the same mistake
elsewhere, and not realize that the same global is being used in
multiple places in your code, which is why "use strict" requires true
references.

> open(EVENTCSV,$filepath);

Be sure to check the return value from open(), so you'll know if the
file can't be opened.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to