Thanks a lot. Your guess was right. The second part was what I needed. I am
still not a little confused about the first, though. They do not teach
this in the institution where I study. :)  

Could you give a good reference to this things, IPC, pipes, fifo, sockets,
etc? I could not make much headway, from what I read in the man pages, and
perldoc. 

Thanks lot, 

-tir




On Fri, 12 Apr 2002, Nikola Janceski wrote:

> no... Open2 opens 2 filehandles for a command.
> 
> this:
> open2(*READ, *ZIPIT, "/apps/bin/zip $FORM{'zipfile'} -@ 2>&1");
> opens a filehandle READ that the command reads from AND
> opens a filehandle ZIPIT that the command outputs from 
> 
> at a command prompt this is what it means:
> 
> cat | /apps/bin/zip somefile.zip -@ 2>&1 | more;
>     ^                                    ^
>    READ                                ZIPIT
> 
> That's where the file handles are.
> Don't know what your command is for or what exactly you are trying to pass
> but here is my guess:
> 
> You really just want to pipe the open to output only:
> 
> open(OUTFILE, ">output.file") || die "Can't open for write: $!";
> open(COMMAND, "bunzip2 -c $ParseFile | discretise $delta $BOD $EOD |") or
> die "Cann't execute: $!";
> while(<COMMAND>){
>       print OUTPUT;
>       }
> close COMMAND;
> close OUTFILE;
> 
> 
> 
> > -----Original Message-----
> > From: Tirthankar C. Patnaik [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, April 12, 2002 2:00 PM
> > To: Nikola Janceski
> > Cc: [EMAIL PROTECTED]
> > Subject: RE: Input | Program | Output : help 
> > 
> > 
> > 
> > 
> > > did you try reading the docs? You didn't even try to use my example.
> > 
> > I did try. I could not understand your example. Let me explain: 
> > 
> > 
> > > > > open2(*READ, *ZIPIT, "/apps/bin/zip $FORM{'zipfile'} -@ 2>&1");
> > > > > READ is the input pipe
> > > > > ZIPIT is the output pipe
> > 
> > Here, are *READ, and *ZIPIT, already open, using open statements? 
> > 
> > e.g., 
> >     open(*READ,"<$ParseFile") || die "$!"; 
> >     open(*ZIPIT,"| discretise 15 35700 55800 > ${OutFile}") 
> > || die "$!"; 
> > 
> >     open2(\*READ,\*ZIPIT); 
> > 
> >  I tried this, and it didn't work. I am confused. Sorry, but please
> >  explain. A working complete example would be great. 
> > 
> > TIA, 
> > 
> > -tir
> > 
> > 
> > 
> > > 
> > > perldoc IPC::Open2
> > > 
> > > > -----Original Message-----
> > > > From: Tirthankar C. Patnaik [mailto:[EMAIL PROTECTED]]
> > > > Sent: Friday, April 12, 2002 1:52 PM
> > > > To: Nikola Janceski
> > > > Cc: [EMAIL PROTECTED]
> > > > Subject: RE: Input | Program | Output : help 
> > > > 
> > > > 
> > > > 
> > > > I'm afraid I couldn't succeed in using the IPC::Open2 module. 
> > > > Where am I
> > > > going wrong? 
> > > > 
> > > > #     }
> > > >     my($IN,$OUT);
> > > >     open(OUT,"| discretise ${delta} ${BOD} ${EOD}") || die 
> > > > "Sorry out: $!";
> > > > 
> > > >     if($suffix eq ".par"){
> > > >     open(IN,"<$ParseFile") || die "Sorry: $!";
> > > >         open2('IN','OUT');
> > > >     }
> > > > 
> > > > Could you please explain the code, in more detail? 
> > > > 
> > > > TIA, 
> > > > -tir
> > > > 
> > > > 
> > > > }
> > > > 
> > > > 
> > > > On Fri, 12 Apr 2002, Nikola Janceski wrote:
> > > > 
> > > > > You might want to look at IPC::Open2
> > > > > 
> > > > > You can open a system command with an INPUT pipe and 
> > OUTPUT pipe.
> > > > > 
> > > > > Here is how I used it.
> > > > > 
> > > > > open2(*READ, *ZIPIT, "/apps/bin/zip $FORM{'zipfile'} -@ 2>&1");
> > > > > READ is the input pipe
> > > > > ZIPIT is the output pipe
> > > > > 
> > > > > Perl Gurus, Yeah I should have used the ZIP module.. I am 
> > > > too lazy to change
> > > > > it now.
> > > > > 
> > > > > 
> > > > > > -----Original Message-----
> > > > > > From: Tirthankar C. Patnaik [mailto:[EMAIL PROTECTED]]
> > > > > > Sent: Friday, April 12, 2002 1:04 PM
> > > > > > To: [EMAIL PROTECTED]
> > > > > > Subject: Input | Program | Output : help 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > Folks, 
> > > > > >     Consider this code snippet: 
> > > > > > 
> > > > > > Here $ParseFile is a plain-text file, which could be gzipped, 
> > > > > > bzipped, or
> > > > > > not compressed at all. I'd like my program to determine 
> > > > this, open the
> > > > > > file, and cat it to another program called discretise. 
> > > > > > 
> > > > > > In the code below, 
> > > > > > 
> > > > > > my(@PARSELIST) = @ARGV;         #  This would be the 
> > .par files.
> > > > > > my($ParseFile);
> > > > > > for $ParseFile (@PARSELIST){
> > > > > >     chomp $ParseFile;
> > > > > >     my($date,$name,$suffix) = &FileTest($ParseFile);  # uses 
> > > > > > File::Basename 
> > > > > >     if($suffix eq ".bz2"){
> > > > > >         system("bunzip2 -c $ParseFile | discretise $delta 
> > > > > > $BOD $EOD > ${OUTFILE}");
> > > > > >     }elsif($suffix eq ".gz"){
> > > > > >         system("gunzip -c $ParseFile | discretise $delta $BOD 
> > > > > > $EOD > ${OUTFILE}");
> > > > > >     }elsif($suffix eq ".par"){
> > > > > >         system("cat $ParseFile | discretise $delta $BOD $EOD 
> > > > > > > ${OUTFILE}");
> > > > > >     }
> > > > > > 
> > > > > > 
> > > > > > As you can see, I've got three system commands to run on 
> > > > $ParseFile,
> > > > > > depending on it's extn (.par/.gz/.bz2).  
> > > > > > 
> > > > > > I don't know how I should ask this, but can I 
> > > > > > 
> > > > > >     1. open $ParseFile and assign a filehandle to it  
> > (IN), say.
> > > > > >     2. open $Outfile and assign a filehandle to it (OUT), 
> > > > > >     3. determine the extension of the input file,
> > > > > > 
> > > > > > And this is the important part:     
> > > > > >     4. Depending on the extension, cat, gunzip -c, or bunzip 
> > > > > > -c the input
> > > > > >         file to the output file, using the _filehandle_, 
> > > > > > without a system
> > > > > >         command. 
> > > > > > 
> > > > > >     Is this possible in Perl, if so how to do it? And is it 
> > > > > > necessary? 
> > > > > > 
> > > > > > For instance, I could have,     
> > > > > > 
> > > > > >     if($suffix eq ".bz2"){
> > > > > >         open(IN, "bunzip2 -c $ParseFile|")
> > > > > >             ||die "Could not open $ParseFile: $!";
> > > > > >     }elsif($suffix eq ".gz"){
> > > > > >         open(IN, "gunzip -c $ParseFile|")
> > > > > >             ||die "Could not open $ParseFile: $!";
> > > > > >     }elsif($suffix eq ".par"){
> > > > > >         open(IN, "<$ParseFile")
> > > > > >             || die "Could not open $ParseFile: $!";
> > > > > >     }
> > > > > > 
> > > > > > And then I open an output file: 
> > > > > > 
> > > > > >     
> > > > > >     open(OUT, "| discretise delta BOD EOD > $OutFile") || die 
> > > > > > "Sorry :$!"; 
> > > > > > 
> > > > > > Problem: How do I channel the input from $ParseFile to the 
> > > > > > OUT filehandle? 
> > > > > > 
> > > > > > Please explain in --verbose mode! I do not know these 
> > things. :)
> > > > > > 
> > > > > > -tir
> > > > > > 
> > > > > > 
> > > > > > TIA, 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > -- 
> > > > > >  Tirthankar, IGIDR. 
> > > > > >  +91-22-8400919 x275 (r), x593(o), x542(CFL). 
> > > > > >  http://www.igidr.ac.in/~tir
> > > > > > 
> > > > > >   ACKNOWLEDGE, v.t.  To confess.  Acknowledgement of 
> > one another's
> > > > > >   faults is the highest duty imposed by our love of truth.
> > > > > > 
> > > > > > 
> > > > > > -- 
> > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > > > 
> > > > > 
> > > > > 
> > > > --------------------------------------------------------------
> > > > --------------
> > > > > --------------------
> > > > > The views and opinions expressed in this email message are 
> > > > the sender's
> > > > > own, and do not necessarily represent the views and 
> > > > opinions of Summit
> > > > > Systems Inc.
> > > > > 
> > > > > 
> > > > > -- 
> > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > > 
> > > > > 
> > > > 
> > > > 
> > > > -- 
> > > >  Tirthankar, IGIDR. 
> > > >  +91-22-8400919 x275 (r), x593(o), x542(CFL). 
> > > >  http://www.igidr.ac.in/~tir
> > > > 
> > > >   SUCCESS, n.  The one unpardonable sin against one's fellows.  In
> > > >   literature, and particularly in poetry, the elements of 
> > success are
> > > >   exceedingly simple, and are admirably set forth in the 
> > > > following lines
> > > >   by the reverend Father Gassalasca Jape, entitled, for some 
> > > > mysterious
> > > >   reason, "John A. Joyce."
> > > >   
> > > >       The bard who would prosper must carry a book,
> > > >           Do his thinking in prose and wear
> > > >       A crimson cravat, a far-away look
> > > >           And a head of hexameter hair.
> > > >       Be thin in your thought and your body'll be fat;
> > > >       If you wear your hair long you needn't your hat.
> > > > 
> > > > 
> > > > 
> > > > -- 
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > 
> > > 
> > > 
> > --------------------------------------------------------------
> > --------------
> > > --------------------
> > > The views and opinions expressed in this email message are 
> > the sender's
> > > own, and do not necessarily represent the views and 
> > opinions of Summit
> > > Systems Inc.
> > > 
> > > 
> > 
> > 
> > -- 
> >  Tirthankar, IGIDR. 
> >  +91-22-8400919 x275 (r), x593(o), x542(CFL). 
> >  http://www.igidr.ac.in/~tir
> > 
> >   MONDAY, n.  In Christian countries, the day after the baseball game.
> > 
> 
> ----------------------------------------------------------------------------
> --------------------
> The views and opinions expressed in this email message are the sender's
> own, and do not necessarily represent the views and opinions of Summit
> Systems Inc.
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
 Tirthankar, IGIDR. 
 +91-22-8400919 x275 (r), x593(o), x542(CFL). 
 http://www.igidr.ac.in/~tir

  ACCORDION, n.  An instrument in harmony with the sentiments of an
  assassin.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to