Do you really need to split the paragraph into lines? You can match a multiline string against a regex, too:
#!/usr/bin/perl
use warnings;
use strict;
$/ = "\n\n";
while (<>) {
my @result;
if ( /objectClass:\s+account/
and /objectClass:\s+ifastUser/
and my ($prods) = /ifastProducts:\s+(.+?)\s*$/mg # The /m is
+important here.
and my ($user) = /dn: uid=(\w+?),./g) {
push @result, $prods, $user;
print join '|', @result;
print "\n";
}
}
But if you need the array, you can have it. The , $_) part of your code does nothing, so remove it. Here is my attempt to do what you need:
#!/usr/bin/perl
use warnings;
use strict;
$/ = "\n\n";
while (<>) {
my @result;
my @lines = split /\n/;
if ( ( grep /objectClass:\s+account/, @lines)
and (grep /objectClass:\s+ifastUser/, @lines)
and (my ($prods) = map /ifastProducts:\s+(.+?)\s*$/g, @lines)
and (my ($user) = map /dn: uid=(\w+?),.+/g, @lines
+)) {
push @result, $prods, $user;
print join '|', @result;
print "\n";
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.