Help a newb? - Simple acces of array element 
Author Message
 Help a newb? - Simple acces of array element

Hi all,

I'm sure you're gonna find this trivial, but I've read the books, and
scoured what tutorials I can find, and am still stumped....

First, I'm running this simple perl pgm on MVS (IBM mainframe), using
Perl561.  This script works on other platforms, and the msgs that warn
and strict give aren't very intuitive.

Heres the code <Plz B Gentle>:

#! /local/bin/perl5.6.1            
 use warnings;                      
 use strict;                        

my $arr = "";                      

 print "Value of var is $arr[1]\n";

I'm simply trying to display the content of the 2nd item, ie, "b"

Execution with strict turned on yields:

/TEST/tmp: >perl002                                                        
Global symbol "$arr[0" requires explicit package name at ./perl002 line
7.
Execution of ./perl002 aborted due to compilation errors.                  
/TEST/tmp: >                                                              

Again, the sample above is taken from a tutorial on array initialization
and element access.  It works fine on HP-Ux, but not my platform.

The Pgm'ing Perl book mentions Pkgs in the context of variable binding
with the 'tie' function...  Almost sounds like the basic function(s) of
Perl aren't working ...

Thoughts please!

--
Insert Catch-phrase here!



Tue, 15 Feb 2005 06:31:07 GMT  
 Help a newb? - Simple acces of array element

Quote:
> First, I'm running this simple perl pgm on MVS (IBM mainframe), using
> Perl561.  This script works on other platforms,

Works on a few OS/Perl combinations for me too.

Quote:

> my $arr = "";                      

>  print "Value of var is $arr[1]\n";

Your scalar $arr, which you set to an empty string, seems useless. Try removing it.

Quote:
> I'm simply trying to display the content of the 2nd item, ie, "b"

> Execution with strict turned on yields:

> /TEST/tmp: >perl002                                                        
> Global symbol "$arr[0" requires explicit package name at ./perl002 line
> 7.

which line is 7?


Tue, 15 Feb 2005 17:49:21 GMT  
 Help a newb? - Simple acces of array element

Quote:

> Subject: Help a newb? - Simple acces of array element

As a newbie you are not ideally qualified to judge if your problem is
simple, or related to your own inexperience.

As such you should avoid wasting space in Subject lines with stuff
like  "Help a newb? - Simple..." and use the space to save to put more
hard facts.

Like for example, the hightly pertenant fact that you have a
portablity issue.

Subject: On MVS OS, symbol "$arr[0" requires explicit package name

Quote:
> I'm sure you're gonna find this trivial,

No, what you have here is an obscure problem.

Quote:
> First, I'm running this simple perl pgm on MVS (IBM mainframe), using
> Perl561.  This script works on other platforms,

This should be your first clue that this isn't a simple newbie issue.

Quote:
>  print "Value of var is $arr[1]\n";
> Global symbol "$arr[0" requires explicit package name at ./perl002 line
> 7.

Are you abcolutely sure that that it says 0 and not 1?

Looks like the Perl compiler is trying to treat the [ character as a
valid word character.  At a guess this is soemthing to do with
character sets.
At a further guess the MVS platform is using some charcter encoding
other than good-ol ASCII and undef this encoding there's more than one
character that looks like "[".  The character set convertion program
you've used to convert the script is using a different one from the
one that Perl uses.

Quote:
> Thoughts please!

This newsgroup does not exist.  Please do not start threads here.  See
FAQ.


Wed, 16 Feb 2005 00:18:22 GMT  
 Help a newb? - Simple acces of array element


Quote:
>> First, I'm running this simple perl pgm on MVS (IBM mainframe), using
>> Perl561.  This script works on other platforms,

> Works on a few OS/Perl combinations for me too.


>> my $arr = "";                      

>>  print "Value of var is $arr[1]\n";

> Your scalar $arr, which you set to an empty string, seems useless. Try
> removing it.

I tried to pre-declare(?) all variables, as that is what I inferred was
being requested by the "Global symbol" msg.  I fails the same way with
or without it.

Quote:

>> I'm simply trying to display the content of the 2nd item, ie, "b"

>> Execution with strict turned on yields:

>> /TEST/tmp: >perl002                                                  
>>      Global symbol "$arr[0" requires explicit package name at
>> ./perl002 line 7.

> which line is 7?

Line 7 is the 'print" line.  

Finally, Thanks for replying.. I've coded for years, but Perl is very new
to me, and has been a very frustrating experience so far.  I am reading
up on all that I can though.

--
Insert Catch-phrase here!



Wed, 16 Feb 2005 00:17:12 GMT  
 Help a newb? - Simple acces of array element

Quote:
> This newsgroup does not exist.  Please do not start threads here.  

This is precisely what makes it so interesting. It doesn't exist, yet
we can read it and post to it. Isn't that fascinating? And every once
in a while, someone reminds us of our mysterious privilege...

:-)



Wed, 16 Feb 2005 23:26:57 GMT  
 Help a newb? - Simple acces of array element

Quote:

>>>my $arr = "";                      
>>Your scalar $arr, which you set to an empty string, seems useless. Try
>>removing it.

Mr. Fun! I'm wondering if M.I.'s response resolved the problem for you,
I can not replicate your problem, but I've never seen it sugested that
when you declare your array variables, that you also delare the errr...
scalar version [sic].


Mon, 21 Feb 2005 13:44:36 GMT  
 Help a newb? - Simple acces of array element


Quote:

>>>>my $arr = "";                      
>>>Your scalar $arr, which you set to an empty string, seems useless. Try
>>>removing it.

> Mr. Fun! I'm wondering if M.I.'s response resolved the problem for you,
> I can not replicate your problem, but I've never seen it sugested that
> when you declare your array variables, that you also delare the errr...
> scalar version [sic].

No, unfortunately it did not.  I've stumbled around, and decided much
more reading was required.  Sad, this is an extremely simple function
in any other language.  Many have said they cannot reproduce it, but
others on the MVS platform have been able to.  I will prolly continue
any future developement on a platform nearer to the origin, ie, Linux
most likely.  My code issue here works fine there...

--
Insert Catch-phrase here!



Tue, 22 Feb 2005 04:40:12 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Acces to matrix elements in C

2. URGENT and Easy : How to acces Data in an array of array with foreach

3. Simple Question: how to add another element to an array

4. getting random elements from a simple array

5. Newb stuck on simple code....

6. Arrays and Hashes to a Newb

7. strip off single quotes from array elements...please help

8. Help: Delete Element From Array?

9. help stripping quotes from array elements please

10. HELP: removing several elements from an array?

11. Plz help a newbie add up elements of an array

12. HELP:Elements in an array have a space in front of them

 

 
Powered by phpBB® Forum Software