GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Text::Outdent(3) User Contributed Perl Documentation Text::Outdent(3)

Text::Outdent - Outdent chunks of text

    my $foo = outdent($bar);

    my $baz = outdent_quote(q{
        this
            is
            a
        string
            that
            is
            indented
        with
            spaces
            or
            tab
    });

This module was created to make it easy to have large chunks of strings in the code. If you use a quote operator that spans over several lines or a "here-doc" and have an indention of the code you get leading whitespaces that you may or may not want. If you don't want them this module easily removes them.

You can also use it for other texts that are indented.

No functions are exported by default. ":ALL" exports all.
"outdent($str)"
Removes the common leading whitespaces for each line. Currently lines with only whitespaces are ignored and left untouched; treated as blank lines if you like. No tab expansion is being performed; a tab is just a whitespace character.

If the indention consists of both spaces and tabs then it's a good idea to expand the tabs first, see &expand_leading_tabs. If the mix of tabs and spaces is consistent, e.g. every line begins with "  \t ", then that is recognized as indention.

    # common leading whitespaces are removed.
    my $str = <<'_STR_';
        this
            is
            a
        string
            that
            is
            indented
        with
            spaces
            or
            tab
    _STR_

    print '* Indented: ', $str;
    print '* Outdented: ', outdent($str);
    

outputs

    * Indented:
        this
            is
            a
        string
            that
            is
            indented
        with
            spaces
            or
            tab

    * Outdented:
    this
        is
        a
    string
        that
        is
        indented
    with
        spaces
        or
        tab
    
"outdent_all($str)"
Like &outdent except it doesn't treat "whitespace lines" as blank lines.
"outdent_quote($str)"
Like &outdent but with some twists to make it smooth to use a (possibly indented) quote operator spanning over several lines in your source. The arrows (that isn't part of the code) below point out the two issues this function takes care of.

    my $foo = q{       <--- newline and possible spaces
        foo
            bar
            baz
        zip
            zap
    };                 <--- empty line with possible spaces
    

First, all whitespaces uptil the first newline plus the newline itself are removed. This takes care of the first issue.

Second, if the string ends with a newline followed by non-newline whitespaces the non-newline whitespaces are removed. This takes care of the second issue.

These fixes serve to make the quote operator's semantics equivalent to a here-docs.

"expand_leading_tabs($tabstop, $str)"
Expands tabs that on a line only have whitespaces before them. Handy to have if you have a file with mixed tab/space indention.

Johan Lodin <lodin@cpan.org>

Copyright 2004-2005 Johan Lodin. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2005-07-23 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.