Newbie wants a simple script in perl

Newbie wants a simple script in perl

am 05.04.2008 21:41:33 von 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

Re: Newbie wants a simple script in perl

am 05.04.2008 22:09:10 von Rui Maciel

On Sat, 05 Apr 2008 12:41:33 -0700, 2007 wrote:

> 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

Re: Newbie wants a simple script in perl

am 06.04.2008 00:22:40 von 2007

On Apr 5, 1:09 pm, Rui Maciel wrote:
> On Sat, 05 Apr 2008 12:41:33 -0700, 2007 wrote:
> > 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

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

Re: Newbie wants a simple script in perl

am 06.04.2008 00:24:02 von jurgenex

2007 wrote:
>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

Re: Newbie wants a simple script in perl

am 06.04.2008 00:47:52 von 2007

On Apr 5, 3:24 pm, Jürgen Exner wrote:
> 2007 wrote:
> >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

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?

Re: Newbie wants a simple script in perl

am 06.04.2008 00:48:16 von Andrew DeFaria

This is a multi-part message in MIME format.
--------------010506040203090205020005
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

2007 wrote:
> On Apr 5, 1:09 pm, Rui Maciel wrote:
>> On Sat, 05 Apr 2008 12:41:33 -0700, 2007 wrote:
>>> 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
> 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?
--
Andrew DeFaria
There's only two things that money can't buy and that's true love and
home grown tomatoes. - Guy Clark

--------------010506040203090205020005
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit






2007 wrote:
id="mid_aa3d71a8-181e-4075-908f-13472b2f3591_z24g2000prf_goo glegroups_com"
cite="mid:aa3d71a8-181e-4075-908f-13472b2f3591@z24g2000prf.g ooglegroups.com"
type="cite">On Apr 5, 1:09 pm, Rui Maciel
wrote:

On Sat, 05 Apr
2008 12:41:33 -0700, 2007 wrote:

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


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?

--



There's only two things that money can't
buy and that's true love and home grown tomatoes. - Guy Clark





--------------010506040203090205020005--

Re: Newbie wants a simple script in perl

am 06.04.2008 01:52:47 von Rui Maciel

On Sat, 05 Apr 2008 15:48:16 -0700, Andrew DeFaria wrote:

> 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?

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

Re: Newbie wants a simple script in perl

am 06.04.2008 03:09:15 von 1usa

2007 wrote in
news:720e7bce-09bc-4870-8877-
607b3ea28afe@p39g2000prm.googlegroups.co
m:

> On Apr 5, 3:24 pm, Jürgen Exner wrote:
....

>> What is your question (if you got any) or the point of your
>> posting?
....
>
> 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 <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

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

Re: Newbie wants a simple script in perl

am 06.04.2008 03:36:36 von jurgenex

2007 wrote:
>> >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".
>>
>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

Re: Newbie wants a simple script in perl

am 06.04.2008 04:04:08 von Andrew DeFaria

This is a multi-part message in MIME format.
--------------030409050606070505010702
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

A. Sinan Unur wrote:
> 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! ;-)
--
Andrew DeFaria
Marriage changes passion. Suddenly you're in bed with a relative.

--------------030409050606070505010702
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit






A. Sinan Unur wrote:

cite="mid:Xns9A77D73032F0Basu1cornelledu@127.0.0.1" type="cite">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! ;-)

--



Marriage changes passion. Suddenly you're
in bed with a relative.





--------------030409050606070505010702--

Re: Newbie wants a simple script in perl

am 06.04.2008 04:14:51 von Andrew DeFaria

This is a multi-part message in MIME format.
--------------030209070701010209060008
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

2007 wrote:
> 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.
--
Andrew DeFaria
Why is the word abbreviation so long?

--------------030209070701010209060008
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit






2007 wrote:

id="mid_720e7bce-09bc-4870-8877-607b3ea28afe_p39g2000prm_goo glegroups_com"
cite="mid:720e7bce-09bc-4870-8877-607b3ea28afe@p39g2000prm.g ooglegroups.com"
type="cite">I need help in writing please


As others have already said - show us what you got already!

id="mid_720e7bce-09bc-4870-8877-607b3ea28afe_p39g2000prm_goo glegroups_com"
cite="mid:720e7bce-09bc-4870-8877-607b3ea28afe@p39g2000prm.g ooglegroups.com"
type="cite">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.

--



Why is the word abbreviation so long?




--------------030209070701010209060008--

Re: Newbie wants a simple script in perl

am 06.04.2008 11:16:56 von 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

Re: Newbie wants a simple script in perl

am 06.04.2008 16:32:44 von Tad J McClellan

2007 wrote:

> 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.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Re: Newbie wants a simple script in perl

am 07.04.2008 08:34:17 von Joe Smith

2007 wrote:

> 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?

1) As written: It simply does not happen that way.

2) I use something like that all the time, by piping the output
from a perl script into 'sh' or 'bash'.

perl generate_commands.pl input.txt | sh

The logic for generate_commands.pl is quite simple.

1) Use <> to read list of names, one line at a time.
2) Parse the input line to get the name of an input data file.
3) Come up with the name of an output file based on that.
4) Execute an external command, giving it the names of the
input data file and output file.
5) Execute a second external command.
6) Loop back to step 1 until end of list.

There are several ways to perform step 4:

my $results = `$command1 $in_file $out_file`;
or
my $error_code = system "$command1 $in_file $out_file";
warn "Something went wrong: $? ($!)" unless $error_code == 0;
or
print PIPE "$command1 $in_file $out_file\n";

The other steps are so trivial that you won't have any problem
finding them in any Perl tutorial.

That should be enough for you to write the script yourself. Good luck.
-Joe