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


Manual Reference Pages  -  TEXT::OUTDENT (3)

.ds Aq ’

NAME

Text::Outdent - Outdent chunks of text

CONTENTS

SYNOPSIS



    my $foo = outdent($bar);

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



DESCRIPTION

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.

EXPORTED FUNCTIONS

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.

AUTHOR

Johan Lodin <lodin@cpan.org>

COPYRIGHT

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.

SEE ALSO

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


perl v5.20.3 TEXT::OUTDENT (3) 2005-07-23

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