HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ifelse + perl
Operating System - HP-UX
1834080
Members
2405
Online
110063
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2007 06:34 PM
04-24-2007 06:34 PM
ifelse + perl
Hi,
I am having a script where too many if else are using can any one advice how to use switch statement.
Script is like this
if (($var1 eq $var2)) && ($op1 < $op2)) {
print "HI";
}
elsif (($var1 < $var2)) && ($op1 > $op2)) {
print "OK";
}
elsif... and so on
I am having a script where too many if else are using can any one advice how to use switch statement.
Script is like this
if (($var1 eq $var2)) && ($op1 < $op2)) {
print "HI";
}
elsif (($var1 < $var2)) && ($op1 > $op2)) {
print "OK";
}
elsif... and so on
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2007 07:01 PM
04-24-2007 07:01 PM
Re: ifelse + perl
google, ask him "perl switch statement"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2007 08:42 PM
04-24-2007 08:42 PM
Re: ifelse + perl
There is no real need in Perl for a switch statement, though many people accustomed to it from C etc. seem to miss this.
There are many ways to implement a switch with common Perl idioms.
Please, run "perldoc -q switch"
or see the "Basic BLOCKs and Switch Statements" section of "perldoc perlsyn".
Also may be found here:
http://perldoc.perl.org/perlsyn.html#Basic-BLOCKs-and-Switch-Statements
There are many ways to implement a switch with common Perl idioms.
Please, run "perldoc -q switch"
or see the "Basic BLOCKs and Switch Statements" section of "perldoc perlsyn".
Also may be found here:
http://perldoc.perl.org/perlsyn.html#Basic-BLOCKs-and-Switch-Statements
Madness, thy name is system administration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2007 10:30 PM
04-24-2007 10:30 PM
Re: ifelse + perl
Drat, I'm sure I replied earlier.
perl up to and including 5.8.x does not have a switch statement, even though many people (think they) need it.
There is a switch statement in the upcoming 5.10 release, which also supports smart matching, but as long as that release is not yet available, it won't help you.
On CPAN, there is a Switch module, but I strongly advice NOT using it, as it is based on source filtering, and wil;l defenitely bring more trouble than good in the longer scripts.
You can make a dispatch table if that suits your needs, something like:
my %dt = (
"-1:-1" => sub {
print "var1 < var2 and op1 < op2\n";
},
:
:
"1:0" => sub {
print "var1 > var 2 & op1 = op2\n";
},
"1:1" => sub {
die "var2 > var1 & op2 > op1: should not happen\n";
},
);
$dt{($var1 <=> $var2).":".($op1 <=> $op2)}->();
Enjoy, Have FUN! H.Merijn
perl up to and including 5.8.x does not have a switch statement, even though many people (think they) need it.
There is a switch statement in the upcoming 5.10 release, which also supports smart matching, but as long as that release is not yet available, it won't help you.
On CPAN, there is a Switch module, but I strongly advice NOT using it, as it is based on source filtering, and wil;l defenitely bring more trouble than good in the longer scripts.
You can make a dispatch table if that suits your needs, something like:
my %dt = (
"-1:-1" => sub {
print "var1 < var2 and op1 < op2\n";
},
:
:
"1:0" => sub {
print "var1 > var 2 & op1 = op2\n";
},
"1:1" => sub {
die "var2 > var1 & op2 > op1: should not happen\n";
},
);
$dt{($var1 <=> $var2).":".($op1 <=> $op2)}->();
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP