Re: reading text data to variable

2018-12-28 Thread Jim Gibson
again. > On Dec 26, 2018, at 9:40 AM, Eldon DeHart wrote: > > I can't figure out how to read each line of text back into my program and > assign it to the variable again. > Thanks for help in advance. > Eldon > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.

Re: reading text data to variable

2018-12-28 Thread Uri Guttman
On 12/26/18 12:40 PM, Eldon DeHart wrote: I can't figure out how to read each line of text back into my program and assign it to the variable again. Thanks for help in advance. Eldon please show us the code you have and then we can better help guide you. also read the FAQ as that is l

reading text data to variable

2018-12-28 Thread Eldon DeHart
I can't figure out how to read each line of text back into my program and assign it to the variable again. Thanks for help in advance. Eldon wbws.pl Description: Perl program -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@per

Re: Declaring and conditionally assigning to a variable on the same line

2017-02-15 Thread SSC_perl
> On Feb 15, 2017, at 11:08 AM, Uri Guttman wrote: > > try the even simpler and cleaner use of || > my $show_ref = delete $log{'show_ref'} || 'no’; Uri, After I had sent in my question, I began wondering if exists was even necessary, so I experimented with the || solution and it worked

Re: Declaring and conditionally assigning to a variable on the same line

2017-02-15 Thread Uri Guttman
't exist. and also the big issue with that code is the conditionally modified assignment with a declaration. the infamous worst example was my $x = 1 if 0;. that would create a static variable in scope. that is very nasty and supplanted by the state declaration. but what about this? m

Declaring and conditionally assigning to a variable on the same line

2017-02-15 Thread SSC_perl
I’ve read where writing a one-liner like this is frowned upon: my $show_ref = delete $log{'show_ref'} if (exists $log{'show_ref'}); but what about this? my $show_ref = exists $log{'show_ref'} ? delete $log{'show_ref'} : 'no’; They both seem to work without a problem in my tests.

Re: Using regular expressions to populate a variable?

2015-01-18 Thread Charles DeRykus
On Sun, Jan 18, 2015 at 9:28 AM, Jim Gibson wrote: > >> On Jan 18, 2015, at 9:03 AM, Mike wrote: >> >> I was able to find match extraction in the perldoc. >> >> Here is a snippet of what I have. >> >> my $insult = ( $mech->text =~ m/Insulter\ (.*)\ Taken/ ); >> print "$insult\n"; >> >> But $insul

Re: Using regular expressions to populate a variable?

2015-01-18 Thread Mike
Thanks. This worked. On 1/18/15 12:28 PM, Jim Gibson wrote: On Jan 18, 2015, at 9:03 AM, Mike wrote: I was able to find match extraction in the perldoc. Here is a snippet of what I have. my $insult = ( $mech->text =~ m/Insulter\ (.*)\ Taken/ ); print "$insult\n"; But $insult is being popula

Re: Using regular expressions to populate a variable?

2015-01-18 Thread Jim Gibson
> On Jan 18, 2015, at 9:03 AM, Mike wrote: > > I was able to find match extraction in the perldoc. > > Here is a snippet of what I have. > > my $insult = ( $mech->text =~ m/Insulter\ (.*)\ Taken/ ); > print "$insult\n"; > > But $insult is being populated with: 1 > > It should be populated wi

Re: Using regular expressions to populate a variable?

2015-01-18 Thread Mike
ong here? Thanks. On 1/18/15 11:49 AM, Mike wrote: Hey everyone, I'm trying to find information on how I can use regular expressions to populate a variable. I want to pull text between one set of characters and another set of characters and use that to populate my variable. Can anyone

Re: Using regular expressions to populate a variable?

2015-01-18 Thread Shawn H Corey
On Sun, 18 Jan 2015 11:49:11 -0500 Mike wrote: > Hey everyone, I'm trying to find information on how I can use regular > expressions to populate a variable. > > I want to pull text between one set of characters and another set of > characters and use that to populate my

Using regular expressions to populate a variable?

2015-01-18 Thread Mike
Hey everyone, I'm trying to find information on how I can use regular expressions to populate a variable. I want to pull text between one set of characters and another set of characters and use that to populate my variable. Can anyone point me in the right direction? Thanks.

Re: share a variable between files

2014-10-09 Thread Shawn H Corey
On Wed, 8 Oct 2014 21:36:06 +0200 Hans Ginzel wrote: > I want to use one global hash variable for options or configuration > variables like verbose, debug. I don't want to pass them to each > function or to almost each object. package main; our %Opts = ( verbose =>

Re: share a variable between files

2014-10-09 Thread Hans Ginzel
On Thu, Oct 09, 2014 at 03:50:02AM +1300, Kent Fredric wrote: First, what are you trying to acheive. Global variables are rarely a good idea, as is sharing variables between files. So the question is, why are you trying to share a variable between files using globals? My suggestion

Re: share a variable between files

2014-10-08 Thread Kent Fredric
On 9 October 2014 08:36, Hans Ginzel wrote: > I want to use one global hash variable for options or configuration > variables > like verbose, debug. I don't want to pass them to each function > or to almost each object. > Indeed, Jim Gibson explains you can simply declare

Re: share a variable between files

2014-10-08 Thread Jim Gibson
The ‘our’ statement associates a simple name with a package global variable in the current package. Therefore, if you want to make $var in file b.pl mean the package global variable $var in package a ($a:var), just put ‘our $var;’ after the ‘package a;’ statement in file b.pl (see below). On

Re: share a variable between files

2014-10-08 Thread Kent Fredric
re 'b.pl'; > package a; > warn "var=$var"; > > How to get rid of "no strict qw/vars/;" to not get message "Global symbol > "$var" requires explicit package name at b.pl", please? There is a package > specification ("package a;&q

share a variable between files

2014-10-08 Thread Hans Ginzel
ot get message "Global symbol "$var" requires explicit package name at b.pl", please? There is a package specification ("package a;") in the b.pl file. Generally, I want to add a key to a global class hash variable (%opt) declared with our in a class module from an

Re: Search and replace trouble with a variable

2014-02-01 Thread Shlomi Fish
Hi Omega, On Sat, 1 Feb 2014 11:36:20 -0500 Omega -1911 <1911...@gmail.com> wrote: > Good advice Shlomi. Thank you again. I should have caught that with fresh > eyes! You're welcome! ☺ Regards, Shlomi Fish -- - Shlomi Fis

Re: Search and replace trouble with a variable

2014-02-01 Thread Omega -1911
look like: $sql = "SELECT > * > > FROM ".$database_prefix."_bs_services"; > > > > I have tried a variety of Perl examples including the the code below, but > > it gives an error. > > > > $_ =~ s/bs_/".$database_prefix."_bs/g;

Re: Search and replace trouble with a variable

2014-02-01 Thread Shlomi Fish
ried a variety of Perl examples including the the code below, but > it gives an error. > > $_ =~ s/bs_/".$database_prefix."_bs/g; > It appears that the right hand side of the s/// operation will try to interpolate «$database_prefix» as a variable. What you need is to escape th

Re: Search and replace trouble with a variable

2014-02-01 Thread Hal Wigoda
What error? (Sent from iPhone, so please accept my apologies in advance for any spelling or grammatical errors.) > On Feb 1, 2014, at 2:40 AM, Omega -1911 <1911...@gmail.com> wrote: > > Hello List: I am trying to go through a folder of php scripts to add a > database prefix to lines that have

Search and replace trouble with a variable

2014-02-01 Thread Omega -1911
Hello List: I am trying to go through a folder of php scripts to add a database prefix to lines that have a select statement. Since the database prefix will differ, I am simply trying to add: ".$database_prefix." to those lines. For example, instead of the line looking like: $sql = "SELECT * FROM

Re: Identifying the current opened filehandle for writing as I'm getting undefined variable concatenation errors

2014-01-14 Thread Matt McAdory
while (@array2) { >> chomp; >> my $thing = $var->sub3($_); # returns a scalar >> print $FH "$thing\n"; >> # >> BOOM!?!? >> } >> } >> >> >>

Re: Identifying the current opened filehandle for writing as I'm getting undefined variable concatenation errors

2014-01-14 Thread Rob Dixon
ew stuff in another array, prints again to the module FH while (@array2) { chomp; my $thing = $var->sub3($_); # returns a scalar print $FH "$thing\n"; # BOOM!?!? } } the last print always

Re: Identifying the current opened filehandle for writing as I'm getting undefined variable concatenation errors

2014-01-14 Thread Brian Fraser
(@array2) { > chomp; > my $thing = $var->sub3($_); # returns a scalar > print $FH "$thing\n"; > ##### BOOM!?!? > } > } > > > > > the last print always give me a ". . . . concatenate (.)

Identifying the current opened filehandle for writing as I'm getting undefined variable concatenation errors

2014-01-14 Thread Matt McAdory
e module FH while (@array2) { chomp; my $thing = $var->sub3($_); # returns a scalar print $FH "$thing\n"; # BOOM!?!? } } the last print always give me a ". . . . concatenate (.) to undefined

Re: inserting a variable server name into code

2013-12-26 Thread Rick T
Many thanks to Andy Bach, Janek Schleicher, Diab Jerius, and David Precious for you helpful comments on my post. My problem is solved and, more importantly, I learned important stuff from all of you! Rick Triplett -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands,

Re: inserting a variable server name into code

2013-12-20 Thread Andy Bach
On Fri, Dec 20, 2013 at 1:46 AM, Janek Schleicher wrote: > * if you lookup perldoc use, > you'll see the use Module is equivalent to > BEGIN { require Module } > and the BEGIN blocks are run first of all. > And so, as it's really a code block, you can, if you want, define vars there BEGIN {

Re: inserting a variable server name into code

2013-12-20 Thread Janek Schleicher
over my head (I’m a beginner!), so I was hoping someone could explain a correct way to write this code if there is one. use is interpreted at first, while the normal my $var = 'xyz' declaration is interpreted at runtime. So when you use use, no variable beside other constants are

Re: inserting a variable server name into code

2013-12-20 Thread Diab Jerius
On Thu, 19 Dec 2013 12:27:09 -0600, Rick T wrote: > The following three lines are from a program that works fine for me. > > # Choose template file > use constant TMPL_FILE => > "/big/dom/xoldserver/www/templates/open_courses3.html"; my $tmpl = new > HTML::Template( filen

Re: inserting a variable server name into code

2013-12-19 Thread David Precious
id several variants I tried. What did the error say? If the above code is verbatim, it's because you missed the trailing semicolon after the variable definition - i.e.: my $server = "newserver"; -- David Precious ("bigpresh") http://www.preshweb.co.uk/ www.pres

inserting a variable server name into code

2013-12-19 Thread Rick T
The following three lines are from a program that works fine for me. # Choose template file use constant TMPL_FILE => "/big/dom/xoldserver/www/templates/open_courses3.html"; my $tmpl = new HTML::Template( filename => TMPL_FILE ); I wanted to make the program more portabl

Re: Using a function in a variable

2013-11-09 Thread Rob Dixon
On 09/11/2013 13:33, Unknown User wrote: I have a variable that has a function in it, e.g. my $newtime = "time() + 30"; How can i use it in code so that it always returns time() + 30 when it is called? Does it *have* to be in a string like this? Where has the string come

Re: Using a function in a variable

2013-11-09 Thread Shawn H Corey
On Sat, 9 Nov 2013 16:27:24 +0200 Shlomi Fish wrote: > #!/usr/bin/perl > > use strict; > use warnings; > > my $sub_ref = sub { return time() + 30 }; > > print "Sub-ref call is: ", scalar( $sub_ref->() ), "\n"; Why not just use a sub? sub time_delay { my $delay = shift @_; return tim

Re: Using a function in a variable

2013-11-09 Thread Shlomi Fish
Hi all, On Sat, 9 Nov 2013 08:45:42 -0500 Shawn H Corey wrote: > On Sat, 9 Nov 2013 19:03:00 +0530 > Unknown User wrote: > > > Hi, > > > > I have a variable that has a function in it, eg: my $newtime = > > "time() + 30"; > > How can i use

Re: Using a function in a variable

2013-11-09 Thread Shawn H Corey
On Sat, 9 Nov 2013 19:03:00 +0530 Unknown User wrote: > Hi, > > I have a variable that has a function in it, eg: my $newtime = > "time() + 30"; > How can i use it in code so that it always returns time() + 30 when > it is called? See `perldoc -f eval` Note that u

Using a function in a variable

2013-11-09 Thread Unknown User
Hi, I have a variable that has a function in it, eg: my $newtime = "time() + 30"; How can i use it in code so that it always returns time() + 30 when it is called?

Re: Problem setting $= (Format Lines Per Page Special Variable)

2013-11-07 Thread Shaji Kalidasan
o God. --- On Thursday, 7 November 2013 3:04 PM, Paul Johnson wrote: On Thu, Nov 07, 2013 at 11:44:27AM +0800, Shaji Kalidasan wrote: > Dear Perlers, > > I am facing problems while setting the $= special variable. Even > t

Re: Problem setting $= (Format Lines Per Page Special Variable)

2013-11-07 Thread Paul Johnson
On Thu, Nov 07, 2013 at 11:44:27AM +0800, Shaji Kalidasan wrote: > Dear Perlers, > > I am facing problems while setting the $= special variable. Even > though I set it to 10 it takes the default value which is 60. In line > number 31, I set the variable to a value of 10. It is n

Problem setting $= (Format Lines Per Page Special Variable)

2013-11-06 Thread Shaji Kalidasan
Dear Perlers, I am facing problems while setting the $= special variable. Even though I set it to 10 it takes the default value which is 60. In line number 31, I set the variable to a value of 10. It is not printing the page number for every 10 lines Please guide me where I am going wrong

Re: Please throw some light on $? variable

2013-10-23 Thread Shaji Kalidasan
o God. --- On Wednesday, 23 October 2013 7:50 PM, Jim Gibson wrote: On Oct 23, 2013, at 12:56 AM, Shaji Kalidasan wrote: > Dear Perlers > > Please throw some light on the $? variable > > I am trying to figure out how the internal structure (format) of $?

Re: Please throw some light on $? variable

2013-10-23 Thread Jim Gibson
On Oct 23, 2013, at 12:56 AM, Shaji Kalidasan wrote: > Dear Perlers > > Please throw some light on the $? variable > > I am trying to figure out how the internal structure (format) of $? variable. > Please throw some light on this topic. The content of $? is explained in th

Please throw some light on $? variable

2013-10-23 Thread Shaji Kalidasan
Dear Perlers Please throw some light on the $? variable I am trying to figure out how the internal structure (format) of $? variable. Please throw some light on this topic. Any help is highly appreciated. [code] system('cat file1.txt'); if($?) {#A Non zero exit code means failure i

Re: Can we use string as variable name

2013-04-30 Thread Charles DeRykus
> On Tue, Apr 30, 2013 at 10:07 AM, Piyush Verma <114piy...@gmail.com> > wrote: > Hi,I want to use string as a variable name, please explain if there is any way > in perl. > ... This is a FAQ. See: http://perldoc.perl.org/perlfaq7.html#How-can-I-use-a-variable-as-a-variabl

Re: Can we use string as variable name

2013-04-30 Thread Lawrence Statton
On 04/30/2013 12:07 PM, Piyush Verma wrote: Hi, I want to use string as a variable name, please explain if there is any way in perl. Yes, there is a way. It is almost always a better idea to NOT do it that way, but to refactor your code to not require using a string as a variable name

Can we use string as variable name

2013-04-30 Thread Piyush Verma
Hi, I want to use string as a variable name, please explain if there is any way in perl. Please have a look on below cases, I want to implement case 2. e.g. Case 1: if I am using global varibale without strict module $var = "this"; $this = "realvalue&quo

Re: substitution: interpolate capture buffer into variable?

2012-12-26 Thread Charles DeRykus
On Wed, Dec 26, 2012 at 10:29 AM, Paul Johnson wrote: > On Wed, Dec 26, 2012 at 04:10:06PM +0100, gator...@yahoo.de wrote: >> Hi, >> >> I would like to store regular expressions and substitution strings in >> a hash variable. If a given string matches any of

Re: substitution: interpolate capture buffer into variable?

2012-12-26 Thread gator_ml
On 2012-12-26 19:29, Paul Johnson wrote: > This is a situation where string eval is warranted: > > eval "\$s =~ s/\$rx/$r/"; ... thanks a lot! Now that I now how it works, I can't believe I couldn't find the problem! I had tried string eval too; the real trick that I didn't get right is that t

Re: substitution: interpolate capture buffer into variable?

2012-12-26 Thread Paul Johnson
On Wed, Dec 26, 2012 at 04:10:06PM +0100, gator...@yahoo.de wrote: > Hi, > > I would like to store regular expressions and substitution strings in > a hash variable. If a given string matches any of the stored patterns, > the corresponding substitution should be applied. What or

Re: substitution: interpolate capture buffer into variable?

2012-12-26 Thread timothy adigun
Hi, Please, check my comments below: On Wed, Dec 26, 2012 at 4:10 PM, wrote: > Hi, > > I would like to store regular expressions and substitution strings in > a hash variable. If a given string matches any of the stored patterns, > the corresponding substitution should b

substitution: interpolate capture buffer into variable?

2012-12-26 Thread gator_ml
Hi, I would like to store regular expressions and substitution strings in a hash variable. If a given string matches any of the stored patterns, the corresponding substitution should be applied. What originally looked trivial turned out to be quite a challenge, particularly if the substitution

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 no

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 p

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

variable definition error not caught when using strict and warnings

2012-11-09 Thread Nemana, Satya
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 executes the code with a war

Re: writing a value from a variable in PDF::API2

2012-08-27 Thread Shlomi Fish
On Mon, 27 Aug 2012 08:11:12 -0400 Shawn H Corey wrote: > On Mon, 27 Aug 2012 17:18:10 +0700 > Eko Budiharto wrote: > > > my $endDate2 = $time{'dd-mm-', time + 86400 * 14}; > > my $startDate2 = $time{'dd-mm-', time - 86400 * 0}; > > Where is the hash %time assigned its values? > > F

Re: writing a value from a variable in PDF::API2

2012-08-27 Thread Shawn H Corey
On Mon, 27 Aug 2012 17:18:10 +0700 Eko Budiharto wrote: > my $endDate2 = $time{'dd-mm-', time + 86400 * 14}; > my $startDate2 = $time{'dd-mm-', time - 86400 * 0}; Where is the hash %time assigned its values? -- Just my 0.0002 million dollars worth, Shawn Programming is as much

writing a value from a variable in PDF::API2

2012-08-27 Thread Eko Budiharto
dear members, I wrote a perl script to write a pdf file. I am stuck in writing a value from a variable. Please help. thanks in advance. Here is my script: #!/usr/local/bin/perl use CGI qw(:standard); use strict; use PDF::API2; my $endDate2 = $time{'dd-mm-', time + 86400

Re: how to set session variable (not session cookie) using perl CGI

2012-08-07 Thread Rajeev Prasad
Thank you Ron and David. - Original Message - From: Ron Bergin To: Rajeev Prasad Cc: perl list Sent: Tuesday, August 7, 2012 9:36 PM Subject: Re: how to set session variable (not session cookie) using perl CGI -- Rajeev Prasad wrote: > I am using CGI.pm on my website, bu

Re: how to set session variable (not session cookie) using perl CGI

2012-08-07 Thread Ron Bergin
-- Rajeev Prasad wrote: > I am using CGI.pm on my website, but I generate my pages using TT > (template Toolkit). >   > I have few questions: >   > 0. how to have a session variable (not a session cookie)? If I do not want > to use cookie, do i have to store session data in

Re: how to set session variable (not session cookie) using perl CGI

2012-08-07 Thread David Christensen
On 08/07/12 14:40, Rajeev Prasad wrote: I am using CGI.pm on my website, but I generate my pages using TT (template Toolkit). I have few questions: 0. how to have a session variable (not a session cookie)? If I do not want to use cookie, do i have to store session data in a temp file on server

how to set session variable (not session cookie) using perl CGI

2012-08-07 Thread Rajeev Prasad
I am using CGI.pm on my website, but I generate my pages using TT (template Toolkit).   I have few questions:   0. how to have a session variable (not a session cookie)? If I do not want to use cookie, do i have to store session data in a temp file on server and check it with each page load

Re: updating variable in Parent using Parallel::ForkManager

2012-08-01 Thread Dr.Ruud
$pm->wait_all_children; However the final value of count is not correct. Is there some race condition on same variable updation by the processes ? pm -> run_on_finish ( sub { my $result = @; if (def

Re: updating variable in Parent using Parallel::ForkManager

2012-07-30 Thread John W. Krahn
ing --- $pm->finish(0, \$result); } $pm->wait_all_children; However the final value of count is not correct. Is there some race condition on same variable updation by the processes ? Regards, Punit pm -> run_on_finish ( sub {

Re: updating variable in Parent using Parallel::ForkManager

2012-07-30 Thread Shlomi Fish
; > > > $pm->wait_all_children; > > > However the final value of count is not correct. Is there some race > condition on same variable updation by the processes ? > > Regards, > Punit > > > > pm -> run_on_finish ( > >

updating variable in Parent using Parallel::ForkManager

2012-07-30 Thread punit jain
result); } $pm->wait_all_children; However the final value of count is not correct. Is there some race condition on same variable updation by the processes ? Regards, Punit pm -> run_on_finish ( sub { my $result = @;

Re: Save contents of double-quotes to a variable?

2012-06-16 Thread Shawn H Corey
On 12-06-16 07:36 AM, John W. Krahn wrote: $ perl -le' my @strings = ( q/phrase1 "phrase2" phrase3/, q/"phrase2" phrase3/, q/phrase1 phrase3 phrase4/, ); for my $string ( @strings ) { # change from here my ( $phrase ) = $string =~ /"([^"]+)"/; print $phrase if $

Re: Save contents of double-quotes to a variable?

2012-06-16 Thread Shlomi Fish
Hi Grant, On Sat, 16 Jun 2012 03:22:58 -0700 Grant wrote: > Can anyone show me how to save to a variable the contents of a set of > double-quotes in a string? The string could look like any of these: > > phrase1 "phrase2" phrase3 > "phrase2" phrase3 >

Re: Save contents of double-quotes to a variable?

2012-06-16 Thread John W. Krahn
Grant wrote: Can anyone show me how to save to a variable the contents of a set of double-quotes in a string? The string could look like any of these: phrase1 "phrase2" phrase3 "phrase2" phrase3 phrase1 phrase3 phrase4 In all of these examples, phrase2 would be saved t

Save contents of double-quotes to a variable?

2012-06-16 Thread Grant
Can anyone show me how to save to a variable the contents of a set of double-quotes in a string? The string could look like any of these: phrase1 "phrase2" phrase3 "phrase2" phrase3 phrase1 phrase3 phrase4 In all of these examples, phrase2 would be saved to the variable. M

Re: ENV variable or others things

2012-04-27 Thread Zapp
$ddd # it always work! >> >> but in perl , how can I do like that ? >> >> I write a file ( my_env.pl ) like: >> #!/usr/bin/perl -w >> my $abc='abc'; >> my $ddd="ddd"; > `my` produces lexical variables which means they are scoped to the file.

Re: ENV variable or others things

2012-04-27 Thread Shawn H Corey
gt; > I write a file ( my_env.pl ) like: > #!/usr/bin/perl -w > my $abc='abc'; > my $ddd="ddd"; `my` produces lexical variables which means they are scoped to the file. These variable will not be accessible outside the file. Tey something like: use vars qw( $abc $

Re: ENV variable or others things

2012-04-27 Thread timothy adigun
Hi zapp, Please my comments below: 2012/4/27 Zapp > when I use bash, I can write a file ( a.sh ) like : > abc='abc' > ddd='aaa' > ... > then I can load it in other file: > source a.sh > echo $abc $ddd # it always work! > > but in perl , how can I do like that ? > > I write a file ( my_env.pl )

Re: ENV variable or others things

2012-04-27 Thread Zapp
t; >> >> do './my_env.pl' or die '$!\n"; >> print $abc $ddd; # and nothing happen >> >> why? anybody knows? Thanks! >> >> -- > >> print $abc $ddd; # and nothing happen > Are you sure that nothing happends? > It should have giv

Re: ENV variable or others things

2012-04-27 Thread Octavian Rasnita
why? anybody knows? Thanks! > > -- > print $abc $ddd; # and nothing happen Are you sure that nothing happends? It should have given an error like "requires explicit package name " for the variables which are not defined in your script if you use "use strict". A

ENV variable or others things

2012-04-27 Thread Zapp
when I use bash, I can write a file ( a.sh ) like : abc='abc' ddd='aaa' ... then I can load it in other file: source a.sh echo $abc $ddd # it always work! but in perl , how can I do like that ? I write a file ( my_env.pl ) like: #!/usr/bin/perl -w my $abc='abc'; my $ddd="ddd"; and in my.pl : #!/

Re: What is the $_ variable?

2011-12-30 Thread Shlomi Fish
Hello Harry, On Fri, 30 Dec 2011 10:03:30 -0800 (PST) Harry wrote: > I am confused what this variable does: $_ > > If someone could give an example or explanation of what this variable $_ does > in perl, that would be great! $_ is the default variable, which gets assigned to

What is the $_ variable?

2011-12-30 Thread Harry
I am confused what this variable does: $_ If someone could give an example or explanation of what this variable $_ does in perl, that would be great! Thanx. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http

Re: Assigning List variable when slicing a list.

2011-12-04 Thread Uri Guttman
On 12/03/2011 08:12 PM, John W. Krahn wrote: my @summer = ( qw| January February March April May June July August September October November December | )[ 0, 1, 2 ); my @winter = ( qw| January February March April May June July August September October November December | )[ 5, 6, 7 ); my @sum

Re: Assigning List variable when slicing a list.

2011-12-03 Thread Jim Gibson
s toes) Use printf: printf( "I am touching my %s and %s\n", (("heads ", "shoulders ", "knees ", "toes ")[$mone, $mtwo]) ); I tried to create a list variable and then return the output of the list interpolated but not getting expected re

Re: Assigning List variable when slicing a list.

2011-12-03 Thread John W. Krahn
printf " I am touching my %s and %s", ( "heads ", "shoulders ", "knees ", "toes " )[ $mone, $mtwo ]; I tried to create a list variable There is no such thing as a "list variable". and then return the output of the list interpolated but

Assigning List variable when slicing a list.

2011-12-03 Thread flebber
); print (("heads ", "shoulders ", "knees ", "toes ")[$mone, $mtwo]); print "\n"; which is fine but say I wanted the print result to be: " I am touching my shoulders and toes" rather than (shoulders toes) I tried to create a list variable

Re: Perl variable indirection

2011-11-05 Thread Shlomi Fish
're using $_[0] both as a string and as a reference. What are you trying to do? > > When the code is executed, I get an error > > *Can't use string ("some") as a SCALAR ref while "strict refs" * > > This is resolved using - *no strict 'r

Re: Perl variable indirection

2011-11-05 Thread Anneli Cuss
gt; > When the code is executed, I get an error > > *Can't use string ("some") as a SCALAR ref while "strict refs" * > > This is resolved using - *no strict 'refs*'; > > Do we need to always use the above while using Perl variable indirection > - ${$_[0]} > > Parag >

Perl variable indirection

2011-11-05 Thread Parag Kalra
); sleep 8; } When the code is executed, I get an error *Can't use string ("some") as a SCALAR ref while "strict refs" * This is resolved using - *no strict 'refs*'; Do we need to always use the above while using Perl variable indirection - ${$_[0]} Parag

Re: sub local variable changes global variable.

2011-10-17 Thread Rob Dixon
On 16/10/2011 00:08, JPH wrote: I am passin a two-dimensional array to a sub and when the sub returns, the original array has changed. Eventually I want to pass the array into a recursive sub, so I want to find a way to circumvent this behaviour. Notice how my global is "@a" and the sub local is

Re: sub local variable changes global variable.

2011-10-16 Thread Rob Dixon
On 16/10/2011 23:18, Rob Dixon wrote: On 16/10/2011 19:10, JPH wrote: Every pass I only change a single character, then I run some tests and so on. I wonder if it is possible to write your subroutine by using a single global array and remembering the change so that you can undo it before the

Re: sub local variable changes global variable.

2011-10-16 Thread Rob Dixon
On 16/10/2011 19:10, JPH wrote: On 10/16/2011 04:05 AM, Shawn H Corey wrote: On 11-10-15 07:44 PM, Rob Dixon wrote: sub try { my @b; foreach my $row (@_) { push @b, [@$row]; } : } Or you could use dclone() from Storable: use Storable qw( dclone ); sub try { my @b = @{ dclone( \@_ ) }; ..

Re: sub local variable changes global variable.

2011-10-16 Thread JPH
Thanks! My script seems to work with dclone. Though the (deep) recursion takes a lot of time ... What is your opinion, would it pay off (in performance) when I rewrite the script in such a way that I do not use dclone, but string manipulation routines instead? So: - passing a single dimension

Re: sub local variable changes global variable.

2011-10-16 Thread JPH
You got me there, John. Indeed I do expect it to contain ' ' and not 0 like I stated. If you originally assign " " to $a[ 0 ][ 1 ] why would you now expect it to contain 0? John -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.

Re: sub local variable changes global variable.

2011-10-15 Thread John W. Krahn
JPH wrote: Hi all, Hello, I am passin a two-dimensional array to a sub and when the sub returns, the original array has changed. Eventually I want to pass the array into a recursive sub, so I want to find a way to circumvent this behaviour. Notice how my global is "@a" and the sub local is "

Re: sub local variable changes global variable.

2011-10-15 Thread Shawn H Corey
On 11-10-15 07:44 PM, Rob Dixon wrote: sub try { my @b; foreach my $row (@_) { push @b, [@$row]; } : } Or you could use dclone() from Storable: use Storable qw( dclone ); sub try { my @b = @{ dclone( \@_ ) }; ... } Storable is a standard modul

Re: sub local variable changes global variable.

2011-10-15 Thread Rob Dixon
On 16/10/2011 00:08, JPH wrote: Hi all, I am passin a two-dimensional array to a sub and when the sub returns, the original array has changed. Eventually I want to pass the array into a recursive sub, so I want to find a way to circumvent this behaviour. Notice how my global is "@a" and the sub

Re: sub local variable changes global variable.

2011-10-15 Thread Paul Johnson
On Sun, Oct 16, 2011 at 01:08:19AM +0200, JPH wrote: > Hi all, > > I am passin a two-dimensional array to a sub and when the sub This is your main problem. Perl doesn't have two-dimensional arrays. What it does have is arrays of array references which, if you squint, can be used as two-dimensio

sub local variable changes global variable.

2011-10-15 Thread JPH
Hi all, I am passin a two-dimensional array to a sub and when the sub returns, the original array has changed. Eventually I want to pass the array into a recursive sub, so I want to find a way to circumvent this behaviour. Notice how my global is "@a" and the sub local is "@b" - Why is this hap

Re: Help, About Global variable.

2011-09-15 Thread Shawn H Corey
On 11-09-14 11:18 PM, Brandon McCaig wrote: Personally I agree that it's very sloppy to write without capitals. I find it sloppy for people whose first language is English not to do their best. Many readers of this list do not have English as a their first language and the best way to improv

Re: Help, About Global variable.

2011-09-14 Thread Uri Guttman
> "BM" == Brandon McCaig writes: BM> [1] I personally find it very petty when Uri mentions his work as a BM> Perl "recruitment agent" (for lack of a better description right now) BM> and implies that he'll never consider you as a potential candidate BM> with regards to that because of

Re: Help, About Global variable.

2011-09-14 Thread Brandon McCaig
they could be. you haven't addressed the scope of the > number of names out there. Rob did a very good job of describing this. The amount of detail required for a variable name is proportional to the scope that the variable is visible to. A two line subroutine usually does not require a 10

  1   2   3   4   5   6   7   8   9   10   >