Discussion:
Bareword "INPUT" not allowed while "strict subs"
Anish Kumar K.
2005-01-27 10:23:01 UTC
Permalink
Hi

I open a file and pass the file handle to the sub routine. I have used "Use Strict"
I am getting the error in the filehandle. Why is this caused.. Is it because I need to pass any other information with this

sub processTextMails
{
while(<INPUT>)
{
$returnMessage=$returnMessage.$_;
}
close(INPUT);
return $returnMessage;
}

Other routine

open (INPUT , "a.txt") II die "Cannot open this file";
$message = &processTextMails(INPUT); = Error in this line

Bareword "INPUT" not allowed while "strict subs" in use at


Thanks
Anish
Ing. Branislav Gerzo
2005-01-27 10:35:08 UTC
Permalink
Anish Kumar K. [AKK], on Thursday, January 27, 2005 at 15:53 (+0530)
wrote these comments:

AKK> open (INPUT , "a.txt") II die "Cannot open this file";
do you mean II is ||

AKK> $message = &processTextMails(INPUT); = Error in this line
AKK> Bareword "INPUT" not allowed while "strict subs" in use at

I think, you have to pass reference to INPUT (filehandler), but I am not sure.
--
...m8s, cu l8r, Brano.

[It's not creeping - Mike on title creature]
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Ankur Gupta
2005-01-27 10:41:15 UTC
Permalink
I think you can't pass filehandles directly to a sub.
You need to use typeglob.

Just add this after opening the file.
my $file = *INPUT;

$message = &processTextMails($file);
sub processTextMails
{
my $file = shift;
while(<$file>)
{
$returnMessage=$returnMessage.$_;
}
close($file);
return $returnMessage;
}

I hope this works.

--
Ankur
Post by Anish Kumar K.
Hi
I open a file and pass the file handle to the sub routine. I have used "Use Strict"
I am getting the error in the filehandle. Why is this caused.. Is it because I need to pass any other information with this
sub processTextMails
{
while(<INPUT>)
{
$returnMessage=$returnMessage.$_;
}
close(INPUT);
return $returnMessage;
}
Other routine
open (INPUT , "a.txt") II die "Cannot open this file";
$message = &processTextMails(INPUT); = Error in this line
Bareword "INPUT" not allowed while "strict subs" in use at
Thanks
Anish
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Jay
2005-01-27 15:06:21 UTC
Permalink
On Thu, 27 Jan 2005 16:11:15 +0530, Ankur Gupta
Post by Ankur Gupta
I think you can't pass filehandles directly to a sub.
You need to use typeglob.
Just add this after opening the file.
my $file = *INPUT;
$message = &processTextMails($file);
sub processTextMails
{
my $file = shift;
while(<$file>)
{
$returnMessage=$returnMessage.$_;
}
close($file);
return $returnMessage;
}
I hope this works.
--
Ankur
Or if it's a simple app, since you use while(<INPUT>) in the
subroutine, you don't actually need to pass the subroutine anything at
all. as long as INPUT is open before you call the subroutine, you
should be able to just call:

$message = &processTextMails() ;

HTH,

--jay
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Loading...