Loading ...
Sorry, an error occurred while loading the content.

Referencing a sub routine

Expand Messages
  • Daniel J. Rychlik
    Hello, Im having a bit of trouble figuring out how to reference a subroutine in perl. I have a check_input subroutine that runs a bit of data checking for
    Message 1 of 3 , May 2, 2003
    • 0 Attachment
      Hello,

      Im having a bit of trouble figuring out how to reference a subroutine in perl.

      I have a check_input subroutine that runs a bit of data checking for fields entered in by a user. My problem is, I have multiple subroutines and I only need to check the field names that correspond to its subroutine. In java, we used a get_current_sub function that would check to see what subroutine the program was currently in.

      pusedo code

      if ((getcurrentsubroutine) == the subroutine that i need to check) {

      if ($uname eq '' or $uname =~ /^\s+$/) {
      print_error('User id is missing');
      } # End If

      }# End IF

      elsif ((getcurrentsubroutine) == the subroutine that i need to check) {

      if (check our input for required fields){...} # end if

      } # end ELSIF


      I hope that this is understandable. I appreciate any advice or solution...

      Kind Regards,
      Daniel






      [Non-text portions of this message have been removed]
    • Charles K. Clarkson
      Daniel, It sounds like you need the caller function. It s in perlfunc . Here s a sub that returns the name of the calling subroutine: sub
      Message 2 of 3 , May 2, 2003
      • 0 Attachment
        Daniel,

        It sounds like you need the 'caller' function. It's
        in 'perlfunc'. Here's a sub that returns the name of the
        calling subroutine:

        sub get_current_sub_name {
        my $name = ( caller(1) )[3];
        return unless $name && $name =~ /::([^:]+)$/;
        return $1;
        }

        HTH,

        Charles K. Clarkson
        --
        Head Bottle Washer,
        Clarkson Energy Homes, Inc.
        Mobile Home Specialists
        254 968-8328
      • Hans Ginzel
        ... The conditions could be merged into one: $uname =~ /^ s*$/ Hans
        Message 3 of 3 , May 3, 2003
        • 0 Attachment
          On Fri, May 02, 2003 at 03:02:36PM -0500, Daniel J. Rychlik wrote:
          > if ($uname eq '' or $uname =~ /^\s+$/) {

          The conditions could be merged into one:

          $uname =~ /^\s*$/

          Hans
        Your message has been successfully submitted and would be delivered to recipients shortly.