#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    USA
    Posts
    67
    Rep Power
    15
    Im trying to write a function that takes an array and does stuff with it.

    i have programed in c++ and i would call it like this "doStuff(arrayName)" how would i write the funciton in perl? this also leads me to ask the question of scope in perl.

    sub doStuff{} how would i write this function to pass an array?


  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Posts
    33
    Rep Power
    16
    just a quick and probably dodgy example:

    @array = (1 .. 10);

    &mysub(@array);
    exit;

    sub mysub
    {
    @temp = @_;

    foreach (@temp)
    {
    print "sub got this number $_n";
    }
    }

    ----
    You might want to get the return values of the array so maybe you could have return(@temp), but then you'd want to call it with @somearay = &mysub(@array); Or something like that.

    as for scopes in perl, a good book is learning perl by O'Reilly, it'll explain that and more. Maybe even check the perl homepage.

    My perl is a tad rusty. :-/

    Imo

IMN logo majestic logo threadwatch logo seochat tools logo