Error I am receiving is the following...
Can't locate object method "new" via package "IO::File" at ExampleForM +onks.pl line 73, <FH> chunk 5.
Here is the code that is generating this error...
#!/usr/bin/perl-Tw use strict; use Text::ParseWords; my $fname = "CommaSample2.dat"; my $toggle = ' '; my @data; my @PER_Data; my @major_PER_Data; BARE: { open FH, "< $fname" or die "Cannot open datfile: ", $!; while (<FH>) { if (/"PER"/) { $toggle = 1, next if /^"PER"\s*$/; } last if /^"EOS"\s*$/; die "Unknown or missing record tag: Got $_ on line $., datafil +e $fname.$/" if $toggle eq ''; chomp; @data = &quotewords('\s+', 0, $_); if ($toggle == 1) { { $toggle = 0; @PER_Data = ($data[0], $data[1], $data[2], $data[3] +); } push @major_PER_Data, [@PER_Data]; } $toggle = ''; } } my $i = 0; my $Num_OF_PER = 0; my @PER_Item; my @PER_Entity; my @PER_Name; my @PER_Color; my @PER_Date; foreach my $PER_item (@major_PER_Data) { $i = 0; foreach my $PER_subitem (@{$PER_item}) { $PER_Item[$i] = $PER_subitem; $i++ } $PER_Entity[$Num_OF_PER] = $PER_Item[0]; $PER_Name[$Num_OF_PER] = $PER_Item[1]; $PER_Color[$Num_OF_PER] = $PER_Item[2]; $PER_Date[$Num_OF_PER] = $PER_Item[3]; $Num_OF_PER++; } my $r = 0; print "Personal Info...\n"; while ($r < $Num_OF_PER) { print "$PER_Entity[$r] "; print "$PER_Name[$r] "; print "$PER_Color[$r] "; print "$PER_Date[$r];\n "; $r++ } my $output = new IO::File(">xxx.xml"); my $writer = new XML::Writer( OUTPUT => $output, DATA_MODE => 1, DATA_ +INDENT =>4 ); $writer=>xmlDecl( "UTF-8", 1 ); $writer=>startTag( "application" ); $writer=>endTag ( "application" ); $writer=>end();
Here is line #73 Specifically,,,
my $output = new IO::File(">xxx.xml");
I realize that this code does not make total sense, but please just help me with this error and do not suggest that I take out any existing logic. I have trimmed this down quite a bit for purposes of posting this on the page and what I think I need help with IO file reading, but please help me out if you can. peace, LOVE and ((code)) basicdez

In reply to How to avoid this error... by basicdez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.