FAQ
Hello all,
I have two quick questions that I would love some help on. I have looked
at the manual (Programming Perl) and I didn't get it, hence my email.

Question 1 - How can I make variables in a function (subroutine) global
(accessible from other functions)?

Question 2 - I am trying to control the actions of a program through an
email; i.e. change the basic parameters by sending an email to a
specific address. Can anyone suggest what regex would get me xxxxxx and
y(y) if the subject line of the email looks like:

Subject: 123456 9 or Subject: 123456 10

The 10 in the line above can be a 1 or 2 digit number. The 6 digit
number right after the 'Subject:' is an employee number and the 1 or 2
digit number after it is the hours worked.

Thank you for any attention you can give to this.

Cheers,
Eric

Search Discussions

  • Mr. Shawn H. Corey at Dec 22, 2008 at 11:23 pm

    On Mon, 2008-12-22 at 15:18 -0700, Eric Krause wrote:
    Hello all,
    I have two quick questions that I would love some help on. I have looked
    at the manual (Programming Perl) and I didn't get it, hence my email.

    Question 1 - How can I make variables in a function (subroutine) global
    (accessible from other functions)?
    By declaring it with 'our' instead of 'my'. See `perldoc -f our` for
    details.
    Question 2 - I am trying to control the actions of a program through an
    email; i.e. change the basic parameters by sending an email to a
    specific address. Can anyone suggest what regex would get me xxxxxx and
    y(y) if the subject line of the email looks like:

    Subject: 123456 9 or Subject: 123456 10

    The 10 in the line above can be a 1 or 2 digit number. The 6 digit
    number right after the 'Subject:' is an employee number and the 1 or 2
    digit number after it is the hours worked.
    if( my ( $employee_number, $hours_worked ) = $_ =~ m{ \A \s* Subject \s* : \s* (\d+) \s+ (\d+) }msx ){
    # validate $employee_number and $hours_worked

    # do stuff with $employee_number and $hours_worked

    }elsif( $_ =~ m{ \A \s* Subject }msx ){
    warn( "Invalid subject line: $_\n"; );
    }


    --
    Just my 0.00000002 million dollars worth,
    Shawn

    Believe in the Gods but row away from the rocks.
    -- ancient Hindu proverb
  • John W. Krahn at Dec 23, 2008 at 12:19 am

    Eric Krause wrote:
    Hello all, Hello,
    I have two quick questions that I would love some help on. I have looked
    at the manual (Programming Perl) and I didn't get it, hence my email.

    Question 1 - How can I make variables in a function (subroutine) global
    (accessible from other functions)?
    Any variable defined outside of and before the subroutine is accessible
    from inside the subroutine.

    Question 2 - I am trying to control the actions of a program through an
    email; i.e. change the basic parameters by sending an email to a
    specific address. Can anyone suggest what regex would get me xxxxxx and
    y(y) if the subject line of the email looks like:

    Subject: 123456 9 or Subject: 123456 10

    The 10 in the line above can be a 1 or 2 digit number. The 6 digit
    number right after the 'Subject:' is an employee number and the 1 or 2
    digit number after it is the hours worked.
    if ( /^Subject:\s+(\d+)\s+(\d+)/ ) {
    ( $employee, $hours ) = ( $1, $2 );
    }



    John
    --
    Those people who think they know everything are a great
    annoyance to those of us who do. -- Isaac Asimov

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedDec 22, '08 at 10:18p
activeDec 23, '08 at 12:19a
posts3
users3
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase