README

NAME

Lines::Containing - look for lines containing a given needle

SYNOPSIS

use Lines::Containing;

# lines with an "a"
.say for lines-containing("foo\nbar\nbaz", "a")  # bar␤baz␤

# lines ending on "r", with their line number
.say for lines-containing("foo\nbar\nbaz", / r $/, :kv);  # 1␤bar␤

# line numbers of lines starting with "f", starting at 1
.say for lines-containing("foo\nbar", *.starts-with("b"), :k, :offset(1));  # 2␤

DESCRIPTION

Lines::Containing exports a single subroutine lines-containing that can either take a Seq or Iterator producing lines, an array with lines, a Hash (or Map) with lines as values, or any other object that supports a lines method producing lines (such as Str, IO::Path, IO::Handle, Supply) as the source to check.

As the second parameter, it takes either a Cool object, a regular expression, or a Callable as the needle to search for.

It returns a (potentially lazy) Seq of the lines that contained the needle.

Additionally, it supports the following named arguments:

  • :p

Produce Pairs with the line number (or the key in case of a Hash) as the key.

  • :k

Produce line numbers only, or keys only in case of a Hash.

  • :kv

Produce line number (or key in case of a Hash) and line alternately.

  • :v (default)

Produce lines only.

  • :i or :ignorecase

Ignore case (only if the needle is a Str).

  • :m or :ignoremark

Ignore mark (only if the needle is a Str).

  • :offset

The line number of the first line in the source (defaults to 0).

AUTHOR

Elizabeth Mattijsen [email protected]

Source can be located at: https://github.com/lizmat/Lines-Containing . Comments and Pull Requests are welcome.

If you like this module, or what I’m doing more generally, committing to a small sponsorship would mean a great deal to me!

COPYRIGHT AND LICENSE

Copyright 2022 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

Lines::Containing v0.0.1

look for lines containing a given needle

Authors

  • Elizabeth Mattijsen

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • Lines::Containing

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.