Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: calling subroutines

by bobosm (Initiate)
on Oct 12, 2013 at 16:06 UTC ( #1057996=note: print w/replies, xml ) Need Help??

in reply to Re: calling subroutines
in thread calling subroutines

Tnx for reply, and how I can generate a random number for variable num1 which is in subroutine?

Replies are listed 'Best First'.
Re^3: calling subroutines
by davido (Archbishop) on Oct 12, 2013 at 16:13 UTC

    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.


      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?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057996]
and the voices are still...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-06-18 07:55 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.