There are a host of problems with my solution. However it solves the posted issue (reporting cached hits) as I understand the snippet. If we assume that @completefile is a file slurp (i.e.
@completefile = <$fh>), then this loop will output the last $exch match in the file. If I misunderstand the spec and each line of @completefile represents a file slurp (i.e.
local $/; push @completefile,<$fh>), then a solution could be obtained using a
g modifier (and likely an m to boot) on the regex and a
while loop:
foreach $exch(@exch) {
for($i=0; $i<=$#completefile; $i++) {
$su_adapter = undef;
$su_date = undef;
while($completefile[$i]=~ m/^.+\\(.+)_.+\..+?:(.+?)\s-\s(.+?)\
+s.+?\/$exch\s\|.+::(.*Up)\(\)/g) {
$su_adapter=$1;
$su_date=$2;
}
print $su_adapter, $su_date;
}
}
I disagree with your point about printing since I generally care as much about a failed match as a successful match, and as long as the OP clearly isn't using warnings, printing undefs (with formatting like perhaps a newline) is appropriate. In any case, were I to have coded this, it would look a lot more like
foreach my $exch (@exch) {
my ($su_adapter, $su_date);
foreach (reverse @completefile) {
last if ($su_adapter, $su_date) = /^.+\\(.+)_.+\..+?:(.+?)\s-\
+s(.+?)\s.+?\/$exch\s\|.+::(.*Up)\(\)/;
}
if (defined $su_adapter) {
print "Last match for $exch: $su_adapter, $su_date\n";
} else {
print "No match for $exch\n";
}
}
In the end, much of this is strictly academic, since this the OP never posted enough code to really understand what they intended.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.