Forum archive 2000-2006

Stephen Corwin - passing references

Stephen Corwin - passing references

by Arnold Pizer -
Number of replies: 0
inactiveTopicpassing references topic started 7/23/2005; 1:18:07 PM
last post 7/23/2005; 2:46:14 PM
userStephen Corwin - passing references  blueArrow
7/23/2005; 1:18:07 PM (reads: 781, responses: 1)
Hi--

I'd like to pass a reference to an array as one usually does in Perl:

@myArry1 = (a,b,c);

@myArry2 = (1,2,3);

mySub(\@myArry1,\@myArry2);

When I do this, I get an error ("not an ARRAY ref"). I've seen tildes and double-tildes in other problems used I *think* to do this kind of thing, but I don't know how or when to use them. Where can I find out this and other particulars of PG?

Thanks,

Steve

<| Post or View Comments |>


userMichael Gage - Re: passing references  blueArrow
7/23/2005; 2:46:14 PM (reads: 1062, responses: 0)
The documentation is quite old but there are a few references. One is http://webhost.math.rochester.edu/webworkdocs/docs/pglanguage/tutorial/perlbasics but it only refers to this item indirectly. Also http://webhost.math.rochester.edu/webworkdocs/docs/pglanguage/pod/pgtranslator

When a .pg problem is read every occurence of a backslash is replaced by a double backslash. This protects the use of the backslash for TeX commands. Then every occurence of the double tilde is replaced by a backslash. This allows you to use references to arrays and hashes and so forth. This can be a nuisance because in the .pl file that often contain macros this kind of preprocessing does not occur.

Hence in a .pg file you use

 

$ra_foo= ~~@array_foo:

in the .pl file you use

$ra_foo = @array_foo;

Likewise "\( \int x^2 dx \)" works fine in a .pg file but must be written as "\\( \\int x^2 dx \\)" in a .pl file.

The logic behind this is that TeX is used a lot in .pg files, but not so often in .pl files. The reverse is true about using the perl version of backslash.

Hope this helps.

-- Mike

<| Post or View Comments |>