Incrementing Strings
If I define a variable as a string my $var = a; I can get the increment to work print ++$var; -- prints b but the decrement print --$var -- prints -1 Why? and how can I decrement it? Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
comparing strings
Does anyone know a way to make boolean comparisons between strings? For example, I want 'a' 'b' to be true, but perl says 'a' == 'b' is true. Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
=
I have written some OO perl and I have a problem that I just realized, when you set an object = to another object, they become irreversibly linked and all operations on one or the other causes changes in both. If I am trying to simply initialize the object and not link them, how do I get around this problem? Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
RE: =
Isn't == a logical operator? I am not trying to compare the two objects. From: Sally [EMAIL PROTECTED] To: Nick Transier [EMAIL PROTECTED] Subject: RE: = Date: Thu, 21 Jun 2001 17:18:47 +0100 You should use == instead of = -Original Message- From: Nick Transier [mailto:[EMAIL PROTECTED]] Sent: 21 June 2001 17:09 To: [EMAIL PROTECTED] Subject: = I have written some OO perl and I have a problem that I just realized, when you set an object = to another object, they become irreversibly linked and all operations on one or the other causes changes in both. If I am trying to simply initialize the object and not link them, how do I get around this problem? Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Cloning
Ok, so I see the way around the = problem with cloning, however, there is a clone module on CPAN, but I have no idea how to install it using win2k. Any ideas? Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
PPM
Ok, I am running windows 2000, I have perl, but I do not know which distribution, I do not think that it is activestate's however. I searched by drive and found ppm in a folder in the perl folder, but there is no executable and I do not know how to run it at the dos command line. I have downloaded a tar file of the module I want, but there is no PPD or XML file like is described in the documentation for ppm. I do have a c compiler however. Please help. Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
PPM
Ok, so I was wrong, I do have ppm, but I have installed the package but it doesn't work. I installed the clone package available from Activstate, but when I say use clone in my program, it says the files are missing. What is this all about? -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
truncating
If I am generating a random number with the rand function, how can I truncate the resulting var to an integer? -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
$self def
Given this is my definition for self in some new constructor: sub new { $self { Next = @[Max_Level], } } First, is this the proper way to have Next be a reference to an annonymous array of size Max_Level? More importantly, how do you reference the elements in the array referenced by Next? Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Passing between Packages
I have two different packages that access each others methods. (where in my case one package is an element I have defined and the other package is an implementation of a list of those elements) When I call a method from package 1 with an object from package 2. the method in package 1 takes a $self var as the first parameter. This much I believe I understand...However, does that $self var then allow you to access all of the methods of it's originial package (2), or do have to make some sort of package definition? Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Re: $self def
So then would I access the nth element by @{$self-{Next}}[n] ?? From: [EMAIL PROTECTED] (Randal L. Schwartz) To: Nick Transier [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: $self def Date: 20 Jun 2001 09:29:41 -0700 Nick == Nick Transier [EMAIL PROTECTED] writes: Nick Given this is my definition for self in some new constructor: Nick sub new { Nick$self { Nick Next = @[Max_Level], Nick} Nick } Nick First, is this the proper way to have Next be a reference to an Nick annonymous array of size Max_Level? No need to predeclare a size. Stop thinking Java/Fortran/C/C++. Arrays have a size because people put things into them! Just let it start out empty, and push @{$self-{Next}}, $new each time you want to add one onto the end. Nick More importantly, how do you reference the elements in the array Nick referenced by Next? Just think of @{$self-{Next}} as an array: foreach my $item (@{$self-{Next}}) { $item is one of the items } -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! _ Get your FREE download of MSN Explorer at http://explorer.msn.com
RE: $self def
You are saying I cannot set the size of an array? I understand that you do not have to, but I need to in this case so that my iteration loops work correctly. From: John Edwards [EMAIL PROTECTED] To: 'Nick Transier' [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: RE: $self def Date: Wed, 20 Jun 2001 17:34:51 +0100 Are you trying to use a hash?? --- @myArray = qw(one two three four); new; sub new { $self{'Next'} = \@myArray; } print Element 0 is $self{'Next'}-[0]\n; --- You can't specifiy the size of the array, it's dynamic. Just enter your data into the array and it will change size accordingly. If you want a scalar reference to an array use this @myArray = qw(one two three four); $reference = \@myArray; print @{$reference}[0]; HTH John -Original Message- From: Nick Transier [mailto:[EMAIL PROTECTED]] Sent: 20 June 2001 17:22 To: [EMAIL PROTECTED] Subject: $self def Given this is my definition for self in some new constructor: sub new { $self { Next = @[Max_Level], } } First, is this the proper way to have Next be a reference to an annonymous array of size Max_Level? More importantly, how do you reference the elements in the array referenced by Next? Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Shell Program
I have written a module I want to test in a shell program, how do I load the module in another perl file to test the methods of the module's packages? -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
method calls outside the package
Ok, I have a package package blah; { sub foo { print I do not understand perl return 5; } } Now, how do I call this function from outside the package? I have written this: $perlversion = blah::-foo; but it doesn't work, it asks for explicit package name. Please help. -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Re: method calls outside the package
I tried that, same error. $perlversion requires explicit package name From: Jeff 'japhy' Pinyan [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: Nick Transier [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: method calls outside the package Date: Wed, 20 Jun 2001 15:53:50 -0400 (EDT) On Jun 20, Nick Transier said: package blah; { sub foo { print I do not understand perl Missing a semicolon above... return 5; } } Now, how do I call this function from outside the package? blah::foo() will work. $perlversion = blah::-foo; That works too, but kinda kruftily. but it doesn't work, it asks for explicit package name. That's on your variable. You need to declare it. my $version = blah::foo(); -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun. Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/ Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/ Acacia Fraternity, Rensselaer Chapter. Brother #734 ** Manning Publications, Co, is publishing my Perl Regex book ** _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Self Def
Given that I am trying to define an object attribute which is an array of references to other object of the same type, how do I define this in the $self portion of my sub new constructor? This is what I have, will this work? Next is meant to hold an array of pointers or references. sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = { Next, @_, }; return bless $self,$class; } thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Re: Self Def
The thing is, I want to set the array reference later and not when the object is being created. From: [EMAIL PROTECTED] (Randal L. Schwartz) To: Nick Transier [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: Self Def Date: 19 Jun 2001 14:12:13 -0700 Nick == Nick Transier [EMAIL PROTECTED] writes: Nick Given that I am trying to define an object attribute which is an array Nick of references to other object of the same type, how do I define this Nick in the $self portion of my sub new constructor? This is what I have, Nick will this work? Next is meant to hold an array of pointers or Nick references. Nick sub new { Nick my $invocant = shift; Nick my $class = ref($invocant) || $invocant; Nick my $self = { Nick Next, Nick @_, Nick }; Nick return bless $self,$class; Nick } You need an array ref there, not an array. Simplest would be a shallow copy of the invocation list. sub new { my $class = shift; # do NOT use the ref() garbage, please my $self = { Next = [@_] }; bless $self, $class; } You might be able to get away with \@_ in place of [@_], but I know this is safer. :) See perldoc perlboot for more details. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! _ Get your FREE download of MSN Explorer at http://explorer.msn.com
scope
If I define a function just in the freespace of a file and have included in that file two packages which are bracketed in like: sub function {} package 1; {} package 2; {} How do I access the function (make a function call) from within one of the packages? is it main::function or is it something else. Also, is it ok to call functions which take no parameters as just the function name. like $var = function; as opposed to $var = function(); Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Sub Calls
Assuming I am defining an object which has as its only property a level associated with it, would these be the correct simple subroutines to retrieve and set that property. Also, is this the correct usage of the @_ array such that the level value would be 999 unless I called new(Level = something else) sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = { Level = 999, @_, }; return bless $self,$class; } sub getlevel { return $$self{Level}; } sub setlevel { $$self{Level} = shift(@_); } _ Get your FREE download of MSN Explorer at http://explorer.msn.com
class stuff
Given this function to create a new class object: sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = { Level = 999, #values Value = 999, Key = 999, @Next, #array of pointers to next elements @_, }; return bless $self,$class; } Can you define an array of pointers (@Next) and leave it with nothing in it at declaration? If so - Is this the proper way to access a class object's Next array at the $level'th level? $self-{Next[$level]} thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com
more class stuff
given this new function which acts as a constructor sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = { Level = 999, Value = 999, Key = 999, @Next, @_, }; return bless $self,$class; } I am getting the following error: Global symbol @Next requires explicit package name at c:\ What does this mean? _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Re: more class stuff
@Next will become a class (or package) variable, but it is not set yet because I have another function which does that after the object is created. It is meant to be an array of pointers or references I guess. Is there anything I can do to quell the error messages without wrongly initializing the var? From: Chas Owens [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: more class stuff Date: 18 Jun 2001 17:57:14 -0400 On 18 Jun 2001 16:42:45 -0500, Nick Transier wrote: given this new function which acts as a constructor sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = { Level = 999, Value = 999, Key = 999, @Next, @_, }; return bless $self,$class; } I am getting the following error: Global symbol @Next requires explicit package name at c:\ What does this mean? snip / It means you are using strict and it is warning you that you have not created @Next. Where is @Next comming from? Is it a class variable? -- Today is Prickle-Prickle, the 23rd day of Confusion in the YOLD 3167 All Hail Discordia! _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Packages
Do you have to end packages with any type of notation or command? I have written a module file with two packages in it, but I am having a hell of a time with miss-referenced or no reference vars in the file. Thanks, -Nick _ Get your FREE download of MSN Explorer at http://explorer.msn.com