in reply to Is it there, or is it not?? Quirkiness with error handling.

Why did you nest the subroutine definition? That's very odd to read and will break if you add lexicals. Also, please do not call subroutines using an ampersand. Write err3() rather than &err3(). Anyway..

If I understand your problem description correctly, you want err3() to only be called when none of your lines match? The way you have it, it will be called once for every time a line does not match. Is that what you want it to do? If not, the following would work:
my $had_match = 0; #see? now the sub nesting breaks the code.. while (<TECH>) { if ( /$cnip/ ) { $had_match++; (@npa) = split (/\:/); print "\n", " " x 14, "*" x 60; print "\n", " " x 24, "=" x 40, "\n"; print " " x 24, "NPANXX Line Switch MSR&CUSTGP VMX +\n"; print " " x 24, "$npa[0] $npa[1] $npa[2] $npa[3] $npa[4] $npa +[5]\n"; print " " x 24, "=" x 40, "\n\n"; con(); } } close(TECH); #Close file err3($cnip) unless $had_match;

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Is it there, or is it not?? Quirkiness with error handling.
by dmmiller2k (Chaplain) on Jul 12, 2002 at 13:07 UTC
    "... please do not call subroutines using an ampersand. Write err3() rather than &err3()."

    FYI: this is a special syntax. Calling a subroutine this way from within a subroutine has the effect of passing the (remaining) arguments to the inner sub that were passed to the outer. To wit:

    # main outer( 1, qw( A Set of Args )); sub outer { my $pass = shift; &inner if $pass; } sub inner { print "inner: ", join( ' ', @_ ), "\n"; }

    will print:

    A Set of Args

    dmm

    If you GIVE a man a fish you feed him for a day
    But,
    TEACH him to fish and you feed him for a lifetime

      Note that you are confusing &mysub; and &mysub(); which are very different. (tye)Re: A question of style goes into these in some detail.

      As for avoiding & on subroutine calls, that is, to a great extent, a style issue. Frankly, several of the reasons for using & on subroutine calls (avoid collisions with built-ins, stylistically distinguish user subs from built-ins, uniformity of sigils with other common user-defined items) are much more compelling to me than any of the reasons for not using them: "looks like Perl4" (big deal), "overrides prototypes" (don't use prototypes in most cases).

      So I strongly disagree with Aristotle on that point.

              - tye (but my friends call me "Tye")

        Whoops! That was a typo! Instead of removing the () from &mysub(), I did just the opposite and removed the &.

        In real code, the compiler usually catches stuff like this ... :)

        dmm

Re: Re: Is it there, or is it not?? Quirkiness with error handling.
by defyance (Curate) on Jul 11, 2002 at 23:48 UTC
    That did the trick!

    I got into a bad habit of using ampersands for every call to a sub when I first started learning Perl. I realize that its not always a good idea, especially in a case like this.

    I nested that for lack of knowing better, put simply. Thanks for the advice, sorry about the confusion in my writeup.

    And no, I didn't not want it to call everytime a line did not match. I was writing this in a hurry, and intern proved that patience pays off, cause had I been patient, I would not have had this problem!!

    /me loves learning new stuff everyday, just wish I could spend more time learning more Perl!

    --~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--~~--

    perl -e '$a="3567"; $b=hex($a); printf("%2X\n",$a);'

      Something I just thought of.. these oodles of "some string" x $repetition look rather ugly. Maybe you would profit from learning about Perl's format support? It lets you write report generation routines in a visually oriented way.

      Makeshifts last the longest.