Bla <> wrote:
> On Mon, 24 Jan 2005 17:35:34 -0700, Eric Schwartz <>
> wrote:
>
>>Bla <> writes:
>>> Trying to print to a file after a while loop.....
>>>
>>>
>>> while {
>>> test
>>> }
>>>
>>> do this
>>>
>>> can I put an else in here if the above is not true????
>>
>>I quoted you fully only because I cannot for the life of me figure out
>>what, in fact, you are trying to do. A while loop doesn't look like
>>that, it looks like this:
>>
>>while (some_test()) {
>> do_something();
>>}
>>
>>Can you please try this question again, with actual Perl?
>>
>>-=Eric
>
> #!/usr/bin/perl -w
> #
> open (SNMPLOG, ">snmp.log") or die "could not open 'snmp.log' $!";
> $ARGV[0] = 'url.log';
> my %status;
> while (<>) {
> / (FAILURE|SUCCESS).+?from (.+)/ and $status{$2} = $1;
> }
> $status{$_} eq 'FAILURE' and print SNMPLOG " 0 " for sort keys
> %status;
>
> #else {
> # print SNMPLOG " 1 " for sort keys %status;
> #}
print SNMPLOG $status{$_} eq 'FAILURE' ? ' 0 ' : ' 1 ' for sort keys %status;
but I don't like that much for maintenance, I wouldn't use it in my code.
I'd "unroll" it, as that seems to make it much easier to see what's going on:
for (sort keys %status) {
if ( $status{$_} eq 'FAILURE' )
{ print SNMPLOG ' 0 ' }
else
{ print SNMPLOG ' 1 ' }
}
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas