Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > open

Reply
 
 
narenkumaraguru@yahoo.co.uk
Guest
Posts: n/a
 
      05-26-2005
Hi,
I'm new to OOP. I'm having trouble with open. It is not behaving as
expected.
I've uploaded a t/c. It is available in the following link...
www.geocities.com/narenkumaraguru/test.tar.gz
Please download it and try to run it.
What I find is that the file t1 is empty and t2 is having both the
lines. Rather t1 and t2 should have one line each.
Please try yourself and get back...
Thanks,
Naren.

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      05-26-2005


http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I'm new to OOP. I'm having trouble with open. It is not behaving as
> expected.


Your problem has nothing to do with OOP or open.

> I've uploaded a t/c. It is available in the following link...
> www.geocities.com/narenkumaraguru/test.tar.gz


Good marks for a minimal but complete stript. But you loose marks by
not putting it in your Usenet post. You should always aim to minimize
the effort that people will need to put into help you.

For the help of others I've included your examples.

Please put "use strict" and "use warnings" in all your Perl source files
so that you get as much help as possible from perl. Remeber, you should
always aim to minimize the effort that _people_ will need to put into
help you (but maximise the effort machines will put in).

Perl will then point out your mistake - that you are using the
undeclared package variable %myclass:bj (global to your package)
rather than the lexically scoped variable $obj.

$obj{fh} should say $$obj{fh} or $obj->{fh}

Note: FileHandle has been replaced by IO::File and that in turn has been
rendered largley redundant by autovivification in open().

open( $obj->{fh},'|-',"cat > t$arg") or die "Can't open file with $arg\n";

(I'm assuming the usless use of cat is just an example)

----------test.pl--------------
#! /usr/bin/perl -w -I.

use myclass;

my $mc1 = new myclass;
my $mc2 = new myclass;

$mc1->fopen(1);
$mc2->fopen(2);

$mc1->print(1);
$mc2->print(2);

$mc1->fclose;
$mc2->fclose;
-------------------------------

-------myclass.pl--------------
use FileHandle;

package myclass;

sub new {
my $class = shift;
my $obj = {};
return bless $obj, $class;
}

sub fopen {
my $obj = shift;
my $arg = shift;

$obj{fh} = new FileHandle;
$obj{fh}->open(" | cat > t$arg") or die "Can't open file with $arg\n";

}

sub print {
my $obj = shift;
my $arg = shift;

$obj{fh}->print("inputs to FH $arg\n");
}

sub fclose {
my $obj = shift;
$obj{fh}->close;
}

1;
----------------------------------------



> Please download it and try to run it.
> What I find is that the file t1 is empty and t2 is having both the
> lines. Rather t1 and t2 should have one line each.
> Please try yourself and get back...
> Thanks,
> Naren.
>


 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      05-27-2005
(E-Mail Removed) <(E-Mail Removed)> wrote:

> I've uploaded a t/c.



What is a "t/c" ?


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
narenkumaraguru@yahoo.co.uk
Guest
Posts: n/a
 
      05-30-2005
a testcase...

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
C# code needed to open the windows "Open with" dialog Shilpa ASP .Net 1 03-22-2006 12:17 PM
How to Redirect to Another Already Open Page (Managing Multiple Open Pages in ASP.Net) TC ASP .Net 3 12-07-2004 07:10 AM
Why cannot open .txt file with Encoding = UNICODE using javascript window.open()? ml Java 0 11-30-2004 07:43 AM
How do I open a database connection on an access file that currently open ? THY ASP .Net 4 08-22-2003 03:50 PM



Advertisments