in reply to Re^2: calling subroutines
in thread calling subroutines

Pass a parameter through your subroutine:

my $number = rand; some($number); sub some { my $num1 = shift; print "$num1\n"; }

But I don't have any idea how you are supposed to be reconciling that with your existing code that takes user input. Why are you taking user input from STDIN if your goal is to generate values from within the program? And is $num2 really supposed to always be the value 2?

This is homework, right? Even on a student's limited budget, Learning Perl, from OReilly, is a worthwhile purchase. Or if you are lucky you can find it or request it at the library. Also, read perlintro, and perlsyn. You could spend countless hours stumbling around in the dark, or spend two hours reading those two free documents, after which you will be able to complete your assignments with swift confidence.

If the web server is down for those two final links I posted, just type "perldoc perlintro", and "perldoc perlsyn" on any system that has Perl installed. They're already on that system, no network access required.


Dave

Replies are listed 'Best First'.
Re^4: calling subroutines
by bobosm (Initiate) on Oct 12, 2013 at 16:25 UTC
    I know why is not oky, Yes I have read some books and rework perl.

      Yes I have read some books...

      Which Perl books have you read?


      Dave