Newbie wants a simple script in perl

2

2007

Hi

I have a file called "list1" - its got about 80 rows - each row is
alpha numeric name w/ ".txt" extension - each name refers to a file in
the dir.

The script reads the list - for each name in the list, it will perform
an operation (an executable of a "C-program" and writes to same name
with a different extension, say ".mp3".

Thanks
 
R

Rui Maciel

Hi

I have a file called "list1" - its got about 80 rows - each row is alpha
numeric name w/ ".txt" extension - each name refers to a file in the
dir.

The script reads the list - for each name in the list, it will perform
an operation (an executable of a "C-program" and writes to same name
with a different extension, say ".mp3".

Nice. What have you written so far? And why didn't you opted for bash?


Rui Maciel
 
2

2007

Nice. What have you written so far? And why didn't you opted for bash?

Rui Maciel

I changed it to bash but the code didn't work

THis is what I really need:
In a summary:
1) say about 80 files (but varies) in a dir with filenameX.txt
extension.

2) CONV1 runs one at a time and gives output w/ a fixed name, CONV.out

3) CONV2 takes CONV.out as well as the final output file (which is
filenameX.mp3). Ideally it puts them in a specified directly.

I really appreciate your help - I want something that works - I
started off with t shell - I am open to change to bash or perl. I
prefer a simpler looking program
 
J

Jürgen Exner

2007 said:
I have a file called "list1" - its got about 80 rows - each row is
alpha numeric name w/ ".txt" extension - each name refers to a file in
the dir.

The script reads the list - for each name in the list, it will perform
an operation (an executable of a "C-program" and writes to same name
with a different extension, say ".mp3".

Ok.
What is your question (if you got any) or the point of your posting?

jue
 
2

2007

Ok.
What is your question (if you got any) or the point of your posting?

jue

I need help in writing please

Also, if I use "print" within perl to the dump a executable command to
the monitor, will the process be executed and the perl will wait
before it throws the next one to screen?
 
A

Andrew DeFaria

2007 said:
I changed it to bash but the code didn't work

THis is what I really need:
In a summary:
1) say about 80 files (but varies) in a dir with filenameX.txt extension.

2) CONV1 runs one at a time and gives output w/ a fixed name, CONV.out

3) CONV2 takes CONV.out as well as the final output file (which is
filenameX.mp3). Ideally it puts them in a specified directly.

I really appreciate your help - I want something that works - I
started off with t shell - I am open to change to bash or perl. I
prefer a simpler looking program
Based on your sketchy requirements I'd say (in bash):

$ cat list1 | while read filename; do
CONV1 $filename
CONV2 CONV.out
done

Am I missing something?
 
R

Rui Maciel

Based on your sketchy requirements I'd say (in bash):

$ cat list1 | while read filename; do

Am I missing something?

Yes, he was trying to get someone to do his work. He obviously never even
gave it a try, not in perl and obviously not in bash. After all, it's one
of the recurring examples in each and every bash tutorial on the web.


Rui Maciel
 
A

A. Sinan Unur

(e-mail address removed)
m:
....

I need help in writing please

First, try to help yourself.

If you want the script written for you, I am sure there will be a
few people who'd do it for $500. If you want tech support to go with
that, maybe $750. If you would like me to write it, the rate goes up
to $2500.

If you are willing to pay for the job, then post an announcement at
http://jobs.perl.org/

Otherwise, try to solve your problem first on your own (make sure to
consult the various resources available to you) and then post
concrete questions here.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
J

Jürgen Exner

2007 said:
I need help in writing please

Ok, what do you have so far? Show us your current code, explain what it
is supposed to do (you got that part already), what it is actually
doing, or where you are stuck. I am sure someone will be happy to show
you how to get unstuck.
Also, if I use "print" within perl to the dump a executable command to
the monitor,

This sentence doesn't compute. I have absolutely no idea what you are
talking about.
will the process be executed and the perl will wait
before it throws the next one to screen?

print() has nothing to do with process control. Where did you get that
idea?

jue
 
A

Andrew DeFaria

A. Sinan Unur said:
First, try to help yourself.

If you want the script written for you, I am sure there will be a few
people who'd do it for $500. If you want tech support to go with that,
maybe $750. If you would like me to write it, the rate goes up
to $2500.
Ow, ow! I'll do it for $250! ;-)
 
A

Andrew DeFaria

2007 said:
I need help in writing please
As others have already said - show us what you got already!
Also, if I use "print" within perl to the dump a executable command to
the monitor, will the process be executed and the perl will wait
before it throws the next one to screen?
You can always tell noobies as they seem to invent strange
terminologies! Print doesn't "dump" executable commands to monitor.
Print prints things. What you tell it to print. It's displayed on
stdout, which nowadays is rarely a monitor but a terminal emulator. The
process will be executed if and when you tell Perl to execute a process
- and not before. Oh, and Perl doesn't throw anything to a screen... not
at all!

Perhaps you meant this:

"If I use 'print' to print the executable command to stdout will the
process be executed?"

Well print doesn't execute processes. The system Perl function will
and/or commands in `` will execute external processes. Printing out the
contents of your command before executing it will not cause it not to be
executed. Instead do something like this. Let's say you were executing a
command stored in $cmd.

my $cmd = "CONV1 $filename";
my @output = `$cmd`;
my $status = $?;
die "Unable to execute $cmd" if $status != 0;

$cmd = "CONV2 $filename2";
@output = `$cmd`;
die "Unable to execute $cmd" if $status != 0;

Change this to:

my $cmd = "CONV1 $filename";
print "About to execute \"$cmd\"\n";
#my @output = `$cmd`;
#my $status = $?;
#die "Unable to execute $cmd" if $status != 0;

print "About to execute \"$cmd\"\n";
#$cmd = "CONV2 $filename2";
#@output = `$cmd`;
#die "Unable to execute $cmd" if $status != 0;

So here I'm just printing out what $cmd contains. Note I commented out
the actual execution of the commands on the assumption that you didn't
want to actually execute them unless you saw that they looked OK.
Actually I would do this in Perl's debugger instead stopping at the
statement that was about to execute the $cmd and display it's contents
and only stepping forward if it were correct.
 
J

Johann Kappacher

Hi,

Rui Macial has already told you: "Do not let others do your homework!"
Try some coding first.
Moreover, many neebies have asked the same question, you will find
helpful replies.

This works at least in ksh/bash: (no shell builtins for var-substitution)

while read file
do
f_short=$(echo $file | cut -d . -f 1) # strip the .txt suffix
C_PROGRAM $file > "${f_short}.mp3"
done < list1

--jk
 
T

Tad J McClellan

2007 said:
Subject: Newbie wants a simple script in perl


Newbie should begin writing a simple script in Perl.

Newbie should post the broken code here when you get stuck.

Then we will help newbie fix the broken code.
 

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

Staff online

Members online

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,686
Latest member
scamivo

Latest Threads

Top