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.) 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];) This method of assignment matches what is found at http://perldoc.perl.org/perldsc.html#Declaration-of-an-ARRAY-OF-HASHES under the secont of add a key/value to an element. Any enlightenment would be appreciated, thanks.
use strict; use warnings; my $filepath = 'C:\Code\EventXML\events.csv'; my $xmlpath = 'C:\Code\EventXML\events.xml'; my @event_line = ""; my @events = ""; my $line = ""; my $cnt = 0; open(EVENTCSV,$filepath); while($line = <EVENTCSV>) { @event_line = split(/,/,$line); $events[$cnt]{title} = $event_line[0]; $events[$cnt]{start} = $event_line[1]; $events[$cnt]{end} = $event_line[2]; $events[$cnt]{display} = $event_line[3]; $events[$cnt]{link} = $event_line[4]; $cnt++; } close(EVENTCSV); $cnt = 0; open(EVENTXML, ">$xmlpath"); print EVENTXML "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; print EVENTXML "<?xml-stylesheet type=\"text/css\" href=\"xmlstyles.css\" ?>\n"; print EVENTXML "<doc>\n"; foreach(@events) { print EVENTXML "<event>\n"; print EVENTXML "\n"; printf EVENTXML " <title>%s</title>\n",$events[$cnt]{title}; printf EVENTXML " <date-start>%s</date-start>\n",$events[$cnt]{start}; printf EVENTXML " <date-end>%s</date-end>\n",$events[$cnt]{end}; printf EVENTXML " <date-display>%s</date-display>\n",$events[$cnt]{display}; printf EVENTXML " <link>%s</link>\n",$events[$cnt]{link}; print EVENTXML "</event>\n"; print EVENTXML "\n"; $cnt++; } print EVENTXML "<doc>\n"; close(EVENTXML); thanks, Travis Hervey