>>>>> "CC" == Chris Coggins <cacogg...@cox.net> writes:
CC> I'm using a perl script to write another perl script that will be CC> executed later. I need to know if all the characters that need to be CC> escaped, are properly escaped. Can someone help, here's a portion of CC> the code below. Are all the characters properly escaped? (note this is CC> part of a much longer script, and I don't want to type it all out CC> incorrectly which is why I'm asking for advice.) the bigger question is why are you generating perl code at all? there is nothing i see here that would help by code generation. it is simple basic perl code that does some file i/o and a little munging. code generation is used when you need to do something very fast and the generated code will be faster than doing it on the fly. i have two modules which do this, Sort::Maker and Template::Simple (though its compiler version which generates code is only in git and not on cpan). in both cases there is a significant speedup when using the generated code. CC> print FILE ("open my \$totdata, \'\<\', \$totalsFile or die CC> \"Unable to open file: \$\!\"\; \n"); CC> print FILE ("\t my \$ttline = \<\$totdata\>\; \n"); CC> print FILE ("close \$totdata\; \n"); CC> print FILE ("\t my \...@totdata = split \/\~\/, \$line\; \n"); CC> print FILE ("open my \$transdata, \'\<\', \$transnums or die CC> \"Unable to open file: \$\!\"\; \n"); CC> print FILE ("\t my \$txline = \<\$transdata\>\; \n"); CC> print FILE ("close \$transdata\; \n"); CC> print FILE ("\t my \...@transdata = split \/\~\/, \$line\; \n\n"); CC> print FILE ("\t \$totdata[0] += $transdata[0]\; \n"); CC> print FILE ("\t \$totdata[1] += $transdata[1]\; \n"); CC> print FILE ("\t \$totdata[2] += $transdata[2]\; \n"); if you must generate code use here docs. that is impossible to read and debug. if you used here docs, you wouldn't need all the "'s, the trailing \n, the print FILE's and even the tabs could be inline. in either case you con't need to escape all the angles or ; or ' chars. why do you think they need escaping in double quotes? they are just text chars there. few chars need escaping in double quotes. CC> It should appear in the new script as follows, which works fine: CC> open my $totdata, '<', $totalsFile or die "Unable to open file: $!"; CC> my $ttline = <$totdata>; CC> close $totdata; CC> my @totdata = split /~/, $line; CC> open my $transdata, '<', $transnums or die "Unable to open file: $!"; CC> my $txline = <$transdata>; CC> close $transdata; CC> my @transdata = split /~/, $line; CC> $totdata[0] += $transdata[0]; CC> $totdata[1] += $transdata[1]; CC> $totdata[2] += $transdata[2]; and where are the speed or complexity issues in that code that require code generation? don't use a tool way more powerful than you need to solve a problem. code generation is extremely powerful (it uses eval STRING) but is very tricky to use correctly. and it is rarely needed. uri -- Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/