Home > Archive > AWK > May 2006 > Awk vs Perl for this assignment
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Awk vs Perl for this assignment
|
|
| amerar@iwc.net 2006-05-01, 6:57 pm |
| Hi All,
I'm trying to decide which is better. I have to take huge record,
5000 bytes long, parse out the fields into variables, and then prompt
the user for each field, allowing them to change the value.
I started doing this with AWK and putting the values into an
associative array. However, I know that Perl can do this
also..........
Which would be better for this task?
Also, I'd like to know how in both AWK & Perl to accept from Standard
Input while going through a loop.........ie, I'd be looping through
each field of each record. And, at the end of the record, I'd print it
to a file, FTP it someplace and continue with the next record.
Thanks in advance!!
| |
| Harlan Grove 2006-05-01, 6:57 pm |
| amerar@iwc.net wrote...
>I'm trying to decide which is better. I have to take huge record,
>5000 bytes long, parse out the fields into variables, and then prompt
>the user for each field, allowing them to change the value.
....
The only questions would be whether you want a GUI interface (in which
case Perl/Tk could provide one, but no awk has anything similar) or
whether your particular awk variant could handle records of 5000-odd
characters. If you don't want GUI and your awk handles the record
length, there's not going to be much difference between the two. A case
could be made for laziness: awk won't require as many semicolons as
Perl.
>Also, I'd like to know how in both AWK & Perl to accept from Standard
>Input while going through a loop.........ie, I'd be looping through
>each field of each record. And, at the end of the record, I'd print it
>to a file, FTP it someplace and continue with the next record.
Looping and I/O are independent of each other. You're not expressing
the problem correctly. Try doing so, and a solution may become clear.
Since this looks like a course assignment, I won't give a straight
answer: you need to focus on I/O.
| |
| Janis Papanagnou 2006-05-01, 6:57 pm |
| amerar@iwc.net wrote:
> Hi All,
>
> I'm trying to decide which is better. I have to take huge record,
> 5000 bytes long, parse out the fields into variables, and then prompt
> the user for each field, allowing them to change the value.
>
> I started doing this with AWK and putting the values into an
> associative array. However, I know that Perl can do this
> also..........
>
> Which would be better for this task?
>
> Also, I'd like to know how in both AWK & Perl to accept from Standard
> Input while going through a loop.........ie, I'd be looping through
> each field of each record. And, at the end of the record, I'd print it
> to a file, FTP it someplace and continue with the next record.
That's more of a shell task than awk. Nevermind, here's some awk code
example for the input/output handling...
{
for (nf=1; nf<=NF; nf++) {
print nf, $nf >"/dev/tty" # whatever to ask for interactively
getline input <"/dev/tty"
printf ("%s -> %s", $nf, input) > "yourfile" # example output
}
print > "yourfile"
close ("yourfile")
system ("whatever-shell-command-to-invoke-for yourfile")
}
> Thanks in advance!!
>
Janis
| |
| Ed Morton 2006-05-01, 6:57 pm |
| amerar@iwc.net wrote:
> Hi All,
>
> I'm trying to decide which is better. I have to take huge record,
> 5000 bytes long, parse out the fields into variables, and then prompt
> the user for each field, allowing them to change the value.
>
> I started doing this with AWK and putting the values into an
> associative array. However, I know that Perl can do this
> also..........
>
> Which would be better for this task?
Are you really stuck with just those 2 options?
> Also, I'd like to know how in both AWK & Perl to accept from Standard
> Input while going through a loop.........ie, I'd be looping through
> each field of each record. And, at the end of the record, I'd print it
> to a file, FTP it someplace and continue with the next record.
It'd be OT here, but your problem seems to be crying out for a simple
shell solution. If that's a possibility in your environment, post a
followup to comp.unix.shell and we can discuss it there.
Ed.
|
|
|
|
|