I'm sure that this can be done is less steps, but it works...

#!/usr/bin/perl -w
use strict;

my $line = "     stuff\n";
print chgSpace($line);

sub chgSpace {
    my $line = shift;
    my ( $spaces ) = $line =~ /^(\s+)/;
    $spaces =~ s/ /_/g;
    $line =~ s/^\s+/$spaces/;
    return $line;
}


Rob

-----Original Message-----
From: Kristin A. I. [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 09, 2002 12:39 PM
To: [EMAIL PROTECTED]
Subject: Search & Replace Issue


I am trying to indent a scroll-thru menu which has been made into a tree
using the following database query:
  select dept_id, LPAD(' ',2*(Level-1))||dept_name dept_name
  from depts
  start with dept_id = 1
  connect by dept_parent = PRIOR dept_id;
My problem is that the query uses spaces to indent the list, and spaces seem
to be automatically removed from the beginnings of items in scroll-thru
menus.  To remedy this, I have decided to replace the spaces with
underscores.  This is where I become confused.
s/ /_/g replaces even spaces between words in the list;
s/^(_*) /_/g would require multiple iterations to catch all the spaces...
Is there a simple way to replace one thing with another in the amount in
which the first thing appeared?  Ex.: 2 spaces becomes 2 underscores, 4
becomes 4, etc. Thank you for any help.

--

Namaste,

Kristin

"I can no other answer make, but, thanks, and thanks"
     - William Shakespeare
       Twelfth N, Act iii, Sc.3

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to