On Fri, Jun 28, 2013 at 12:04 AM, Charles DeRykus <dery...@gmail.com> wrote:
>
>
>
> On Thu, Jun 27, 2013 at 1:31 PM, Dr.Ruud <rvtol+use...@isolution.nl> wrote:
>>
>> On 27/06/2013 22:01, Shawn H Corey wrote:
>>>
>>> On Thu, 27 Jun 2013 21:53:46 +0200
>>> "Dr.Ruud" <rvtol+use...@isolution.nl> wrote:
>>>>
>>>> See also 'Statement Modifiers' in perlsyn.
>>>> There it is shown how to make next and last work with do{}. I read
>>>> that as a rather funny way to discourage people from do-ing it.
>>>
>>> "Here be dragons." I would say that was a warning to avoid it
>>> altogether.
>>
>>
>> The "Here be dragons." there, is about something different, namely the "my
>> $x if ... ;" type of code.
>> (at least in the version I last read, 5.14.2
>>
>
> True.  But, "do" should probably draw a more explicit caution in the docs
> since there are less tricky ways in most cases.
>
> However, there may be a few places when 'do' isn't always a don't :)
>
> 'do' might be a shorter, more readable idiom in the sense of "do something
> until a condition occurs":
>

I can't agree with the either or here

> perl -e 'do {$in =<>; ... } until $in =~ /q/'
>
>  vs.
>
> perl -e 'while ( $in = <>; ... ) { ... last if $in =~ /q/}'
>

I find a combination of the two is most useful for quickly generating reports:
perl -nle 'do {$h{$1}{count}++; $h{$1}{$2} = $3;} if /Jun 23.+: input
ACCEPT.+SRC=([0-9\.]+).+PROTO=(TCP|UDP|ICMP).+DPT=([0-9]+)/ }{use
Data::Dumper; foreach my $i (sort {$h{$a}{count} <=> $h{$b}{count}}
keys %h) {print "$i " . Dumper($h{$i}) unless ($h{$i}{TCP} =~
/808[0128]|443|8[08]/) }' /var/log/iptlog

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to