Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

How to avoid this error...

by basicdez (Pilgrim)
on Nov 16, 2001 at 01:38 UTC ( #125688=perlquestion: print w/replies, xml ) Need Help??

basicdez has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: How to avoid this error...
by rchiav (Deacon) on Nov 16, 2001 at 01:44 UTC
    You might want to use IO::File; before you actually use it. It looks like you included your entire script and there's no declaration to use IO::File;

    Hope this helps,
    Rich

      Thanks Rich, that is exactly what I needed. You are a life savor... peace, LOVE and ((code)) basicdez
Re: How to avoid this error...
by davorg (Chancellor) on Nov 16, 2001 at 14:02 UTC

    One other small point, please change the line:

    my $output = new IO::File(">xxx.xml");

    to

    my $output = IO::File->new(">xxx.xml");

    Using the indirect object syntax can potentially lead to problems. For a discussion of these problems, see this sub-thread.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://125688]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2022-05-24 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?