poplines()
Return the specified number of lines from the beginning of a variable.
Syntax
Parameter
Parameter | Definition |
---|---|
text_variable | variable to be edited by poplines() This parameter must be a variable. You cannot use a string because poplines() edits the content of the variable. |
num_lines | number of lines to be returned by this function |
w | optional flag that removes all trailing whitespace from the text returned by poplines() |
Description
The poplines() function returns the specified number of lines from the beginning of the user-defined variable, and it deletes these lines from the variable.
This function returns NULL when it encounters an error. Use the following values for the errno variable to troubleshoot poplines().
errno Value | Description of Failure |
---|---|
0 | No error |
68 | E_PSL_EDOM |
96 | E_PSL_BAD_FUNCTION_PARAMETER |
Example
The following example demonstrates the poplines() function.
text_var=" Line 1\n Line 2\n Line 3\n Line 4";
print("Before poplines, text_var=".text_var);
result_text=poplines(text_var, 3);
print("\n\nAfter poplines, text_var=".text_var);
print("\n\nThe following lines were removed:\n". result_text);
The following output results from the preceding code.
Line 2
Line 3
Line 4
After poplines, text_var= Line 4
The following lines were removed:
Line 1
Line 2
Line 3