Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Perl : Convert a monolithic code to a function

by 1s44c (Scribe)
on Jun 28, 2014 at 23:26 UTC ( [id://1091589]=note: print w/replies, xml ) Need Help??


in reply to Perl : Convert a monolithic code to a function

sub mysub { my ( $var1, $var2 ) = @_; rest of your process } Call with: mysub($var1, $var2);

It's all in the learning perl book, it's probably easiest to start there.

EDIT: No ampersand before the subroutine's name!

Replies are listed 'Best First'.
Re^2: Perl : Convert a monolithic code to a function
by user786 (Sexton) on Jun 29, 2014 at 00:58 UTC
    This is what i tried ,when i compile the code it doesn't throw an error.But it is not working, Am i missing something here?
    sub mysub { my ($var1) = @_; $ssh->exec("cmd1"); $ssh->exec("cmd2"); open my $prep, '<', $var1; while (my $config = <$prep>) { chomp $config; my $conf = $ssh->exec("$config"); print("$conf"); } mysub("config.txt");
Re^2: Perl : Convert a monolithic code to a function
by user786 (Sexton) on Jun 28, 2014 at 23:47 UTC

    Thanks for the reply. Pardon my ignorance. 1)Does $var1, $var 2 refer to the config file ? 2)And why & before mysub &mysub($var1, $var2);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1091589]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-29 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found