|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use General::Parse;
my $string = q{Some "not very long" string of 6 tokens.};
my $token1 = cutToken(\$string); # $token1 = "Some";
my ($token2, $token3) = cutTokens(\$string, 2);
my @subtokens = getTokens($token2); # ("not", "very", "long")
my $subtoken1 = getToken($token2); # the same as $subtokens[0]
my $endingArrayRef = getTokens($string); # ["of", "6", "tokens."]
If the string is empty or consists of only spaces the returned token is undef.
If the caller expects a scalar - the token is returned. If it expects an array - 2 values returned, the token and the rest of the string.
If the string is empty or consists of only spaces the returned token is undef and the string is changed to an empty string.
The returned array may contain less tokens than requested if the string is too short. Particularly, the returned array is empty if the string is empty or consists of only spaces.
If the caller expects a scalar - a reference to the token array is returned. If it expects an array - the token array is returned.
The returned array may contain less tokens than requested if the string is too short. Particularly, the returned array is empty if the string is empty or consists of only spaces.
If the caller expects a scalar - a reference to the token array is returned. If it expects an array - the token array is returned.
Last modified on August 26, 2005