in reply to Re^4: undef a variable for a loop
in thread undef a variable for a 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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: undef a variable for a loop
by ikegami (Patriarch) on May 15, 2009 at 19:34 UTC | |
by kennethk (Abbot) on May 15, 2009 at 19:43 UTC | |
by ikegami (Patriarch) on May 15, 2009 at 20:48 UTC | |
|
Re^6: undef a variable for a loop
by csiepka (Initiate) on May 15, 2009 at 21:33 UTC |