Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

gawk to perl

by rmflow (Beadle)
on Apr 09, 2010 at 06:13 UTC ( #833707=perlquestion: print w/replies, xml ) Need Help??
rmflow has asked for the wisdom of the Perl Monks concerning the following question:

Is there any way to automatically convert gawk script to perl?
a2p is an awk converter and reports many errors

Replies are listed 'Best First'.
Re: gawk to perl
by CountZero (Bishop) on Apr 09, 2010 at 06:31 UTC
    Have a look at this article on stackoverflow: How can I make Perl's a2p support gawk?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      The article suggests:

      If your gawk program doesn't make calls to other cygwin/unix utilities then it would probably be better to just distribute a Windows gawk executable to your colleagues along with the program.

      But my problem is different - gawk is extremely buggy, often fails with INTERNAL ERROR and different versions of gawk behave differently. The last drop was that gawk was unable to make console output in proper codepage in Windows 7, so I decided to get rid of gawk completely.

        So, maybe, instead of trying to rely on buggy translators, consider simply rewriting the awk script in Perl?

        If you have a problem with a specific awk construct, maybe we can help you there. Alternatively, you'll have to explain what the awk snippet does and then find out how to accomplish the same using Perl.

        different versions of gawk behave differently

        I think you found the reason why it is difficult to write a gawk to perl converter.

        My best suggestion is to use a2p and then hand-code Perl where you get the errors. To be honest converted code is rarely readable and often inefficient so Corion's suggestion might be better in the long term.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://833707]
Approved by ahmad
help
Chatterbox?
[Tux]: Corion++ hippo++
[ovedpo15]: it isn't homework. its a module I use at work. The process to add additional module isn't worth it. p.s never heard a university course which teach perl
[marto]: there are many, to this day.
[ovedpo15]: @Corion Yes I use the regex you showed me. its very good regex. although now i need to know that substring unit that comma
marto mad corrections to one around 18 months ago
[ovedpo15]: my code checks the value after that comma, if it isn't valid it will remove it. so I would like to remove the substring after that comma meaning getting the string before comma.
[hippo]: Are you sure that Text::CSV_XS isn't already installed at your work? It's such a useful module that it might well be there.
[marto]: pointing out the advantages of cpan modules is well worth in, as both developer and $client/$company benefit greatly
[Tux]: $src =~ m{^(.*),(.*)$/ and $2 !~ $valid and $src = $1;
[Tux]: s,/,},

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2018-05-27 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?