View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Stuart Caie > Test-MockCommand-0.02 > Test::MockCommand::ScalarReadline



Annotate this POD


New  2
Open  0
View/Report Bugs
Source   Latest Release: Test-MockCommand-0.03


Test::MockCommand::ScalarReadline - reads scalars using $/ behaviour


 use Test::MockCommand::ScalarReadline qw(scalar_readline);

 my $s = "Hello\nWorld\n";

 $/ = "\n";  my @x = scalar_readline($s); # returns ("Hello\n", "World\n");
 $/ = "xyz"; my @x = scalar_readline($s); # returns ("Hello\nWorld\n");
 $/ = "or";  my @x = scalar_readline($s); # returns ("Hello\nWor", "ld\n");

 my $record_size = 3; $/ = \$record_size;
 my @x = scalar_readline($string); # returns ("Hel", "lo\n", "Wor", "ld\n");

 # can also be used in scalar context to get one line at a time
 my ($line, $chars_to_cut);
 while (defined ($line = scalar_readline($s, $chars_to_cut))) {
     # ...
     $s = substr($s, $chars_to_cut);


This module provides the scalar_readline function, which breaks a scalar into a list the same way that readline breaks an input stream up into lines, depending on the current value of $/.


@all_lines = scalar_readline($string)
$line = scalar_readline($string, $chars_to_cut)

In list context, returns a list containing $string broken apart into lines according to the current value of $/.

In a scalar context, returns the first line from $string, In order to get the next line, you have to provide a second parameter, which must be a scalar variable. The number of bytes to cut from the start of your data will be written back into this variable.

In order to fully emulate readline(), when $/ is set to undef (slurp mode), you must return "" the first time a string is empty and undef thereafter. This function does not do that.


perlvar, "readline" in perlfunc

syntax highlighting: