Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems removing leading whitespace
by haukex (Archbishop) on Jan 30, 2020 at 11:54 UTC | |
by Anonymous Monk on Jan 30, 2020 at 16:22 UTC | |
by Anonymous Monk on Jan 30, 2020 at 12:13 UTC |