Can AWK be used in Perl? 
Author Message
 Can AWK be used in Perl?

Trying to find out if an AWK command can be used in Perl and if so, what is
the syntax?

I want to pass a variable into an AWK command, edit the string it contains
and store part of it in a new variable that I need to pass back into Perl.

Hope someone can help.

Thanks,

Steve.



Tue, 24 Dec 2002 03:00:00 GMT  
 Can AWK be used in Perl?

Quote:

>Trying to find out if an AWK command can be used in Perl and if so, what is
>the syntax?

>I want to pass a variable into an AWK command, edit the string it contains
>and store part of it in a new variable that I need to pass back into Perl.

This is about the 3rd time this idea has come up in this NG.  One or the
other of the following must be true:

        1) It is a plant/political-agenda of some sort (though from which
           camp is far from clear).
        2) There really is a mass of Perl code out there that people are now
           being asked to maintain, and that people are finding out what a
           mess Perl really is (both in concept and in implementation).

           I.e., that Perl has acheived fortran-like status - you have
           to maintain it, but the urge to find easier, more logical
           alternatives (such as Awk) is hard to resist.

Quote of the month: Perl can do everything Awk can do, but not as elegantly.



Tue, 24 Dec 2002 03:00:00 GMT  
 Can AWK be used in Perl?

Quote:

>Trying to find out if an AWK command can be used in Perl and if so, what is
>the syntax?

>I want to pass a variable into an AWK command, edit the string it contains
>and store part of it in a new variable that I need to pass back into Perl.

Why would you want to do that with awk inside Perl?

Perl is perfectly capable of copying and then editing a string with
it's s command, very similar to sed's s command, but more powerful.  

If you want to know how to do that in Perl, I suggest you ask in a Perl
newsgroup.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 24 Dec 2002 03:00:00 GMT  
 Can AWK be used in Perl?

Quote:

> Trying to find out if an AWK command can be used in Perl and if so, what is
> the syntax?

> I want to pass a variable into an AWK command, edit the string it contains
> and store part of it in a new variable that I need to pass back into Perl.

Q. "I have a nail I need to drive into the wall. I want to use a
ball pein hammer first, then a claw hammer. Can this be done and,
if so, how?"

A. "Pick the right hammer for the job and use it. (To learn to use
the hammer, read the hammer manual.)"

The correct answer to your question is yes, an awk script can be
invoked from within a Perl script, and values can be passed between
them. Here's an example that does just that (but not an example
of "*the* syntax"):

$ perl -e '$foo = "bar"; print `awk -v baz=$foo "BEGIN { print baz }"`'
bar
$

The correct response to your inquiry is you're doing something
wrong. Don't do that.

Quote:
> Hope someone can help.

Me too.

--
Jim Monty

Tempe, Arizona USA



Wed, 25 Dec 2002 03:00:00 GMT  
 Can AWK be used in Perl?
Thanks for the hints.

Do you think the sarcasm was really required?

Steve.



Mon, 30 Dec 2002 03:00:00 GMT  
 Can AWK be used in Perl?


Quote:
>Thanks for the hints.

>Do you think the sarcasm was really required?

It is unfortunate that you interpret it as sarcasm.

We are trying to get at "What problem are you really trying to solve?",
and to help you solve that problem.  Just out of curiosity, was my
hunch, which was that you have a chunk of Perl code to maintain
(something over which you have no control) and wanted to do your task
in AWK (a much more sane language), close to the mark?



Mon, 30 Dec 2002 03:00:00 GMT  
 Can AWK be used in Perl?

Quote:

> Thanks for the hints.

You're welcome.

Quote:
> Do you think the sarcasm was really required?

"Required"? No. Nor was an answer to your question "required".

What you describe as "sarcasm" was simply a metaphor (How do I use
two kinds of hammers for one task?) used to help illustrate for
your benefit the misguided nature of what it was you were asking
how to do (How do I use Perl and awk for one task?).

--
Jim Monty

Tempe, Arizona USA



Tue, 31 Dec 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Substituting single quotes from Perl via shell using awk and gsub

2. extracting top 100 data using awk or sed/perl

3. Using CGI module with 'canned queries'

4. Outputting info from awk and using the info to name the awk output file

5. Urgent!!Oracle9i:using ODBC, I am noy able to link to my database tables using Access

6. sed, awk, perl

7. perl hash vs awk array

8. AWK vs PERL - splitting fields

9. problem with awk in perl script

10. AWK in Perl

11. Simple awk command within a perl script

12. Q - perl 2 awk

 

 
Powered by phpBB® Forum Software