Re: case statement in perl
Thanks for everybody assistance, found a an appropiate solution to my problem. Without having to use the case statement. Cheers Paul From: Hal Wigoda To: beginners@perl.org Sent: Thursday, 2 August 2012 5:38 AM Subject: Re: case statement in perl so why don't they get rid of it? On Wed, Aug 1, 2012 at 2:33 PM, Chris Nehren wrote: > On Wed, Aug 01, 2012 at 12:02:04 -0400 , Uri Guttman wrote: >> On 08/01/2012 03:08 AM, Paul.G wrote: >> >The example below is just a test, I need to be able to insert >> >multiple values a command, those values can be either 1, 2 or >> >upto 5. >> > >> > >> you aren't getting the issue. the switch module was a major mistake >> and no one should be using it. you have to understand the downside to >> source filtering. no module can properly filter perl code as it is >> too subtle and complex to do so automatically. so source filters can >> seem to work now and if you do some changes to your code (not even >> near the switch stuff), it could break and you will have a hell of a >> time fixing it. the downside of that nasty hard to find bug is never >> worth it even if switch.pm appeals to you. modern perl's have a >> builtin given/when statement, you can use dispatch tables (especially >> for a fixed list of numbers or tokens) and other methods too. just >> avoid using the switch module. there is no way you can defend its use >> given the extremely nasty possible bugs it can introduce. > > +1 > > Though given/when is too smart for its own good, I agree with everything > here. When uri and I agree on something, it's a strong indicator to pay > attention. > > -- > Chris Nehren | Coder, Sysadmin, Masochist > Shadowcat Systems Ltd. | http://shadowcat.co.uk/ -- - Chicago Hal Wigoda -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: case statement in perl
I have removed the switch funtion from the script. From: Uri Guttman To: beginners@perl.org Sent: Thursday, 2 August 2012 2:02 AM Subject: Re: case statement in perl On 08/01/2012 03:08 AM, Paul.G wrote: > The example below is just a test, I need to be able to insert multiple values > into a command, those values can be either 1, 2 or upto 5. > > you aren't getting the issue. the switch module was a major mistake and no one should be using it. you have to understand the downside to source filtering. no module can properly filter perl code as it is too subtle and complex to do so automatically. so source filters can seem to work now and if you do some changes to your code (not even near the switch stuff), it could break and you will have a hell of a time fixing it. the downside of that nasty hard to find bug is never worth it even if switch.pm appeals to you. modern perl's have a builtin given/when statement, you can use dispatch tables (especially for a fixed list of numbers or tokens) and other methods too. just avoid using the switch module. there is no way you can defend its use given the extremely nasty possible bugs it can introduce. uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: case statement in perl
On Wed, Aug 01, 2012 at 14:38:42 -0500 , Hal Wigoda wrote: > so why don't they get rid of it? I'm not sure which "it" you're referring to: Switch.pm or given/when. For better or worse, Perl has a strong culture of backwards compatibility. Perl is one of the few languages where you can use code written 10-20 years ago on a new version with few difficulties. As for given/when, there are some threads on the perl5-porters mailing list (where perl development is discussed) about changing given/when to something that is less ambiguous and less "clever". As for Switch.pm, it has been removed from perl core. -- Chris Nehren | Coder, Sysadmin, Masochist Shadowcat Systems Ltd. | http://shadowcat.co.uk/ pgprSLgwr7Uhb.pgp Description: PGP signature
Re: case statement in perl
so why don't they get rid of it? On Wed, Aug 1, 2012 at 2:33 PM, Chris Nehren wrote: > On Wed, Aug 01, 2012 at 12:02:04 -0400 , Uri Guttman wrote: >> On 08/01/2012 03:08 AM, Paul.G wrote: >> >The example below is just a test, I need to be able to insert >> >multiple values a command, those values can be either 1, 2 or >> >upto 5. >> > >> > >> you aren't getting the issue. the switch module was a major mistake >> and no one should be using it. you have to understand the downside to >> source filtering. no module can properly filter perl code as it is >> too subtle and complex to do so automatically. so source filters can >> seem to work now and if you do some changes to your code (not even >> near the switch stuff), it could break and you will have a hell of a >> time fixing it. the downside of that nasty hard to find bug is never >> worth it even if switch.pm appeals to you. modern perl's have a >> builtin given/when statement, you can use dispatch tables (especially >> for a fixed list of numbers or tokens) and other methods too. just >> avoid using the switch module. there is no way you can defend its use >> given the extremely nasty possible bugs it can introduce. > > +1 > > Though given/when is too smart for its own good, I agree with everything > here. When uri and I agree on something, it's a strong indicator to pay > attention. > > -- > Chris Nehren | Coder, Sysadmin, Masochist > Shadowcat Systems Ltd. | http://shadowcat.co.uk/ -- - Chicago Hal Wigoda -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: case statement in perl
On Wed, Aug 01, 2012 at 12:02:04 -0400 , Uri Guttman wrote: > On 08/01/2012 03:08 AM, Paul.G wrote: > >The example below is just a test, I need to be able to insert > >multiple values into a command, those values can be either 1, 2 or > >upto 5. > > > > > you aren't getting the issue. the switch module was a major mistake > and no one should be using it. you have to understand the downside to > source filtering. no module can properly filter perl code as it is > too subtle and complex to do so automatically. so source filters can > seem to work now and if you do some changes to your code (not even > near the switch stuff), it could break and you will have a hell of a > time fixing it. the downside of that nasty hard to find bug is never > worth it even if switch.pm appeals to you. modern perl's have a > builtin given/when statement, you can use dispatch tables (especially > for a fixed list of numbers or tokens) and other methods too. just > avoid using the switch module. there is no way you can defend its use > given the extremely nasty possible bugs it can introduce. +1 Though given/when is too smart for its own good, I agree with everything here. When uri and I agree on something, it's a strong indicator to pay attention. -- Chris Nehren | Coder, Sysadmin, Masochist Shadowcat Systems Ltd. | http://shadowcat.co.uk/ pgpWgsnYFeliD.pgp Description: PGP signature
Re: case statement in perl
On 08/01/2012 03:08 AM, Paul.G wrote: The example below is just a test, I need to be able to insert multiple values into a command, those values can be either 1, 2 or upto 5. you aren't getting the issue. the switch module was a major mistake and no one should be using it. you have to understand the downside to source filtering. no module can properly filter perl code as it is too subtle and complex to do so automatically. so source filters can seem to work now and if you do some changes to your code (not even near the switch stuff), it could break and you will have a hell of a time fixing it. the downside of that nasty hard to find bug is never worth it even if switch.pm appeals to you. modern perl's have a builtin given/when statement, you can use dispatch tables (especially for a fixed list of numbers or tokens) and other methods too. just avoid using the switch module. there is no way you can defend its use given the extremely nasty possible bugs it can introduce. uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: case statement in perl
Paul.G wrote: The example below is just a test, I need to be able to insert multiple values into a command, those values can be either 1, 2 or upto 5. Below is closer to the working example, but I will read that document and to help make a final decision. # Check Free PV's operation_CHECKFREEPVS(); $NEWMIRROR = $MIRROR + $numPV; if ($numPV ne 0&& $MIRROR le 5) { You are using string comparisons on numerical values which may not work out the way you intended: $ perl -le' for my $MIRROR ( 0, 1, 4, 5, 6, 10, 4000 ) { print "$MIRROR le 5 is ", $MIRROR le 5 ? "TRUE" : "FALSE"; } ' 0 le 5 is TRUE 1 le 5 is TRUE 4 le 5 is TRUE 5 le 5 is TRUE 6 le 5 is FALSE 10 le 5 is TRUE 4000 le 5 is TRUE # lvextend print "$numPV $NEWMIRROR $MIRROR\n"; switch ($numPV) { case 1 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0]"); } case 2 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] $FreePV[1]"); } case 3 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] $FreePV[1] $FreePV[2]"); } case 4 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] $FreePV[1] $FreePV[2] $FreePV[3]"); } case 5 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] $FreePV[1] $FreePV[2] $FreePV[3] $FreePV[4]"); } You could do that like this: if ( @FreePV && @FreePV <= 5 ) { run( "/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv @FreePV" ); } } # lvsync run("/usr/sbin/lvsync -T $sourcelv"); logprint "Successful $NEWMIRROR mirrors \t\t synced"; } else { cleanexit (10, "FAIL \t\t No Free PV's Available"); } return 0; } John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: case statement in perl
On Wed, Aug 1, 2012 at 9:08 AM, Paul.G wrote: > The example below is just a test, I need to be able to insert multiple > values into a command, those values can be either 1, 2 or upto 5. > > Below is closer to the working example, but I will read that document and > to help make a final decision. > > # Check Free PV's > operation_CHECKFREEPVS(); > > $NEWMIRROR = $MIRROR + $numPV; > > if ($numPV ne 0 && $MIRROR le 5) { ># lvextend > print "$numPV $NEWMIRROR $MIRROR\n"; > switch ($numPV) { > case 1 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv > $FreePV[0]"); } > case 2 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv > $FreePV[0] $FreePV[1]"); } > case 3 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv > $FreePV[0] $FreePV[1] $FreePV[2]"); } > case 4 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv > $FreePV[0] $FreePV[1] $FreePV[2] $FreePV[3]"); } > case 5 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv > $FreePV[0] $FreePV[1] $FreePV[2] $FreePV[3] $FreePV[4]"); > } >} ># lvsync >run("/usr/sbin/lvsync -T $sourcelv"); >logprint "Successful $NEWMIRROR mirrors \t\t synced"; > } > else { >cleanexit (10, "FAIL \t\t No Free PV's Available"); > } > > return 0; > } > > > > ____ > From: John W. Krahn > To: Perl Beginners > Sent: Wednesday, 1 August 2012 4:58 PM > Subject: Re: case statement in perl > > Paul.G wrote: > > Below is an extract from the perl script, the switch/case statement > seemed like a simple solution. > > > > > > > > # Mail Program # > > > > operation_CHECKFREEPVS(); > > print "$numPV \n"; > > # print "$FreePV[1] $FreePV[0] $numPV\n"; > > if ($numPV ne 0 ) { > > switch ($numPV) { > >case 1 { print "$FreePV[0] \n"; } > >case 2 { print "$FreePV[0] $FreePV[1] \n"; } > >case 3 { print "$FreePV[0] $FreePV[1] $FreePV[2] \n"; } > > } > > } > > Couldn't you just do that like this: > > if ( @FreePV && @FreePV <= 3 ) { > print join( ' ', @FreePV ), "\n"; > } > > > > else { > > print "No PV's available \n"; > > } > > > > John > -- > Any intelligent fool can make things bigger and > more complex... It takes a touch of genius - > and a lot of courage to move in the opposite > direction. -- Albert Einstein > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > Why make life so hard as John suggested you check for the number of arguments and as long as it is less then 5 you simply join them with a space and you are done with a single line... No matter what you do you will always have to check the variables that you are going to push out, right now I could very well feed a parameter that ends in a ; and then do something like *rm -rf /* which could make a serious mess of your system... Personally I would suggest checking the command flags if they are valid, and do not contain any funny characters before even considdering putting this in a system call or equivalent. Regards, Rob
Re: case statement in perl
The example below is just a test, I need to be able to insert multiple values into a command, those values can be either 1, 2 or upto 5. Below is closer to the working example, but I will read that document and to help make a final decision. # Check Free PV's operation_CHECKFREEPVS(); $NEWMIRROR = $MIRROR + $numPV; if ($numPV ne 0 && $MIRROR le 5) { # lvextend print "$numPV $NEWMIRROR $MIRROR\n"; switch ($numPV) { case 1 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0]"); } case 2 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] $FreePV[1]"); } case 3 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] $FreePV[1] $FreePV[2]"); } case 4 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] $FreePV[1] $FreePV[2] $FreePV[3]"); } case 5 { run("/usr/sbin/lvextend -m $NEWMIRROR -s $sourcelv $FreePV[0] $FreePV[1] $FreePV[2] $FreePV[3] $FreePV[4]"); } } # lvsync run("/usr/sbin/lvsync -T $sourcelv"); logprint "Successful $NEWMIRROR mirrors \t\t synced"; } else { cleanexit (10, "FAIL \t\t No Free PV's Available"); } return 0; } ____ From: John W. Krahn To: Perl Beginners Sent: Wednesday, 1 August 2012 4:58 PM Subject: Re: case statement in perl Paul.G wrote: > Below is an extract from the perl script, the switch/case statement seemed > like a simple solution. > > > > # Mail Program # > > operation_CHECKFREEPVS(); > print "$numPV \n"; > # print "$FreePV[1] $FreePV[0] $numPV\n"; > if ($numPV ne 0 ) { > switch ($numPV) { > case 1 { print "$FreePV[0] \n"; } > case 2 { print "$FreePV[0] $FreePV[1] \n"; } > case 3 { print "$FreePV[0] $FreePV[1] $FreePV[2] \n"; } > } > } Couldn't you just do that like this: if ( @FreePV && @FreePV <= 3 ) { print join( ' ', @FreePV ), "\n"; } > else { > print "No PV's available \n"; > } John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: case statement in perl
Paul.G wrote: Below is an extract from the perl script, the switch/case statement seemed like a simple solution. # Mail Program # operation_CHECKFREEPVS(); print "$numPV \n"; # print "$FreePV[1] $FreePV[0] $numPV\n"; if ($numPV ne 0 ) { switch ($numPV) { case 1 { print "$FreePV[0] \n"; } case 2 { print "$FreePV[0] $FreePV[1] \n"; } case 3 { print "$FreePV[0] $FreePV[1] $FreePV[2] \n"; } } } Couldn't you just do that like this: if ( @FreePV && @FreePV <= 3 ) { print join( ' ', @FreePV ), "\n"; } else { print "No PV's available \n"; } John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: case statement in perl
Hi, On Wed, Aug 1, 2012 at 6:18 AM, Paul.G wrote: > Below is an extract from the perl script, the switch/case statement seemed > like a simple solution. > > from perldoc -q switch <== reads and I quote "...Starting from Perl 5.8, a source filter module, Switch, can also be used to get switch and case. Its use is now discouraged, because it's not fully compatible with the native switch of Perl 5.10, and because, as it's implemented as a source filter, it doesn't always work as intended when complex syntax is involved..." Seriously, I think you should do **perldoc -q switch** and read the documentation. It just a few lines. > # Mail Program # > > operation_CHECKFREEPVS(); > print "$numPV \n"; > # print "$FreePV[1] $FreePV[0] $numPV\n"; > if ($numPV ne 0 ) { > I don't know your data, but with the expression above, are you sure you wouldn't get an error message. Is that not suppose to be if( $numPV != 0 ). Just saying... switch ($numPV) { > case 1 { print "$FreePV[0] \n"; } > case 2 { print "$FreePV[0] $FreePV[1] \n"; } > case 3 { print "$FreePV[0] $FreePV[1] $FreePV[2] \n"; } >} > } > else { >print "No PV's available \n"; > } > > > > From: Chris Nehren > To: beginners@perl.org > Sent: Wednesday, 1 August 2012 2:54 PM > Subject: Re: case statement in perl > > On Tue, Jul 31, 2012 at 23:47:45 -0500 , Hal Wigoda wrote: > > Use the switch/case combination. > > > > On Tue, Jul 31, 2012 at 11:41 PM, Paul.G wrote: > > > Hi All > > > > > > > > > Does perl have a case statement or an equivalent? > > > > > > > > > Cheers > > > > > > Paul > > Don't use Switch.pm. It's a source filter and causes indeterministic > code evalution. See perldoc -q switch on a recent perl (5.12 or so or > above). Consider a dispatch table. > > -- > Chris Nehren | Coder, Sysadmin, Masochist > Shadowcat Systems Ltd. | http://shadowcat.co.uk/ > -- Tim
Re: case statement in perl
Below is an extract from the perl script, the switch/case statement seemed like a simple solution. # Mail Program # operation_CHECKFREEPVS(); print "$numPV \n"; # print "$FreePV[1] $FreePV[0] $numPV\n"; if ($numPV ne 0 ) { switch ($numPV) { case 1 { print "$FreePV[0] \n"; } case 2 { print "$FreePV[0] $FreePV[1] \n"; } case 3 { print "$FreePV[0] $FreePV[1] $FreePV[2] \n"; } } } else { print "No PV's available \n"; } From: Chris Nehren To: beginners@perl.org Sent: Wednesday, 1 August 2012 2:54 PM Subject: Re: case statement in perl On Tue, Jul 31, 2012 at 23:47:45 -0500 , Hal Wigoda wrote: > Use the switch/case combination. > > On Tue, Jul 31, 2012 at 11:41 PM, Paul.G wrote: > > Hi All > > > > > > Does perl have a case statement or an equivalent? > > > > > > Cheers > > > > Paul Don't use Switch.pm. It's a source filter and causes indeterministic code evalution. See perldoc -q switch on a recent perl (5.12 or so or above). Consider a dispatch table. -- Chris Nehren | Coder, Sysadmin, Masochist Shadowcat Systems Ltd. | http://shadowcat.co.uk/
Re: case statement in perl
On Tue, Jul 31, 2012 at 23:47:45 -0500 , Hal Wigoda wrote: > Use the switch/case combination. > > On Tue, Jul 31, 2012 at 11:41 PM, Paul.G wrote: > > Hi All > > > > > > Does perl have a case statement or an equivalent? > > > > > > Cheers > > > > Paul Don't use Switch.pm. It's a source filter and causes indeterministic code evalution. See perldoc -q switch on a recent perl (5.12 or so or above). Consider a dispatch table. -- Chris Nehren | Coder, Sysadmin, Masochist Shadowcat Systems Ltd. | http://shadowcat.co.uk/ pgpzHvtoASnYU.pgp Description: PGP signature
Re: case statement in perl
Use the switch/case combination. On Tue, Jul 31, 2012 at 11:41 PM, Paul.G wrote: > Hi All > > > Does perl have a case statement or an equivalent? > > > Cheers > > Paul -- - Chicago Hal Wigoda -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
case statement in perl
Hi All Does perl have a case statement or an equivalent? Cheers Paul
Re: Case Statement
Pablo Fischer wrote at Sat, 26 Jul 2003 23:35:14 +: > I need to evaluate a lot of conditionals, and of course the use of a lot of > if's its not the 'right' way, so Im using something like this: > > CASE: { > ($string == "match1") && do { > actions.. > last CASE; > }; > ($string == "match2") && do { > actions.. > last CASE; > }; > and a lot more.. > } > > The question, where does the 'default' case starts?. The last 5 years I have > been programming in C/C++/C#/Php.. C-styles languages, so in Perl, where does > the 'default' case begins? You might also have a look to the Switch module (from CPAN). It makes it easier to work with good old known switch (...) { case X {...} case Y {...} case Z {...} } style. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Case Statement
Pablo Fischer wrote: > > Hello Again! Hello, > I need to evaluate a lot of conditionals, and of course the use of a lot of > if's its not the 'right' way, so Im using something like this: > > CASE: { > ($string == "match1") && do { ^^^ > actions.. > last CASE; > }; > ($string == "match2") && do { ^^^ You can't use the "==" operator to compare strings, you have to use the "eq" operator instead. > actions.. > last CASE; > }; > and a lot more.. > } > > The question, where does the 'default' case starts?. The last 5 years I have > been programming in C/C++/C#/Php.. C-styles languages, so in Perl, where does > the 'default' case begins? Have you read the FAQ entry on this? perldoc -q "How do I create a switch or case statement" Or read the "Basic BLOCKs and Switch Statements" section of perlsyn.pod? perldoc perlsyn Or had a look at the Switch module? http://search.cpan.org/author/DCONWAY/Switch-2.09/Switch.pm John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Case Statement
- Original Message - From: "Pablo Fischer" <[EMAIL PROTECTED]> To: "Perl Beginners" <[EMAIL PROTECTED]> Sent: Saturday, July 26, 2003 1:35 PM Subject: Case Statement > Hello Again! > > I need to evaluate a lot of conditionals, and of course the use of a lot of > if's its not the 'right' way, so Im using something like this: > > CASE: { > ($string == "match1") && do { > actions.. > last CASE; > }; > ($string == "match2") && do { > actions.. > last CASE; > }; > and a lot more.. > } > > The question, where does the 'default' case starts?. The last 5 years I have > been programming in C/C++/C#/Php.. C-styles languages, so in Perl, where does > the 'default' case begins? > > Thanks > Pablo > -- Pabalo - The 'default' sarts after your last 'do', where you have 'and a lot more...' above. Also, you should use 'eq' NOT '==' for alphanumeric compares: ($string eq 'whatever') && do { ... }; You may want to put your test staing in $_ and use regexs: $_ = $string; CASE: { /match 1/ && do { ... }: ... } Aloha => Beau; == please visit == <http://beaucox.com> => main site <http://howtos.beaucox.com> => howtos <http://PPM.beaucox.com> => perl PPMs <http://CPAN.beaucox.com> => CPAN == thank you == -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Case Statement
Hello Again! I need to evaluate a lot of conditionals, and of course the use of a lot of if's its not the 'right' way, so Im using something like this: CASE: { ($string == "match1") && do { actions.. last CASE; }; ($string == "match2") && do { actions.. last CASE; }; and a lot more.. } The question, where does the 'default' case starts?. The last 5 years I have been programming in C/C++/C#/Php.. C-styles languages, so in Perl, where does the 'default' case begins? Thanks Pablo -- Pablo Fischer Sandoval ([EMAIL PROTECTED]) http://www.pablo.com.mx http://www.debianmexico.org GPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C Firma URL: http://www.pablo.com.mx/firmagpg.txt -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: k-shell case statement
On Mon, 20 Aug 2001 [EMAIL PROTECTED] wrote: > What is the best perl example of a k-shell case statement as follows: > > case "$VAR1" > in > 1 ) > statements > ;; > 2) > statements > ;; > * ) > other statements > esac Perl does not have a built in case statement (also known as a switch statement in the C/C++/Java world). You can simulate it in Perl in a variety of ways which have been documented very well elsewhere. Here's the first place you should start, by typing this at your command-line: perldoc -q switch You'll probably also want to check out the perlsyn document (type perldoc perlsyn) if you aren't familiar with Perl syntax. And if you aren't familiar with Perl syntax, you should get one of the books listed on http://learn.perl.org and start studying it -- Brett http://www.chapelperilous.net/btfwk/ You will be run over by a bus. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: k-shell case statement
Hello Robert, Tuesday, August 21, 2001, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: Ric> What is the best perl example of a k-shell case statement as follows: Ric> case "$VAR1" Ric> in take a look at "Basic BLOCKs and Switch Statements" in perldoc perlsyn Best wishes, Maximmailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: k-shell case statement
perldoc -q switch -Original Message- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: 8/20/2001 4:25 PM Subject: k-shell case statement What is the best perl example of a k-shell case statement as follows: case "$VAR1" in 1 ) statements ;; 2) statements ;; * ) other statements esac -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
k-shell case statement
What is the best perl example of a k-shell case statement as follows: case "$VAR1" in 1 ) statements ;; 2) statements ;; * ) other statements esac
Re: Perl-case statement, and module syntax error
Damian Conway has written a module that simulates a switch for Perl. http://search.cpan.org/doc/DCONWAY/Switch-2.03/Switch.pm";> SYNOPSIS use Switch; switch ($val) { case 1 { print "number 1" } case "a"{ print "string a" } case [1..10,42] { print "number in list" } case (@array) { print "number in list" } case /\w+/ { print "pattern" } case qr/\w+/{ print "pattern" } case (%hash){ print "entry in hash" } case (\%hash) { print "entry in hash" } case (\&sub){ print "arg to subroutine" } else{ print "previous case not true" } } On 10 Jul 2001 11:01:57 -0400, Jason Purdy wrote: > Just got the answer to #1 for you: check out 'switch' - documented in the > 'perlsyn' perldoc. There is no 'case' or 'switch' function, but you can > emulate it with a block & exit routine, as documented. > > Jason > > - Original Message - > From: "Sparkle Williams" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Tuesday, July 10, 2001 9:43 AM > Subject: Perl-case statement, and module syntax error > > > > I'm having two problems > > 1) Is there an equivalent of the case function in Perl? > > > > 2)I'm also getting a syntax error for the following part of my program > that > > I'm attempting to run on my Unix system. I get a syntax error message for > > 'new($url, ', 'login($username, 'cwd($ftp_home), ', and 'get($filename '. > I > > don't understand why and I don't know how to fix it...help! > > > > $ftp = Net::FTP->new($url, Debug=>0); > > > > $ftp->login($username, $password); > > > > echo $ftp->cwd($ftp_home), "\n"; > > > > $ftp->get($filename); > > > > $ftp->quit; > > > > _ > > Get your FREE download of MSN Explorer at http://explorer.msn.com > > > > -- Today is Sweetmorn, the 45th day of Confusion in the YOLD 3167 Or is it?
Re: Perl-case statement, and module syntax error
--- Michael Fowler <[EMAIL PROTECTED]> wrote: > On Tue, Jul 10, 2001 at 09:43:26AM -0400, Sparkle Williams wrote: > > I'm having two problems > > 1) Is there an equivalent of the case function in Perl? > > perldoc -q switch, or Check out Damian Conway's Switch module. http://search.cpan.org/doc/DCONWAY/Switch-2.03/Switch.pm (Has anyone mentioned today how hard Damian rocks? >:O) __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Re: Perl-case statement, and module syntax error
On Tue, Jul 10, 2001 at 09:43:26AM -0400, Sparkle Williams wrote: > I'm having two problems > 1) Is there an equivalent of the case function in Perl? perldoc -q switch, or http://www.perldoc.com/perl5.6/pod/perlfaq7.html#How%20do%20I%20create%20a%20switch%20or%20case%20statement%3f > $ftp = Net::FTP->new($url, Debug=>0); > > $ftp->login($username, $password); > > echo $ftp->cwd($ftp_home), "\n"; echo is not a valid Perl operator. You probably want print. > $ftp->get($filename); > > $ftp->quit; Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
Re: Perl-case statement, and module syntax error
Just got the answer to #1 for you: check out 'switch' - documented in the 'perlsyn' perldoc. There is no 'case' or 'switch' function, but you can emulate it with a block & exit routine, as documented. Jason - Original Message - From: "Sparkle Williams" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, July 10, 2001 9:43 AM Subject: Perl-case statement, and module syntax error > I'm having two problems > 1) Is there an equivalent of the case function in Perl? > > 2)I'm also getting a syntax error for the following part of my program that > I'm attempting to run on my Unix system. I get a syntax error message for > 'new($url, ', 'login($username, 'cwd($ftp_home), ', and 'get($filename '. I > don't understand why and I don't know how to fix it...help! > > $ftp = Net::FTP->new($url, Debug=>0); > > $ftp->login($username, $password); > > echo $ftp->cwd($ftp_home), "\n"; > > $ftp->get($filename); > > $ftp->quit; > > _ > Get your FREE download of MSN Explorer at http://explorer.msn.com >
Perl-case statement, and module syntax error
I'm having two problems 1) Is there an equivalent of the case function in Perl? 2)I'm also getting a syntax error for the following part of my program that I'm attempting to run on my Unix system. I get a syntax error message for 'new($url, ', 'login($username, 'cwd($ftp_home), ', and 'get($filename '. I don't understand why and I don't know how to fix it...help! $ftp = Net::FTP->new($url, Debug=>0); $ftp->login($username, $password); echo $ftp->cwd($ftp_home), "\n"; $ftp->get($filename); $ftp->quit; _ Get your FREE download of MSN Explorer at http://explorer.msn.com