You're going to be told repeatedly that "In perl, there's more than one way to do it.". And, there is more than one way to do what you want.
Are you using strict and warnings in your example? The first thing that jumps out at me is that you may have a problem with scoping. If you have a
my $Folder;
my $Readme;
Before your switch statement, the results may be somewhat different to what you are seeing. (by the way, just what is it doing?)
You may also want to consider using a hash, if you don't have too many options:
my %folder_options=('170'=>'winvista',
'173'=>'winvista64',
'119'=>'winvxp',
'210'=>'winxp64',
'541'=>'windows*7 graphics',
'525'=>'winvista64');
my $Folder=$folder_options{$operatingsystem};
Another option is to use something like this:
my $Folder;
my $Readme;
SWITCH:
{
($operatingsystem eq '170') and do {
$Folder='winvista';
$Readme='readme_winvista.txt';
last SWITCH;
}
($operatingsystem eq '173') and do {
$Folder='winvista64';
$Readme='readme_winvista64.txt';
last SWITCH;
}
}
etc. etc.
Or, as already mentioned, use Switch.
use Switch;
my $Folder;
my $Readme;
switch ($operatingsystem) {
case '170' { $Folder='winvista';
$Readme='readme_winvista.txt';
}
case '173' { $Folder='winvista64';
$Readme='readme_winvista64.txt';
}
}
etc. etc.
As a final note, if you're using 5.10, there's always the builtin given/when.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.