Syntax Error?

G

g4173c

Hi:

I found this bit of code on this news group from Tom Christiansen and
thought it would work very well is my perl script, however I get a
syntax error and can't figure out why? Here's the code:

system {
exec 3>&1;
exit `( (myprogram; echo $? 1>&4 3>&- 4>&-) |
tee afile.log 1>&3 3>&- 4>&1 ) 4>&1`;
};

if ($?) { warn "myprogram failed: $?" }

The error:

syntax error at zz line 9, near "};"

Any ideas?

Thanks in Advance
Tom
 
A

anno4000

Hi:

I found this bit of code on this news group from Tom Christiansen and
thought it would work very well is my perl script, however I get a
syntax error and can't figure out why? Here's the code:

system {
exec 3>&1;
exit `( (myprogram; echo $? 1>&4 3>&- 4>&-) |
tee afile.log 1>&3 3>&- 4>&1 ) 4>&1`;
};

if ($?) { warn "myprogram failed: $?" }

The error:

syntax error at zz line 9, near "};"

I doubt that TomC posted that code. "system" cannot be followed
by a block, that's a syntax error by itself. Please give a reference.

Anno
 
A

anno4000

Hi

I searched for "exit status from system with tee" and got the
following message, which that code
was at the bottom:

http://groups.google.com/group/comp...system+with+tee&rnum=1&hl=en#a7b6faac68ee60d6

Ugh. That's a thread of 6 articles, none of which is by Tom
Christiansen. It took me a while to find that what you mean is
a posting by Charles DeRykus who quotes TomC's solution.
Unfortunately there's a typo -- there should be a "q" before
the first "{", making quoted text out of what looks like a bare
block. Change that and the code will run -- whatever it is
supposed to do.

Anno
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to

I doubt that TomC posted that code. "system" cannot be followed
by a block, that's a syntax error by itself.

Of course it can.

Hope this helps,
Ilya

P.S. perl -wle 'system {"/bin/echo"} qw(foo bar)'
 
P

Peter Scott

Of course it can.

P.S. perl -wle 'system {"/bin/echo"} qw(foo bar)'

Hmmm,

$ perl -wle 'system {"/bin/echo"} qw(foo bar)'
bar

$ perl -MO=Deparse -wle 'system {"/bin/echo"} qw(foo bar)'
BEGIN { $^W = 1; }
BEGIN { $/ = "\n"; $\ = "\n"; }
system do {
'/bin/echo'
}, 'foo', 'bar';
-e syntax OK

$ perl -wle 'system do {"/bin/echo"}, qw(foo bar)'
foo bar

Urp.
 
A

anno4000

Ilya Zakharevich said:
[A complimentary Cc of this posting was sent to

I doubt that TomC posted that code. "system" cannot be followed
by a block, that's a syntax error by itself.

Of course it can.
[...]

P.S. perl -wle 'system {"/bin/echo"} qw(foo bar)'

Oh well... indirect object syntax. Does that even count? :)

Anno
 
C

comp.llang.perl.moderated

Ugh. That's a thread of 6 articles, none of which is by Tom
Christiansen. It took me a while to find that what you mean is
a posting by Charles DeRykus who quotes TomC's solution.
Unfortunately there's a typo -- there should be a "q" before
the first "{", making quoted text out of what looks like a bare
block. Change that and the code will run -- whatever it is
supposed to do.

Apologies for the dropped 'q'. Humbled though I am, this was
probably a "paste-o", not a "typo". I'm not sure why you've
added the dismissive "-- whatever it is supposed to do" either.

TomC's incantation with a clever series of redirections rolled
up inside a backtick to capture initial upstream pipe status still
works. For example, if myprogram is a simple shell script that
just does an 'exit 2', the following Perl:


system q{ exec 3>&1;exit `((myprogram;echo $? 1>&4 3>&- 4>&-)| tee
afile.log 1>&3
3>&1 4>&1) 4>&1`};
if ($?) { warn "myprogram failed: $?" }


generates: myprogram failed: 512 at ./test.pl line 7

Perhaps, there's a more elegant way nowdays though.
 
A

anno4000

comp.llang.perl.moderated said:
<[email protected]> wrote in comp.lang.perl.misc:
[...]

Apologies for the dropped 'q'. Humbled though I am, this was
probably a "paste-o", not a "typo". I'm not sure why you've
added the dismissive "-- whatever it is supposed to do" either.

Sorry if that sounded dismissive. I intended to indicate that
I hadn't followed the intricate code inside the quote but only
fixed the quoting mechanism.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top