Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-25 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found