Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Remove leading spaces (left justify)

by TheDamian (Priest)
on May 19, 2003 at 01:23 UTC ( #259036=note: print w/replies, xml ) Need Help??

in reply to Remove leading spaces (left justify)

It's of no help yet, but it might interest folks to know that in Perl 6 you'd just write that as:
my $s = <<'EOS'; hello there test EOS
and the interpreter will strip as many whitespaces off each line as there are before the terminator.

Replies are listed 'Best First'.
Re: Re: Remove leading spaces (left justify)
by halley (Prior) on May 19, 2003 at 02:13 UTC
    I read about that, and my instant worry was about the whole world of tabs-vs-spaces. So-called "smart" editors might think that the indent in your example is best served by a tab and some spaces to 'hello', two tabs to 'there', and two tabs and some spaces to 'test'. What is the right amount to remove?

    Since indentation is a visual thing but perl and emacs and vim and msdev.exe will likely not discuss their various rendering strategies, these indented here-docs are likely to get out of whack.

    [ e d @ h a l l e y . c c ]

Re: Re: Remove leading spaces (left justify)
by Anonymous Monk on May 19, 2003 at 04:31 UTC

    Presumably, if the terminator is prefixed with 1 or more tabs, then that same number of tabs will be removed from the other lines (if they are present), and if it has 2 spaces and a tab, the 2 spaces and a tab will be removed from the other lines if present?

    This won't do the right thing if the whitespace is mixed and variable, but it might do 'the right thing' more often than not.

    From what I've read around the Monastery, you'd be forgiven that HEREDOCS were dangerous, unuseful animals that should have been depricated long ago.

    It's nice to see an old favorite of mine reinventing itself. I wonder if this change will satisfy its detractors?

      Yep, the leading whitespace will, by default, be matched exactly. If perl6 detects heterogeneous whitespace, it will detab from the first heterogeneous character, assuming 8-spaced hard tabs extending from the margin.

      And, yes, there will be a pragma to change that default behaviour in various ways (e.g. to 4-space tabs, full-detabbing, no-detabbing, etc. etc.).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://259036]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2019-12-11 00:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found