RCP has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a perl script to extract a integer from a file and for each line generated, the integer is increased by 1.0.
I am not sure how to imbed the awk command within my perl script, as I get a lot of error messages.
At the top of the code, I included the files the script is extracting info from.
Can I get some pointers to get (line 22) the awk line to work?
Thanks RCP
#!perl ## comp_prim_loc file > Location: X:75.4634 Y:15.875 Side: +1 Rotation:0 ## comp_locs file> Reference Designator: C1000 ## comp_locs file> Reference Designator: C1002 ## comp_locs file> Reference Designator: C1004 open(MYOUTFILE, ">align_comp_cc.txt"); open (FILEH, "comp_prim_loc"); while (<FILEH>) { chomp; if ( /Location:/i ) { tr/:)(/ /; ($xloc,$yloc,$rot) = (split)[2,4,8]; open(MYOUTFILE, ">>align_comps_cc.txt"); $count = $yloc; open (FILEH, "comp_locs"); while (<FILEH>) { chomp; if ( /Reference Designator:/i ) { ($name) = (split)[2]; my $count="`awk -v x=$count -v y=1.0 'BEGIN{ printf "%3f\n", x+y}'`"; print "\$\place_component_by_reference_with_mrf('$name', [['$xloc', '$ +count', 'BO\$board'], 0, 0], 0, \@NoRepeat);\n"; } } } } close(MYOUTFILE);
The results should look like this:
$place_component_by_reference_with_mrf('C1000', ['70.4469', '16.875', 'BO$board', 0, 0], 0, @NoRepeat);
$place_component_by_reference_with_mrf('C1002', ['70.4469', '17.875', 'BO$board', 0, 0], 0, @NoRepeat);
$place_component_by_reference_with_mrf('C1004', ['70.4469', '18.875', 'BO$board', 0, 0], 0, @NoRepeat);

Replies are listed 'Best First'.
Re: awk issues
by Abigail-II (Bishop) on May 11, 2004 at 15:31 UTC
    Write that as:
    my $count=`awk -v x=$count -v y=1.0 'BEGIN{ printf "%3f\n", x+y}'`;
    But why bother with awk? Why not:
    my $count = sprintf "%3f\n" => $count + 1;

    Abigail

Re: awk issues
by runrig (Abbot) on May 11, 2004 at 15:14 UTC
    Backticks don't work inside double quotes. But why are you using awk to essentially do a sprintf?