[ Pobierz całość w formacie PDF ]

context, returns the number of times the expression was true.
@foo = grep(!/^#/, @bar); # weed out comments
Note that, since $_ is a reference into the array value, it can be used to modify the elements of the
array. While this is useful and supported, it can cause bizarre results if the LIST is not a named
array.
join(EXPR,LIST)
join(EXPR,ARRAY)
Joins the separate strings of LIST or ARRAY into a single string with fields separated by the value
of EXPR, and returns the string. Example:
$_ = join( : ,
$login,$passwd,$uid,$gid,$gcos,$home,$shell);
See split.
keys(ASSOC_ARRAY)
keys ASSOC_ARRAY
Returns a normal array consisting of all the keys of the named associative array. The keys are
returned in an apparently random order, but it is the same order as either the values() or each()
function produces (given that the associative array has not been modified). Here is yet another way
to print your environment:
@keys = keys %ENV;
@values = values %ENV;
while ($#keys >= 0) {
print pop(@keys),  = , pop(@values), "\n";
}
or how about sorted by key:
foreach $key (sort(keys %ENV)) {
print $key,  = , $ENV{$key}, "\n";
}
pop(ARRAY)
pop ARRAY
Pops and returns the last value of the array, shortening the array by 1. Has the same effect as
$tmp = $ARRAY[$#ARRAY--];
If there are no elements in the array, returns the undefined value.
push(ARRAY,LIST)
Treats ARRAY (@ is optional) as a stack, and pushes the values of LIST onto the end of ARRAY.
The length of ARRAY increases by the length of LIST. Has the same effect as
for $value (LIST) {
$ARRAY[++$#ARRAY] = $value;
}
but is more efficient.
reverse(LIST)
reverse LIST
In an array context, returns an array value consisting of the elements of LIST in the opposite order.
In a scalar context, returns a string value consisting of the bytes of the first element of LIST in the
opposite order.
shift(ARRAY)
shift ARRAY
shift Shifts the first value of the array off and returns it, shortening 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 @ARGV array in the main program, and the @_ array in subroutines. (This is
determined lexically.) See also unshift(), push() and pop(). Shift() and unshift() do the same thing
to the left end of an array that push() and pop() do to the right end.
sort(SUBROUTINE LIST)
sort(LIST)
sort SUBROUTINE LIST
sort BLOCK LIST
sort LIST
Sorts the LIST and returns the sorted array value. Nonexistent values of arrays are stripped out. If
SUBROUTINE or BLOCK is omitted, sorts in standard string comparison order. If
SUBROUTINE is specified, gives the name of a subroutine that returns an integer less than, equal
to, or greater than 0, depending on how the elements of the array are to be ordered. (The and
cmp operators are extremely useful in such routines.) SUBROUTINE may be a scalar variable
name, in which case the value provides the name of the subroutine to use. In place of a
SUBROUTINE name, you can provide a BLOCK as an anonymous, in-line sort subroutine.
In the interests of efficiency the normal calling code for subroutines is bypassed, with the
following effects: the subroutine may not be a recursive subroutine, and the two elements to be
compared are passed into the subroutine not via @_ but as $a and $b (see example below). They
are passed by reference so don t modify $a and $b.
Examples:
# sort lexically
@articles = sort @files;
# same thing, but with explicit sort routine
@articles = sort {$a cmp $b} @files;
# same thing in reversed order
@articles = sort {$b cmp $a} @files;
# sort numerically ascending
@articles = sort {$a $b} @files;
# sort numerically descending
@articles = sort {$b $a} @files;
# sort using explicit subroutine name
sub byage {
$age{$a} $age{$b}; # presuming integers
}
@sortedclass = sort byage @class;
sub reverse { $b cmp $a; }
@harry = ( dog , cat , x , Cain , Abel );
@george = ( gone , chased , yz , Punished , Axed );
print sort @harry;
# prints AbelCaincatdogx
print sort reverse @harry;
# prints xdogcatCainAbel
print sort @george,  to , @harry;
# prints AbelAxedCainPunishedcatchaseddoggonetoxyz
splice(ARRAY,OFFSET,LENGTH,LIST)
splice(ARRAY,OFFSET,LENGTH)
splice(ARRAY,OFFSET)
Removes the elements designated by OFFSET and LENGTH from an array, and replaces them
with the elements of LIST, if any. Returns the elements removed from the array. The array grows
or shrinks as necessary. If LENGTH is omitted, removes everything from OFFSET onward. The
following equivalencies hold (assuming $[ == 0):
push(@a,$x,$y)\h |3.5i splice(@a,$#a+1,0,$x,$y)
pop(@a)\h |3.5i splice(@a,-1)
shift(@a)\h |3.5i splice(@a,0,1) [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • skydive.htw.pl
  • Copyright © 2016 Moje życie zaczęło siÄ™ w dniu, gdy ciÄ™ spotkaÅ‚em.
    Design: Solitaire