However, awk, a common gadget in Linux system, is naturally friendly to column operations. Sometimes calling awk directly in perl is much more convenient and effective than writing corresponding perl scripts. For example, insert awk statement with system:
Copy the codeThe code is as follows:
system(gawk '{print $1}' $filename);
Execute the l statement and you will find that this line will report an error, prompting you to use the read-only variable $1.
So, how to deal with conflicts under the two ecosystems?
There is a simple solution:
Copy the codeThe code is as follows:
my $i="$1";
system(gawk '{print $i}' $filename);
This solves the problem of conflict between $1 of (g)awk and the built-in variable $1 of perl.