Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 347

# shift ...

Hello experts,

can anyone please tell me what the following code means ? may I have some examples as well ? thanks.

------------------------
sub Meow {
my(\$cat) = shift;
return int(\$cat + .1 * (\$cat <=> 0));
}
-------------------------
0
meow00
• 3
1 Solution

Commented:
perldoc -f shift
shift ARRAY
shift   Shifts the first value of the array off and returns it, short-
ening the array by 1 and moving everything down.  If there are
no elements in the array, returns the undefined value.  If
ARRAY is omitted, shifts the @_ array within the lexical scope
of subroutines and formats, and the @ARGV array at file scopes
or within the lexical scopes established by the "eval ''",
"BEGIN {}", "INIT {}", "CHECK {}", and "END {}" constructs.

do the same thing to the left end of an array that "pop" and
"push" do to the right end.

so
my(\$cat) = shift;
gets the first argument passed to the Meow sub
0

Commented:
.1 * (\$cat <=> 0)
is
-.1 if \$cat < 0
0 if \$cat == 0
.1 if \$cat > 0
so
Meow(-2.91) is -3)
Meow(-2.89) is -2)
0

Author Commented:
sorry ... i don't understand the following part :

-----------
Meow(-2.91) is -3)
Meow(-2.89) is -2)
--------------

why ???
0

Commented:
because .1 * (-2.91<=> 0) == -0.1
-2.91 + -0.1 == -3.01
int(-3.01) == -3

.1 * (-2.89<=> 0) == -0.1
-2.89 + -0.1 == -2.99
int(-2.99) == -2
0

## Featured Post

• 3
Tackle projects and never again get stuck behind a technical roadblock.