[28191] in Perl-Users-Digest
Perl-Users Digest, Issue: 9555 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 3 11:10:17 2006
Date: Thu, 3 Aug 2006 08:10:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 3 Aug 2006 Volume: 10 Number: 9555
Today's topics:
Re: How probably not to hand over a variable from one p <jurgenex@hotmail.com>
Re: How probably not to hand over a variable from one p <youcontrol@hispeed.ch>
Re: How probably not to hand over a variable from one p <youcontrol@hispeed.ch>
Re: How probably not to hand over a variable from one p <mritty@gmail.com>
Re: How probably not to hand over a variable from one p <jurgenex@hotmail.com>
Re: How probably not to hand over a variable from one p <youcontrol@hispeed.ch>
Re: How probably not to hand over a variable from one p <mritty@gmail.com>
Re: How probably not to hand over a variable from one p <1usa@llenroc.ude.invalid>
Re: How probably not to hand over a variable from one p <1usa@llenroc.ude.invalid>
Re: How probably not to hand over a variable from one p <youcontrol@hispeed.ch>
Re: How probably not to hand over a variable from one p <jurgenex@hotmail.com>
Re: How probably not to hand over a variable from one p <jurgenex@hotmail.com>
Re: How probably not to hand over a variable from one p <1usa@llenroc.ude.invalid>
Re: How probably not to hand over a variable from one p <youcontrol@hispeed.ch>
Re: How probably not to hand over a variable from one p <tzz@lifelogs.com>
Re: How probably not to hand over a variable from one p <jurgenex@hotmail.com>
Re: How probably not to hand over a variable from one p <David.Squire@no.spam.from.here.au>
Re: How probably not to hand over a variable from one p <syscjm@gwu.edu>
Re: How probably not to hand over a variable from one p <David.Squire@no.spam.from.here.au>
Re: How probably not to hand over a variable from one p <David.Squire@no.spam.from.here.au>
Re: How to pass 2D array to sub function and return 2D <sisyphus1@nomail.afraid.org>
Re: How to pass 2D array to sub function and return 2D <mritty@gmail.com>
Re: Ideas for Plotting aircraft tracks in real-time <zentara@highstream.net>
Unicode & Upgrading Perl <bill@ts1000.us>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 03 Aug 2006 13:07:26 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <iymAg.15282$c11.7029@trnddc08>
Markus Hänchen wrote:
> Thought, this might work instead:
>
> #! /usr/bin/perl
> $variable = @ARGV;
Ok, now $variable contains the number or arguments that were passed to the
script.
Is that what you want?
jue
------------------------------
Date: Thu, 3 Aug 2006 15:08:52 +0200
From: =?ISO-8859-1?Q?Markus_H=E4nchen?= <youcontrol@hispeed.ch>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <44d1f562@news1.ethz.ch>
On 2006-08-03 14:34:48 +0200, "Paul Lalli" <mritty@gmail.com> said:
> Now, in your situation, you are using a separate program to call
> runit.pl, rather than typing it on the command line. That's the only
> difference. When you use the system() function, Perl executes the
> program that you passed as system()'s first argument, passing that
> program the remaining arguments.
>
> Does that help to clarify at all?
>
> Paul Lalli
Thanks a lot. I understood $ARGV, I did not know that the equivalent of
typing "./runit.pl 'Hello World'" at the command line would be: "system
'runit8.pl', 'Hello World';". And I still do not understand why a
global variable is global enough to mess up things (i.e. requiring the
use of 'my') but not global enough to be just available.
But more importantly, how does this work for arrays and hashes? (Since
taking the array apart and putting it back together was most of the
work in my previous approach using a temp file.)
------------------------------
Date: Thu, 3 Aug 2006 15:39:03 +0200
From: =?ISO-8859-1?Q?Markus_H=E4nchen?= <youcontrol@hispeed.ch>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <44d1fc75@news1.ethz.ch>
> Note this is really a question about command line arguments, not
> passing perl variables between perl scripts.
I am realising this. In other words, instead of writing the values of
the variables to a temp file (my original approach), I am writing them
to the command line and reading them back from there, probably a better
approach but stil a pain for arrays and hashes (which I have to take
apart and reassemble for both approaches).
------------------------------
Date: 3 Aug 2006 06:44:45 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <1154612685.459725.307650@b28g2000cwb.googlegroups.com>
Markus H=E4nchen wrote:
> On 2006-08-03 14:34:48 +0200, "Paul Lalli" <mritty@gmail.com> said:
> > Now, in your situation, you are using a separate program to call
> > runit.pl, rather than typing it on the command line. That's the only
> > difference. When you use the system() function, Perl executes the
> > program that you passed as system()'s first argument, passing that
> > program the remaining arguments.
>
> Thanks a lot. I understood $ARGV,
No, you don't. $ARGV is a *completely* separate concept that has
nothing to do with anything else talked about in this thread. The
previous discussion is entirely about @ARGV. They are not the same
variable.
> I did not know that the equivalent of
> typing "./runit.pl 'Hello World'" at the command line would be: "system
> 'runit8.pl', 'Hello World';". And I still do not understand why a
> global variable is global enough to mess up things (i.e. requiring the
> use of 'my') but not global enough to be just available.
I have *no* idea what you mean by this. Can you please explain?
If you're talking about the variable you were trying to "pass" from one
script to another its because of exactly that reason - they are two
completely different scripts. Two completely different *processes*.
They are not at all related. system() is used to run an external
command - the language in which that command is written is wholly
irrelevant.
> But more importantly, how does this work for arrays and hashes? (Since
> taking the array apart and putting it back together was most of the
> work in my previous approach using a temp file.)
It doesn't. That's why people in this thread have been telling you to
do this the *right* way. Don't use two separate and distinct scripts.
Write one script, and write a module that script uses. That module
will contain one or more functions your module can call, and you can
pass arrays and hashes to and from functions arbitrarily.
Paul Lalli
------------------------------
Date: Thu, 03 Aug 2006 13:50:58 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <6bnAg.9827$j9.6722@trnddc02>
Markus Hänchen wrote:
> On 2006-08-03 14:34:48 +0200, "Paul Lalli" <mritty@gmail.com> said:
[...]
>> difference. When you use the system() function, Perl executes the
>> program that you passed as system()'s first argument, passing that
>> program the remaining arguments.
>
> Thanks a lot. I understood $ARGV,
What does $ARGV have to do with system() and command line arguments?
From perldoc perlvar:
$ARGV contains the name of the current file when reading from <>.
Did you mean @ARGV instead?
> I did not know that the equivalent
> of typing "./runit.pl 'Hello World'" at the command line would be:
> "system 'runit8.pl', 'Hello World';".
Well, kinda sort of. For once the first argument is more like './runit.pl'
rather than 'runit8.pl'. Yes, those nitpicking details are important.
Computers are notoriuously unforegiving when you make a typo.
And second for this example the command is not passed to the shell but
exec()uted directly. That means any shell meta characters are not evaluated
but passed directly.
> But more importantly, how does this work for arrays and hashes?
Command line arguments are nice to pass small sets of information. They are
unsuitable for large sets and most OS even impose a limit to the maximum
lenght of the command line. If you still want to pass the content of a whole
array or hash it's easy enough to do:
In the calling program:
system 'myotherprogram', @myarray;
In the called program:
@mynewarray = @ARGV;
But as mentioned before that can easily exceed the limits of your OS.
A better method is to use one of the standard methods for data passing:
files, pipes, sockets, shared memory, ....
> (Since
> taking the array apart and putting it back together was most of the
> work in my previous approach using a temp file.)
Why would you need to take the array apart and put it back together?
In the program that writes the file:
print @myarray;
In the program that reads the file (after opening file handle FH):
@mynewarray = <FH>;
jue
jue
------------------------------
Date: Thu, 3 Aug 2006 15:56:32 +0200
From: =?ISO-8859-1?Q?Markus_H=E4nchen?= <youcontrol@hispeed.ch>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <44d2008e@news1.ethz.ch>
>
> This is known as "throwing it at the wall and seeing what sticks" and
> is a very poor method of programming. Please go read a decent tutorial
> on Perl. How to get one item out of an array is a very basic concept.
> If you are a beginner, that's fine. We all were at one point. But you
> must accept that you are a beginner, and *learn* the language, not just
> type random lines of code until something works.
Thanks for the tutorials. About the 'throwing it at the wall', I did
read the first half of a good book on Perl (and browse and search it as
well as the internet before posting here) but there this saying about
learning by doing and learning by making mistakes.
I know how to get an item out of an array but if the array contains
only one element calling the array without any arguments should give me
that element, Perl should be smart enough to do this (and I guess it
would be, were it not for the fact that @arrayname is reserved to give
me the number of elements of an array, which I did not know since I
always used $#arrayname to get the length of an array).
------------------------------
Date: 3 Aug 2006 07:01:04 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <1154613664.797137.131140@i3g2000cwc.googlegroups.com>
Markus H=E4nchen wrote:
> I know how to get an item out of an array
No, apparently you do not.
> but if the array contains
> only one element calling the array without any arguments should give me
> that element, Perl should be smart enough to do this
Ahhh, so it's the *language*'s fault that your programs aren't working.
Okay.
Because the language does not do what *you* want it to do does not mean
the language is in some way deficient. To be blunt, it means that you
are.
An array evaluated in a scalar context gives the size of that array.
That is a feature, and an often used one.
> (and I guess it
> would be, were it not for the fact that @arrayname is reserved to give
> me the number of elements of an array, which I did not know since I
> always used $#arrayname to get the length of an array).
$#arrayname does *not* give you the "length" (I assume you mean "size")
of the array. It gives you the last index of the array.
Here's a quick summary:
my $size_of_array =3D @array;
my $last_index_of_array =3D $#array;
my ($first_element_of_array) =3D @array;
my $first_element_of_array =3D $array[0];
Paul Lalli
------------------------------
Date: Thu, 03 Aug 2006 14:01:20 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <Xns9814660C2EA81asu1cornelledu@127.0.0.1>
Markus Hänchen <youcontrol@hispeed.ch> wrote in news:44d1fc75
@news1.ethz.ch:
>> Note this is really a question about command line arguments, not
>> passing perl variables between perl scripts.
>
> I am realising this. In other words, instead of writing the values of
> the variables to a temp file (my original approach), I am writing them
> to the command line and reading them back from there, probably a better
> approach but stil a pain for arrays and hashes (which I have to take
> apart and reassemble for both approaches).
You should not be doing that at all. As I said, this is a point where you
stop, reflect, realize that you should learn more, and read some.
Why are you passing arrays and hashes on the command line?
Are you trying to break your program in to logically separate modules?
perldoc perlmod
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Thu, 03 Aug 2006 14:10:03 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <Xns98146786A8A80asu1cornelledu@127.0.0.1>
Markus Hänchen <youcontrol@hispeed.ch> wrote in
news:44d2008e@news1.ethz.ch:
> if the array contains only one element calling the array
There is no such thing as 'calling an array'.
> without any arguments should give me that element, Perl should be
> smart enough to do this (and I guess it would be, were it not for the
> fact that @arrayname is reserved to give me the number of elements of
> an array, which I did not know since I always used $#arrayname to get
> the length of an array).
Oh, but, $#arrayname does not give the length of the array. It gives the
last index of the array.
perldoc perlvar
read about $[
Sinan
<rant>
I consider this poster a good example of what happens when people are not
immediately hit by a clue-by-four. I mean, look at this thread: A bunch of
us patiently explaining the most elementary concepts that one ought to
learn by reading a book, and what do we get in return? "Perl should be
smart enough"? And a complete resistance to learning.
Perl, just like any other programming language, has rules. Those rules
make the language. The programmer learns those rules, and abides by them.
If said programmer does not like the rules of a language, the programmer
should look for another languages which is more to his liking.
I am out of this thread.
</rant>
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Thu, 3 Aug 2006 16:14:52 +0200
From: =?ISO-8859-1?Q?Markus_H=E4nchen?= <youcontrol@hispeed.ch>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <44d204d9@news1.ethz.ch>
>>
>> Thanks a lot. I understood $ARGV,
>
> No, you don't. $ARGV is a *completely* separate concept that has
> nothing to do with anything else talked about in this thread. The
> previous discussion is entirely about @ARGV. They are not the same
> variable.
Typing '$ARGV' was a typo, I naturally meant '@ARGV'.
>> And I still do not understand why a
>> global variable is global enough to mess up things (i.e. requiring the
>> use of 'my') but not global enough to be just available.
>
> I have *no* idea what you mean by this. Can you please explain?
On the advice of David Squire I used 'strict' which gave me a
warning/error when I tried to use
$variable = $ARGV[0] and no warning/error when I used my($variable) =
$ARGV[0] from which I drew the wrong conclusions.
>> But more importantly, how does this work for arrays and hashes? (Since
>> taking the array apart and putting it back together was most of the
>> work in my previous approach using a temp file.)
>
> It doesn't. That's why people in this thread have been telling you to
> do this the *right* way. Don't use two separate and distinct scripts.
> Write one script, and write a module that script uses. That module
> will contain one or more functions your module can call, and you can
> pass arrays and hashes to and from functions arbitrarily.
By now, I guess I have learned that thanks to all the helpful people.
To summarize for other people having the same question:
Question:
'How can I pass (hand over) a variable from one perl script to another?'
Answer:
'You cannot. You can only pass scalars via the command line (or via a
temp file) by giving them as arguments when using the system command
(system 'script.pl', $scalar). But you can pass a variable to modules,
i.e. make your second script a module.'
------------------------------
Date: Thu, 03 Aug 2006 14:20:21 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <FCnAg.9832$j9.6042@trnddc02>
Markus Hänchen wrote:
> I know how to get an item out of an array but if the array contains
> only one element calling the array without any arguments should give
> me that element,
Why? I wouldn't expect that behaviour at all. If I assign an array to
something, then I expect to get an array again, no matter if it has one
element or many.
If I want an item from the array, then I would use whatever syntax the
programming language provides to access array elements, no matter if the
array contains one item or many.
> Perl should be smart enough to do this
I seriously hope it never will because I don't want to test every single
time if my array has only one element or many.
> (and I guess
> it would be, were it not for the fact that @arrayname is reserved to
> give me the number of elements of an array, which I did not know
Wrong, it doesn't. @arrayname gives you the _WHOLE_ array.
@foo = @bar.
Now @foo contains the same values as @bar.
Only the scalar value of @foo is it's length.
> since I always used $#arrayname to get the length of an array).
But $#arrayname does not give you the length of an array, it gives you the
last index.
Which most often happens to be number of elements -1, but can be any other
value if someone tinkered with the start index $[.
jue
------------------------------
Date: Thu, 03 Aug 2006 14:31:26 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <2NnAg.9836$j9.958@trnddc02>
Markus Hänchen wrote:
> To summarize for other people having the same question:
> Question:
> 'How can I pass (hand over) a variable from one perl script to
> another?'
You can generalize the question to:
'How can I pass (hand over) a variable from one program (regardless of
programming language) to another?'
> Answer:
> 'You cannot. You can only pass scalars via the command line (or via a
> temp file) by giving them as arguments when using the system command
> (system 'script.pl', $scalar). But you can pass a variable to modules,
> i.e. make your second script a module.'
Then the answer becomes:
'You cannot. You can use the normal interprocess communication methods like
signals, command line arguments, files, pipes, sockets, shared memory, ...
to pass the data.
If you want to pass or actually 'share' a variable then in general(*) you
should use modules or whatever concept your programming language provides
for programming_in_the_large.'
(*): Just for completeness: Of course there are some IPCs that allow sharing
variables, too, like e.g. shared memory.
jue
------------------------------
Date: Thu, 03 Aug 2006 14:39:39 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <Xns98146C8B597C9asu1cornelledu@127.0.0.1>
David Squire <David.Squire@no.spam.from.here.au> wrote in news:eat1le$27f
$1@gemini.csx.cam.ac.uk:
> A. Sinan Unur wrote:
>> Markus Hänchen <youcontrol@hispeed.ch> wrote in
>> news:44d1ee5f@news1.ethz.ch:
>>>
>>> But, helas, nope.
>>
>> ITYM, 'alas'.
>
> Not necessarily. 'helas' is perfectly good French, and is also used in
> (mostly literary) English. The OED does mark it as obsolete though.
I learn something new everyday.
Thanks.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Thu, 3 Aug 2006 16:40:03 +0200
From: =?ISO-8859-1?Q?Markus_H=E4nchen?= <youcontrol@hispeed.ch>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <44d20ac1@news1.ethz.ch>
> Did you mean @ARGV instead?
Yes, I did, sorry for the typo.
> Well, kinda sort of. For once the first argument is more like
> './runit.pl' rather than 'runit8.pl'. Yes, those nitpicking details are
> important. Computers are notoriuously unforegiving when you make a typo.
I am running scripts on both Unix (./runit.pl) and Windows (runit.pl),
I know the difference. It is just that when I am quoting other people I
tend to use their syntax, and this gets messy when I quote several
people.
> Command line arguments are nice to pass small sets of information. They
> are unsuitable for large sets and most OS even impose a limit to the
> maximum lenght of the command line. If you still want to pass the
> content of a whole array or hash it's easy enough to do:
>
> In the calling program:
> system 'myotherprogram', @myarray;
> In the called program:
> @mynewarray = @ARGV;
>
> But as mentioned before that can easily exceed the limits of your OS.
My arrays are really small, maybe 15 entries, so I am going to try
this. Thanks.
> A better method is to use one of the standard methods for data passing:
> files, pipes, sockets, shared memory, ....
I guess modules, as suggested by other people, fall also into this category?
> Why would you need to take the array apart and put it back together?
My temp file contained both an array and scalars, so instead of trying
to figure it out, I just took the array apart. Using your syntax via
the command line should naturally make that obsolete.
However, for hashes I still have a problem, I guess this is not the
correct syntax:
In the calling program:
system 'myotherprogram', %myhash;
In the called program:
%mynewhash = %ARGV; (or @ARGV)
------------------------------
Date: Thu, 03 Aug 2006 10:57:48 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <g69d5bhhno3.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 3 Aug 2006, youcontrol@hispeed.ch wrote:
>> Note this is really a question about command line arguments, not
>> passing perl variables between perl scripts.
>
> I am realising this. In other words, instead of writing the values of
> the variables to a temp file (my original approach), I am writing them
> to the command line and reading them back from there, probably a
> better approach but stil a pain for arrays and hashes (which I have to
> take apart and reassemble for both approaches).
If you need multi-level data structures, write them to a file using
YAML, XML, or something like that. Please don't try to make your own
data language, as appealing as that is to most programmers.
You can easily pass lists and 1-level hashes (just key/value, not
complex values that are lists or hashes in themselves) with the
AppConfig/Getopt modules from the command line, but if you expect your
program to ever need complex data, just bite the bullet now.
Finally, do NOT write your file as executable code so you can then run
eval() on it. Bad idea, even for advanced programmers.
Ted
------------------------------
Date: Thu, 03 Aug 2006 15:00:49 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <BcoAg.9856$j9.6789@trnddc02>
A. Sinan Unur wrote:
> David Squire <David.Squire@no.spam.from.here.au> wrote in
> news:eat1le$27f $1@gemini.csx.cam.ac.uk:
>
>> A. Sinan Unur wrote:
>>> Markus Hänchen <youcontrol@hispeed.ch> wrote in
>>> news:44d1ee5f@news1.ethz.ch:
>>>>
>>>> But, helas, nope.
>>>
>>> ITYM, 'alas'.
>>
>> Not necessarily. 'helas' is perfectly good French, and is also used
>> in (mostly literary) English. The OED does mark it as obsolete
>> though.
>
> I learn something new everyday.
Although, Wikipedia does not know it, my standard dictionaries don't know
it, and only the 2000+ page 8 pound Webster Encyclopedic Dictionary has a
very short entry. Not commonly used, I would conclude.
jue
------------------------------
Date: Thu, 03 Aug 2006 14:18:16 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <east2p$m45$1@gemini.csx.cam.ac.uk>
Markus Hänchen wrote:
> On 2006-08-03 14:34:48 +0200, "Paul Lalli" <mritty@gmail.com> said:
>> Now, in your situation, you are using a separate program to call
>> runit.pl, rather than typing it on the command line. That's the only
>> difference. When you use the system() function, Perl executes the
>> program that you passed as system()'s first argument, passing that
>> program the remaining arguments.
>>
>> Does that help to clarify at all?
>>
>> Paul Lalli
>
> Thanks a lot. I understood $ARGV, I did not know that the equivalent of
> typing "./runit.pl 'Hello World'" at the command line would be: "system
> 'runit8.pl', 'Hello World';". And I still do not understand why a global
> variable is global enough to mess up things (i.e. requiring the use of
> 'my') but not global enough to be just available.
Global variables are global to a program, not a computer (and the 'my'
issue here is a red herring. 'use strict;' requires you to declare
variables with 'my' to help save you from typos magically creating new
variables).
>
> But more importantly, how does this work for arrays and hashes? (Since
> taking the array apart and putting it back together was most of the work
> in my previous approach using a temp file.)
You appear still to be wanting to do something that can't be done[1].
Variables in separate programs cannot be passed to one another as
variables. Stuff on the command line is just text.
DS
[1] Except by using protocols (and modules that understand them) that
handle the serialization and reconstruction of the variables for you,
such as COM, CORBA, SOAP, etc.
------------------------------
Date: Thu, 03 Aug 2006 09:42:03 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <12d3v9cbghv0g3c@corp.supernews.com>
David Squire wrote:
>
>
> You appear still to be wanting to do something that can't be done[1].
> Variables in separate programs cannot be passed to one another as
> variables. Stuff on the command line is just text.
>
>
> DS
>
> [1] Except by using protocols (and modules that understand them) that
> handle the serialization and reconstruction of the variables for you,
> such as COM, CORBA, SOAP, etc.
Or by using shared memory, but at his level, he REALLY REALLY doesn't
want to try that.
Chris Mattern
------------------------------
Date: Thu, 03 Aug 2006 15:05:54 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <easvs2$rsj$1@gemini.csx.cam.ac.uk>
Markus Hänchen wrote:
> I know how to get an item out of an array but if the array contains only
> one element calling the array without any arguments should give me that
> element, Perl should be smart enough to do this
It is. You need to read up on list vs scalar context in Perl.
----
#!/usr/bin/perl
use strict;
use warnings;
my @test_array = qw (frog);
my ($element) = @test_array;
print $element;
----
Output:
frog
> (and I guess it would
> be, were it not for the fact that @arrayname is reserved to give me the
> number of elements of an array, which I did not know since I always used
> $#arrayname to get the length of an array).
Well, first this is not about @arrayname being reserved, it's about what
happens when you use it in a scalar context. Secondly, they don't return
the same thing. scalar(@arrayname) gives the number of elements in the
array (length), whereas $#arrayname gives in the index of the last
element (which is one less).
DS
------------------------------
Date: Thu, 03 Aug 2006 15:36:30 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: How probably not to hand over a variable from one perl script to another
Message-Id: <eat1le$27f$1@gemini.csx.cam.ac.uk>
A. Sinan Unur wrote:
> Markus Hänchen <youcontrol@hispeed.ch> wrote in
> news:44d1ee5f@news1.ethz.ch:
>>
>> But, helas, nope.
>
> ITYM, 'alas'.
Not necessarily. 'helas' is perfectly good French, and is also used in
(mostly literary) English. The OED does mark it as obsolete though.
DS
------------------------------
Date: Thu, 3 Aug 2006 23:54:42 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: How to pass 2D array to sub function and return 2D array?
Message-Id: <44d2011b$0$22358$afc38c87@news.optusnet.com.au>
"Paul Lalli" <mritty@gmail.com> wrote in message
news:1154608790.029895.97250@p79g2000cwp.googlegroups.com...
.
.
>
> This code contains the same error as the OP's.
The code I posted does not contain any errors.
I was aware that the OP's subroutine took no arguments. If I had also
noticed that the OP was calling the subroutine *with* an argument then I
would have amended that when I did the copy'n'paste of his code. I did not
notice the OP had done this until Anno pointed it out.
It's good that you took the time to explain how to pass the argument to the
subroutine. I ignored that aspect because (I thought) the question asked was
concerned with the sub's *return* value - but given the subject line, your
explanation is certainly warranted.
Cheers,
Rob
------------------------------
Date: 3 Aug 2006 07:03:45 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: How to pass 2D array to sub function and return 2D array?
Message-Id: <1154613825.832704.147090@i3g2000cwc.googlegroups.com>
Sisyphus wrote:
> "Paul Lalli" <mritty@gmail.com> wrote in message
> news:1154608790.029895.97250@p79g2000cwp.googlegroups.com...
> .
> .
> >
> > This code contains the same error as the OP's.
>
> The code I posted does not contain any errors.
It does not contain any errors in that it will, indeed, work exactly as
posted. However, the general methodology given by your example will
not. Passing an argument into a subroutine and later referring to that
argument in the subroutine by the name it had as an argument to the
function call is an error. Because it "works" under a specific
circumstance (the call and the definition being in the same scope) does
not make it not an error.
Paul Lalli
------------------------------
Date: Thu, 03 Aug 2006 14:01:47 GMT
From: zentara <zentara@highstream.net>
Subject: Re: Ideas for Plotting aircraft tracks in real-time
Message-Id: <u004d2hmrm564uc1r5057ak19jnqj65b1o@4ax.com>
On Thu, 03 Aug 2006 06:51:09 GMT, "Clyde Ingram"
<clydenospamorham@nospamorhamgetofftheline.freeservenospamorham.co.uk>
wrote:
>I am building software to receive and handle aircraft track data (position,
>altitude, course, speed, etc).
>Just simulating a dozen aircraft, with the data for each aircraft updating a
>couple of times per minute.
>This is to run as a local application on a PC -- no need for web graphics.
>Where do I start with the graphics display?
>What about Tk's Canvas widget? Or is that versatile enough?
>Can anyone offer suggestions about tools to focus on or have experience of
>this kind of thing?
You are close with the Tk::Canvas. You are looking for Tk::Zinc, which
is a greatly improved Canvas.
Zinc is made by CENA and is used in France for....... guess what?
That's right, plotting radar displays of aircraft. The demo has some
plotting examples, plus many other examples of cool Zinc usage.
Zinc runs great on linux, and has a Windows version too.
http://www.tkzinc.org/
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
------------------------------
Date: 3 Aug 2006 06:29:34 -0700
From: "Bill H" <bill@ts1000.us>
Subject: Unicode & Upgrading Perl
Message-Id: <1154611774.759019.21360@h48g2000cwc.googlegroups.com>
Thanks to all who answered the questions I had on Unicode, I have
learned that I need to upgrade the version of Perl of I have on one of
my Cobalt Raq4 servers. I currently have 5.005.03 and need to upgrade
to 5.8. Can anyone give me some hints/pointers on how to go about this
and where to get the upgrade for this system?
Bill H www.ts1000.us
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9555
***************************************