Name : perl-Perl6-Slurp
| |
Version : 0.051005
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : 1.2
| Date : 2015-10-05 02:15:24
|
Group : Development/Libraries/Perl
| Source RPM : perl-Perl6-Slurp-0.051005-1.2.src.rpm
|
Size : 0.02 MB
| |
Packager : (none)
| |
Summary : Implements the Perl 6 \'slurp\' built-in
|
Description :
\'slurp\' takes:
* *
a filename,
* *
a filehandle,
* *
a typeglob reference,
* *
an IO::File object, or
* *
a scalar reference,
converts it to an input stream (using \'open()\' if necessary), and reads in the entire stream. If \'slurp\' fails to set up or read the stream, it throws an exception.
If no data source is specified \'slurp\' uses the value of \'$_\' as the source. If \'$_\' is undefined, \'slurp\' uses the \'AATTARGV\' list, and magically slurps the contents of _all_ the sources listed in \'AATTARGV\'. Note that the same magic is also applied if you explicitly slurp < *ARGV>, so the following three input operations:
$contents = join \"\", < ARGV>
$contents = slurp \\*ARGV;
$/ = undef; $contents = slurp;
are identical in effect.
In a scalar context \'slurp\' returns the stream contents as a single string. If the stream is at EOF, it returns an empty string. In a list context, it splits the contents after the appropriate input record separator and returns the resulting list of strings.
You can set the input record separator (\'{ irs => $your_irs_here}\') for the input operation. The separator can be specified as a string or a regex. Note that an explicit input record separator has no input-terminating effect in a scalar context; \'slurp\' always reads in the entire input stream, whatever the \'\'irs\'\' value.
In a list context, changing the separator can change how the input is broken up within the list that is returned.
If an input record separator is not explicitly specified, \'slurp\' defaults to \'\"\ \"\' (_not_ to the current value of \'$/\' ndash since Perl 6 doesn\'t _have_ a \'$/\');
You can also tell \'slurp\' to automagically \'chomp\' the input as it is read in, by specifying: (\'{ chomp => 1 }\')
Better still, you can tell \'slurp\' to automagically \'chomp\' the input and _replace_ what it chomps with another string, by specifying: (\'{ chomp => \"another string\" }\')
You can also tell \'slurp\' to compute the replacement string on-the-fly by specifying a subroutine as the \'chomp\' value: (\'{ chomp => sub{...} }\'). This subroutine is passed the string being chomped off, so for example you could squeeze single newlines to a single space and multiple consecutive newlines to a two newlines with:
sub squeeze { my ($removed) = AATT_; if ($removed =~ tr/\ /\ / == 1) { return \" \" } else { return \"\ \ \"; } }
print slurp(\\*DATA, {irs=>qr/[ \\t]*\ +/, chomp=>\\&squeeze}), \"\ \";
Which would transform:
This is the first paragraph
This is the second paragraph
This, the third
This one is the very last
to:
This is the first paragraph
This is the second paragraph
This, the third
This one is the very last
Autochomping works in both scalar and list contexts. In scalar contexts every instance of the input record separator will be removed (or replaced) within the returned string. In list context, each list item returned with its terminating separator removed (or replaced).
You can specify I/O layers, either using the Perl 5 notation:
slurp \"< :layer1 :layer2 :etc\", $filename;
or as an array of options:
slurp $filename, [layer1=>1, layer2=>1, etc=>1]; slurp [layer1=>1, layer2=>1, etc=>1], $filename;
or as individual options (each of which must be in a separate hash):
slurp $filename, {layer1=>1}, {layer2=>1}, {etc=>1}; slurp {layer1=>1}, {layer2=>1}, {etc=>1}, $filename;
(...which, of course, would look much cooler in Perl 6:
slurp $filename, :layer1 :layer2 :etc; slurp :layer1 :layer2 :etc, $filename;
)
A common mistake is to put all the options together in one hash:
slurp $filename, {layer1=>1, layer2=>1, etc=>1};
This is almost always a disaster, since the order of I/O layers is usually critical, and placing them all in one hash effectively randomizes that order. Use an array instead:
slurp $filename, [layer1=>1, layer2=>1, etc=>1];
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl/openSUSE_Leap_42.1/noarch |
Hmm ... It's impossible ;-) This RPM doesn't exist on any FTP server
Provides :
perl(Perl6::Slurp)
perl-Perl6-Slurp
Requires :