In Perl, and almost all "modern" languages, that is the wrong question. Think instead of writing lumps of code to handle specific small problems. In Perl we call those lumps of code "subroutines" and write them like:

sub printString { my ($str) = @_; print $str; }

and execute the code in the sub by "calling" it:

printString("Hello world\n");

There are many ways to call a specific subroutine according to some information you have. The best choice for whatever you are doing depends on many factors, but (probably) the simplest is to use a chain of if statements:

if ($num == 1) { sub1(); } elsif ($num == 2) { sub2(); } ...

If you need to deal with many cases that gets hard to maintain. With Perl you can instead:

use strict; use warnings; my $num = 1; my $mainObj = bless {}; my $handler = $mainObj->can("sub$num"); die "No handler for $num\n" if !defined $handler; $handler->(); sub sub1 { print "Handling case 1\n"; }

which reduces the maintenance to just adding a handler for each number you want to handle, but is much harder to understand without a fairly good understanding of Perl.

If you tell us more about your problem we can give you example code that is a better fit to your situation.

Premature optimization is the root of all job security

In reply to Re: how to jump to some specific line in my code ? by GrandFather
in thread how to jump to some specific line in my code ? by ankit.tayal560

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.