my $text;
my $opt = substr($text, 12);
...will give undef errors when you use use strict; use warnings;
-- is this what you intend? You seem to be missing some code. You're using three different variable names: $text
, $opt
, and $command
but do you intend these all to be the same value?
Perhaps this is what you intend, but without more information it's hard to tell:
if ($command =~ /^Hello World Application/i)
{
print substr($command, 12);
}
...but that will always just print Hello World
, so you don't really even need to use a substr
.
EDIT: You still haven't edited your question to give a real example, but you seem to want to be able to modify a variable from inside an if
block and then access it outside the if
block. You can do that by simply ensuring that the variable is declared outside the if
block:
my $variable;
if (something...)
{
$variable = "something else";
}
Please read about "variable scope" at perldoc perlsyn.