in reply to Re: Get variables from if with regex
in thread Get variables from if with regex
Thanx, all help much appreciated.
The suggestion by choroba seems to work, and is part of the solution, but I can't seem to get it working with more than one instance of it in the same if statement: Works:# add 1362072030 dc=ifdsgroup,dc=com dn: uid=nce9834xdho,ou=user,ou=nce,ou=prod ! port 1362 dc=isgrp,dc=com changetype: add ifastCreateDate: 1362072030649 objectClass: account objectClass: ifastUser objectClass: top ifastModifyDate: 1362072030649 uid: nce9834xdho cn: nce9834xdho ifastProducts: WEB ifastGivenName: Omar ifastLanguage: en ifastFailedLogons: 0 ifastLastLogon: 15764 ifastEmailAddr: omar.hafez@td.com ifastSurname: Hafez structuralObjectClass: account entryUUID: e587875c-1616-1032-93e5-4b7d087c5768 createTimestamp: 20130228172030Z modifyTimestamp: 20130228172030Z # end add 1362072030 # add 1362072030 dc=ifdsgroup,dc=com ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # end add 1362072030
But this does not:undef $/; $/="\n\n"; while(<IFILE>) { my @RESULT=(); my @LINES=split (/\n/, $_); if ((grep /objectClass:\s+account/, @LINES) && (grep /objectClass:\s+ifastUser/, @LINES) #&& (my ( $PRODS ) = /ifastProducts:\s+(.+)\s*$/, $_) && (my ( $USER ) = /dn: uid=(\w+?),.+/, $_)) { push(@RESULT, $USER); #push(@RESULT, $PRODS, $USER); print join "|", @RESULT; #print OFILE join "|", @RESULT; #print OFILE "\n"; print "\n"; } }
undef $/; $/="\n\n"; while(<IFILE>) { my @RESULT=(); my @LINES=split (/\n/, $_); if ((grep /objectClass:\s+account/, @LINES) && (grep /objectClass:\s+ifastUser/, @LINES) && (my ( $PRODS ) = /ifastProducts:\s+(.+)\s*$/, $_) && (my ( $USER ) = /dn: uid=(\w+?),.+/, $_)) { #push(@RESULT, $USER); push(@RESULT, $PRODS, $USER); print join "|", @RESULT; #print OFILE join "|", @RESULT; #print OFILE "\n"; print "\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Get variables from if with regex
by choroba (Cardinal) on Mar 08, 2013 at 13:51 UTC | |
by Saved (Beadle) on Mar 08, 2013 at 14:08 UTC |
In Section
Seekers of Perl Wisdom