Greetings Perl Monks I have a problem which I'm struggling with due to my limited perl knowledge, which I hope you can assist me with.

I have a string which Dumper displays like this

$VAR1 = [ " echo ", " ----------", " REPVersion", "", " Version + + ", " ---------------------------------------------------------- +--------------------------------------------------------------------- +---------------", " Replication Server/16.0/EBF 27617 SP03 PL03 rs160sp03pl03/ +Linux AMD64/Linux 2.6.32.59-0.19-default x86_64/2214/OPT64/Tue Dec 19 + 19:00:15 2017 ", " echo ", " -----------", " REPErrorlog", "", " Log File Name ", " --------------------------------------------------------", " /logdisk/logs/my.log", " echo ", " --------------", " REPSiteVersion", "", " Site Version", " ------------", " 1600302", " echo ", " -----------", " REPRSSDName", "", " RSSD Dataserver RSSD Database ", " ------------------------- ------------------", " SYBASE_APP123_MYRSSD_SERV SYBASE_APP123_RSSD", " ------------", " REPQueueSize", "", " ", " -----------", " 102396", " ", " ---------------", " REPLossDetected", "", " ", " -----------", " 0", " ", " -------------", " REPSSLEnabled", "", " ", " -----------", " 0" ]; ARRAY(0x20794b0)

I'm trying to remove the leading whitespace using this code

my $result = runDBsql($server,$user,$pass); # Cannot modify runDBsql remove_leadspace($result); local $Data::Dumper::Useqq = 1;# In case it is not whitespace but some + other character print Dumper($result); print "\n$result\n"; # added for further debugging sub remove_leadspace { return if not defined wantarray; return map { s/^\s+//r } @_ if wantarray; return shift =~ s/^\s+//r; }

The remove_leadspace is not removing the leftmost spaces

So when I consequently use the returned data which I reference using $result->[n] it looks like this

(' REPErrorlog', ' /logdisk/logs/my.log') (' REPSiteVersion', ' 1600302') (' REPRSSDName', ' SYBASE_APP123_MYRSSD_SERV SYBASE_APP123_RSSD') (' REPQueueSize', ' 102396') (' REPLossDetected', ' 0') (' REPSSLEnabled', ' 0')

I inherited this code and I think I'm confusing scalar and array strings.

How do I get rid of the leading whitespace ?

Any help much appreciated


In reply to Problems removing leading whitespace by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.