Re: Statement failure inside a loop

2015-06-18 Thread Илья Рассадин
200 > Marco wrote: > > > Hello. > > > > I need some help in understanding why the first > > > > my ($Count,$Saw)=$self->{_Portobj}->read(1); > > > > is executed without any problem , however the second identical statement > > inside the while

Re: Statement failure inside a loop

2015-06-18 Thread Shlomi Fish
Hi Marco, see below for my response. On Thu, 18 Jun 2015 15:17:27 +0200 Marco wrote: > Hello. > > I need some help in understanding why the first > > my ($Count,$Saw)=$self->{_Portobj}->read(1); > > is executed without any problem , however the second ident

Statement failure inside a loop

2015-06-18 Thread Marco
Hello. I need some help in understanding why the first my ($Count,$Saw)=$self->{_Portobj}->read(1); is executed without any problem , however the second identical statement inside the while loop fails with the error Can't call method "read" on an undefined value

Re: last statement in a package

2015-05-21 Thread Brandon McCaig
On Thu, May 21, 2015 at 3:41 AM, Vincent Lequertier wrote: > From http://perldoc.perl.org/perlmod.html#Perl-Modules, "1;" is used to end > with a true value There is a bit better explanation here: http://www.perlmonks.org/?node_id=781340 In short, `use' is like syntactic sugar around `require'

Re: last statement in a package

2015-05-21 Thread Vincent Lequertier
From http://perldoc.perl.org/perlmod.html#Perl-Modules, "1;" is used to end with a true value --- Vincent Lequertier s...@riseup.net Le 2015-05-21 08:13, Sunita Pradhan a écrit : Hi Why a perl programmer use 1 or any number as last statement in module or package (like : 1;)?I check

Re: last statement in a package

2015-05-21 Thread Uday Vernekar
When a module is loaded (via use) the compiler will complain unless the last statement executed when it is loaded is true. This line ensures that this is the case (as long as you don't place any code after this line). Perl's way of making sure that it successfully parsed all the way to

Re: last statement in a package

2015-05-21 Thread Uday Vernekar
As Per my Understanding... The last line file must contain the line with the 1; statement. As This in effect returns a true value to the program using the module. if you are Not using the 1; statement it will not let the module be loaded correctly. On Thu, May 21, 2015 at 11:43 AM, Sunita

last statement in a package

2015-05-20 Thread Sunita Pradhan
Hi Why a perl programmer use 1 or any number as last statement in module or package (like : 1;)?I checked without that also package gets loaded . Can somebody please explain properly , it would be good with examples ? ThanksSunita

Re: Argument isn't numeric warning in if statement

2014-09-18 Thread Rob Dixon
I correct in thinking that Perl evaluates an inline 'if' from right to left - meaning that if $item->{optionprice} is NOT true, then the addition will not even be seen? Or does Perl look at the entire line before performing it? I'm not clear what you mean by an *inline* i

Re: Argument isn't numeric warning in if statement

2014-09-17 Thread SSC_perl
On Sep 17, 2014, at 3:32 PM, Rob Dixon wrote: > As you have presented them, those code fragments are identical in meaning. That was my understanding as well, but the inline 'if' gave an error while the block didn't. Running the code by itself in TextWrangler does not produce the warning

Re: Argument isn't numeric warning in if statement

2014-09-17 Thread Rob Dixon
->{'unitprice'} += $item->{'optionprice'} if ($item->{'optionprice'}); Given the following values: $item->{'unitprice'} = '12.16'; $item->{'optionprice'} = ''; the 2nd statement returns an "Argumen

Re: Argument isn't numeric warning in if statement

2014-09-17 Thread Lawrence Statton
On 09/17/2014 12:46 PM, SSC_perl wrote: > On Sep 16, 2014, at 6:58 PM, > wrote: >> Are you sure you've quoted the code (that's producing the warning) correctly? > > Yes, I did. I double-checked it just to be certain. However, I ran > the code by itself and it doesn't produce that warni

Re: Argument isn't numeric warning in if statement

2014-09-17 Thread SSC_perl
On Sep 16, 2014, at 6:58 PM, wrote: > Are you sure you've quoted the code (that's producing the warning) correctly? Yes, I did. I double-checked it just to be certain. However, I ran the code by itself and it doesn't produce that warning, so it must be something upstream that's caus

Re: Argument isn't numeric warning in if statement

2014-09-16 Thread sisyphus1
-Original Message- From: SSC_perl Sent: Wednesday, September 17, 2014 10:37 AM To: Perl Beginners Subject: Argument isn't numeric warning in if statement I just ran across something puzzling. Why are these two statements not equivalent when it comes to warnings? if (

Argument isn't numeric warning in if statement

2014-09-16 Thread SSC_perl
} += $item->{'optionprice'} if ($item->{'optionprice'}); Given the following values: $item->{'unitprice'} = '12.16'; $item->{'optionprice'} = ''; the 2nd statement returns an "Argument '' isn

Re: Single equals operator inside an if statement

2013-08-14 Thread Alexey Mishustin
2013/8/15 Brian Fraser : > On Wed, Aug 14, 2013 at 6:09 PM, Alexey Mishustin >> I'm sorry only that there is no built-in option with which one could >> enable/disable easily assignments inside `if'. (E.g., like re 'eval'/ >> no re 'eval'). It would "provide choices"... >> > > It might not be too

Re: Single equals operator inside an if statement

2013-08-14 Thread Brian Fraser
igning it - I have never done this at the same > >>> time... > >> > >> > >> > >> Doing both in while statements is very common: > >> > >>while( my $line = <$fh> ) { > >> ... > >>} > >>

Re: Single equals operator inside an if statement

2013-08-14 Thread Alexey Mishustin
gt; Doing both in while statements is very common: >> >>while( my $line = <$fh> ) { >> ... >>} >> >> Try to write that loop with two separate statements, one an >> assignment > > and the other an if statement, and you may see the

Re: Single equals operator inside an if statement

2013-08-14 Thread Uri Guttman
t loop with two separate statements, one an assignment and the other an if statement, and you may see the advantage of the currently-allowed syntax. The general policy is that assignment statements return a value that may be further used or tested. i have a common idiom when dealing with a

Re: Single equals operator inside an if statement

2013-08-14 Thread Jim Gibson
s, one an assignment and the other an if statement, and you may see the advantage of the currently-allowed syntax. The general policy is that assignment statements return a value that may be further used or tested. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional command

Re: Single equals operator inside an if statement

2013-08-14 Thread Alexey Mishustin
Thanks to all, 2013/8/14 Jim Gibson : > The problem is that the construct > > if( $foo = $bar ) { > ... > > is not always a typo. It means: "assign value of $bar to variable $foo and > test if the result is logically true", which is perfectly valid. If that were > not allowed, then you wo

Re: Single equals operator inside an if statement

2013-08-14 Thread Jing Yu
Or maybe he can write a perl script to check the "if/while" conditionals of his perl script... while(<>){ say '= is detected where == is expected at line ',"$." if /if\s*\(\S+?=[^=]/; } On 15 Aug 2013, at 03:02, Rob Dixon wrote: > On 14/08/2013 18:21, Alexey Mishustin wrote: >> >> If

Re: Single equals operator inside an if statement

2013-08-14 Thread Jing Yu
Hi Alex, I guess it would be very difficult and error-prone to do it. Here's my thought: my $bar = 3; my $assign = (my $foo = $bar); if($assign){ say '$assign=',$assign; } my $equal = ($foo == $bar); if($equal){ say '$equal=',$equal; } output: $ perl tst.pl $assign=3 $equal=1 But if $

Re: Single equals operator inside an if statement

2013-08-14 Thread Rob Dixon
On 14/08/2013 18:21, Alexey Mishustin wrote: If I make a typo and write a single "equals" operator here: if ($foo = 2) { print "yes\n"; } ...then the "warnings" pragma works OK and tells me "Found = in conditional, should be ==..." But if I make the same typo and write a single "equal

Re: Single equals operator inside an if statement

2013-08-14 Thread Jim Gibson
On Aug 14, 2013, at 11:34 AM, Alexey Mishustin wrote: > Hi Jing, > > Thanks for the reply. > > So, there is no built-in way to catch these typos? The problem is that the construct if( $foo = $bar ) { ... is not always a typo. It means: "assign value of $bar to variable $foo and test i

Re: Single equals operator inside an if statement

2013-08-14 Thread Alexey Mishustin
Hi Jing, Thanks for the reply. So, there is no built-in way to catch these typos? -- Regards, Alex -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Single equals operator inside an if statement

2013-08-14 Thread Jing Yu
Hi there, Allow me to correct myself, the value of the assignment is the new value of the variable. But in the end it is the same. The compiler won't be able to see what $bar is when used in if ($foo=$bar), therefore won't throw any warnings. Cheers, Jing On 15 Aug 2013, at 01:21, Alexey Mishus

Re: Single equals operator inside an if statement

2013-08-14 Thread Jing Yu
Hi Alexey, If I remember correctly, when you assign a value to an lvalue like this: $foo = 1; The value of the assignment is the value on the right hand side of the equal sign. So when you do something like: if ($foo=2){...} It has the same effect as this: $foo=2; If (2){...} The condition

Single equals operator inside an if statement

2013-08-14 Thread Alexey Mishustin
Hello all, If I make a typo and write a single "equals" operator here: #!/usr/bin/perl use strict; use warnings; my $foo = 1; my $bar = 2; if ($foo = 2) { print "yes\n"; } else { print "no\n"; } ...then the "warnings" pragma works OK and tells me "Found = in conditional, shoul

Re: case statement in perl

2012-08-02 Thread Paul.G
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

Re: case statement in perl

2012-08-01 Thread Paul.G
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 a

Re: case statement in perl

2012-08-01 Thread Chris Nehren
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 wr

Re: case statement in perl

2012-08-01 Thread Hal Wigoda
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 >> av

Re: case statement in perl

2012-08-01 Thread Chris Nehren
m 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

Re: case statement in perl

2012-08-01 Thread Uri Guttman
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

Re: case statement in perl

2012-08-01 Thread John W. Krahn
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_CHECKFREE

Re: case statement in perl

2012-08-01 Thread Rob Coops
]"); > } >} ># 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; > } &g

Re: case statement in perl

2012-08-01 Thread Paul.G
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

Re: case statement in perl

2012-07-31 Thread John W. Krahn
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&qu

Re: case statement in perl

2012-07-31 Thread timothy adigun
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,

Re: case statement in perl

2012-07-31 Thread Paul.G
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 ($numP

Re: case statement in perl

2012-07-31 Thread Chris Nehren
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 >

Re: case statement in perl

2012-07-31 Thread Hal Wigoda
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.

case statement in perl

2012-07-31 Thread Paul.G
Hi All Does perl have a case statement or an equivalent? Cheers Paul

Re: Problem with unless statement

2012-04-28 Thread sono-io
On Apr 28, 2012, Shawn H Corey wrote: > Moral of the story: use meaningful variable names. Yep, you're right. =:\ I thought it was going to be a simple question about the unless statement. Turns out I was headed down the wrong path, so I changed the variable name to make

Re: Problem with unless statement

2012-04-28 Thread Uri Guttman
On 04/28/2012 01:28 PM, Shawn H Corey wrote: On 12-04-28 12:36 PM, Uri Guttman wrote: that reduces to just: my $host = $mail_field || 'localhost' ; which is the classic defaulting style. it has one flaw, it makes '' and 0 not allowed for values in $mail_field. but i doubt those would ever be g

Re: Problem with unless statement

2012-04-28 Thread Shawn H Corey
On 12-04-28 12:36 PM, Uri Guttman wrote: that reduces to just: my $host = $mail_field || 'localhost' ; which is the classic defaulting style. it has one flaw, it makes '' and 0 not allowed for values in $mail_field. but i doubt those would ever be good host names so it should be fine here. you

Re: Problem with unless statement

2012-04-28 Thread Uri Guttman
On 04/28/2012 12:10 PM, Jim Gibson wrote: On Apr 28, 2012, at 9:04 AM, sono...@fannullone.us wrote: my $host = 'localhost'; if ( defined ($mail_field) and ($mail_field ne '') ) { $host = $mail_field; } I would use: my $host = $mail_field ? $mail_field : 'localhost' ; that reduces

Re: Problem with unless statement

2012-04-28 Thread Michael Rasmussen
On Sat, Apr 28, 2012 at 12:16:57PM -0400, Shawn H Corey wrote: > On 12-04-28 12:10 PM, Jim Gibson wrote: >> >> On Apr 28, 2012, at 9:04 AM, sono...@fannullone.us wrote: >> >>> my $host = 'localhost'; >>> >>> if ( defined ($mail_field) and ($mail_field ne '') ) { >>> $host = $mail_field; >>> } >

Re: Problem with unless statement

2012-04-28 Thread Shawn H Corey
On 12-04-28 12:10 PM, Jim Gibson wrote: On Apr 28, 2012, at 9:04 AM, sono...@fannullone.us wrote: my $host = 'localhost'; if ( defined ($mail_field) and ($mail_field ne '') ) { $host = $mail_field; } I would use: my $host = $mail_field ? $mail_field : 'localhost' ; Well, since

Re: Problem with unless statement

2012-04-28 Thread Jim Gibson
On Apr 28, 2012, at 9:04 AM, sono...@fannullone.us wrote: > my $host = 'localhost'; > > if ( defined ($mail_field) and ($mail_field ne '') ) { > $host = $mail_field; > } I would use: my $host = $mail_field ? $mail_field : 'localhost' ; -- To unsubscribe, e-mail: beginners-unsubscr...@

Re: Problem with unless statement

2012-04-28 Thread sono-io
On Apr 28, 2012, Lesley Binks wrote: > To be robust, you might need to check that $xtra is defined AND has something > sensible in it using a regexp. Well, after being set straight to the error of my ways, I finally have code that seems to work in any situation: my $mail_field; # set

Re: Problem with unless statement

2012-04-28 Thread Lesley Binks
On Sat, Apr 28, 2012 at 08:00:09AM -0700, sono...@fannullone.us wrote: > Shawn, > > > are you sure this is what you want? > > I'm not sure of anything anymore. ;) > > I found something that sets $host properly: > > my $xtra = 'mail.example.com'; > my $host = 'localhost'; > That's a

Re: Problem with unless statement

2012-04-28 Thread John SJ Anderson
efined as 'mail.example.com' so $host won't be. > > That makes sense. What I'm trying to do is set $host to one of the two > values - if $xtra is set, use it; if not, use localhost. I was just trying > to get it as short as possible. Maybe I'll go back to

Re: Problem with unless statement

2012-04-28 Thread Chris Charley
but I was just trying for a one-liner. ;) It's a bad idea to declare variables with a trailing conditional statement modifier (such as "if COND();" or "unless COND();"). Why is it a bad idea? Can you point me to something to read about this? My Google searches ha

Re: Problem with unless statement

2012-04-28 Thread sono-io
Shawn, > are you sure this is what you want? I'm not sure of anything anymore. ;) I found something that sets $host properly: my $xtra = 'mail.example.com'; my $host = 'localhost'; $host = $xtra if (length $xtra > 0); Can anyone see any holes in this code? Marc --

Re: Problem with unless statement

2012-04-28 Thread Shawn H Corey
On 12-04-28 10:16 AM, sono...@fannullone.us wrote: I'm having a problem with the following code: #!/usr/bin/perl use strict; use warnings; my $xtra = 'mail.example.com'; my $host = 'localhost' unless (defined ($xtra)); # this is the same as saying: my $xtra = 'mail.example.com'; my

Re: Problem with unless statement

2012-04-28 Thread sono-io
Shlomi, > It's a bad idea to declare variables with a trailing conditional statement Never mind my "why" question. It finally dawned on me that the unless statement will not set the $host variable. And I thought sleeping on it would help. :\ Marc -- To unsubscribe,

Re: Problem with unless statement

2012-04-28 Thread sono-io
x27;m trying to do is set $host to one of the two values - if $xtra is set, use it; if not, use localhost. I was just trying to get it as short as possible. Maybe I'll go back to the if statement I had before. Thanks, Marc -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For ad

Re: Problem with unless statement

2012-04-28 Thread sono-io
trying for a one-liner. ;) > It's a bad idea to declare variables with a trailing conditional statement > modifier (such as "if COND();" or "unless COND();"). Why is it a bad idea? Can you point me to something to read about this? My Google searches ha

Re: Problem with unless statement

2012-04-28 Thread Lesley Binks
On Sat, Apr 28, 2012 at 07:16:18AM -0700, sono...@fannullone.us wrote: > I'm having a problem with the following code: > > #!/usr/bin/perl > use strict; > use warnings; > > my $xtra = 'mail.example.com'; > > my $host = 'localhost' unless (defined ($xtra)); > > print $host; > > I ge

Re: Problem with unless statement

2012-04-28 Thread Lawrence Statton
On 04/28/2012 09:16 AM, sono...@fannullone.us wrote: I'm having a problem with the following code: #!/usr/bin/perl use strict; use warnings; my $xtra = 'mail.example.com'; my $host = 'localhost' unless (defined ($xtra)); print $host; I get the message "Use of uninitialized va

Re: Problem with unless statement

2012-04-28 Thread Shlomi Fish
27; unless (defined ($xtra)); > It's a bad idea to declare variables with a trailing conditional statement modifier (such as "if COND();" or "unless COND();"). What you should do is: [CODE] my $host; unless (defined($xtra)) { $host = 'localhost'; } [

Problem with unless statement

2012-04-28 Thread sono-io
I'm having a problem with the following code: #!/usr/bin/perl use strict; use warnings; my $xtra = 'mail.example.com'; my $host = 'localhost' unless (defined ($xtra)); print $host; I get the message "Use of uninitialized value $host in print". Does anyone know why this doesn'

Re: using cmp for if statement comparisons

2012-03-14 Thread Shawn H Corey
On 12-03-14 12:35 AM, John W. Krahn wrote: cmp is a binary operator just like eq, ne, gt, lt, ge and le. See `perldoc perlop` and search for /Equality Operators/ -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about co

Re: using cmp for if statement comparisons

2012-03-13 Thread John W. Krahn
Noah wrote: Hi there, Hello, I am trying to get two conditions matched how can I get if ( ($source_location eq $destination_location ) && ( $source_device < $destination_device ) ) { That should be: if ( $source_location eq $destination_location && $source_device lt $destination_device )

using cmp for if statement comparisons

2012-03-13 Thread Noah
Hi there, I am trying to get two conditions matched how can I get if ( ($source_location eq $destination_location ) && ( $source_device < $destination_device ) ) { and if ( ($source_location eq $destination_location ) && ( $source_device > $destination_device ) ) {

Re: Need Help. .Issue with format statement

2011-03-23 Thread Chas. Owens
On Wed, Mar 23, 2011 at 08:47, Sudhir wrote: > My work environment recently shifted from perl v5.6 to perl v5.10 > > I found one issue with perl format statement in latest version v5.10 > > sample code: > > #!/bin/env perl > use strict; > > &genRep(); > &

Need Help. .Issue with format statement

2011-03-23 Thread Sudhir
My work environment recently shifted from perl v5.6 to perl v5.10 I found one issue with perl format statement in latest version v5.10 sample code: #!/bin/env perl use strict; &genRep(); sub genRep { format DURATION_TOP = @<<<<<<<<<

Re: given-when statement as a rvalue?

2010-12-26 Thread Peter Daum
On 2010-12-26 18:28, Brian Fraser wrote: > Your example actually works -- On perl 5.13.+: > http://www.effectiveperlprogramming.com/blog/683 that's good news (even though it means I'll have to wait a little longer until I can actually use it) - at least I'm obviously not the only one who felt, tha

Re: given-when statement as a rvalue?

2010-12-26 Thread Paul Johnson
On Sun, Dec 26, 2010 at 06:13:06PM +0100, Peter Daum wrote: > Is it possible to get a value from a given-when statement? > > Suppose I have a long comparison in which all branches affect > the same variable. Here's a short example (minor variation > from"perlsyn

Re: given-when statement as a rvalue?

2010-12-26 Thread Brian Fraser
Your example actually works -- On perl 5.13.+: http://www.effectiveperlprogramming.com/blog/683 Brian.

given-when statement as a rvalue?

2010-12-26 Thread Peter Daum
Is it possible to get a value from a given-when statement? Suppose I have a long comparison in which all branches affect the same variable. Here's a short example (minor variation from"perlsyn"): given($something) { when (/^abc/) { $x = 1; } when (/^def/) { $x = 2; }

Re: current record number with if statement

2010-09-20 Thread Shlomi Fish
On Monday 20 September 2010 12:30:55 Raj wrote: > Hi, > > I am a newbie for perl. > > It would be fine if some explain how the following code prints first > 10 lines of the file. > My question here is, how/what if condition match happens? Is there > anything related to current record number ($.

current record number with if statement

2010-09-20 Thread Raj
Hi, I am a newbie for perl. It would be fine if some explain how the following code prints first 10 lines of the file. My question here is, how/what if condition match happens? Is there anything related to current record number ($.) variable? while () { print if 1 .. 10; } Regards, Raj

Re: Is this perl statement valid?

2010-08-04 Thread Chas. Owens
On Thu, Aug 5, 2010 at 00:16, HACKER Nora wrote: > Hi, > > Additional noob question: What would be wrong with > >        $version = '0'.$version; snip Do you always want one 0 in front of version? What if the version is 9? Shouldn't it be "009" then? You could write: #version should be th

AW: Is this perl statement valid?

2010-08-04 Thread HACKER Nora
Betreff: Re: Is this perl statement valid? > > On 10-08-04 05:39 AM, Sooraj S wrote: > > Hi, > > > > My code is accepting an option "version" as an integer. If it is > less > > than 100, i need to add a zero in front of it so that i can do the > > fur

Re: Is this perl statement valid?

2010-08-04 Thread Bob goolsby
Mornin' Sooraj, As is true of most "does this work in Perl" questions, the answer is "Try it" -- C:\Documents and Settings\Administrator>perl -e "$version=9;$version=sprintf(\"0%d\",$version); print $version; " 09 C:\Documents and Settings\Administrator> Enjoy --- B On Wed, Aug 4, 2010 at 4:5

Re: Is this perl statement valid?

2010-08-04 Thread Shawn H Corey
On 10-08-04 05:39 AM, Sooraj S wrote: Hi, My code is accepting an option "version" as an integer. If it is less than 100, i need to add a zero in front of it so that i can do the further processing. Although this code is working, i am not sure that its the proper way. if ($version< 100) {

Is this perl statement valid?

2010-08-04 Thread Sooraj S
Hi, My code is accepting an option "version" as an integer. If it is less than 100, i need to add a zero in front of it so that i can do the further processing. Although this code is working, i am not sure that its the proper way. if ($version < 100) { # convert an integer-variable to string

Re: AW: an odd conditional statement

2010-06-09 Thread Uri Guttman
>>>>> "TB" == Thomas Bätzler writes: TB> You can do something like TB> my $cond = eval( $statement ); TB> The two important things to keep in mind: TB> 1) Make sure you sanitize $statement very carefully. Otherwise people can run arbitrary perl

AW: an odd conditional statement

2010-06-09 Thread Thomas Bätzler
sillymonkeysoftw...@gmail.com asked: > I'm working with some customizable data from a config file, and can't > for the life of me figure out how to test conditionals from an > external source. > Does anyone have an idea how to accomplish something like: > > m

Re: an odd conditional statement

2010-06-09 Thread Uri Guttman
f me figure out how to test conditionals from an >> external source. >> Does anyone have an idea how to accomplish something like: >> >> my $statement = "1 < 10 and 2 > 10"; # obviously false >> my $result = ($statement) ? 1 : 0;# condit

Re: an odd conditional statement

2010-06-09 Thread Shlomi Fish
ve an idea how to accomplish something like: > > my $statement = "1 < 10 and 2 > 10"; # obviously false > my $result = ($statement) ? 1 : 0;# conditional test > > Now, $result will always be true(1), because the conditional is > really, in effect, just val

Re: an odd conditional statement

2010-06-09 Thread Uri Guttman
> Does anyone have an idea how to accomplish something like: sc> my $statement = "1 < 10 and 2 > 10"; # obviously false sc> my $result = ($statement) ? 1 : 0; # conditional test that will never work as is. perl doesn't interpret $statement as code. if

an odd conditional statement

2010-06-09 Thread sillymonkeysoftw...@gmail.com
Hi everyone, I'm working with some customizable data from a config file, and can't for the life of me figure out how to test conditionals from an external source. Does anyone have an idea how to accomplish something like: my $statement = "1 < 10 and 2 > 10"; # obvi

Re: How to manage large Conditional Statement

2010-04-21 Thread Uri Guttman
> "OR" == Octavian Rasnita writes: OR> From: "Uri Guttman" >> >> it isn't religious. it is just no one is taught the right way >> anymore. it used to be always done this way (in the good very old >> day). with the onslaught of redmond and aol the unwashed masses didn't >> learn

Re: How to manage large Conditional Statement

2010-04-21 Thread Octavian Rasnita
From: "Uri Guttman" > MC> Uri: I think the quoting is much a religious issue as everyone has their > MC> preferred way, but I now know what you meant. :-) > > it isn't religious. it is just no one is taught the right way > anymore. it used to be always done this way (in the good very old > day)

Re: How to manage large Conditional Statement

2010-04-21 Thread Uri Guttman
> "MC" == Mimi Cafe writes: MC> Earlier I thought of using an eval or BEGIN block to evaluate the MC> SQL, but then I thought wait a minute, that wouldn't be the MC> correct way of using them. Now I see that doing as you guys MC> recommended is the right way forward. a BEGIN block ma

RE: How to manage large Conditional Statement

2010-04-21 Thread Mimi Cafe
>> -Original Message- >> I'm talking for myself here, but the way I usually do this is that I wrap >> up each SQL query or set of related SQL queries in a subroutine. >> >> If the sub's going to be used as a predicate I make sure it returns >> true/false and pass all of the relevant data

AW: How to manage large Conditional Statement

2010-04-20 Thread Thomas Bätzler
Mimi Cafe asked: > I need to evaluate a statement in an if, elsif, else block, and the > statement to evaluate in the elsif is too large as I need to run a SQL > query and act on the return value. > What would be a better way to achieve this? Putting the SQL statement > elsewh

Re: How to manage large Conditional Statement

2010-04-20 Thread Uri Guttman
>>>>> "MC" == Mimi Cafe writes: MC> I need to evaluate a statement in an if, elsif, else block, and MC> the statement to evaluate in the elsif is too large as I need to MC> run a SQL query and act on the return value. What would be a MC> better

How to manage large Conditional Statement

2010-04-20 Thread Mimi Cafe
I need to evaluate a statement in an if, elsif, else block, and the statement to evaluate in the elsif is too large as I need to run a SQL query and act on the return value. What would be a better way to achieve this? Putting the SQL statement elsewhere outside the block cannot be right, so I am

Re: Fw: Modifiers on the right side of the statement

2009-07-17 Thread Soham Das
. Thanks Soham - Original Message From: Uri Guttman To: Soham Das Cc: beginners@perl.org Sent: Thursday, 16 July, 2009 11:30:31 AM Subject: Re: Fw: Modifiers on the right side of the statement >>>>> "SD" == Soham Das writes: SD> - Forwarded Messag

Re: Modifiers on the right side of the statement

2009-07-16 Thread Chas. Owens
On Wed, Jul 15, 2009 at 19:19, Steve Bertrand wrote: > Hi all, > > While writing some tests, I ran into something that took me quite a > while to troubleshoot. Although I figured out the problem, I don't > understand why the problem is occurring. > > Can someone point out the importance of the brac

Re: Fw: Modifiers on the right side of the statement

2009-07-15 Thread Uri Guttman
>>>>> "SD" == Soham Das writes: SD> - Forwarded Message SD> From: Soham Das SD> To: Uri Guttman SD> Sent: Thursday, 16 July, 2009 11:23:29 AM SD> Subject: Re: Modifiers on the right side of the statement SD> I believe its beca

Fw: Modifiers on the right side of the statement

2009-07-15 Thread Soham Das
- Forwarded Message From: Soham Das To: Uri Guttman Sent: Thursday, 16 July, 2009 11:23:29 AM Subject: Re: Modifiers on the right side of the statement I believe its because =~ has the highest priorty... - Original Message From: Uri Guttman To: John W. Krahn Cc

Re: Modifiers on the right side of the statement

2009-07-15 Thread John W. Krahn
Uri Guttman wrote: "JWK" == John W Krahn writes: >>> Can someone point out the importance of the brackets in which '2' >>> prints, but '1' does not? I've always thought that the brackets could be >>> omitted: >>> >>> print "1" if ref $href =~ /HASH/; >>> print "2" if ref($href)

Re: Modifiers on the right side of the statement

2009-07-15 Thread Steve Bertrand
Uri Guttman wrote: > you need to wrap the call in block eval and check for die > afterwards. see perldoc -f eval and perlvar for $...@. note that this is > BLOCK eval which is fine to use anywhere you want to trap dies and not > string eval which is evil unless absolutely necessary. > > SB> is

Re: Modifiers on the right side of the statement

2009-07-15 Thread Steve Bertrand
etter test > and the op is faster and binds better. Ok. > SB> I don't want to change the object method's behaviour just for a test, so > SB> can anyone point me in the right direction as to how I can override the > SB> object method's needed die() statemen

  1   2   3   4   5   6   >