Accessing an object in a sub-routine

Discussion in 'Perl Misc' started by C GIllespie, Jun 10, 2004.

  1. C GIllespie

    C GIllespie Guest

    Dear All,

    I'm not too sure on the exact terminology, so I hope you will bare with me
    :)

    In my small script, I have:

    my $varA = $f->fault;

    How do I pass $f to a subountine, i.e.

    sub sub1(
    $_->fault; #This is wrong!
    )
    sub1($f);

    Declaring $f as global variable is one way, but are there any others?

    Thanks

    Colin
     
    C GIllespie, Jun 10, 2004
    #1
    1. Advertising

  2. C GIllespie

    Ben Morrow Guest

    Quoth "C GIllespie" <>:
    >
    > In my small script, I have:
    >
    > my $varA = $f->fault;
    >
    > How do I pass $f to a subountine, i.e.
    >
    > sub sub1(
    > $_->fault; #This is wrong!


    Sub args come in in @_. Read perldoc perlsub.

    sub sub1 {
    $_[0]->fault;
    }

    > )
    > sub1($f);


    Ben

    --
    Musica Dei donum optimi, trahit homines, trahit deos. |
    Musica truces molit animos, tristesque mentes erigit. |
    Musica vel ipsas arbores et horridas movet feras. |
     
    Ben Morrow, Jun 10, 2004
    #2
    1. Advertising

  3. C GIllespie

    gnari Guest

    "C GIllespie" <> wrote in message
    news:ca96i4$eh9$...

    > my $varA = $f->fault;
    >
    > How do I pass $f to a subountine, i.e.
    >
    > sub sub1(
    > $_->fault; #This is wrong!
    > )
    > sub1($f);


    $_[0]

    gnari
     
    gnari, Jun 10, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D. Shane Fowlkes

    just tinkering with a Sub Routine in ASP.NET

    D. Shane Fowlkes, Nov 12, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    442
    Scott M.
    Nov 13, 2003
  2. Neo
    Replies:
    6
    Views:
    418
    Mark A. Odell
    Dec 2, 2003
  3. Ben
    Replies:
    2
    Views:
    930
  4. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,101
    Lawrence D'Oliveiro
    May 20, 2011
  5. erik
    Replies:
    12
    Views:
    178
    Tad McClellan
    Apr 3, 2005
Loading...

Share This Page