Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help calling method "new" in perl script

Status
Not open for further replies.

Mabdi

MIS
Jul 12, 2000
6
CA
I need help, I just installed perl503, and wrote a little perl scrip, howover when I try run it, it is aborting due to this error:-

Can't call method "new" on an undefined value at
simple_report.pl line 7

This is cause by calling new in this line:-

my $FH = new $FILEHANDLE ("$file");

Can some help me please.

Thanks
[sig][/sig]
 
try:

my $file = "textfile.txt";
open(FH,$file) || die "Can't open $file to read it\n$!\n";

while(<FH>){ # while i'm not at eof
print $_; # print each line out
}

I'm sure that you want to do more than just work through the file and print each line -- but I thought I'd include that just in case you, or maybe someone else, found it useful. [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>[/sig]
 
Thanks Mike, I appreciate your help.

I forget to put

use FileHandle;

I did this, and it solved my original problem.

Thanks again.. [sig][/sig]
 
Ah right --- I don't use FileHandle and so didn't think of the package.

It seems to becoming more popular though -- I should take a look. [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>[/sig]
 
Hi Mike

Thanks for looking into my perl question, I have now substr error, :-

mabdi@hris /home/mabdi/work/perl->simple_report.pl expense.rpt
substr outside of string at simple_report.pl line 14, <GEN0> chunk 1.
Use of uninitialized value at simple_report.pl line 18, <GEN0> chunk 1.
substr outside of string at simple_report.pl line 14, <GEN0> chunk 6.
substr outside of string at simple_report.pl line 14, <GEN0> chunk 6.
Use of uninitialized value at simple_report.pl line 18, <GEN0> chunk 6.

this is refering into this this line


my ($person, $expense, $reason) = ( I have initialized the substr here I don't know why I get the error...?)
(substr($line,0,11),
substr($line,11,18),
substr($line,29,20));
if ($reason =~ m&quot;Travel&quot;i)
{
$expenses{$person} += $expense;
}
}


Thanks
Mabdi
 
Ooops, It had something to do with the flat file layout,

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top