From: "Siva Prasad" <[EMAIL PROTECTED]>
> I am trying to do (read/write/append) operations on file using oops in perl.

WHY??? I mean if it's just an exercise, so be it, otherwise it's 
simply pointless. Sorry to say that, but this looks like a case of an 
OOoverdose.


> But I am getting the following error
> 
> Bareword "FileOperations" not allowed while "strict subs" in use at
> readwriteapp
> 
> end.pl line 14.
> 
> <snipped>
>             bless $file, FileOperations;

Change that to 

        bless $file, 'FileOperations';

The next problem is that you can only bless a reference, not a 
string. So you'd have to change the sub new to something like:

sub new {
        my $class = shift;
        my $self = { file => $_[0], err_code => 1};
        bless $self, $class;
}


There are several problems in the original version.
1) the first parameter to the new() method is the classname
2) enclosing a single variable (or an array or hash item) in 
doublequotes is not needed, except in very rare cases. What's more 
... it can break things, but even if it doesn't it will slow your 
scripts down and increase the memory footprint as it forces perl to 
make a copy of the value and possibly even convert between a number 
and string.
3) the $err_code variable is completely pointless. You seem to have 
misunderstood the "my" keyword. It declares a block-scoped variable. 
That is a variable that only exists until the end of the enclosing {} 
block (or the end of file). So you declared a variable and never used 
it. If you want to create a property you either need to add it into 
the $self hash that you then bless or use some of the OO frameworks. 
Moose (http://search.cpan.org/search?query=Moose&mode=module) comes 
to mind.
4) you are blessing a string, you can only bless a reference.


I think you should wait a bit and learn some more Perl before you 
start creating objects.

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to