Haved used Perl for years on Windows, Linux, and UNIX.
In the last few days, me and the rest of the team have been getting thwarted by a silly character escaping issue related to C shell on Unix (Sun).
We have a working .pl script that needs to be used as a 'one-liner' with the -e option. The problem is that the script will not run when you use the -e option in CSH. We believe it may have to do with escaping characters in the Perl code since it will run as-is on Linux in BASH.
Note that the code sample is indented oddly due to its inclusion in a shell script.
Here is our Perl code inside our shell script:
#!/usr/bin/csh -f
#
perl -e '$outputDir = "/tmp/foo/";\
$input = "file.java";\
open( INPUT_FILE,"<$input" ) or die ("Could not open $input :$!"); \
$file = "";\
$dir = "";\
$package = "";\
@imports = "";\
while( <INPUT_FILE> ) {\
if(s/^\/\/<END_CLASS: (.*) ?$/$1/) {\
close(OUTPUT);\
$file = "";}\
if($file) {\
print OUTPUT $_;}\
if(s/^package ([a-zA-Z\._0-9]+).*$/$1/) {\
$package = $dir = $1;\
$dir =~ tr/\./\//;}\
if(/^import.*/) {\
push(@imports,$_);}\
if(s/^\/\/<BEGIN_CLASS: ([a-zA-Z_0-9]+).*$/$1/) {\
if($dir) {\
$file = "$dir/$1.java";\
} else {\
$file = "$1.java";}\
open(OUTPUT,">$outputDir$file") or die("Could not open output file
+ $outputDi
r$file $!"); \
print "Created $file\n";\
if($package) {\
print OUTPUT "package $package;\n";}\
print OUTPUT @imports;\
}\
}\
close( INPUT_FILE );'
Note that the end of each line is escaped with a backslash. We expected to have to do this.
But we get this error when you run the script on Sun UNIX:
");: Event not found
We have escaped the quotes and the parens (together and individually) and nothing seems to change the error.
We have to use CSH and we have to use Perl -e for this code, so we have no choice but to find a way to progress.
Our Perl version is 5.004_04 for SunOS.
Any suggestions on how to escape this code would help. We have burned a lot of time on this and are getting nowhere.
Thanks in advance for any suggestions you may have.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.