(1) Your first if condition calls itself - you are nesting a restart of the program.
(2) I do not think this 'elsif' can execute since the simpler first part [$UL_PROCESS -eq 0] would always be caught above.
(3) I cannot say for sure, but your "if then elsif else fi" does not quite feel right. Perhaps it requires "elif then" to make computer logic correct.
I am running an Ubuntu Gutsy laptop with Advanced Compiz fusion options enabled. I am using xdotool to simulate keyboard input in order to rotate through multiple desktops.
I am looking for a way to kill a while true loop when the Enter key (or Control+C if it is easier) is pushed when the... (2 Replies)
I wonder if someone could help me here. I am trying to find a way of exiting from a loop but not exiting me from the script for example
#!/bin/ksh
# ************* FUNCTIONS ******************
function1() { #ping test
ping $1 2 > /dev/null
if ; then
... (13 Replies)
Greeting,
The following script completes after reading only one record from the input file that contains many records. I commented out the "ssh" and get what I expect, an echo of all the records in the input.txt file. Is ssh killing the file handle?
On the box "uname -a" gives "SunOS... (2 Replies)
Hi my code looks like:
if test $STEP -le 10
then
.
.
ls -1d AM*-OUT|while read MYDIR
do
cd $MYDIR
ls |tail -n1| while read MYFILE
do
.
.
if test -s $MYFILE
then
sqlldr ....
rc=$?
if test $rc -ne 0 (3 Replies)
Hi,
I have a really simple script which I want to run forever, inside the loop it runs a C application which if it exits should restart.
#!/bin/sh
while true
do
./SCF scf.conf >> scf.log
sleep 2
done
For some reason the SCF C application coredumps and the script is exiting.... (3 Replies)
Hi I am having a problem exiting a WHILE loop. I am on a Sun server using ksh.
I am running a Veritas Cluster Software (High Availablity) command to obtain a group status and grepping the command output for status "G" which means that the filesystem is frozen and therefore not available to... (3 Replies)
We are trying to design a flow so that an ETL job shouldn't start until the previous job completes. The script we have written is
while ; do sleep 2; done
The loop however exits even when the process is actually running. Why could this be happening? (12 Replies)
Hi ,
I am processing some files using below shell script the problem for loop exit after processing some files even though it exist.After modifying file.txt and rerunning the script and its running .Any Advise
for i in `cat /xx/file.txt |tr -s "," '\n' ` ; do
echo $i... (3 Replies)
Discussion started by: mohan705
3 Replies
LEARN ABOUT OSX
context::preserve
Context::Preserve(3) User Contributed Perl Documentation Context::Preserve(3)NAME
Context::Preserve - run code after a subroutine call, preserving the context the subroutine would have seen if it were the last statement
in the caller
SYNOPSIS
Have you ever written this?
my ($result, @result);
# run a sub in the correct context
if(!defined wantarray){
some::code();
}
elsif(wantarray){
@result = some::code();
}
else {
$result = some::code();
}
# do something after some::code
$_ += 42 for (@result, $result);
# finally return the correct value
if(!defined wantarray){
return;
}
elsif(wantarray){
return @result;
}
else {
return $result;
}
Now you can just write this instead:
use Context::Preserve;
return preserve_context { some::code() }
after => sub { $_ += 42 for @_ };
DESCRIPTION
Sometimes you need to call a function, get the results, act on the results, then return the result of the function. This is painful
because of contexts; the original function can behave different if it's called in void, scalar, or list context. You can ignore the
various cases and just pick one, but that's fragile. To do things right, you need to see which case you're being called in, and then call
the function in that context. This results in 3 code paths, which is a pain to type in (and maintain).
This module automates the process. You provide a coderef that is the "original function", and another coderef to run after the original
runs. You can modify the return value (aliased to @_) here, and do whatever else you need to do. "wantarray" is correct inside both
coderefs; in "after", though, the return value is ignored and the value "wantarray" returns is related to the context that the original
function was called in.
EXPORT
"preserve_context"
FUNCTIONS
preserve_context { original } [after|replace] => sub { after }
Invokes "original" in the same context as "preserve_context" was called in, save the results, runs "after" in the same context, then
returns the result of "original" (or "after" if "replace" is used).
If the second argument is "after", then you can modify @_ to affect the return value. "after"'s return value is ignored.
If the second argument is "replace", then modifying @_ doesn't do anything. The return value of "after" is returned from
"preserve_context" instead.
Run "preserve_context" like this:
sub whatever {
...
return preserve_context { orginal_function() }
after => sub { modify @_ };
}
or
sub whatever {
...
return preserve_context { orginal_function() }
replace => sub { return @new_return };
}
Note that there's no comma between the first block and the "after =>" part. This is how perl parses functions with the "(&@)" prototype.
The alternative is to say:
preserve_context(sub { original }, after => sub { after });
You can pick the one you like, but I think the first version is much prettier.
AUTHOR AND COPYRIGHT
Jonathan Rockway "<jrockway@cpan.org>"
Copyright (c) 2008 Infinity Interactive. You may redistribute this module under the same terms as Perl itself.
perl v5.16.2 2008-01-15 Context::Preserve(3)