RE: variable definition error not caught when using strict and warnings

2012-11-09 Thread Nemana, Satya
From: Rob Dixon [rob.di...@gmx.com] Sent: 09 November 2012 17:17 To: beginners@perl.org Cc: Nemana, Satya Subject: Re: variable definition error not caught when using strict and warnings On 09/11/2012 17:08, Nemana, Satya wrote: > Hi > > I am

Re: variable definition error not caught when using strict and warnings

2012-11-09 Thread Rob Dixon
On 09/11/2012 17:08, Nemana, Satya wrote: Hi I am a little confused with this program Program: use strict; use warnings; if ($999 == 1056) { print ("\nequal"); } else { print ("\nnot equal"); } What I expect: Perl to throw me an error as $999 variable is not defined, but perl execu

Re: variable definition error not caught when using strict and warnings

2012-11-09 Thread Andy Bach
On Fri, Nov 9, 2012 at 11:08 AM, Nemana, Satya wrote: > > if ($999 == 1056) > { > print ("\nequal"); > } > else > { > print ("\nnot equal"); > } > > What I expect: Perl to throw me an error as $999 variable is not defined, > but perl executes the code with a warning.(I don't expect the co

Re: variable definition error not caught when using strict and warnings

2012-11-09 Thread Robert Wohlfarth
On Fri, Nov 9, 2012 at 11:08 AM, Nemana, Satya wrote: > Program: > use strict; > use warnings; > > if ($999 == 1056) > { > print ("\nequal"); > } > else > { > print ("\nnot equal"); > } > > What I expect: Perl to throw me an error as $999 variable is not defined, > but perl executes the c

Re: Variable Assignment

2011-08-16 Thread Octavian Rasnita
From: "shawn wilson" > On Aug 16, 2011 9:48 PM, "John W. Krahn" wrote: >> >> Joseph L. Casale wrote: >>> >>> What is the correct way to quickly assign the result of a regex against >>> a cmdline arg into a new variable: >>> >>> my $var = ($ARGV[0] =~ s/(.*)foo/$1/i); >> >> >> my ( $var ) = $ARGV[

Re: Variable Assignment

2011-08-16 Thread Jim Gibson
At 11:43 PM -0400 8/16/11, shawn wilson wrote: On Aug 16, 2011 9:48 PM, "John W. Krahn" wrote: Joseph L. Casale wrote: What is the correct way to quickly assign the result of a regex against a cmdline arg into a new variable: my $var = ($ARGV[0] =~ s/(.*)foo/$1/i); my ( $var ) = $AR

Re: Variable Assignment

2011-08-16 Thread shawn wilson
On Aug 16, 2011 9:48 PM, "John W. Krahn" wrote: > > Joseph L. Casale wrote: >> >> What is the correct way to quickly assign the result of a regex against >> a cmdline arg into a new variable: >> >> my $var = ($ARGV[0] =~ s/(.*)foo/$1/i); > > > my ( $var ) = $ARGV[0] =~ /(.*)foo/i; IIRC, that rede

Re: Variable Assignment

2011-08-16 Thread John W. Krahn
Joseph L. Casale wrote: What is the correct way to quickly assign the result of a regex against a cmdline arg into a new variable: my $var = ($ARGV[0] =~ s/(.*)foo/$1/i); my ( $var ) = $ARGV[0] =~ /(.*)foo/i; John -- Any intelligent fool can make things bigger and more complex... It takes a

RE: Variable Assignment

2011-08-16 Thread Joseph L. Casale
>Yes, you can use: > >( my $var = $ARGV[0] ) =~ s/(.*)foo/$1/i; Rob/Octavian, Thanks for the quick help! jlc -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Variable Assignment

2011-08-16 Thread Octavian Rasnita
From: "Joseph L. Casale" What is the correct way to quickly assign the result of a regex against a cmdline arg into a new variable: my $var = ($ARGV[0] =~ s/(.*)foo/$1/i); Obviously that's incorrect but is there a quick way without intermediate assignment? Thanks! jlc Yes, you can use: ( my

Re: Variable Assignment

2011-08-16 Thread Rob Coops
On Tue, Aug 16, 2011 at 8:27 PM, Joseph L. Casale wrote: > What is the correct way to quickly assign the result of a regex against > a cmdline arg into a new variable: > > my $var = ($ARGV[0] =~ s/(.*)foo/$1/i); > > Obviously that's incorrect but is there a quick way without intermediate > assign

Re: variable name in 'data' ... don't really know how to say it...

2011-06-06 Thread Chris Nehren
On Thu, May 26, 2011 at 10:18:51 -0700 , PetePDX wrote: > > > I want to update a rrd database file, I'm using RRDTool::OO the data > is coming out of a database table. > each row in the database has in it two columns that are the dsname and > the associated value. Pete, perhaps the reason that y

Re: Variable variable names

2010-10-29 Thread Shlomi Fish
Hi Nora, On Friday 29 October 2010 07:23:13 HACKER Nora wrote: > Hello, > > In the below code I am desperately trying to accomplish the valid use of > variable variable names but still fail. I have already read many sites, > tutorials, mailing list posts, all saying that this is best accomplished

Re: variable naming

2010-06-20 Thread Uri Guttman
> "JL" == Jason Lewis writes: JL> Hey, this might be a stupid question... not a stupid question. but a dangerous one. JL> If I need to name a variable with the contents of another scalar, how do I JL> do that? reference? the answer is you don't do it (even though you can in perl). it

Re: variable scope

2010-02-07 Thread Dr.Ruud
Eric wrote: I have a program that requests many config values from an ini file using Config::IniFiles. I import all of these values into my main:: script but it's pretty ugly. Is there a way to import my value definitions int variables in a sub or another module and have them visible in the main

Re: variable scope

2010-02-07 Thread Eric
On Feb 6, 11:01 pm, jeffp...@netzero.net (Jeff Peng) wrote: > 在 2010-02-05五的 06:27 -0800,Eric写道: > > > I have a program that requests many config values from an ini file > > using Config::IniFiles. I import all of these values into my main:: > > script but it's pretty ugly. Is there a way to import

Re: variable scope

2010-02-06 Thread Jeff Peng
在 2010-02-05五的 06:27 -0800,Eric写道: > I have a program that requests many config values from an ini file > using Config::IniFiles. I import all of these values into my main:: > script but it's pretty ugly. Is there a way to import my value > definitions int variables in a sub or another module and h

Re: Variable to refer to program name

2009-08-21 Thread asmith9983
Hi Erez You may also be surprised to learn that all perl features are well documented. You get the index with "perldoc perl", and the page referring to the one you needed "perldoc perlvar". I'd recommend reading all the online docs as they describe all the features of the language. -- Andr

Re: Variable to refer to program name

2009-08-21 Thread pdfeeny
Erez Schatz wrote on 08/21/2009 02:58:23 PM: > You can also read on all the special variables in Perl by typing > 'perldoc perlvar' on your shell, or at > http://perldoc.perl.org/perlvar.html > Thanks, Erez. That's exactly what I was looking for. (told you it was a noob question) > 2009/8/21

Re: Variable to refer to program name

2009-08-21 Thread Erez Schatz
You can also read on all the special variables in Perl by typing 'perldoc perlvar' on your shell, or at http://perldoc.perl.org/perlvar.html 2009/8/21 Erez Schatz : > 2009/8/21  : >> In *NIX shell scripting, the variable $0 refers to the >> zeroth command line parameter, >> i.e., the program itsel

Re: Variable to refer to program name

2009-08-21 Thread jm
this is what i use for all my scripts. note there are 2 underscores "_" before and after FILE my $program_name = __FILE__; $program_name =~ s/^.*\///;# remove all path, leaving only actual program name On Fri, Aug 21, 2009 at 1:52 PM, wrote: > Hi All, > > I am about as noob as you ca

Re: Variable to refer to program name

2009-08-21 Thread Steve Bertrand
pdfe...@aep.com wrote: > Hi All, > > I am about as noob as you can get so please forgive my complete naivete. > > I have jumped into the world of perl with both feet and have gotten hung > up on a seemingly > trivial matter. In *NIX shell scripting, the variable $0 refers to the > zeroth comm

Re: Variable to refer to program name

2009-08-21 Thread Erez Schatz
2009/8/21 : > In *NIX shell scripting, the variable $0 refers to the > zeroth command line parameter, > i.e., the program itself.  I would like to use something like this in my > perl scripts.  Is there an > equivalent to this in perl? > (un)surprisingly enough, it's $0. -- Erez "The governmen

Re: Variable in for loop is not automatically local?

2009-05-04 Thread Gunnar Hjalmarsson
Bryan Harris wrote: Note that the foreach variable is an alias to the loop list so modifying the variable also modifies the list elements. Out of curiosity, is it possible to manually create aliases like this as well? e.g. to make $x an alias to $y? I do not know the exact answer to your que

Re: Variable in for loop is not automatically local?

2009-05-04 Thread Bryan Harris
[lots of stuff cut out] > Note that the foreach variable is an alias to the loop list so modifying > the variable also modifies the list elements. Out of curiosity, is it possible to manually create aliases like this as well? e.g. to make $x an alias to $y? - B -- To unsubscribe, e-mail: b

Re: Variable in for loop is not automatically local?

2009-05-02 Thread John W. Krahn
Kelly Jones wrote: If I do a for loop in a subroutine, do I have to declare it private with my()? I always though for() did that for me, but I ran into a bug where code like this: sub foo {for $i (1..2) {print $i;}} affected my global $i (I think). Or was I imagining it? The variable in a for

Re: Variable in for loop is not automatically local?

2009-05-02 Thread Gunnar Hjalmarsson
Kelly Jones wrote: If I do a for loop in a subroutine, do I have to declare it private with my()? I always though for() did that for me, but I ran into a bug where code like this: sub foo {for $i (1..2) {print $i;}} affected my global $i (I think). Or was I imagining it? Probably, since $i ou

Re: variable in perl

2008-10-16 Thread Jean-Rene David
* Telemachus [2008.10.15 12:35]: > In Debian (and so probably many of its > children), perl-doc is a distinct package and > not installed automatically when you install the > perl package. > > Stupid, but true. Well, not to drift off-topic but it is my understanding that it is general Debian poli

Re: variable in perl

2008-10-15 Thread Mr. Shawn H. Corey
On Wed, 2008-10-15 at 12:25 -0400, Telemachus wrote: > On Tue Oct 14 2008 @ 3:58, Rob Dixon wrote: > > Chas. Owens wrote: > > > > > > [...] if for some reason you don't have access to perldoc > > > > Are there any installations of perl that don't include the manual? > > In Debian (and so probab

Re: variable in perl

2008-10-15 Thread Telemachus
On Tue Oct 14 2008 @ 3:58, Rob Dixon wrote: > Chas. Owens wrote: > > > > [...] if for some reason you don't have access to perldoc > > Are there any installations of perl that don't include the manual? In Debian (and so probably many of its children), perl-doc is a distinct package and not inst

Re: variable in perl

2008-10-15 Thread Peter Scott
On Tue, 14 Oct 2008 15:58:58 +0100, Rob Dixon wrote: > Are there any installations of perl that don't include the manual? Yes. Perl 5.8.5 on OS2008 on my handheld Nokia 810. 4GB internal memory; the POD was even stripped from the .pm files included. -- Peter Scott http://www.perlmedic.com/ htt

Re: variable in perl

2008-10-14 Thread Dr.Ruud
"Sandy lone" schreef: > I didn't have "man" installed on one of my hosts, so I can't read > perldoc documents on that host.:-) perldoc -oHtml perldoc | lynx -stdin -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL

Re: variable in perl

2008-10-14 Thread Sandy lone
On Tue, Oct 14, 2008 at 10:58 PM, Rob Dixon <[EMAIL PROTECTED]> wrote: > Chas. Owens wrote: >> >> [...] if for some reason you don't have access to perldoc > > Are there any installations of perl that don't include the manual? > Yes, I didn't have "man" installed on one of my hosts, so I can't rea

Re: variable in perl

2008-10-14 Thread Paul Johnson
On Tue, Oct 14, 2008 at 03:58:58PM +0100, Rob Dixon wrote: > Chas. Owens wrote: > > > > [...] if for some reason you don't have access to perldoc > > Are there any installations of perl that don't include the manual? > > Clearly you could be perverse and delete the documentation after an > insta

Re: variable in perl

2008-10-14 Thread Rob Dixon
Chas. Owens wrote: > > [...] if for some reason you don't have access to perldoc Are there any installations of perl that don't include the manual? Clearly you could be perverse and delete the documentation after an installation, but I thought a standard build of perl included it, regardless of

Re: variable in perl

2008-10-14 Thread Chas. Owens
On Tue, Oct 14, 2008 at 08:26, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote: > On Tue, 2008-10-14 at 17:33 +0530, [EMAIL PROTECTED] wrote: >> >> But then what is the difference between $0 and $^X > > Answers can be found in `perldoc perlvar`. snip Or http://perldoc.perl.org/perlvar.html#$0 and htt

RE: variable in perl

2008-10-14 Thread Mr. Shawn H. Corey
On Tue, 2008-10-14 at 17:33 +0530, [EMAIL PROTECTED] wrote: > > But then what is the difference between $0 and $^X > > Answers can be found in `perldoc perlvar`. -- Just my 0.0002 million dollars worth, Shawn Linux is obsolete. -- Andrew Tanenbaum -- To unsubscribe, e-mail: [EMAIL

RE: variable in perl

2008-10-14 Thread Irfan.Sayed
But then what is the difference between $0 and $^X From: Jeff Pang [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 14, 2008 5:28 PM To: Sayed, Irfan (Cognizant); beginners@perl.org Subject: Re:variable in perl > Message du 14/10/08 13:54 > De : [EMAIL PROTECTED] >

RE: variable in perl

2008-10-14 Thread Irfan.Sayed
thanks From: Jeff Pang [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 14, 2008 5:28 PM To: Sayed, Irfan (Cognizant); beginners@perl.org Subject: Re:variable in perl > Message du 14/10/08 13:54 > De : [EMAIL PROTECTED] > A : beginners@perl.org > Copie à :

Re: Variable passing to functions like read() / sysread() etc

2008-09-20 Thread Peter Scott
On Fri, 19 Sep 2008 06:58:33 -0700, wikenfalk wrote: > When using read/sysread you pass variables like $fo->sysread($buf, > $buflen), and the data is returned in buf. > This is magic to me, normally you ought to call sysread like $fo- >>sysread(\$buf,$buflen), passing a reference/pointer to the bu

Re: Variable passing to functions like read() / sysread() etc

2008-09-19 Thread Mr. Shawn H. Corey
On Fri, 2008-09-19 at 06:58 -0700, [EMAIL PROTECTED] wrote: > Hi > > When using read/sysread you pass variables like $fo->sysread($buf, > $buflen), and the data is returned in buf. > This is magic to me, normally you ought to call sysread like $fo- > >sysread(\$buf,$buflen), passing a reference/p

RE: Variable passing to functions like read() / sysread() etc

2008-09-19 Thread Thomas Bätzler
Hi, <[EMAIL PROTECTED]> wrote: > When using read/sysread you pass variables like > $fo->sysread($buf, $buflen), and the data is returned in buf. > This is magic to me, normally you ought to call sysread like $fo- > >sysread(\$buf,$buflen), passing a reference/pointer to the buffer. > > Apparan

Re: variable will not stay shared

2008-04-10 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi Members, Hello, 2)How do I shorten/improve this script. You could try it like this: # start of script # use strict; use warnings; use List::Util qw/ shuffle /; my %config = ( number_of_games=> 5_000, capital

Re: variable will not stay shared

2008-04-10 Thread Jenda Krynicky
From: <[EMAIL PROTECTED]> > Hi Members, > 1)The script below produce the following warnings:- "variable > $betting_system will not stay shared at roulette.pl line 61." >What is the problem and how do I rectify this problem. Don't write a named subroutine within another named subrouti

Re: variable help

2008-03-04 Thread Chas. Owens
On Tue, Mar 4, 2008 at 11:18 PM, yitzle <[EMAIL PROTECTED]> wrote: > On Tue, Mar 4, 2008 at 10:35 PM, Chas. Owens <[EMAIL PROTECTED]> wrote: > > A terminal that can handle UTF-8. > > > > You may need to put this in your profile > > #fix UTF-8 support > > export LC_CTYPE=en_US.UTF-8 #vim ne

Re: variable help

2008-03-04 Thread yitzle
On Tue, Mar 4, 2008 at 10:35 PM, Chas. Owens <[EMAIL PROTECTED]> wrote: > A terminal that can handle UTF-8. > > You may need to put this in your profile > #fix UTF-8 support > export LC_CTYPE=en_US.UTF-8 #vim needs this to swtich it from Latin1 to UTF-8 > export PERL_UNICODE=SDL #Makes Per

Re: variable help

2008-03-04 Thread Chas. Owens
On Tue, Mar 4, 2008 at 10:23 PM, yitzle <[EMAIL PROTECTED]> wrote: > On Tue, Mar 4, 2008 at 8:29 PM, Chas. Owens <[EMAIL PROTECTED]> wrote: > > Nope, due to addition of Unicode support in recent versions of Perl it > > will also match "\x{1814}" the Mongolian digit 4. The \d character > > cl

Re: variable help

2008-03-04 Thread yitzle
On Tue, Mar 4, 2008 at 8:29 PM, Chas. Owens <[EMAIL PROTECTED]> wrote: > Nope, due to addition of Unicode support in recent versions of Perl it > will also match "\x{1814}" the Mongolian digit 4. The \d character > class is not the same as [0-9], it matches all number characters, > including t

Re: variable help

2008-03-04 Thread Chas. Owens
On Tue, Mar 4, 2008 at 8:06 PM, MK <[EMAIL PROTECTED]> wrote: > On 03/04/2008 03:41:44 PM, yitzle wrote: > > -> I'd use a RegEx and test to see if the string is made up entirely of > > -> integers. > -> print "The variable containing $p is an interger\n" if ($p =~ > -> /^[0-9]+$/); > > yitzle

Re: variable help

2008-03-04 Thread MK
On 03/04/2008 03:41:44 PM, yitzle wrote: -> I'd use a RegEx and test to see if the string is made up entirely of -> integers. -> print "The variable containing $p is an interger\n" if ($p =~ -> /^[0-9]+$/); yitzle would seem to have the most foolproof solution. The only problem would be if

Re: variable help

2008-03-04 Thread Dr.Ruud
[EMAIL PROTECTED] schreef: > How to find out the specific variable contains integer value. In my > script ,variable is storing some value but I want to find out whether > that value is string or integer. In Perl, data types are like scalar, array, hash. Operator types are like numeric, string. $

Re: variable help

2008-03-04 Thread yitzle
Andrew has got a good point. The perldoc page says: if (/^\d+$/) { print "is a whole number\n" } which would indicate that the author of the perldoc page believes "123\n" should classify as a number, while "123foo" shouldn't, even though Perl sometimes treats "123foo" as a number. I was going to

Re: variable help

2008-03-04 Thread Chas. Owens
On Tue, Mar 4, 2008 at 4:44 PM, Randal L. Schwartz <[EMAIL PROTECTED]> wrote: > > ""Andrew" == "Andrew Curry" <[EMAIL PROTECTED]> writes: > > "Andrew> If you are not 100% sure then you can also do if ($x =~/^\d*$/) for > an > "Andrew> actual integer i.e. a number in the positive whole set of

RE: variable help

2008-03-04 Thread Andrew Curry
can use Scalar::Util but most people just want a simple test. -Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 04 March 2008 21:45 To: beginners@perl.org Subject: Re: variable help >>>>> ""Andrew" == "Andrew Curry" <[EM

Re: variable help

2008-03-04 Thread Randal L. Schwartz
> "Chas" == Chas Owens <[EMAIL PROTECTED]> writes: Chas> I cannot disagree with this sentiment more. Bad answers offer the Chas> chance to teach more than one person at a time. People should not be Chas> afraid to post answers to this list; however, it is a good idea to Chas> test your answe

Re: variable help

2008-03-04 Thread Chas. Owens
On Tue, Mar 4, 2008 at 4:43 PM, Randal L. Schwartz <[EMAIL PROTECTED]> wrote: snip > And you might want to note that submitting a *bad* answer to the beginners > mailing list is worse than submitting *no* answer, because it means that the > resources of People With More Experience Than You now h

Re: variable help

2008-03-04 Thread Randal L. Schwartz
> ""Andrew" == "Andrew Curry" <[EMAIL PROTECTED]> writes: "Andrew> If you are not 100% sure then you can also do if ($x =~/^\d*$/) for an "Andrew> actual integer i.e. a number in the positive whole set of numbers { "Andrew> 1,2,3} or negative whole numbers -1,-2,-3 or 0. This also f

Re: variable help

2008-03-04 Thread Randal L. Schwartz
> ""Rodrick" == "Rodrick Brown" <[EMAIL PROTECTED]> writes: "Rodrick> #!/usr/bin/perl "Rodrick> my $p = 10; "Rodrick> if( int($p) ) { "Rodrick> print "$p is an interger\n"; "Rodrick> } "Rodrick> ~ Not even close. $ perldoc -f int int EXPR int Returns the integer portion of EXP

RE: variable help

2008-03-04 Thread Andrew Curry
erl.org Subject: RE: variable help Be warned though that int isn't cleaver enough to deal with say... $x='0'; print int($x); still says it's a string as It is. If you are not 100% sure then you can also do if ($x =~/^\d*$/) for an actual integer i.e. a number in the positive wh

RE: variable help

2008-03-04 Thread Andrew Curry
} or negative whole numbers -1,-2,-3 or 0. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 04 March 2008 20:42 To: [EMAIL PROTECTED] Cc: beginners@perl.org Subject: RE: variable help Thanks Brown. It worked. -Original Message- From: Rodrick

Re: variable help

2008-03-04 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi All, Hello, How to find out the specific variable contains integer value. In my script ,variable is storing some value but I want to find out whether that value is string or integer. perldoc -q integer Also look for the function looks_like_number() in: perldoc

RE: variable help

2008-03-04 Thread Irfan.Sayed
Internet: http://www.t-systems.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of yitzle Sent: Wednesday, March 05, 2008 2:12 AM To: Rodrick Brown Cc: Sayed, Irfan; beginners@perl.org Subject: Re: variable help This approach does not consider "0&q

RE: variable help

2008-03-04 Thread Irfan.Sayed
Thanks Brown. It worked. -Original Message- From: Rodrick Brown [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 05, 2008 1:50 AM To: Sayed, Irfan Cc: beginners@perl.org Subject: Re: variable help #!/usr/bin/perl my $p = 10; if( int($p) ) { print "$p is an interger\n"; }

Re: variable help

2008-03-04 Thread yitzle
This approach does not consider "0" to be an integer. I'd use a RegEx and test to see if the string is made up entirely of integers. print "The variable containing $p is an interger\n" if ($p =~ /^[0-9]+$/); On Tue, Mar 4, 2008 at 3:19 PM, Rodrick Brown <[EMAIL PROTECTED]> wrote: > #!/usr/bin/pe

Re: variable help

2008-03-04 Thread Rodrick Brown
#!/usr/bin/perl my $p = 10; if( int($p) ) { print "$p is an interger\n"; } ~ On Tue, Mar 4, 2008 at 3:16 PM, <[EMAIL PROTECTED]> wrote: > Hi All, > > > > How to find out the specific variable contains integer value. In my > script ,variable is storing some value but I want to find out whethe

Re: variable module

2007-12-20 Thread Chas. Owens
On Dec 20, 2007 2:19 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: > Octavian Rasnita wrote: > > and I want to be able to choose the wanted module at runtime snip > Assuming that the path to the directory right above Questionnaire is > included in @INC, this should work: > > require "Quest

Re: variable module

2007-12-20 Thread Gunnar Hjalmarsson
Octavian Rasnita wrote: I have a directory named "Questionnaire" which contains some modules like "Files.pm", "MySQL.pm", and maybe others... and I want to be able to choose the wanted module at runtime, using a code like: my $module = "Files"; require Questionnaire::$module; my $obj = Ques

Re: variable module

2007-12-20 Thread John W . Krahn
On Thursday 20 December 2007 10:38, Octavian Rasnita wrote: > > Hello, Hello, > I have a directory named "Questionnaire" which contains some modules > like "Files.pm", "MySQL.pm", and maybe others... > > and I want to be able to choose the wanted module at runtime, using a > code like: > > my $mo

Re: variable module

2007-12-20 Thread Tom Phoenix
On 12/20/07, Octavian Rasnita <[EMAIL PROTECTED]> wrote: > I want to be able to choose the wanted module at runtime At runtime, or at compile time? You have to write your code with some additional care if it has to be compiled before the module is loaded. In any case, see the source for AnyDBM_F

Re: variable module

2007-12-20 Thread [EMAIL PROTECTED]
On Dec 20, 6:38 pm, [EMAIL PROTECTED] (Octavian Rasnita) wrote: > I have a directory named "Questionnaire" which contains some modules like > "Files.pm", "MySQL.pm", and maybe others... > > and I want to be able to choose the wanted module at runtime, using a code > like: > > my $module = "Files";

Re: Variable division, assignment and sprintf in one line

2007-11-29 Thread Jenda Krynicky
From: Steve Bertrand <[EMAIL PROTECTED]> > >> $var = sprintf ("%.2f", (($var /=1024) /=1024))) > > > > What the ...?!? > > > > /= ? > > It was an off the top of my head example of what I wanted to do. Without > being at the code at the time, I was simply thinking +=. If you want to divide somet

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Steve Bertrand
> $var = sprintf ("%.2f", $var / (1024*1024)); > > And it will be more efficient because the multiplication will be done > at compile time (once) and you'll only do a single division each > time. Which is also more precise, though in this case it doesn't seem > to matter. Oh, and furthermore,

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Steve Bertrand
>> $var = sprintf ("%.2f", (($var /=1024) /=1024))) > > What the ...?!? > > /= ? It was an off the top of my head example of what I wanted to do. Without being at the code at the time, I was simply thinking +=. > You divide the value of $var by 1024, assign it back to $var, divide > it by anot

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Jenda Krynicky
From: Steve Bertrand <[EMAIL PROTECTED]> > Hi again all, > > Is there a way that one can use sprintf on a variable and assign the > value back to the variable without having the leading $var= ? > > $var = sprintf ("%.2f", (($var /=1024) /=1024))) What the ...?!? /= ? You divi

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Steve Bertrand
Gunnar Hjalmarsson wrote: > Steve Bertrand wrote: >> Is there a way that one can use sprintf on a variable and assign the >> value back to the variable without having the leading $var= ? >> >> $var = sprintf ("%.2f", (($var /=1024) /=1024))) > > You can write a function. > > convert( $var );

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Gunnar Hjalmarsson
Steve Bertrand wrote: Is there a way that one can use sprintf on a variable and assign the value back to the variable without having the leading $var= ? $var = sprintf ("%.2f", (($var /=1024) /=1024))) You can write a function. convert( $var ); sub convert { $_[0] = sprintf '%.2f', $

Re: Variable division, assignment and sprintf in one line

2007-11-28 Thread Aaron Priven
On Nov 28, 2007, at 11:26 AM, Steve Bertrand wrote: Is there a way that one can use sprintf on a variable and assign the value back to the variable without having the leading $var= ? I don't think you can do it directly, but you can use the aliasing properties of sub or for: $a_really_long_

Re: Variable scope

2007-10-02 Thread Chas. Owens
On 10/2/07, Beginner <[EMAIL PROTECTED]> wrote: snip > > > $| = 1; > > I wasn't aware this only applied to STDOUT. My log messages all > appear at once, when the script has exited and I was hoping for some > 'realtime' messages. snip It applies to stdout because it is the currently selected fileh

Re: Variable scope

2007-10-02 Thread Chas. Owens
On 10/2/07, Bob McConnell <[EMAIL PROTECTED]> wrote: snip > > > > $| = 1; > > > > I wasn't aware this only applied to STDOUT. My log messages all > > appear at once, when the script has exited and I was hoping for some > > 'realtime' messages. > > It used to be possible to turn off buffering on sp

RE: Variable scope

2007-10-02 Thread Bob McConnell
> -Original Message- > From: Beginner [mailto:[EMAIL PROTECTED] > Sent: Tuesday, October 02, 2007 10:39 AM > To: perl beginners > Subject: Re: Variable scope > > On 2 Oct 2007 at 15:23, Rob Dixon wrote: > > > > > > > $| = 1; > > I

Re: Variable scope

2007-10-02 Thread Beginner
On 2 Oct 2007 at 15:23, Rob Dixon wrote: > Hi Dermot. You're a little confused, but you're not far out! Your being kind. > > > > $| = 1; I wasn't aware this only applied to STDOUT. My log messages all appear at once, when the script has exited and I was hoping for some 'realtime' messages.

Re: Variable scope

2007-10-02 Thread Tom Phoenix
On 10/2/07, Beginner <[EMAIL PROTECTED]> wrote: > Ideally I want to create the log file outside any sub routines so > that $log to be available to any sub I have created and hence not > scoped to any one sub routine. In other words, $log needs to be a global variable, so that it's available every

Re: Variable scope

2007-10-02 Thread Rob Dixon
Beginner wrote: I thought that the code snip below should work but I am not getting my text into the the file. The file is created but it's empty. Ideally I want to create the log file outside any sub routines so that $log to be available to any sub I have created and hence not scoped to an

Re: Variable $i count a lot numbers...

2007-09-02 Thread Ron Bergin
On Sep 1, 5:03 pm, [EMAIL PROTECTED] (Rodrigo Tavares) wrote: > Hello, > > I have a problem with a counter. > > #!/usr/bin/perl > > use strict; > use warnings; > > print "Write a number:"; > my $number= ; > > my @array; > my $div = $number * 2 ; > my $i=0; > > while ($div > 0) > { > $div = $div

Re: Variable $i count a lot numbers...

2007-09-02 Thread Chas Owens
On 9/1/07, Rodrigo Tavares <[EMAIL PROTECTED]> wrote: snip > Write a number:23 > Value i is : 1081 > 23 > 11.5 > 5.75 > 2.875 > 1.4375 > > Why did script show the value ? > > The counter must be six. snip Sounds like you want integer math rather than floating point math. In floating point math re

Re: Variable $i count a lot numbers...

2007-09-01 Thread Prosenjit Kundu
Rightly said by Gunnar. To see all the values stored in @array add: foreach (@array) { print "$_\n"; } On 9/2/07, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: > > Rodrigo Tavares wrote: > > Hello, > > > > I have a problem with a counter. > > > > #!/usr/bin/perl > > > > use strict; > > use warn

Re: Variable $i count a lot numbers...

2007-09-01 Thread Gunnar Hjalmarsson
Rodrigo Tavares wrote: Hello, I have a problem with a counter. #!/usr/bin/perl use strict; use warnings; print "Write a number:"; my $number= ; my @array; my $div = $number * 2 ; my $i=0; while ($div > 0) { $div = $div / 2; $array[$i]=$div; $i++; } print "Value i is: $i\n"; pr

Re: $/ variable trouble

2007-08-24 Thread Paul Lalli
On Aug 24, 1:12 pm, [EMAIL PROTECTED] (Yoyoyo Yoyoyoyo) wrote: > Hi all, > > I am using the diamond operator to redirect input to my perl script. I want > to copy all of the input on to a single variable using the following > subroutine: > > sub getfile # Copies the file redirected to this perl

Re: $/ variable trouble

2007-08-24 Thread Mr. Shawn H. Corey
Yoyoyo Yoyoyoyo wrote: Is there anyway to add the End of file marker to the variable before I print it, so I don't have to do ctrl-d? The control-D is part of the shell, not Perl. You didn't say so but from your message I assume that this did the trick. In other words, you are not redirecti

Re: $/ variable trouble

2007-08-24 Thread yitzle
On 8/24/07, Yoyoyo Yoyoyoyo <[EMAIL PROTECTED]> wrote: > Hi all, > > I am using the diamond operator to redirect input to my perl script. I want > to copy all of the input on to a single variable using the following > subroutine: > > sub getfile # Copies the file redirected to this perl script

Re: $/ variable trouble

2007-08-24 Thread Mr. Shawn H. Corey
Yoyoyo Yoyoyoyo wrote: Hi all, I am using the diamond operator to redirect input to my perl script. I want to copy all of the input on to a single variable using the following subroutine: sub getfile # Copies the file redirected to this perl script to the varialbe $x { my $x; local $/ =

RE: variable in cgi param

2007-07-23 Thread Moon, John
-Original Message- From: ubergoonz [mailto:[EMAIL PROTECTED] Sent: Monday, July 23, 2007 10:06 AM To: Perl Beginners Subject: variable in cgi param Hi, I am trying to parse a param in cgi script. basically how can i make use of a for loop to parse the variables, from the url http://som

Re: variable in cgi param

2007-07-23 Thread thomas polnik
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello, > for ($1=1; $i <= $cgi->param('totalkey') ; $i++) { $1 is not $i - If you would use 'use strict', you would find mistakes like this very easy :) > print "$i - $cgi->param('ip$i') cgi->param('hn$i') "; Please try: print "$i - " . $cgi->param('i

Re: variable in cgi param

2007-07-23 Thread jm
i have used this, just to display all param()s and verify the data being passed. i'm thinking someone showed me a newer version for looking at multiple values for checkboxes, etc. but i'm not sure and i don't have more recent code available to verify. hope this helps # foreach my

Re: Variable-sized hash of booleans

2005-02-05 Thread Randal L. Schwartz
> "Errin" == Errin M HMMA/IT Larsen <[EMAIL PROTECTED]> writes: Errin> And furthermore, I will assume that the values in the hash are boolean Errin> (i.e. '1' (ones) or '0' (zeros)). Now, I want to see if the WHOLE hash Errin> is true, this being defined as every key having a value of '1'.

Re: Variable-sized hash of booleans

2005-02-04 Thread John W. Krahn
Larsen, Errin M HMMA/IT wrote: Hi everyone, As always, we'll start with some necessary code: #!/usr/bin/perl use warnings; use strict; use Data::Dumper; Let's say I have a hash, but I don't know at compile time how many keys it has in it: my %things; die "You have

RE: Variable-sized hash of booleans

2005-02-04 Thread Larsen, Errin M HMMA/IT
> -Original Message- > From: Chris Charley [mailto:[EMAIL PROTECTED] > Sent: Friday, February 04, 2005 10:45 AM > To: beginners@perl.org > Subject: Re: Variable-sized hash of booleans > > > > You can use grep. > > > > my %hash = (ONE =>

RE: Variable-sized hash of booleans

2005-02-04 Thread Larsen, Errin M HMMA/IT
> -Original Message- > From: Chris Charley [mailto:[EMAIL PROTECTED] > Sent: Friday, February 04, 2005 10:21 AM > To: beginners@perl.org > Subject: Re: Variable-sized hash of booleans > > > You can use grep. > > my %hash = (ONE => 1, TWO => 0,

Re: Variable-sized hash of booleans

2005-02-04 Thread Chris Charley
You can use grep. my %hash = (ONE => 1, TWO => 0, THREE => 1); if (grep {! $hash{$_}} keys %hash) { print "false\n"; } else { print "true\n"; } Prints 'false'. Guess it would be helpful to explain how grep works here. From the perlfunc man page: Evaluates the BLOCK or EXPR for each element of LIST

Re: Variable-sized hash of booleans

2005-02-04 Thread Chris Charley
You can use grep. my %hash = (ONE => 1, TWO => 0, THREE => 1); if (grep {! $hash{$_}} keys %hash) { print "false\n"; } else { print "true\n"; } Prints 'false'. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

  1   2   3   >