http://www.perlmonks.org?node_id=1212628

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I have a problem with Perl killing my script. Basically I have quite long foreach cycle in my script (estimated number of iterations is about 800) and Perl is killing it with message "This does not look like start-end". I am not quite sure what is the cause of this , because I have no such problem with infinite loops. Thanks

Replies are listed 'Best First'.
Re: This does not look like start end -- perldiag
by Discipulus (Canon) on Apr 10, 2018 at 08:40 UTC
    > Perl is killing it with message "This does not look like start-end"..

    I bet is not perl emitting this message; it comes or from your own script or by some module you use. Infact all messages emitted by perl itself are in perldiag and nothing similar to what you received is there.

    L*

    PS meh! since you provided some more info I won the bet: look here

    grep { croak "This doesn't look like start-end\n" unless /(.*)-(.*)/; push @a, $1; push @b, $2; } @cidr;

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Yeah, thank you, you are right. The problem is in source file with subnet information, validation check solved the issue.
Re: [OT]: This does not look like start end (grep vice for)
by AnomalousMonk (Archbishop) on Apr 10, 2018 at 20:02 UTC

    WRT this reply:

    grep { croak "This doesn't look like start-end\n" unless /(.*)-(.*)/; push @a, $1; push @b, $2; } @cidr;
    I've seen map (mis)used in place of a for-loop before (although I've never understood the attraction of this unclean practice), but never grep. Purely to satisfy my idle curiosity, can anyone speculate on the rationale for this odd syntactic tic? Why not just
    for (@cidr) { croak "This doesn't look like start-end\n" unless /(.*)-(.*)/; push @a, $1; push @b, $2; }


    Give a man a fish:  <%-{-{-{-<

      My thought was that somewhere in the development line, the author had switched from grepping into a single array to push @a...; push @b...;. But I went back all the way to the v0.02 (the farthest that metacpan would take me in BackPAN), and it was still the grep { ... push ... }-in-void-context construct. So if it was the change to push that caused it, the change happened before it was tracked in CPAN.

        ... switched from grepping into a single array to push @a...; push @b...;.

        But there are many examples of statements like  grep { $_=0 } @acopy; Very strange.


        Give a man a fish:  <%-{-{-{-<

      "...speculate on the rationale for this odd syntactic tic?"

      No problem at all:

      • Someone told the author that grep is cool
      • Someone told the author that grep is for real men
      • Someone told the author that grep is cooler than foreach
      • The author doesn't know foreach
      • Other reason

      Hey - it looks a bit like a poll.

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

        ◦ The author doesn't know foreach

        In support of which we have, just three lines past the grep statement:

        my $i; for ($i=0; $i <= $#a; $i++) { next if _ipcmp($b[$i], $lo) < 0; next if _ipcmp($hi, $a[$i]) < 0; return 1; }
        A genuine Perlish for-loop written in C-style. This peculiarity and another grep-loop are found also in cidradd() at line 985. I haven't looked further at the code. OTOH, in the very next function defined after cidrlookup(), cidrvalidate(), we see four kosher Perlish for-loops and a properly (IMHO) used grep, although I must admit there is no guarantee both functions were written by the same programmer. This is doing my nut.


        Give a man a fish:  <%-{-{-{-<

Re: This does not look like start end
by karlgoethebier (Abbot) on Apr 10, 2018 at 18:40 UTC

    grep::cpan

    Probably this is from CIDR.pm line 1000?

    grep { croak "This doesn't look like start-end\n" unless /(.*)-(.*)/; push @a, $1; push @b, $2; } @cidr;

    OK, i'm too late...

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: This does not look like start end
by jimpudar (Pilgrim) on Apr 10, 2018 at 08:24 UTC

    I don't think we have enough information to help you here. Is it possible for you to post the script?

    It is usually helpful to distill your script down to the bare minimum amount of code which still exhibits your bug.

    Also, if you add use strict and use warnings to the top of your script you might get some clues from Perl itself.

    Jim

      The problematic part is this one:

      foreach my $subnet (($ip->bits() == 32)?@IPv4Subnets:@IPv6Subnets) { next if ($subnet eq ''); my @subnetInfo = split(/;/x, $subnet); if (Net::CIDR::cidrlookup($params{ip}, trim($subnetInfo[0]))) { return (1, \@subnetInfo); } }

      I have also tried to rewrite it to while cycle with the same result.

      my $number = 0; my @subnets = ($ip->bits() == 32)?@IPv4Subnets:@IPv6Subnets; while ($number < scalar @subnets) { my $subnet = @subnets[$number]; if ($subnet eq '') { $number++; next; } my @subnetInfo = split(/;/x, $subnet); if (Net::CIDR::cidrlookup($params{ip}, trim($subnetInfo[0]))) { return (1, \@subnetInfo); } else { $number++; } } return (0, "Could not find ip '$params{ip}' in subnets list");
      Funnily enough the script worked when I had incorrect comparison operator ($subnet == '') in my code (with a lot of complaining from Perl of course)