Equivalent ruby for this perl?

  • Thread starter Ezra Zygmuntowicz
  • Start date
E

Ezra Zygmuntowicz

Hey there list-
I'm writing some simple gui's for some ruby scripts with Pashua
and Cocoa Dialogs. I need a little help with a perl example that I
want to convert to ruby. Any help is much appreciated.

Here is the perl code:

#!/usr/bin/perl -w

use strict;
use IO::File;

our $COCOA_DIALOG = "$ENV{HOME}/Applications/CocoaDialog.app/Contents/
MacOS/CocoaDialog";
die "$COCOA_DIALOG doesn't exist" unless -e $COCOA_DIALOG;

###
### EXAMPLE 1
###

### Open a pipe to the program
my $fh = IO::File->new("|$COCOA_DIALOG progressbar");
die "no fh" unless defined $fh;
$fh->autoflush(1);

my $percent = 0;
for (my $percent = 0; $percent <= 100; $percent++) {
if (!($percent % 5)) {
### Update the progressbar and its label every 5%
print $fh "$percent we're at $percent%\n";
} else {
### Update the progressbar every percent
print $fh "$percent\n";
}
### simulate a long operation
1 for (0 .. 90_000);
}

### Close the filehandle to send an EOF
$fh->close();

Now the loops and most of the structure I am fine with. It's mainly
the IO::File->new part that I need to know the ruby equivalent of. It
is basically just a named pipe if I did it in a shell script. What is
the ruby command for a named pipe?

Thanks-
-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
509-577-7732
(e-mail address removed)
 
E

Esteban Manchado Velázquez

Hey there list-
I'm writing some simple gui's for some ruby scripts with Pashua =20
and Cocoa Dialogs. I need a little help with a perl example that I =20
want to convert to ruby. Any help is much appreciated.
[...]
Now the loops and most of the structure I am fine with. It's mainly =20
the IO::File->new part that I need to know the ruby equivalent of. It =20
is basically just a named pipe if I did it in a shell script. What is =20
the ruby command for a named pipe?

http://www.ruby-doc.org/find/pickaxe/io#IO.pipe ?

--=20
Esteban Manchado Vel=E1zquez <[email protected]> - http://www.foton.es
EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es
 
G

Greg Millam

IO.popen("#{COCOA_DIALOG} progressbar",'w') do |pbar|
pbar.puts "5 We're at 5%"
end

or

pbar = IO.popen(...,'w')
pbar.puts "5 We're at 5%"
pbar.close

Hope that helps.

- Greg

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Double posts? 7
Qt 4.0 ruby bindings? 3
RubyCocoa question 5
Re RubyConf Presentation Audio 2
Regex help 5
Re RubyConf for Stragglers 2
RubyConf 05 Audio and Video files resurrected! 1
RubyConf Presentations! 6

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top