Click to See Complete Forum and Search --> : Perl to bash translation please.


Dizzybacon
06-14-2002, 09:11 AM
I've written a perl script but I think it would work better if I converted it to bash and ran it that way.

In perl I have something like:

open (DATA,"$path/$in");
@data = <DATA>;
close DATA;

foreach $line (@data){
print `rioutil -a $line`;
}

The idea is to open a file and execute the command for each line in the file.

I can't find out how to open the file in bash or to seperate out the lines.

Could someone give me a pointer?

Dizzy

Stuka
06-14-2002, 10:23 AM
Well, here's an ugly method, but it works..
#!/usr/bin/bash

for i in [`cat filename`]
do
rioutil -a $i
done

Dizzybacon
06-14-2002, 10:33 AM
That looks incredibly simple!

Thanks I'll try it out as soon as I can.

Dizzy

jemfinch
06-14-2002, 11:28 AM
Why would it be better in bash?

Perl is everywhere; bash isn't.

Jeremy

Dizzybacon
06-14-2002, 11:38 AM
To run the rioutil command I have to su to root, so I can only run it from the command line.

I figured that bash would be the tidier way to do this and it would allow me to specify the file to read when I call the command, ie ./upload -file_to _read.
Also once it is done in the the right path it will be easier to use.

That's why I want to change it to bash, but suggestions in perl are welcome too.

Dizzy

debiandude
06-14-2002, 03:34 PM
Perl has an argument array to :-)


#!/usr/bin/perl -w

use strict;

unless(open FILE, shift @ARGV) {
die "Cannot open file: !$\n";
}

while($_ = chomp(<FILE> )) {
print "rioutil -a $_";
system("rioutil -a $_");
}

exit(0);