in reply to Re^3: Splitting a long row with multiple delimiters.
in thread Splitting a long row with multiple delimiters.

yes the keys which donot have "=" (in this case only first value) or have "key=<whitespace>",value will be considered as null or undef.

  • Comment on Re^4: Splitting a long row with multiple delimiters.

Replies are listed 'Best First'.
Re^5: Splitting a long row with multiple delimiters.
by poj (Abbot) on Jan 19, 2018 at 15:13 UTC

    Do all the keys which do not have "=" appear at the beginning of the string ?

    poj

      Yes Buddy, fortunately, its only in beginning and that too only single string.

        OK try

        #!perl use strict; use Data::Dumper; my $str = 'eab12345 a b c id=00000 x= pgrp=abc=defgh groups=abcdefgh a +nd more roles='; my @f = split / (\w+=)/,$str; my @array = (); while (@f){ my $k = shift @f; if ($k =~ /=$/){ my $v = shift @f; push @array,"$k$v"; } else { # key no equal push @array,"$_=" for split /\s+/,$k; } } print Dumper \@array;
        #!/usr/bin/perl # http://perlmonks.org/?node_id=1207515 use strict; use warnings; $_ = <<END; eab12345 id=00000 pgrp=abcdefgh groups=abcdefgh home=/home/eab12345 sh +ell=/usr/bin/ksh gecos=AB/C/Y0000/ABC/XYZ RTYUI, LMNOP *CONTRACTOR* ( +AS 00000) auditclasses=general,files,TCPIP login=true su=true rlogin= +true daemon=true admin=false sugroups=ALL admgroups= tpath=nosak ttys +=ALL expires=0 auth1=SYSTEM auth2=NONE umask=00 registry=AD SYSTEM=AD + logintimes= loginretries=5 pwdwarntime=5 account_locked=false minage +=0 maxage=13 maxexpired=0 minalpha=1 minother=1 mindiff=1 maxrepeats= +2 minlen=8 histexpire=13 histsize=8 pwdchecks= dictionlist=/abc/def/g +hi/jkl default_roles= fsize=-1 cpu=-1 data=-1 stack=65536 core=000000 + rss=65536 nofiles=2000 time_last_login=1512632113 time_last_unsucces +sful_login=1505304923 tty_last_login=ssh tty_last_unsuccessful_login= +ssh host_last_login=0.000.000.000 host_last_unsuccessful_login=0.000. +000.000 unsuccessful_login_count=0 roles= END my @answers = /(?|^(\S+)|([^\s=]+=[^=\n]*)(?=\s))/g; use Data::Dump 'pp'; pp \@answers;