Re: Trap undefined barewords in subroutines

2017-08-02 Thread Shawn H Corey
On Wed, 2 Aug 2017 18:48:43 + "Dyer, Dustin E. (KSC-VAH10)" wrote: > So is there something different I can do to cause an error when > provided files contain undefined barewords? Do you mean something like this? my $someVar = '[map {$_ - 250 * FT2M} 1,2,3,]'; #FT2M is undef eval $someVar;

Re: Trap undefined barewords in subroutines

2017-08-02 Thread Chas. Owens
;; }; my $result = eval $perl_code or do { print "The perl code:\n\n$perl_code\n\ndied with $@"; exit; }; print encode_json $return; On Wed, Aug 2, 2017 at 2:55 PM Dyer, Dustin E. (KSC-VAH10) < dustin.e.d...@nasa.gov> wrote: > How can I detect and/or error on undefined bareword

Trap undefined barewords in subroutines

2017-08-02 Thread Dyer, Dustin E. (KSC-VAH10)
How can I detect and/or error on undefined barewords in perl subroutines? I receive data files in perl, and I'd like to read them into Matlab. Some of the files contain barewords that I don't have an implementation for. When I process these files using the do command, the undefined

Re: postderef with subroutines

2017-05-11 Thread Shawn H Corey
On Thu, 11 May 2017 13:10:03 +0200 Luca Ferrari wrote: > Hi all, > according to the documentation the postderef for code blocks $ref->&* > and $ref->() have different meanings > > > While I can use the following: > > my $sub_ref

postderef with subroutines

2017-05-11 Thread Luca Ferrari
Hi all, according to the documentation the postderef for code blocks $ref->&* and $ref->() have different meanings While I can use the following: my $sub_ref = sub { say "Hello world: @_ !" }; $sub_ref->( 'and the camels go' ); &{

Re: accessing variables in subroutines

2013-06-28 Thread Shlomi Fish
Hi Lee, On Fri, 28 Jun 2013 15:15:27 +0200 lee wrote: > timothy adigun <2teezp...@gmail.com> writes: > > use strict; > use warnings; > > > sub test { > print $counter . "\n"; > } > > > my $counter = 0; > while($counter < 5) { >

Re: accessing variables in subroutines

2013-06-28 Thread lee
timothy adigun <2teezp...@gmail.com> writes: use strict; use warnings; sub test { print $counter . "\n"; } my $counter = 0; while($counter < 5) { test(); $counter++; } It says "Global symbol "$counter"

Re: accessing variables in subroutines

2013-06-27 Thread Dr.Ruud
On 27/06/2013 15:44, Shawn H Corey wrote: On Thu, 27 Jun 2013 15:07:58 +0200 "Dr.Ruud" wrote: On 27/06/2013 12:58, lee wrote: Ok, so perl has a totally broken design with variables :( No, your understanding is broken. Can you come back after you fixed it? That is rude. The reason this li

Re: accessing variables in subroutines

2013-06-27 Thread Andy Bach
On Thu, Jun 27, 2013 at 11:22 AM, Rob Dixon wrote: > Something like this may help you > > use strict; > use warnings; > > do_something({ title => 'TEST', value => 42 }); > > sub do_something { > my ($params) = @_; > print $params->{title}, "\n"; > do_something_el

Re: accessing variables in subroutines

2013-06-27 Thread Rob Dixon
design with variables :( What's the solution to this problem? I do not want to: + define the subroutines after the program + carry the needed variables all over the place as parameters to every function that might need it + declare the variables on top of the program because that increases

Re: accessing variables in subroutines

2013-06-27 Thread Brandon McCaig
and make sense of them. > I do not want to: > > > + define the subroutines after the program A common practice is to wrap the core of the program into a subroutine, much like is required by C or C++. For example, you might write a main subroutine and invoke that from the global

Re: accessing variables in subroutines

2013-06-27 Thread John SJ Anderson
> That is rude. The reason this list exists is to help people, not to > tell them to go away. No wonder Perl is not a popular language. Agreed. Dr. Ruud, that was uncalled for. You're not obligated to respond to posters, and if that's the best response you have, not responding would be a better ch

Re: accessing variables in subroutines

2013-06-27 Thread Shawn H Corey
On Thu, 27 Jun 2013 15:07:58 +0200 "Dr.Ruud" wrote: > On 27/06/2013 12:58, lee wrote: > > > Ok, so perl has a totally broken design with variables :( > > No, your understanding is broken. Can you come back after you fixed > it? > That is rude. The reason this list exists is to help people, no

Re: accessing variables in subroutines

2013-06-27 Thread timothy adigun
Hi, On 6/27/13, lee wrote: > Shlomi Fish writes: > >> Hi Lee, >> >> On Wed, 26 Jun 2013 10:18:44 +0200 >> lee wrote: >> >>> Hi, >>> >>> the following example doesn't compile: >>> >>> >>> use strict; >>> use warnings; >>> >>> >>> sub test { >>> print $counter . "\n"; >>> } >>> >>> >>> my $cou

Re: accessing variables in subroutines

2013-06-27 Thread Dr.Ruud
On 27/06/2013 12:58, lee wrote: Ok, so perl has a totally broken design with variables :( No, your understanding is broken. Can you come back after you fixed it? -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http:/

Re: accessing variables in subroutines

2013-06-27 Thread Shawn H Corey
On Thu, 27 Jun 2013 12:58:38 +0200 lee wrote: > Ok, so perl has a totally broken design with variables :( What's the > solution to this problem? The usual technique is to declare the configuration variables at the top, followed by the file-scoped variables. It is convention that these variable

Re: accessing variables in subroutines

2013-06-27 Thread lee
declared, so it is always available to the subroutine. There should be an error only for instances when the subroutine is called before $counter is declared. > For more information, see: > > * http://www.plover.com/FAQs/Namespaces.html Ok, so perl has a totally broken design with variables :( What

Re: accessing variables in subroutines

2013-06-26 Thread timothy adigun
Hi On 26 Jun 2013 09:49, "lee" wrote: > > Hi, > > the following example doesn't compile: > > > use strict; > use warnings; > > > sub test { > print $counter . "\n"; The variable $counter is not known here > } > > > my $counter = 0; > while($counter < 5) { > test(); > $counter++; > } >

Re: accessing variables in subroutines

2013-06-26 Thread Shlomi Fish
Hi Lee, On Wed, 26 Jun 2013 10:18:44 +0200 lee wrote: > Hi, > > the following example doesn't compile: > > > use strict; > use warnings; > > > sub test { > print $counter . "\n"; > } > > > my $counter = 0; > while($counter < 5) { > test(); > $counter++; > } > > > It says "Gl

Re: accessing variables in subroutines

2013-06-26 Thread bill pemberton
Scope? On Wednesday, June 26, 2013, lee wrote: > Hi, > > the following example doesn't compile: > > > use strict; > use warnings; > > > sub test { > print $counter . "\n"; > } > > > my $counter = 0; > while($counter < 5) { > test(); > $counter++; > } > > > It says "Global symbol "$cou

accessing variables in subroutines

2013-06-26 Thread lee
Hi, the following example doesn't compile: use strict; use warnings; sub test { print $counter . "\n"; } my $counter = 0; while($counter < 5) { test(); $counter++; } It says "Global symbol "$counter" requires explicit package name ...". When I put the subroutine after the 'whil

Re: nested subroutines

2013-03-02 Thread Chris Stinemetz
Sent from my iPhone On Mar 2, 2013, at 7:49 PM, "John W. Krahn" wrote: > Chris Stinemetz wrote: >> Thanks in advance. >> >> I have a subroutine inside another subroutine in a module I am tyring to >> put together. >> >> I would like to pass the value assigned to $srt in the while loop as the

Re: nested subroutines

2013-03-02 Thread John W. Krahn
Chris Stinemetz wrote: Thanks in advance. I have a subroutine inside another subroutine in a module I am tyring to put together. I would like to pass the value assigned to $srt in the while loop as the parameter for the session_attempts subroutine called withing the processPegs subroutine. The

nested subroutines

2013-03-02 Thread Chris Stinemetz
Thanks in advance. I have a subroutine inside another subroutine in a module I am tyring to put together. I would like to pass the value assigned to $srt in the while loop as the parameter for the session_attempts subroutine called withing the processPegs subroutine. The error I am getting is:

Re: subroutines only return once

2012-07-29 Thread lina
On Sun, Jul 29, 2012 at 11:19 PM, Andy Bach wrote: > On Sun, Jul 29, 2012 at 10:01 AM, lina wrote: >> Strangely, it only substituted once, but not for the later once. >> Thanks ahead for your suggestions, I don't know why, > > Not exactly sure what you're up to - but you only open fh1 once - so >

Re: subroutines only return once

2012-07-29 Thread Andy Bach
On Sun, Jul 29, 2012 at 10:01 AM, lina wrote: > Strangely, it only substituted once, but not for the later once. > Thanks ahead for your suggestions, I don't know why, Not exactly sure what you're up to - but you only open fh1 once - so the inner while in your sub is going to read until eof and c

subroutines only return once

2012-07-29 Thread lina
Hi, I have written something as following, my $template_file="template"; my $h_data_file="h_data"; open my $fh1, '<', $template_file; open my $fh2, '<', $h_data_file; while(<$fh2>){ my ($h11,$h21,$h22,$h33)=split ' ', $_; &substitute($h11,$h21,$h22,$h33); say $h11,$h21

Re: subroutines, my and parentheses

2011-11-01 Thread Jim Gibson
On 11/1/11 Tue Nov 1, 2011 12:02 PM, "rent0n" scribbled: > Hi all, > > Can somebody please explain what is the difference between: > > sub subroutine { > my $var = @_; > ... > return 1; > } > > and: > > sub subroutine { > my ($var) = @_; > ... > return 1; > } > > I think it's something rel

Re: subroutines, my and parentheses

2011-11-01 Thread Uri Guttman
On 11/01/2011 03:02 PM, rent0n wrote: Hi all, Can somebody please explain what is the difference between: sub subroutine { my $var = @_; that puts @_ in a scalar context which returns the number of elements in an array. ... return 1; } and: sub subroutine { my ($var) = @_; ... that puts

subroutines, my and parentheses

2011-11-01 Thread rent0n
Hi all, Can somebody please explain what is the difference between: sub subroutine { my $var = @_; ... return 1; } and: sub subroutine { my ($var) = @_; ... return 1; } I think it's something related to the context but I'm not completely sure.

Re: Naming subroutines WAS: special method name start with "_"

2011-04-28 Thread Uri Guttman
>>>>> "TL" == Tim Lewis writes: TL> What is considered to be the proper way of naming internal subroutines? TL> Example: TL> my_special_subroutine or mySpecialSubroutine again it is a convention but perl names (other than class names) are best done with

Re: Naming subroutines WAS: special method name start with "_"

2011-04-28 Thread Jeff Pang
2011/4/28 Tim Lewis : > What is considered to be the proper way of naming internal subroutines? > > Example: > my_special_subroutine or mySpecialSubroutine > neither. But it could be: _my_special_subroutine -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additio

Naming subroutines WAS: special method name start with "_"

2011-04-28 Thread Tim Lewis
What is considered to be the proper way of naming internal subroutines? Example: my_special_subroutine or mySpecialSubroutine -Original Message- From: Uri Guttman [mailto:u...@stemsystems.com] Sent: Thursday, April 28, 2011 12:50 AM To: Shawn H Corey Cc: beginners@perl.org Subject: Re

Re: Calling subroutines with the & sigil

2011-04-14 Thread Peter Scott
On Thu, 14 Apr 2011 08:49:45 -0700, sono-io wrote: > The only one I was concerned with was a sub called "if", Sounds like a great device for an obfuscated Perl contest entry. That's the only place I want to see it, though. >but it doesn't > look like it's a built-in function. How

Re: Calling subroutines with the & sigil

2011-04-14 Thread C.DeRykus
lsub >         I've also read where it's faster to call a sub like this: > &subroutine; > > than it is to call like this: > subroutine(); You may be thinking of recursive calls. From perlsub : Subroutines may be called recursively. If a subroutine is called

Re: Calling subroutines with the & sigil

2011-04-14 Thread sono-io
Thanks to both Peter Scott, and Brian Fraser (who wrote me off-list). Very informative. I'm cleaning up a very old script that uses the &subroutine construct and learning more Perl in the process. > If you're worried about the speed overhead of one vs the other then either > you are w

Re: Calling subroutines with the & sigil

2011-04-13 Thread Peter Scott
&subroutine; > > than it is to call like this: > subroutine(); > > Is this true? I searched but I can't find a good recent discussion of > this. What is the best (preferred) way to call subroutines today? It is better to call them as subroutine() provided

Calling subroutines with the & sigil

2011-04-13 Thread sono-io
but I can't find a good recent discussion of this. What is the best (preferred) way to call subroutines today? Thanks, Marc -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: parse arguments passed to subroutines

2011-01-30 Thread Jim Green
this will work, Thank you! On 30 January 2011 22:00, wrote: > Jim Green writes: >> >> Hello, >> I usually use my ($arg1, $arg2) = @_; >> to get the arguments parsed to a subroutine. >> I want this to be smarter. Sometimes I want to pass $start, $end to >> the sub, sometimes I want to pass $start

Re: parse arguments passed to subroutines

2011-01-30 Thread pyh
Jim Green writes: Hello, I usually use my ($arg1, $arg2) = @_; to get the arguments parsed to a subroutine. I want this to be smarter. Sometimes I want to pass $start, $end to the sub, sometimes I want to pass $start, $count to the sub. but in this case my ($arg1, $arg2) = @_; will get co

parse arguments passed to subroutines

2011-01-30 Thread Jim Green
Hello, I usually use my ($arg1, $arg2) = @_; to get the arguments parsed to a subroutine. I want this to be smarter. Sometimes I want to pass $start, $end to the sub, sometimes I want to pass $start, $count to the sub. but in this case my ($arg1, $arg2) = @_; will get confused, it doesn't know i

Re: Perl: Subroutines and use of the "GD::Graph::bars;" Module

2010-04-11 Thread alekto
Hi! I did what you told me, but I just gets this error msg in return when I am trying to execute the script: Invalid data set: 0 at ./test.pl line 105, line 1. This error is referring to this line in my script: my $gd = $graph->plot($ydata) or die $graph->error; I seems like there is somethin

Re: Perl: Subroutines and use of the "GD::Graph::bars;" Module

2010-04-09 Thread alekto
Hi again, thank you for trying to help! I have been looking at the script once again, I could not really get your suggestion to work, but I have been doing some new changes thought. With this script I am pasting her, I manage to print the graph to a .png file, but the histogram does not show. Th

Re: Perl: Subroutines and use of the "GD::Graph::bars;" Module

2010-04-07 Thread alekto
Hi, Thanks for helping! The ting is that my age file only contain age values like this: 22 22 23 24 26 26 26 26 28 28 30 30, and I have no input for a second array! I want these age values to be the bars(x-values), and a want the number of times each of these are represented, to be the y-values.

Re: Perl: Subroutines and use of the "GD::Graph::bars;" Module

2010-04-07 Thread alekto
Hi guys! Tnx for answering! Of course it was the /misplacing of the \ that caused my error;) But after changing this error I still get an other error msg like this: Invalid data set: 1 at ./bars.pl line 90, line 1. which is referring to this line in my script: my $gd = $graph->plot(\...@array)

AW: Perl: Subroutines and use of the "GD::Graph::bars;" Module

2010-04-06 Thread Thomas Bätzler
alekto asked: > I manage to generate the array from the input file, but it seems like > there is something wrong with my subroutine at the end, I have been > using the examples at cpan.org as an templat for this subroutine. > Following is the error msg, as well as the complete script. > hostname$

Re: Perl: Subroutines and use of the "GD::Graph::bars;" Module

2010-04-06 Thread Jins Thomas
Hi alekto, My guess Main error is due to my $gd = $graph->plot(/@array) (Line 90) Did u meant \ (bless operator) instead of / . Same is being repeated in printHistogram(/@array Also hope last } was for printHistogram subroutine was copy paste problem while emailing. Other than that this looks

Perl: Subroutines and use of the "GD::Graph::bars;" Module

2010-04-06 Thread alekto
Hi, I got this scrip that is suppsed to use the use the Getopt::Std; and GD::Graph::bars; to input generate an array from a file (age). With this array, the GD::Graph::bars is going to create a subroutine printHistogram() which generates a png file based on a supplied array. The signature of th

RE: Subroutines With Multiple Parameters

2010-03-26 Thread Bob McConnell
From: Shlomi Fish [mailto:shlo...@iglu.org.il] > On Friday 26 Mar 2010 18:39:30 Shawn H Corey wrote: >> It's nice to be brief but only providing it does interfere with >> understanding. Remember: Hard to understand code is costly to >> maintain code. > > I don't believe in programming in an id

Re: Subroutines With Multiple Parameters

2010-03-26 Thread Shlomi Fish
Hi Shawn, On Friday 26 Mar 2010 18:39:30 Shawn H Corey wrote: > On Fri, 26 Mar 2010 16:06:04 +0300 > > Shlomi Fish wrote: > > One thing hackers like is brevity. > > I got a better idea. Let's assume that the person who maintains your > code is a recent graduate that doesn't have any experience

Re: Subroutines With Multiple Parameters

2010-03-26 Thread Shawn H Corey
On Fri, 26 Mar 2010 16:06:04 +0300 Shlomi Fish wrote: > One thing hackers like is brevity. I got a better idea. Let's assume that the person who maintains your code is a recent graduate that doesn't have any experience with Perl. How would he know that shift does two different things? It's nic

Re: Subroutines With Multiple Parameters

2010-03-26 Thread Shlomi Fish
Hi Shawn! On Thursday 25 Mar 2010 20:38:59 Shawn H Corey wrote: > On Thu, 25 Mar 2010 19:54:48 +0200 > > Shlomi Fish wrote: > > Well, this is a bike shed argument. I find using "shift;" instead of > > "shift(@_);" when inside subroutines to be f

Re: Subroutines With Multiple Parameters

2010-03-25 Thread Shawn H Corey
On Thu, 25 Mar 2010 19:54:48 +0200 Shlomi Fish wrote: > Well, this is a bike shed argument. I find using "shift;" instead of > "shift(@_);" when inside subroutines to be faster to write, more > concise and more idiomatic. shift has this magic for a reason. I'm

Re: Subroutines With Multiple Parameters

2010-03-25 Thread Shlomi Fish
gt; > Without the array, it's easy to forget what is being shifted. > Remember, things that behave differently should look different. Well, this is a bike shed argument. I find using "shift;" instead of "shift(@_);" when inside subroutines to be faster to write, m

Re: Subroutines With Multiple Parameters

2010-03-25 Thread Shawn H Corey
On Thu, 25 Mar 2010 17:13:53 +0200 Shlomi Fish wrote: > sub display_page > { > my $a_server = shift; > my $a_pass = shift; > . > . > . > } > }}} > > (shift is short for << shift(@_) >> ) If you're going to use shift, name the array. my $var; sub foo { $var = shi

Re: Subroutines With Multiple Parameters

2010-03-25 Thread Shlomi Fish
AM > To: Pry, Jeffrey > Subject: RE: Subroutines With Multiple Parameters > > Jeffery > > When you call your subroutine make sure you have the '&' in front of > your subroutine name: > > Like this > > &displayPage($servername, $password);

Re: Subroutines With Multiple Parameters

2010-03-25 Thread Damon Allen Davison
than some other options for a list of this length, but it's really up to you. By the way, calling subroutines with ampersand '&' is no longer recommended, mainly because it clutters up your code. And if you *do* actually want to use prototypes, then '&' cannot be u

Re: Subroutines With Multiple Parameters

2010-03-25 Thread Shawn H Corey
On Thu, 25 Mar 2010 09:54:13 -0400 "Pry, Jeffrey" wrote: > Hey, > > I have a subroutine > > sub displayPage($) { > > my($server) = shift; > print $server; > } > > Which I can call using displayPage("servername"); > > My question is lets say I wanted to pass a password

RE: Subroutines With Multiple Parameters

2010-03-25 Thread Pry, Jeffrey
That was exactly what I was looking for! Thank you so much! - Jeffrey Kevin Pry -Original Message- From: Gorrebeeck, Robert [mailto:gorrebeec...@cvty.com] Sent: Thursday, March 25, 2010 10:01 AM To: Pry, Jeffrey Subject: RE: Subroutines With Multiple Parameters Jeffery When you call

Subroutines With Multiple Parameters

2010-03-25 Thread Pry, Jeffrey
Hey, I have a subroutine sub displayPage($) { my($server) = shift; print $server; } Which I can call using displayPage("servername"); My question is lets say I wanted to pass a password as well. So I would like to call it as displayPage("servername","mypassword"); How

Re: On using $_ in subroutines

2009-07-29 Thread Bryan R Harris
> Bryan R Harris wrote: >>> Bryan Harris wrote: John W. Krahn wrote: > Bryan Harris wrote: >> ... but by modifying $_ I was clobbering $_ elsewhere in the larger >> program! > Yes because $_ is a special global variable. This effect is called > "action at a distance" whic

Re: On using $_ in subroutines

2009-07-28 Thread Chas. Owens
On Tue, Jul 28, 2009 at 16:12, Chas. Owens wrote: snip > I actually find the new style annoying.  The floating toolbar obscures > part of the doc, especially when you use a target like > #Temporary-Values-via-local(). snip Note, you can fix this behavior by going to http://perldoc.perl.org/prefere

Re: On using $_ in subroutines

2009-07-28 Thread Chas. Owens
is mostly used when the current value of a variable must be visible to called subroutines. snip > That feels like a really bad idea for me, though, since I'm writing scripts > where my primary goal is portability.  Having my own compiled copy seems > like a recipe for disaster if

Re: On using $_ in subroutines

2009-07-28 Thread Chas. Owens
On Tue, Jul 28, 2009 at 15:50, John W. Krahn wrote: snip > local() only works on variables that are in the symbol table, in other words > package variables.  All variables that are a single puntuation character are > package variables and some are global and effect all packages.  local() does > not

Re: On using $_ in subroutines

2009-07-28 Thread John W. Krahn
Bryan R Harris wrote: Bryan Harris wrote: John W. Krahn wrote: Bryan Harris wrote: ... but by modifying $_ I was clobbering $_ elsewhere in the larger program! Yes because $_ is a special global variable. This effect is called "action at a distance" which is why it is better to use named lex

Re: On using $_ in subroutines

2009-07-28 Thread Shlomi Fish
On Tuesday 28 July 2009 20:06:34 Bryan R Harris wrote: > > Bryan Harris wrote: > >> John W. Krahn wrote: > >>> Bryan Harris wrote: > ... but by modifying $_ I was clobbering $_ elsewhere in the larger > program! > >>> > >>> Yes because $_ is a special global variable. This effect is call

Re: On using $_ in subroutines

2009-07-28 Thread Shawn H. Corey
e are also dynamic, meaning that the new version of the variable will be used in all called subroutines, even if the subroutines are in another file or package. Makes sense. What happened to Perl 5.9? Odd numbered Perls are for development. If you really want to run one, you can but bugs

Re: On using $_ in subroutines

2009-07-28 Thread Bryan R Harris
> On Mon, Jul 27, 2009 at 09:49, Bryan Harris wrote: > snip >>> Yes because $_ is a special global variable.  This effect is called >>> "action at a distance" which is why it is better to use named lexically >>> scoped variables instead of $_. >> >> I have the Perl Bookshelf on CD (and perldoc,

Re: On using $_ in subroutines

2009-07-28 Thread Bryan R Harris
> Bryan Harris wrote: >> >> John W. Krahn wrote: >>> >>> Bryan Harris wrote: ... but by modifying $_ I was clobbering $_ elsewhere in the larger program! >>> Yes because $_ is a special global variable. This effect is called >>> "action at a distance" which is why it is better t

Re: On using $_ in subroutines

2009-07-28 Thread Chas. Owens
On Tue, Jul 28, 2009 at 11:05, John W. Krahn wrote: snip > Perl 5.10 is still at the .0 stage (5.10.0) and a lot of people like to wait > until software has progressed past the .0 phase. snip The good news is that 5.10.1RC1 looks like it will be released shortly, so 5.10.1 will be here soon. --

Re: On using $_ in subroutines

2009-07-28 Thread Shawn H. Corey
John W. Krahn wrote: Perl 5.10 is still at the .0 stage (5.10.0) and a lot of people like to wait until software has progressed past the .0 phase. Actually it has more to do with hate than like, as in, "I hate things that create more work for me." It ranks right up there beside, "I have

Re: On using $_ in subroutines

2009-07-28 Thread John W. Krahn
Bryan Harris wrote: John W. Krahn wrote: Bryan Harris wrote: ... but by modifying $_ I was clobbering $_ elsewhere in the larger program! Yes because $_ is a special global variable. This effect is called "action at a distance" which is why it is better to use named lexically scoped variab

Re: On using $_ in subroutines

2009-07-28 Thread Chas. Owens
On Mon, Jul 27, 2009 at 09:49, Bryan Harris wrote: snip >> Yes because $_ is a special global variable.  This effect is called >> "action at a distance" which is why it is better to use named lexically >> scoped variables instead of $_. > > I have the Perl Bookshelf on CD (and perldoc, obviously) -

Re: On using $_ in subroutines

2009-07-28 Thread Bryan Harris
>> For example, my temptation was to do this: >> >> ** >> sub isDate { >> >> $_ = shift; >> if (m!\d{2}/\d{2}/\d{2}!) { return 1; } >> else { return 0; } >> >> >> } > > Why is this in a subroutine at all? If you are using it like: [stuff cut

Re: On using $_ in subroutines

2009-07-26 Thread Chas. Owens
On Sun, Jul 26, 2009 at 17:59, John W. Krahn wrote: > Bryan Harris wrote: snip >> Oddly, perl won't let me do "my ($_) = shift;", so I'm stuck having to use >> another variable. > > Perl 5.10 *will* let you do "my $_". snip Be warned that you may reveal bugs if you use make $_ lexical: #!/usr/bin

Re: On using $_ in subroutines

2009-07-26 Thread John W. Krahn
Bryan Harris wrote: Is it not possible to use $_ in subroutines? Yes it is, just not the way you seem to want to use it. For example, my temptation was to do this: ** sub isDate { $_ = shift; if (m!\d{2}/\d{2}/\d{2}!) { return 1; } else

Re: On using $_ in subroutines

2009-07-26 Thread Shawn H. Corey
Bryan Harris wrote: ... but by modifying $_ I was clobbering $_ elsewhere in the larger program! Oddly, perl won't let me do "my ($_) = shift;", so I'm stuck having to use another variable. Why can't we do that? Is using $_ in subroutines discouraged?? The us

On using $_ in subroutines

2009-07-26 Thread Bryan Harris
Is it not possible to use $_ in subroutines? For example, my temptation was to do this: ** sub isDate { $_ = shift; if (m!\d{2}/\d{2}/\d{2}!) { return 1; } else { return 0; } } ** ... but by modifying $_ I

Re: local and my in subroutines

2009-02-23 Thread John W. Krahn
Karyn Stump wrote: I am trying to learn subroutines. I have seen refernces to using my and local for passing variables so I am playing with them to try to understand better how this all works. http://perl.plover.com/FAQs/Namespaces.html There is also some information in: perldoc perlsub

Re: local and my in subroutines

2009-02-23 Thread Karyn Stump
At 05:09 PM 2/23/09 -0800, Jim Gibson wrote: >On 2/23/09 Mon Feb 23, 2009 4:30 PM, "Karyn Stump" >scribbled: > >> I am trying to learn subroutines. I have seen refernces to using my and >> local for passing variables so I am playing with them to try to understa

Re: local and my in subroutines

2009-02-23 Thread Gunnar Hjalmarsson
Karyn Stump wrote: I am trying to learn subroutines. I have seen refernces to using my and local for passing variables You seem to be dealing with named variables within subroutines, not passing them. Global symbol "$name" requires explicit package name at ./user-sub.p

Re: local and my in subroutines

2009-02-23 Thread Karyn Stump
At 04:30 PM 2/23/09 -0800, Karyn Stump wrote: >I am trying to learn subroutines. I have seen refernces to using my and >local for passing variables so I am playing with them to try to understand >better how this all works. > >I have a subroutine in the script below, printsub that

Re: local and my in subroutines

2009-02-23 Thread Jim Gibson
On 2/23/09 Mon Feb 23, 2009 4:30 PM, "Karyn Stump" scribbled: > I am trying to learn subroutines. I have seen refernces to using my and > local for passing variables so I am playing with them to try to understand > better how this all works. Neither 'local' nor

local and my in subroutines

2009-02-23 Thread Karyn Stump
I am trying to learn subroutines. I have seen refernces to using my and local for passing variables so I am playing with them to try to understand better how this all works. I have a subroutine in the script below, printsub that errors when it is run with Global symbol "$name"

Re: help with subroutines and reading/writing to file

2008-12-02 Thread Jim Hill
blake in <[EMAIL PROTECTED]>: > I am new to perl and attempting to write a script that will do a reverse dns > lookup on an ip [snip] Just looking that far, I don't think your script will work as you intend. Here's a ptr lookup using dig ... | dig -x 217.151.101.100 | 100.101.151.217.in-addr.ar

Re: help with subroutines and reading/writing to file

2008-12-01 Thread Telemachus
On Mon Dec 01 2008 @ 7:13, blake askew wrote: > Thanks for the help John. I have made the changes you suggested and managed > to get everything working properly. One more question though that is > completely different, how do I allow users to specify switches on the > command line in any order to

Re: help with subroutines and reading/writing to file

2008-12-01 Thread blake askew
print ("Creating results file $ip-results.txt\n"); >> #call file creation subroutine >> #&createfile; >> >> print ("Attempting reverse DNS lookup\n"); >> # call reverse DNS lookup subroutine >> &reversedns; >> > > Th

Re: help with subroutines and reading/writing to file

2008-11-30 Thread John W. Krahn
\n"); # call reverse DNS lookup subroutine &reversedns; The proper form for calling a subroutine in perl is: reversedns(); print ("Attempting whois lookup\n"); #call whois subroutine &whois; print ("Program executed successfully"); # --

help with subroutines and reading/writing to file

2008-11-30 Thread blake askew
kup\n"); #call whois subroutine &whois; print ("Program executed successfully"); # -subroutines-- # create file subroutine sub createfile { # opens the -results.txt file to write the resuls to. Prints error message

Re: [Oc-pm] need help with subroutines & funtion

2008-09-08 Thread Ben Tilly
On Mon, Sep 8, 2008 at 3:04 AM, Raul Ruiz Jr. <[EMAIL PROTECTED]> wrote: > I am taking an online ceu course in scripting with Unix. I have been stumped > by this project. Can anyone out there help me out a bit. I created a script > at the bottom and it does not quite work. What am I missing? > I kn

Re: need help with subroutines & funtions

2008-09-08 Thread John W. Krahn
Raul Ruiz Jr. wrote: I am taking an online ceu course in scripting with Unix. I have been stumped by this project. Can anyone out there help me out a bit. I created a script at the bottom and it does not quite work. What am I missing? perldoc -q "How do I do .anything.?" I know I am missing

Re: need help with subroutines & funtion

2008-09-08 Thread Jeff Pang
2008/9/8 Raul Ruiz Jr. <[EMAIL PROTECTED]>: > I am taking an online ceu course in scripting with Unix. I have been stumped > by this project. Can anyone out there help me out a bit. I created a script > at the bottom and it does not quite work. What am I missing? Hello, Please always 'use stri

need help with subroutines & funtions

2008-09-08 Thread Raul Ruiz Jr.
I am taking an online ceu course in scripting with Unix. I have been stumped by this project. Can anyone out there help me out a bit. I created a script at the bottom and it does not quite work. What am I missing?  I know I am missing some thing but this is my first time working with perl. I kno

Re: return sorted hashes from subroutines

2008-08-29 Thread Rob Dixon
Rob Dixon wrote: > > You can pass single hashes to and from subroutines as a simple list. So you > successfully passed in %db_del, for instance, but if you need to keep two or > more hashes separate you must pass them by reference. I should also have mentioned that a hash won'

Re: return sorted hashes from subroutines

2008-08-29 Thread Rob Dixon
8 > B6 9 > what i need is to get for each (non redundant) value from column 1, the > corresponding non redundant values from column 2 and 3. e.g: > For A (col 1), I want 5 -10, 5-11 and 6-8. For B: 5-8 and 6-9. > I wrote a script to get rid of the redundant values

Re: return sorted hashes from subroutines

2008-08-29 Thread Amit Saxena
. > I wrote a script to get rid of the redundant values using hashes and > subroutines and it worked. However I still need to compare the elements > from > col2 and col3 with other values. To do this I want to sort the data, but I > am struggling to sort the hash. It prints what I want b

Re: return sorted hashes from subroutines

2008-08-29 Thread Xavier Mas
ript to get rid of the redundant values using hashes and > subroutines and it worked. However I still need to compare the elements > from col2 and col3 with other values. To do this I want to sort the data, > but I am struggling to sort the hash. It prints what I want but only if ask > it to

Re:return sorted hashes from subroutines

2008-08-29 Thread Jeff Pang
> Message du 29/08/08 13:41 > De : "Pedro Soto" > A : beginners@perl.org > Copie à : > Objet : return sorted hashes from subroutines > > I do not know how to return a hash > with the sorted values. Hi, You could simply say "return %hash" to return

return sorted hashes from subroutines

2008-08-29 Thread Pedro Soto
) value from column 1, the corresponding non redundant values from column 2 and 3. e.g: For A (col 1), I want 5 -10, 5-11 and 6-8. For B: 5-8 and 6-9. I wrote a script to get rid of the redundant values using hashes and subroutines and it worked. However I still need to compare the elements from

Re: How do I access module subroutines?

2008-04-09 Thread Jonathan Mast
ast wrote: > > I know this seems to be a very basic question, but I cannot figure out > how > > to access a modules subroutines. > > > > We a module named FOO::BAR in which we access some hashes using this > form: > > $FOO::BAR::hash1 > > and it works fine. >

  1   2   3   4   >