[13594] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1004 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 6 16:15:47 1999

Date: Wed, 6 Oct 1999 13:15:34 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <939240934-v9-i1004@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 6 Oct 1999     Volume: 9 Number: 1004

Today's topics:
    Re: Question on Traversing through a File <skilchen@swissonline.ch>
    Re: Question on Traversing through a File <sariq@texas.net>
    Re: Question on Traversing through a File (Larry Rosler)
    Re: Random Numbers <dwoods@ucalgary.ca>
    Re: Random Numbers (Matthew Bafford)
    Re: Random Numbers (Abigail)
    Re: regexp question - last occurrence of an expression  (Charles DeRykus)
        Remote Documents <alligator333@my-deja.com>
    Re: Remote Documents (Larry Rosler)
    Re: Response appreciated but.... <rhomberg@ife.ee.ethz.ch>
    Re: Response appreciated but.... (Matthew Bafford)
    Re: Solaris 7 gcc 2.95.1 perl 5.005_03 wont Configure <elaine@chaos.wustl.edu>
    Re: Specifying start row for DB access <hartleh1@westat.com>
    Re: To Abigail re: reading current threads <uri@sysarch.com>
    Re: To Abigail re: reading current threads (Abigail)
    Re: To Abigail re: reading current threads (Jon Bell)
        Uploading Files via the Web jdkronicz@my-deja.com
    Re: using strict, no soft references!! now what? <aqumsieh@matrox.com>
        Very simple redirect script needed (webmaster@film.tierranet.com)
    Re: Very simple redirect script needed (d.k. henderson)
    Re: Very simple redirect script needed <jb4mt@verbatims.com>
        We do complex Perl Programming <sehgal@del2.vsnl.net.in>
    Re: why use references - in laymans terms? <aqumsieh@matrox.com>
    Re: why use references - in laymans terms? jdkronicz@my-deja.com
    Re: why use references - in laymans terms? (Larry Rosler)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 06 Oct 1999 16:14:42 GMT
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: Question on Traversing through a File
Message-Id: <SzKK3.22567$m4.83274599@news.magma.ca>

Joe Stocker wrote in:
news:37FB6EC8.ECF77546@bellsouth.net

>if ($line = "a")
>{$result = 1;
>print ",";
>print $result * $ALG;}

You have an assignment statement (expression?) in your if's, but you want to
do a string comparison, so change your if() lines to something like:
if ($line eq "a")




------------------------------

Date: Wed, 06 Oct 1999 11:23:16 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Question on Traversing through a File
Message-Id: <37FB7774.60EA5047@texas.net>

Joe Stocker wrote:
> 
> Hello.
> I am trying  to open a file and read in one character at a time and then
> 
> print out the value to the screen after changing the value of the
> character, but I'm not doing something right, someone help me please!
> 

OK, I'll try to be gentle...

First, you should either get a good Perl intro book, like 'Learning
Perl' from O'Reilly, and/or read:

perldoc perldoc
perldoc perl
perldoc perltoc

You'll then be able to find your own solutions to most problems.

> 
> #!/usr/bin/perl

You should always use '-w', which causes Perl to warn you when you've
mucked up certain things.

Then, you should include 'use strict;', which forces you to use a number
of good programming practices.

For more info on the above, try:

perldoc perlrun
perldoc perldiag
perldoc strict

> open(FILE,"$input");

Always check the success of your 'open' function, and other
system-related functions as well.

I.e.,

open FILE, $input or die "Can't open input file: $!\n";

> if ($line = "a")

A) Read 'perldoc perlsyn', and pay special attention to the section that
discusses 'SWITCH'.

B) Read 'perldoc perlop', and pay special attention to the section that
discusses '==' and 'eq'.

- Tom


------------------------------

Date: Wed, 6 Oct 1999 10:18:59 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Question on Traversing through a File
Message-Id: <MPG.1265245a39359cf498a048@nntp.hpl.hp.com>

In article <37FB6EC8.ECF77546@bellsouth.net> on Wed, 06 Oct 1999 
11:46:16 -0400, Joe Stocker <stockerj@bellsouth.net> says...

 ...

> $line = $_;
> if ($line = "a")
> {$result = 1;
> print ",";
> print $result * $ALG;}

 ...

> if ($line = "z")
> {$result = 26;
> print ",";
> print $result * $ALG;}

None of the other comments have dealt with the repetitive nature of your 
code.  Whenever you have to write something 26 times to deal with 26 
cases, there is likely to be a better way.  In this case, there are 
several better ways.  Here is one of them (which relies on the 
sequential nature of letters in the ASCII encoding):

  chomp;
  if ('a' le $_ && $_ le 'z') {
     $result = ord() - ord('a') + 1;
     ...
  }

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Wed, 06 Oct 1999 11:59:45 -0700
From: Dan Woods <dwoods@ucalgary.ca>
Subject: Re: Random Numbers
Message-Id: <7tg2sv$ka8@ds2.acs.ucalgary.ca>

> c style for loops are not cool in perl. rarely needed in fact. and i
> don't mean foreach loops which are a different animal.

Humm, how many times have I read in this list that it's spelt "Perl"  ;)

 ...Dan


------------------------------

Date: Wed, 06 Oct 1999 18:41:33 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Random Numbers
Message-Id: <slrn7vn4ip.1kb.*@dragons.duesouth.net>

On Wed, 06 Oct 1999 11:59:45 -0700, Dan Woods <dwoods@ucalgary.ca>
spewed forth: 
: > c style for loops are not cool in perl. rarely needed in fact. and i
: > don't mean foreach loops which are a different animal.
: 
: Humm, how many times have I read in this list that it's spelt "Perl"  ;)

Uri is too lazy to capitalize most things.  When he does, it apears to be
purely at random. :-)
 
: ...Dan

--Matthew


------------------------------

Date: 6 Oct 1999 14:09:36 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Random Numbers
Message-Id: <slrn7vn832.23p.abigail@alexandra.delanet.com>

ItsMe9905 (itsme9905@aol.comnojunk) wrote on MMCCXXVI September MCMXCIII
in <URL:news:19991005170201.12873.00001172@ng-fm1.aol.com>:
 .. @ran=();
 .. for ($i=0; $i<9; $i++) {
 ..   $ran[$i] = int(rand()*100);
 .. }
 .. 
 .. The above will generate random numbers from 0 to 99 and puts those in an array.


And could also be written as:

    @ran = map {int (100 * rand)} 1 .. 9;



Abigail
-- 
perl -weprint\<\<EOT\; -eJust -eanother -ePerl -eHacker -eEOT


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: Wed, 6 Oct 1999 19:14:24 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: regexp question - last occurrence of an expression before another
Message-Id: <FJ7440.D7v@news.boeing.com>

In article <slrn7vieri.o01.gerry@xmission.xmission.com>,
Gerry JJ Dyn-O-Myte Walker <gerry@xmission.com> wrote:
>How do I extract the last occurrence of an expression occurring before
>another expression.  For example in the following string:
>
>A <b> lot </b> of <b> html </b> text, some of it in <b> bold </b>.  I
>want to extract the last <b> bold </b> section of <b> text </b> prior
>to a list of items - <ul> <li> item one </ul> - maybe more <b> bold </b> 
>still.
>
>I want to to extract only the last bold item (which is "text" in this
>example) which occurs before the list <ul>.*<\/ul>
>

Here's the fastest way I've found: 

$bold = $1 while $string =~ m%\G<b>(.*?)</b>(?=<ul>)%gs;

--
Charles DeRykus


------------------------------

Date: Wed, 06 Oct 1999 17:25:50 GMT
From: Alligator <alligator333@my-deja.com>
Subject: Remote Documents
Message-Id: <7tg0mb$3pg$1@nnrp1.deja.com>

Before I start, I'd like to thank Larry Rosler for directing me to the
LWP modules for this problem.

I'm trying to get the "last-modified" date of a document on a remote
server.  I have tried both LWP::UserAgent and the LWP::Simple head()
function for numerous servers on the internet.  Different servers have
returned different amounts of information, but all of them have left
'last_modified' undefined.  I've tried both the HEAD and GET methods
for LWP::UserAgent.  What might be going wrong?

Thanks for any help.


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 6 Oct 1999 10:57:32 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Remote Documents
Message-Id: <MPG.12652d6a1393fcd198a04b@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7tg0mb$3pg$1@nnrp1.deja.com> on Wed, 06 Oct 1999 17:25:50 
GMT, Alligator <alligator333@my-deja.com> says...
> Before I start, I'd like to thank Larry Rosler for directing me to the
> LWP modules for this problem.

You're quite welcome.

> I'm trying to get the "last-modified" date of a document on a remote
> server.  I have tried both LWP::UserAgent and the LWP::Simple head()
> function for numerous servers on the internet.  Different servers have
> returned different amounts of information, but all of them have left
> 'last_modified' undefined.  I've tried both the HEAD and GET methods
> for LWP::UserAgent.  What might be going wrong?

Try 'last-modified', not 'last_modified'.  :-)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Wed, 06 Oct 1999 18:18:32 +0200
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Response appreciated but....
Message-Id: <37FB7658.FD3F67FD@ife.ee.ethz.ch>

Henry Penninkilampi wrote:

> > HTH, HAND,
> 
> Alright, I give up.  What do these acronyms stand for?  No idea bout the
> first.  Would the last be "Have A Nice Day"?


Hope This Helps

HTH ;-)
- Alex


------------------------------

Date: Wed, 06 Oct 1999 17:41:33 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Response appreciated but....
Message-Id: <slrn7vn141.1e5.*@dragons.duesouth.net>

On Wed, 06 Oct 1999 19:21:32 +0930, spamfree@metropolis.net.au (Henry
Penninkilampi) enriched us with: 
: In article <slrn7vkvdd.2j4.*@dragons.duesouth.net>, *@dragons.duesouth.net
: wrote:
: > HTH, HAND,
: 
: Alright, I give up.  What do these acronyms stand for?  No idea bout the
: first.  Would the last be "Have A Nice Day"?

HTH, Hope This Hurts

HAND, Have a Nice Day, often used sarcasticly.
 
: Henry.

--Matthew


------------------------------

Date: Wed, 06 Oct 1999 12:46:39 -0400
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: Solaris 7 gcc 2.95.1 perl 5.005_03 wont Configure
Message-Id: <37FB7C22.8678DC0E@chaos.wustl.edu>

[ Courtesy CC to original poster ]

Martien Verbruggen wrote:
> If that doesn't work, I suggest you add something to your path.

There is a known issue with Solaris 7 and gcc 2.95.1 if the as patch is
present [ 107058-01 ] as it causes problems. It is a 64-bit specific
patch, but will install on a 32-bit system. Also, it is for the SunPro
compilers so systems that have this patch should also have
/opt/SUNWspro. 

If this doesn't apply, then try "sh Configure -de" and see if that fixes
your problem. 

If you think the compiler itself is wonky and you compiled it yourself,
try getting the gcc package at http://www.sunfreeware.com/ 

e.


------------------------------

Date: Wed, 06 Oct 1999 13:41:02 -0400
From: HHH <hartleh1@westat.com>
Subject: Re: Specifying start row for DB access
Message-Id: <37FB89AE.CE500DBE@westat.com>

Scott McMahan wrote:
> pyammine@my-deja.com wrote:
> > I was wondering if anybody knew if it is possible with DBI::ODBC and/or
> > WIN32::ODBC to specify what row/record to start fetching from in a
> > database. Meaning, If I execute a SQL statement and than want to put
> > the records into arrays, can I say I only want it to start at the 10th
> > record and end at the 20th?
> 
> Unless you can do a SELECT on the row sequence number on the table,
> you will probably need a cursor to do this. 

I suppose you could have a pair of while loops.  The first loop would
just fetch rows and throw them away until you got to the record just
before the first record you want (i.e. stop when you have fetched 9
records per above example).  The second loop would fetch rows, put the
data into your array and then end when you've gotten to the end of what
you want (i.e. after recording records 10 through 20).

I can even see a use for this.  If this script generates a web page and
you want to give a manageable chunk at a time, get the first 10 records,
then, when the user asks for the next screen, you give them 11 through
20, etc. until you don't have any more records to fetch.  I'm not sure
how effecient this is but it should work.

> Relational databases are *NOT* designed to do this, however, and I have
> to wonder about the design of a solution that uses this particular type
> of record selection. Rows are not kept "in order" in a relational
> database.

But they can be put in whatever order is necessary by the sql statement.

HHH


------------------------------

Date: 06 Oct 1999 15:05:50 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: To Abigail re: reading current threads
Message-Id: <x7hfk4qpgx.fsf@home.sysarch.com>

>>>>> "ll" == lt lindley <ltl@rgsun5.viasystems.com> writes:


  ll> I've been cut by Abigail's razor.  It stings a bit and isn't always
  ll> completely deserved.  One reason that she isn't ostracized by many
  ll> long timers here may be that her sharp edge is usually supported by
  ll> the weight of a strong logical argument.  And though her dialog isn't
  ll> usually funny, her Perl is hillarious.  uri on the other hand just
  ll> uses a club.  :-)

  ll> Ohhh.  That brings another picture to my mind of those poor innocent
  ll> newbies as fluffy white baby seals and the mean ol' denizens of
  ll> c.l.p.m clubbing them bloody as they wade through the carnage.  Oh,
  ll> the horror!  Have pity on the baby seals.

funny, that's how i think about you. bash!!

honey, i got another newbie skin coat for you!! we just have to remove
the blood stains.

:-)

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


------------------------------

Date: 6 Oct 1999 14:42:25 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: To Abigail re: reading current threads
Message-Id: <slrn7vna0p.23p.abigail@alexandra.delanet.com>

Elaine -HFB- Ashton (elaine@chaos.wustl.edu) wrote on MMCCXXVII September
MCMXCIII in <URL:news:37FAAA1F.ADBF866C@chaos.wustl.edu>:
!! 
!! It just seems pointless to rant on over and over and over and over again
!! and yet, the same behaviour persists. I'd be happy just to see a higher
!! signal to noise ratio. Not replying at all is an option.


Not replying means someone else with half a clue is going to reply,
giving wrong answers. Not replying also means that others might get
the impression that posting without doing any research yourself is
acceptable behaviour - after all, answers are coming.

I do not think that's a situation anyone benefits from.



Abigail
-- 
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


------------------------------

Date: Wed, 6 Oct 1999 19:57:19 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: To Abigail re: reading current threads
Message-Id: <FJ763K.IG7@presby.edu>

 Benjamin Franz <snowhare@long-lake.nihongo.org> wrote:
>
>About 2 years ago I completely undid a cow-orker when I was playing
                                        ^^^
>a tape that included 24 variations of a song titled 'Fly me to the Moon'. 
                                                                    ^^^^
I bet you really made her jump.  :-)

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA
        [     Information about newsgroups for beginners:     ]            
        [ http://www.geocities.com/ResearchTriangle/Lab/6882/ ]


------------------------------

Date: Wed, 06 Oct 1999 17:36:39 GMT
From: jdkronicz@my-deja.com
Subject: Uploading Files via the Web
Message-Id: <7tg1b6$48c$1@nnrp1.deja.com>

I want users of my website to be able to upload files to my site without
using FTP.  Is there a way to do it from the web by using a perl script?

Any help appreciated.

JDK


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 6 Oct 1999 12:11:08 -0400 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: using strict, no soft references!! now what?
Message-Id: <x3ybtac79lw.fsf@tigre.matrox.com>


cLive hoLLoway <cLive@direct2u.co.uk> writes:

[snip]

> # $field{'There'} = 'hash element value';
> 
> my $Hello = 'well, hello';
> my $There = 'there we go';
> 
> my $a = "Hello There";
> $a =~ /(\w+) (\w+)/;
> 
> my $var_value = $field{$2} || ${$2} || 'null';
> 
> print $var_value;
> 
> ie, I want to get the value of $There in the ${$2} bit... but I get the
> "Can't use soft references under strict" error.

Don't do that. Use a special hash to store your values. Ie instead of
having a variable called '$There', you would have a hash with key
'There':

	my $var_value = $field{$2} || $values{$2} || 'null';

(why 'null'? Why not undef?)

If you really insist, you can turn off your strict pragma in a limited
scope, and do your soft referencing:

	{
		no strict 'refs';
		# do your thing
	}

HTH,
--Ala



------------------------------

Date: Wed, 06 Oct 1999 17:41:59 GMT
From: webmaster@film.tierranet.com (webmaster@film.tierranet.com)
Subject: Very simple redirect script needed
Message-Id: <37fb8a63$0$222@nntp1.ba.best.com>

I need a very simple redirect script that uses a button to redirect a user to 
a different web page. The HTML should look something like the following.

<form method="POST" action="/cgi-bin/redirect.cgi"> 
<input type="Hidden" value= "http://www.example.com/newpage.html">
<input type="button" value="Go To Redirect">
</form>

As you noticed the web page it redirects to is in the hidden field. I looked 
at all the free CGI sites and didn't see anything. Can anyone type up a script 
for me or direct me to a place that has a basic script like this available?

Thanks.


------------------------------

Date: Wed, 06 Oct 1999 18:05:11 GMT
From: dalekh@hotmail.com (d.k. henderson)
Subject: Re: Very simple redirect script needed
Message-Id: <8E568FAFEdkhenderson@207.14.236.51>

 Try these:

http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Redirection/Form_or_Li
nk_Based/


------------------------------

Date: Wed, 06 Oct 1999 18:13:36 GMT
From: "George Jempty" <jb4mt@verbatims.com>
Subject: Re: Very simple redirect script needed
Message-Id: <kjMK3.870$ry3.8873@news.rdc1.ne.home.com>

<webmaster@film.tierranet.com> wrote in message
news:37fb8a63$0$222@nntp1.ba.best.com...
> I need a very simple redirect script that uses a button to redirect a user
to
> a different web page. The HTML should look something like the following.
>
> <form method="POST" action="/cgi-bin/redirect.cgi">
> <input type="Hidden" value= "http://www.example.com/newpage.html">
> <input type="button" value="Go To Redirect">
> </form>
>
> As you noticed the web page it redirects to is in the hidden field.

Since the field is hidden, I'm assuming the script has been executed at
least once and dynamically generates the above HTML.  In that case, instead
of having the user go through an extra step by outputting the above form and
requiring him/her to submit it yet again, do something like:

print "Location: http://www.example.com/newpage.html\n\n";

HTH

George Jempty




------------------------------

Date: Wed, 6 Oct 1999 22:07:38 +0530
From: "Sahil" <sehgal@del2.vsnl.net.in>
Subject: We do complex Perl Programming
Message-Id: <7th2f6$n1u$1@news.vsnl.net.in>

Hi,
We are an E-commerce based company and do any type of complex Perl
programming in record time.

Sahil
www.enabling-information.com




------------------------------

Date: Wed, 6 Oct 1999 11:52:26 -0400 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: why use references - in laymans terms?
Message-Id: <x3yd7us7ah1.fsf@tigre.matrox.com>


jdkronicz@my-deja.com writes:
> > foo(%bar, %baz);
> >
> > is flattened to something like:
> >
> > foo((all of the keys and values in both hashes))
> >
> > without references.
> >
> Could you give me a concrete example?

% perl -wl
my %h1 = ( a => 1, b => 2, c => 3 );
my %h2 = ( d => 4, e => 5, c => 8 );

foo(%h1, %h2);

sub foo {
	print join ' & ' => @_;
}
__END__
a & 1 & b & 2 & c & 3 & c & 8 & d & 4 & e & 5

From perlsub:

     The Perl model for function call and return values is
     simple: all functions are passed as parameters one single
     flat list of scalars, and all functions likewise return to
     their caller one single flat list of scalars.  Any arrays or
     hashes in these call and return lists will collapse, losing
     their identities--but you may always use pass-by-reference
     instead to avoid this.  Both call and return lists may
     contain as many or as few scalar elements as you'd like.
     (Often a function without an explicit return statement is
     called a subroutine, but there's really no difference from
     the language's perspective.)

Read more of perlsub if you need more detail.

> Where might I find perltoot?

It should be installed on your system. It is part of the standard
documentation that comes with Perl. Just type:

	perldoc perltoot

on your command line. If you get some error message, then your Perl
installation wasn't complete, and you should re-install Perl. You can
still, however, access all of Perl's documentation on the web if you
go to www.perl.com and click on 'Documentation'.

HTH,
--Ala



------------------------------

Date: Wed, 06 Oct 1999 17:20:35 GMT
From: jdkronicz@my-deja.com
Subject: Re: why use references - in laymans terms?
Message-Id: <7tg0ci$3e8$1@nnrp1.deja.com>

Thank you very much for your thoughtful response Jeff.  It was quite helpful.

JDK

In article <7sr1v2$j75$1@nnrp1.deja.com>,
  Jeff S. <jeff@jhmi.edu> wrote:
> In article <7sqt5h$ff6$1@nnrp1.deja.com>,
>   jdkronicz@my-deja.com wrote:
> > Could someone explain to me the purpose for references?  I've read
> that they
> > allow complex datastructures, nesting etc.  I realize that this is a
> > fundamental question and very basic for most reading this newsgroup
> but I
> > would really like to hear the laymans explanation of why they are
> necessary?
>
> Since I am just a bit above layman myself, maybe I can explain... and
> this explanation is going to include a bit of C and general computer
> architecture as well as perl type stuff.
>
> From what I understand, references allow things like arrays of arrays to
> be possible. I don't fully understand or know why, but (at least as far
> as Perl is concerned), the original design of Perl allowed only scalar
> values in arrays. so a reference is a scalar value that is equal to the
> name/number of a memory address. anything can be stored in that address,
> including another array, so an array of references to arrays is a lot
> like an array of arrays.
>
> since that sounded like mumbo jumbo, think of this:
> a computer's memory can be thought of as a contiguous row of cells:
> +-----+
> | 001 |   (these numbers are the addresses, not the values!)
> +-----+
> | 002 |
> +-----+
> | 003 |
> +-----+
> | 004 |
> +-----+
> | ... |
> +-----+
>
> for simplification sake, i'll say that each cell can contain a value,
> like a number or a letter. "12" or  "A". So 001 may contain "42", for
> example.
>
> Now, an array is a list, and thus would use several cells in a row for
> its data. I guess in perl, these lists were originally restricted to
> being only lists of scalar data, like "42" or "A", and the array was
> known to the computer to be "Cell 002 through 004" or somesuch.
> (Actually, at least in C, an array is known to the computer as more like
> "Starts in cell 002, is of length three cells").
>
> Anyways, if you want to make an array that is itself composed of
> separate arrays, (and take my word for it, you do), you can't if
> individual array entries can only be scalar. So Perl got around its
> original problem by using references, that is, scalar values that tell
> the computer that the rest of this list is located "over there--->".
>
> +-----+
> | 002 |<-------+
> |=099 |--+     +-(these numbers are "address=value of another address")
> +-----+  |
> | 003 |  |          +-----+
> |=400 |+ +--------->| 099 |
> +-----+|            +-----+
> | 004 ||            | 100 |
> +-----+|            +-----+
> | 005 ||            | 101 |
> +-----+|            +-----+
> | ... ||            | ... |
> +-----+|            +-----+
>        |
>        |            +-----+
>        +----------->| 400 |
>                     +-----+
>                     | 401 |
>                     +-----+
>                     | ... |
>                     +-----+
> So the array in this case is cells 002-003, each cell contains a
> reference that points to 099, and to 400, respectively. Now 099 and 400
> are memory locations that contain arrays.
> Naturally, the computer has to know information like how long these
> referenced arrays are, and what type of information they contain (like a
> hash or a scalar or an array) and this info is stored in the reference.
> in fact, if you call up the value of a scalar reference without
> "de-referencing" it, you will see a value like
> SCALAR0xbff009 or
> ARRAY990xff01
> if you dereference it properly, Perl will go to the memory location and
> get the value you want, and you won't even see the differenc between a
> referenced value and an actual value.
>
> In C, you must declare the size of an array from the start, and this
> cannot be changed (mostly). this is because of the nature of arrays, and
> how the computer knows where to find them in its memory.
> Perl will let you expand arrays at will. I infer from this (although I
> am not sure) that Perl's arrays are constructed differently than C's,
> and probably using an invisible referencing scheme similar to what I
> discussed here. Of course that's just a guess.
>
> I hope this was helpful at all. I describe these things in order to both
> inform someone else, and to learn myself, because I find that one of the
> best ways to learn something is to explain it in detail to someone else.
>
> later...
>
> --
>  | |\  /\ ---------------------------------------*
>  | | | \      Jeffrey D. Silverman * jeff@jhmi.edu
> \/ |/  \/ Johns Hopkins University * Baltimore, MD
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 6 Oct 1999 10:54:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: why use references - in laymans terms?
Message-Id: <MPG.12652c9ffc9f261298a04a@nntp.hpl.hp.com>

In article <7tg0ci$3e8$1@nnrp1.deja.com> on Wed, 06 Oct 1999 17:20:35 
GMT, jdkronicz@my-deja.com <jdkronicz@my-deja.com> says...
> Thank you very much for your thoughtful response Jeff.  It was quite helpful.

Was the response so helpful that you felt impelled to repost all 110 
lines of it?  What could your purpose have been, other than sheer 
laziness because your so-called newsreader 'X-Http-User-Agent: 
Mozilla/2.0 (compatible; MSIE 3.02; Update a; Windows 95)' made it easy 
for you to do that?

Sheesh!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 1004
**************************************


home help back first fref pref prev next nref lref last post