views:

248

answers:

4

I had read somewhere about one specific feature that is present in awk but not in Perl. I have failed in locating it again.

I would appreciate it if anyone here can point it out.

This might be a useless trivia, but I am still curious to know.

+16  A: 

From perldoc perlvar:

Remember: the value of $/ is a string, not a regex. awk has to be better for something. :-)

eugene y
you can always do `split /regex/ => do {local $/; <>}` so long as your file can fit into memory
Eric Strom
Back in the day I wrote File::Stream (on CPAN) to fix this "issue". :)
tsee
exactly the thing i was looking for.i will be able to sleep soundly from now on. :)
alvin
+4  A: 

perltrap - Awk Traps lists several differences between awk and perl.

See also: a2p - Awk to Perl translator

toolic
very useful link.
alvin
+6  A: 

The awk to perl translator man page digs up one thing that Perl can't do:

  • Perl does not attempt to emulate the behavior of awk in which nonexistent array elements spring into existence simply by being referenced. (lvalue autovivification)

But in general, Perl is turing complete, it can do everything awk can do. The fact that an awk to perl translator exists should be proof enough :)

rjh
hmmm, this is interesting.
alvin
A: 

Regular expression subroutines like

/regex/ {
         awk code here
}

for pattern matching is a feature I miss from awk.

MkV
You're not serious, right? if (/regex/) { perl code here }
Sean
/$regexp/ and do { ... };
dsm
`{ perl code here } if /regex/`
Dave Sherohman
wow, I totally didn't know you could use if and and in Perl. Thanks for missing the point.
MkV