Re: testing return values
Mike Lesser wrote: Hiya. I'm looking for the correct Perl style for testing and storing a return value in a control statement. The solution in any other language is pretty obvious, but I get the distinct impression that there's a 'right' way in Perl... Let's say I want to test a scalar returned from a subroutine, and also keep a copy for my own use: $scalar = sub( $argument ); if( $scalar ){ } Naturally that's no big deal. Now let's say I have a tree I want to traverse, or some similar open-ended thing to evaluate, and want to run it until a condition is reached.. while( read_tree( $argument ){ } Again no biggie. The problem is if I want to keep the result. Obviously I can't do this: while( $tree_element = read_tree( $argument ) ){ do_something( $tree_element ); } I can come up with a brute-force solution of course, but there's probably a better, Perlish way that I'm not aware of. In addition, I don't expect a return value from some module to be consistently undefined or zero; it could change under some circumstances. This makes me think that the problem has been dealt with long ago, and just doesn't stick out in the llama/alpaca/whatever books. Hopefully I explained this correctly! while (my $x = func()) { : } is perfectly valid. In Perl every operator returns a value, and the assignment operator is no exception. It's value is the expression on the left of the equals sign, and it's even an lvalue so you can do things like ($x = 3)++; leaving $x with a value of four. This sort of thing is more useful for things like $p = $q = 'A'; which is the same as $p = ($q = 'A'); or $q = 'A'; $p = $q; But the bottom line is that your while loop is quite valid. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: testing return values
Now, why can't you do this? while( $tree_element = read_tree( $argument ) ){ do_something( $tree_element ); } I would certainly use it. In C this is called operation overflow or something... On 4/22/07, Mike Lesser <[EMAIL PROTECTED]> wrote: Hiya. I'm looking for the correct Perl style for testing and storing a return value in a control statement. The solution in any other language is pretty obvious, but I get the distinct impression that there's a 'right' way in Perl... Let's say I want to test a scalar returned from a subroutine, and also keep a copy for my own use: $scalar = sub( $argument ); if( $scalar ){ } Naturally that's no big deal. Now let's say I have a tree I want to traverse, or some similar open-ended thing to evaluate, and want to run it until a condition is reached.. while( read_tree( $argument ){ } Again no biggie. The problem is if I want to keep the result. Obviously I can't do this: while( $tree_element = read_tree( $argument ) ){ do_something( $tree_element ); } I can come up with a brute-force solution of course, but there's probably a better, Perlish way that I'm not aware of. In addition, I don't expect a return value from some module to be consistently undefined or zero; it could change under some circumstances. This makes me think that the problem has been dealt with long ago, and just doesn't stick out in the llama/alpaca/whatever books. Hopefully I explained this correctly! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
testing return values
Hiya. I'm looking for the correct Perl style for testing and storing a return value in a control statement. The solution in any other language is pretty obvious, but I get the distinct impression that there's a 'right' way in Perl... Let's say I want to test a scalar returned from a subroutine, and also keep a copy for my own use: $scalar = sub( $argument ); if( $scalar ){ } Naturally that's no big deal. Now let's say I have a tree I want to traverse, or some similar open-ended thing to evaluate, and want to run it until a condition is reached.. while( read_tree( $argument ){ } Again no biggie. The problem is if I want to keep the result. Obviously I can't do this: while( $tree_element = read_tree( $argument ) ){ do_something( $tree_element ); } I can come up with a brute-force solution of course, but there's probably a better, Perlish way that I'm not aware of. In addition, I don't expect a return value from some module to be consistently undefined or zero; it could change under some circumstances. This makes me think that the problem has been dealt with long ago, and just doesn't stick out in the llama/alpaca/whatever books. Hopefully I explained this correctly! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
cpanplus module cyclic dependency
Hi, I tried to install CPANPLUS with my cpan module. The installation ended with the following error: Recursive dependency detected:s/Autoflush.pm blib/lib/CPANPLUS/Internals/Utils/ACPANPLUS - K/KA/KANE/CPANPLUS-0.78.tar.gzb/lib/CPANPLUS/Module/Fake.pm - CPANPLUS::Shell::Defaultb/lib/CPANPLUS/Error.pm - K/KA/KANE/CPANPLUS-0.78.tar.gz..pm blib/lib/CPANPLUS/Internals/Constants.pm Cannot continue.Dist/Base.pm blib/lib/CPANPLUS/Dist/Base.pm I am tring to install cpanplus on a cygwin. Has anyone a clue for that? Best regards, Yaron Kahanovitch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/