in reply to how to jump to some specific line in my code ?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to jump to some specific line in my code ?
by ankit.tayal560 (Beadle) on Sep 27, 2016 at 08:16 UTC |