[11236] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4836 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 5 23:07:11 1999

Date: Fri, 5 Feb 99 20:00:20 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 5 Feb 1999     Volume: 8 Number: 4836

Today's topics:
        ActivePerl on NT- HELP! <sigi@rueckenwind.org>
    Re: C->Perl->C Problem (Ilya Zakharevich)
    Re: Changing drives with ActiveState Perl on NT (Phil Tomson)
    Re: Cookie not working, any idea why? (Ronald J Kimball)
    Re: database <mike.lee@sandiegoca.ncr.com>
    Re: deleting hash entries <user@home.com>
        Determining time, date, and month with CGI (Newbie Ques (G.IM)
    Re: Excel and perl <mike.lee@sandiegoca.ncr.com>
        Local modules and long paths and install question (Bill Moseley)
    Re: Math::TrulyRandom on RH Linux (Randy Kobes)
    Re: Math::TrulyRandom on RH Linux <palincss@his.com>
    Re: NEWBIE regexp for web server conf file <jcounts@voicenet.com>
        passing info from one script to another using POST <alex@digi-q.com>
        passing info from one script to another using POST <alex@digi-q.com>
    Re: Perl Includes? <palincss@his.com>
    Re: Perl5.005002 Broken on number passing? (Ronald J Kimball)
        Program needs compactification (Peter J. Kernan)
        push (@INC) problem (Bob)
    Re: push (@INC) problem (Ronald J Kimball)
    Re: Python vs. Perl vs. tcl ? (Sam Holden)
    Re: Reference Question.... (Ronald J Kimball)
        Reference to an array <alex.simpson@usa.net>
    Re: Reference to an array (Sam Holden)
    Re: regular expression (Ronald J Kimball)
    Re: Using Perl to interrogate Hotmail <knetter@nortelnetworks.com>
    Re: What's happening with this hash? (Ronald J Kimball)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sat, 6 Feb 1999 01:15:50 -0000
From: "sugus" <sigi@rueckenwind.org>
Subject: ActivePerl on NT- HELP!
Message-Id: <79g20j$h4j$1@news4.muc.eurocyber.net>

Hi!

I'm very new here, but you are my great hope for help:
I've installed the ActiveState Perl Distribution of Perl for WinNT and
everything was fine.
The example.pl run.
That was two days ago. Doing the same now, I get the alert:
Dynamic Link Library PerlCRT.dll was not found in the path
D:\perl\bin;.;D:\WINNT\Sytem32;.......
(translated, as I've got a german NT-System).
What happened? What's wrong? And most importend: how can I get perl running
again?
There is no way to install it again as installation is aborted every time.
Neither it can be deinstalled. Or can it?
Sorry for my stupid asking (I'm not an NT-Expert...),
I would appreciate your help anyway.

Thanks, sugus




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

Date: 6 Feb 1999 02:46:52 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: C->Perl->C Problem
Message-Id: <79gaes$2ue$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Robert J. Irwin
<rjirwin@top.cis.syr.edu>],
who wrote in article <36bb5b8c.0@news.syr.edu>:
> The C->Perl set-up has worked for me previously, but that ended when
> I changed the Perl code to "use" the XS module I wrote -- i.e., when I
> tried a C->Perl->C route.  Specifically, I get a msg to the effect
> that my perl wasn't built for dynamic loading, so my XS module can't
> be loaded.

So why do not you build your application so that it *is* build for
dynamic loading?  Diff miniperlmain.c vs. perlmain.c to see what
need to be changed.

Hope this helps,
Ilya


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

Date: 5 Feb 1999 17:26:27 -0800
From: ptkwt@user2.teleport.com (Phil Tomson)
Subject: Re: Changing drives with ActiveState Perl on NT
Message-Id: <79g5o3$t0$1@user2.teleport.com>

In article <YgNnSm8T#GA.154@pet.hiwaay.net>,
Rob Lemley <RobLemley@nospam.com> wrote:
>How do you know that what you're doing is not working?



>And what do you mean that the "working directory in the
>context of the perl script is still ..."?

In other words, if we tried to get a list of all the files in the current
directory, we still got the list from the original directory - ie we had
not moved to a new directory.

I finally found a solution though, using the chdir that is overridden in
the Cwd module works:

use Cwd 'chdir';
chdir ....

this does what we need it to do.

Phil
-- 
Phil Tomson
FreeHDL Project
http://www.freehdl.seul.org/


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

Date: Fri, 5 Feb 1999 22:49:32 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Cookie not working, any idea why?
Message-Id: <1dmrv2z.2qdyff1mzungmN@bay2-365.quincy.ziplink.net>

Andri Bell [aka Andre Bell] <cookies@ONE-CLICK.COM> wrote:

> This cookie isn't being returned to me when the html form is submitted. Any
> ideas why?

> %cookies = &getCookies;

> sub
> GetCookie {
>  [...]
> } 

The problem might be related to the fact that your subroutine names for
getting a cookie don't coincide.

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Fri, 5 Feb 1999 17:35:49 -0800
From: "Mike Lee" <mike.lee@sandiegoca.ncr.com>
Subject: Re: database
Message-Id: <79g6k5$rfj@rap.SanDiegoCA.NCR.COM>

Write the script on the NT machine using perl's ODBC module or the ActiveX
module
and NT's ADO.  You'd use the ActiveState perl on NT.  Then you can write a
simple
perl client-server (eg using sockets) to send requests to the NT machine and
return
results.  Your Unix perl client will talk to your NT server script over the
network, and
the server script will call your script that talks to Oracle.

Not simple, but it is a perl-based solution.

--Mike

Steven T. Henderson wrote in message ...
>nope sorry, this still requires either middleware or some custom
>programming. you still need to somehow connect the two machines, check out:
>
>www.ensodex.com
>www.openlinsw.com
>
>or contact me directly since i have some experience in this.
>
>
>cnsxxx@my-dejanews.com wrote in message
<79f0nf$ri1$1@nnrp1.dejanews.com>...
>>Hi,
>>
>>A year (or so) ago I posted a question asking if I could run a Perl script
>on
>>UNIX (Solaris7 now) to connect up to an Oracle8 database on NT4....without
>>using any 3rd party software.
>>
>>I have no Oracle s/ware at all on UNIX so that route is closed.
>>
>>At the time it didn't seem possible....is there a solution now?
>>Any useful URL's out there?
>>
>>Chris
>>-=-=-
>>
>>please reply to: chrisNOSPAM@mdrive.demon.co.uk
>>
>>-----------== Posted via Deja News, The Discussion Network ==----------
>>http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
>
>




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

Date: Fri, 5 Feb 1999 20:34:04 -0800
From: "John Doe" <user@home.com>
Subject: Re: deleting hash entries
Message-Id: <u_Mu2.547$O4.4084@eagle.america.net>

I have had the same problem and could not resolve this.

If you figure it out, I would appreciate you emailing me, and
if I figure it out, I'll let you know.  I ended up writing a new hash
without the vaue that I wanted and renamed it with the
name of the original hash.  Very crude fix.

Steve Kohler
skohler@mindspring.com






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

Date: Sat, 06 Feb 1999 03:15:18 GMT
From: noone@home.com (G.IM)
Subject: Determining time, date, and month with CGI (Newbie Question)
Message-Id: <atOu2.1498$175.3424@news.rdc1.sdca.home.com>

If possible, how would one go about determining time, date, and month with CGI 
script? I am able to do it most efficiently with javascript, but that poses to 
be a problem. I'd appreciate any help. Thanks!


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

Date: Fri, 5 Feb 1999 17:42:58 -0800
From: "Mike Lee" <mike.lee@sandiegoca.ncr.com>
Subject: Re: Excel and perl
Message-Id: <79g71j$rfn@rap.SanDiegoCA.NCR.COM>

Alternately, you can use Excel to SaveAs and select the "csv" format to
produce a text file in comma-separated-values format.  The resulting
csv file is a text file with rows in text lines, and columns separated by
commas.

Perl is then a great tool to read and manipulate the text file.

Excel can be used to read csv files too.

--Mike

Mark Wright wrote in message <36b9cad2.0@news3.uswest.net>...
>>>On Sat, 30 Jan 1999, Steve . wrote:
>>>
>>>> I have an excel spreadsheet that I want to extract the data from
>for
>>>> manipulation.  Is there a way in perl to read an excel
>spreadsheet?
>
>
>I've never tried this out, but this site claims to have perl scripts
>that can parse MS document files:
>
>http://user.cs.tu-berlin.de/~schwartz/pmh/index.html
>
>Mark Wright
>---
>mwright@pro-ns.net
>
>
>




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

Date: Fri, 5 Feb 1999 16:32:05 -0800
From: moseley@best.com (Bill Moseley)
Subject: Local modules and long paths and install question
Message-Id: <MPG.11252d61126810ba9896a4@nntp1.ba.best.com>

Oh another installing modules question! -- part of Perl that's a bit 
mysterious to me.

I just installed libnet in a local directory -- not in the main perl 
distribution.

I used the PREFIX=~/lib command to specify a local directory.

And instead of ending up with a ~/lib/Net directory, I ended up with
~/lib/perl5/site_perl/5.005/sun4-solaris/Net

There's four directories above ~/lib.  That makes for a longish
use lib line in my script.

My questions are:
Is there a way to install modules locally without
all the perl5/site_perl/5.005/sun4-solaris directories?

Or is that dependent on the module's installation routine?

Any reason I can't just move the files from 
~/lib/perl5/site_perl/5.005/sun4-solaris/Net
to ~/lib/Net?

And don't some modules include compiled extensions?  Can someone explain 
how they fit into the picture?  For example, if libnet included binaries, 
where would they end up locally?  Same directories as the .pm files?

Sorry for being so clueless...

-- 
Bill Moseley mailto:moseley@best.com


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

Date: 6 Feb 1999 00:23:35 GMT
From: randy@theory.uwinnipeg.ca (Randy Kobes)
Subject: Re: Math::TrulyRandom on RH Linux
Message-Id: <slrn7bn3em.88c.randy@theory.uwinnipeg.ca>

On Fri, 05 Feb 1999 18:07:47 -0500, Steve Palincsar <palincss@his.com> wrote:
>I've tried to build this module from source
>from CPAN on my RedHat 5.1 Linux box, and had
>no luck: execution would hang on the test
>scripts.  The documentation did say 'this has
>been tested on Solaris only, and if you are
>on anything else you are on your own'. 

Hi,
   Using Linux 2.0.36, and perl 5.005_02, this module built
OK and passed the tests for me (which are fairly basic). Were there
any errors during the build phase? Is this version 1.0 of
the distribution?

-- 
		Best regards,
		Randy Kobes

Physics Department		Phone: 	   (204) 786-9399
University of Winnipeg		Fax: 	   (204) 774-4134
Winnipeg, Manitoba R3B 2E9	e-mail:	   randy@theory.uwinnipeg.ca
Canada				http://theory.uwinnipeg.ca/


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

Date: Fri, 05 Feb 1999 22:42:27 -0500
From: Steve Palincsar <palincss@his.com>
Subject: Re: Math::TrulyRandom on RH Linux
Message-Id: <36BBBA23.C63CD61A@his.com>

I've replied to Randy by mail, but more generally -
no errors I could see during the build, but as it
starts to do the test, it prints the 1 prior to
executing the function that provides a random
number, then hangs.

This is so whether I build it from source from
CPAN or whether I unpack the rpm.

I understand others are running this successfully on
Linux, but I've not been successful in several
build attempts.

Does anybody have even a guess as to what might
be happening?

Randy Kobes wrote:
> 
> On Fri, 05 Feb 1999 18:07:47 -0500, Steve Palincsar <palincss@his.com> wrote:
> >I've tried to build this module from source
> >from CPAN on my RedHat 5.1 Linux box, and had
> >no luck: execution would hang on the test
> >scripts.  The documentation did say 'this has
> >been tested on Solaris only, and if you are
> >on anything else you are on your own'.
> 
> Hi,
>    Using Linux 2.0.36, and perl 5.005_02, this module built
> OK and passed the tests for me (which are fairly basic). Were there
> any errors during the build phase? Is this version 1.0 of
> the distribution?
> 
> --
>                 Best regards,
>                 Randy Kobes
> 
> Physics Department              Phone:     (204) 786-9399
> University of Winnipeg          Fax:       (204) 774-4134
> Winnipeg, Manitoba R3B 2E9      e-mail:    randy@theory.uwinnipeg.ca
> Canada                          http://theory.uwinnipeg.ca/


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

Date: Fri, 5 Feb 1999 19:11:48 -0500
From: "John Counts" <jcounts@voicenet.com>
Subject: Re: NEWBIE regexp for web server conf file
Message-Id: <79g1q9$lr7$1@news1.fast.net>


I modified Bill's code a little

while (<INFILE>) {
     /^<VirtualHost/ig;
     @list = ( /([^\s>]+)/gc ) ;
     print "@list \n";
}







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

Date: Fri, 05 Feb 1999 18:29:25 -0800
From: Alex Guberman <alex@digi-q.com>
Subject: passing info from one script to another using POST
Message-Id: <36BBA905.3F25@digi-q.com>

Hi,

Would anyone know how to pass information from one Perl/CGI script to
another using POST method.  Another words, the first script would get
the fields, read it, manipulate them and then pass it on to the second
script to read it like it was passed from an HTML form in the first
place.

I know about the LWP module, but I can't figure out how to make it do
this and if it can do it at all.

Please help.

regards,
Alex Guberman


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

Date: Fri, 05 Feb 1999 18:28:47 -0800
From: Alex Guberman <alex@digi-q.com>
Subject: passing info from one script to another using POST
Message-Id: <36BBA8DF.1E9F@digi-q.com>

Hi,

Would anyone know how to pass information from one Perl/CGI script to
another using POST method.  Another words, the first script would get
the fields, read it, manipulate them and then pass it on to the second
script to read it like it was passed from an HTML form in the first
place.

I know about the LWP module, but I can't figure out how to make it do
this and if it can do it at all.

Please help.

regards,
Alex Guberman


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

Date: Fri, 05 Feb 1999 22:57:09 -0500
From: Steve Palincsar <palincss@his.com>
To: Chad Lawson <wildcard3927@hotmail.com>
Subject: Re: Perl Includes?
Message-Id: <36BBBD95.8F1581C4@his.com>

So this is a module, not just a chunk of perl code
that returns true.  Or so you say.

Does it export the function
names like a true module?  I think this is a case
where we'll have to see the actual code rather than
a generic hypothetical example, because the devil
is in the details here.

After all, at this point I see you are using code.pm
which I will take on faith is actally on the @INC path,
but although you talk about a sub called ReadData your
error is in calling AddressBook.  I have no assurance
AddressBook is even defined in code.pm at all, never
mind whether it's exported correctly to package main.


Chad Lawson wrote:
> 
> I am trying to write a generic CGI engine that will load (include)
> functions from other perl scripts.
> 
> According to the documentation, I should be able to have other simple
> perl functions withing the @INC path, and say:
> 
>         use code;
> 
> And if code.pm contains "sub ReadData", I should be able to call:
> 
>         &ReadData;
> 
> But I keep getting:
>         Undefined subroutine &main::AddressBook called at ./index.cgi line 29.
> 
> I have a routine in the main code to 'use' each file in a "Mod" directory,
> and I want to be able to call functions without having to know what
> included file they are in.

Without knowing that, how are you going to be sure you load the
correct module?  Is this an example of code.pm not including the
definition for AddressBook because it's actually defined in
blech.pm?
 
> My CGI gets the name of the function it should call from the QUERY_STRING.

So I call your script thusly: 
http://your.server.com/cgi-bin/some.cgi?foobazbarnowayjose
and you expect to execute that sub?  I just made it up, how could
you possibly
expect to find it actually defined?

You are really going to have to rethink this.

> 
> How can I have extra snipits of perl code that are included into the main
> script at runtime, and are considered part of the main file?
>

package main;
sub arbitrary_code {
  print "I am a chunk of arbitrary code\n";
}

1;

put this in a file called chunk_of_code.pl
on the @INC search path and load it with a "require"
or put it anywhere you like where your program has
rights to read it, and load it with a do, giving
the full path name.

Please note, however, this is*NOT* a module.  A module
has to do specific things, which this snipet of code
does not do.  

> I don't even know how to ask the question simply to look in a FAQ or search
> online documentation.  Can anyone point me to a source, or tell me what to do?

If you have Programming Perl read about modules.  Also, look in
perl documentation for "require", "use" and "do".

 
> Thanks in advance,
> CDL


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

Date: Fri, 5 Feb 1999 22:49:33 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Perl5.005002 Broken on number passing?
Message-Id: <1dmrx0u.1d0yovq12ut2zcN@bay2-365.quincy.ziplink.net>

[posted and mailed]

Xeno Campanoli <xeno@bigger.aa.net> wrote:

> I've got the following:
> 
> $n = 005.5;
> 
> I then print
> 
> print STDERR "trace $n\n";
> 
> I get back:
> 
> trace 55
> 
> You can't tell me that this isn't broken.

I can, and I will.

A literal number beginning with 0 and another digit is an octal integer.
Octal integers don't have decimal points, so the period is parsed as the
concatenation operator, with the result that you concatenate the two
strings '5' and '5'.

Similarly, 010.8 would give you '88', because octal 010 is decimal 8.

> P.S., a quick fix is $n = "005.5" instead.

Another fix is to leave off leading zeros:

$n = 5.5;


Note that a literal number beginning with 0 and a decimal point is
parsed as a floating point number, so this is okay:

$n = 0.5;

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 6 Feb 1999 02:17:35 GMT
From: pjk6@po.cwru.edu (Peter J. Kernan)
Subject: Program needs compactification
Message-Id: <79g8o0$lad$1@pale-rider.INS.CWRU.Edu>



This program prints the unique words in a file, one per-line. 
The problem is, obviously, it is too verbose. 

Note: the line "require 5.005;" was omitted for brevity.

Program: unique.pl  (I apologize in advance if this program has
already been written down somewhere.)

#!/usr/bin/perl -0anl012

print for sort keys%{{@F}}
-- 
   the readiness is all --Hamlet


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

Date: 6 Feb 1999 00:42:34 GMT
From: bob@ggrweb.com (Bob)
Subject: push (@INC) problem
Message-Id: <79g35q$q1@bgtnsc02.worldnet.att.net>

Hello:

I have a question about how to use CPAN module:

I am trying to use CPAN which is installed in my home directory.
When I run my script, got the following error:

-------------------------------------------------------
Can't locate LWP/Simple.pm in @INC (@INC contains: 
/usr/local/lib/perl5/sun4-solaris/5.00404 /usr/local/lib/perl5 
/usr/local/lib/perl5/site_perl/sun4-solaris /usr/local/lib/perl5/site_perl .) 
------------------------------------------------------

My script is:

-------------------------------
#!/usr/local/bin/perl

push (@INC, '/home/bob/perl');

use LWP::Simple;
use HTML::Parse;

$html = get $ARGV[0];
  print parse_html($html)->format;
exit;     
-----------------------------------          

All CPAN modules are install under ~/perl dir and I can run my program without
any problem if I am in the ~/perl dir., but can not run it on any other
dirs.

What did I do something wrong ?

Any suggestions are greatly appreciated !!

Many thanks !

Bob Young              



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

Date: Fri, 5 Feb 1999 22:49:34 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: push (@INC) problem
Message-Id: <1dmrxex.10b2an7lgivzfN@bay2-365.quincy.ziplink.net>

[posted and mailed]

Bob <bob@ggrweb.com> wrote:

> push (@INC, '/home/bob/perl');
> 
> use LWP::Simple;
> use HTML::Parse;
  
use is a *compile-time* directive.

push() happens at *run-time*.

Thus, you are telling Perl to load the modules beforeyou have told it
where to find them.  push(@INC, 'path') worked fine when 'require' was
the thing to do, but with recent Perl versions you should do the
following instead:

use lib '/home/bob/perl';

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 6 Feb 1999 01:56:24 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Python vs. Perl vs. tcl ?
Message-Id: <slrn7bn8a9.aau.sholden@pgrad.cs.usyd.edu.au>

On Fri, 5 Feb 1999 16:09:38 -0500 , Ala Qumsieh <aqumsieh@matrox.com> wrote:
>
>epement@jpusa.chi.il.us (Eric Pement) writes:
>
>>    Here is yet another Perl-Python comparison, entitled "What's Wrong
>> With Perl?" URL is in Norway, but text is in English.
>> 
>>    http://www.stud.ifi.uio.no/~larsga/download/artikler/perl.html
>
>I disagree on several points with the author of the above article. I
>am not against Python by any means. In fact, I'm starting to read more
>and more about it every day. But that specific article bothered me a
>bit, and I want to comment on it.

<snip all the points>

A friend of mine sent me a copy of that article a fairly long time ago. I
also had some problems with some of it's content and added some comments to
my copy of the page. If anyone is interested you can find the annotated 
version of the page at :

http://www.cs.usyd.edu.au/~sholden/pythonperl.html

Note I probably made some mistakes since it was a long time ago and I never
really finished (I gave up at the sheer amount of basically incorrect
information). Also newer versions of Perl have made even more of the
articles points invalid. The obvious one being the qr{} syntax for 
regexes is one obvious example.

My formatting is bad and my spelling is attrocious and since I wasn't
intending on giving out the url in such a public place. I'm sure I made
some errors in fact as well.

Anyway take a look if your interested (the full text of the original is
their, and if those style sheet things work my stuff should be in italics)...


-- 
Sam

 "... the whole documentation is not unreasonably transportable in a
 student's briefcase." - John Lions describing UNIX 6th Edition
 "This has since been fixed in recent versions." - Kernighan & Pike


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

Date: Fri, 5 Feb 1999 22:49:35 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Reference Question....
Message-Id: <1dmrxpk.1xp8792qwovk8N@bay2-365.quincy.ziplink.net>

<droby@copyright.com> wrote:

>   @{$hash{foo}} = $obj->function;

Note that if $hash{foo} already has a value, then it will be treated as
a symbolic reference to a named array.  $hash{foo} will be autovivified
as a hard reference to an anonymous array only if it was previously
uninitialized.

Thus, $hash{foo}} = [$obj->function] is safer.

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Fri, 5 Feb 1999 15:10:27 -0000
From: "Alex Simpson" <alex.simpson@usa.net>
Subject: Reference to an array
Message-Id: <36bb0971.0@davide.msoft.it>

Hi, I'm having a little trouble passing a reference to an array in to a
subroutine. A short example that shows the problem is shown below:

@array = ("Test1", "Test2");
$array_ref = \@array;

foreach (@{$array_ref}) {
    print "$_\n";
    $_ = "Gone";
}

foreach (@{$array_ref}) {
    print "$_\n";
}

This code prints:
Test1
Test2
Gone
Gone

The same effect occurs with the first two lines shortened to:
$array_ref = ["Test1", "Test2"];

Can anyone explain why $_ appears to be a reference to the elements of the
array (from the overwriting effect), but can be printed without ${$_}?

Does $_ actually overlay on to the scalars in the array? If so, I guess I'll
have to use the line below, to avoid overwriting the scalar:
foreach my $element (@{$array_ref});

Thanks for any help you can offer,

Alex.








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

Date: 6 Feb 1999 01:33:36 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Reference to an array
Message-Id: <slrn7bn6vg.a27.sholden@pgrad.cs.usyd.edu.au>

On Fri, 5 Feb 1999 15:10:27 -0000, Alex Simpson <alex.simpson@usa.net> wrote:
>Hi, I'm having a little trouble passing a reference to an array in to a
>subroutine. A short example that shows the problem is shown below:
>
>@array = ("Test1", "Test2");
>$array_ref = \@array;
>
>foreach (@{$array_ref}) {
>    print "$_\n";
>    $_ = "Gone";
>}
>
>foreach (@{$array_ref}) {
>    print "$_\n";
>}
>
>This code prints:
>Test1
>Test2
>Gone
>Gone
>
>The same effect occurs with the first two lines shortened to:
>$array_ref = ["Test1", "Test2"];
>
>Can anyone explain why $_ appears to be a reference to the elements of the
>array (from the overwriting effect), but can be printed without ${$_}?

Because that is how it works, and is amazingly useful for things like :

for ($variable) {
	s/...//; # do something to $variable
	s/...//; # do something else to $variable
}

The documentation does say that this is how it will work :

perldoc perlsyn :
The foreach modifier is an iterator: For each value in EXPR, it aliases
$_ to the value and executes the statement.


>
>Does $_ actually overlay on to the scalars in the array? If so, I guess I'll
>have to use the line below, to avoid overwriting the scalar:
>foreach my $element (@{$array_ref});
>

You'll have the same effect, since even though the documentation I quoted
says it aliasas $_ it actually aliases whatever iterator is used. Then again
you could have tried that yourself and seen in no time at all...

If you don't want to modify the original array then don't modify the iterator.
Something like :

$element;
foreach (@{$array_ref}) {
	$element = $_; # work with a copy
}


-- 
Sam

You are bordering on ridiculous if you think you need to support your
premises.  Such an argument is an infinite regression.
 	--George Reese in <wv0O1.1521$Ge.4809664@ptah.visi.com>


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

Date: Fri, 5 Feb 1999 22:49:36 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: regular expression
Message-Id: <1dmrxts.1m6swei10iyb0pN@bay2-365.quincy.ziplink.net>

[posted and mailed]

JD Anderson <jd.anderson@boeing.com> wrote:

> I need a pattern like this X.+Y except it must exclude the instance
> XrrY.

Zero-length negative lookahead assertion!

/(?!XrrY)X.+Y/


Refer to the perlre documentation for more details.

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Fri, 05 Feb 1999 19:33:13 -0600
From: Scott Netterville <knetter@nortelnetworks.com>
Subject: Re: Using Perl to interrogate Hotmail
Message-Id: <36BB9BD9.F0F4C88E@nortelnetworks.com>

This is a multi-part message in MIME format.
--------------F6D858DA259CF2548AE4014B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I've used Net::POP3 for a net@ddress account. It was fairly straightforward.
Search on libnet on CPAN.

Scott

Abigail wrote:

> Barb - perlgirl (perlquestions@yahoo.com) wrote on MCMLXXVII September
> MCMXCIII in <URL:news:78t356$38n$1@nnrp1.dejanews.com>:
> "" I want to write something that will log into my hotmail and yahoo accounts
> "" and identify whether I have any new messages.  I normally set up an account
> "" on one or the other for each project on which I work (I do a little
> "" consulting) and it's a pain after awhile to log into 8-9 accounts each day.
> "" I have been noodling with a couple Perl libraries, but haven't figured out
> "" where to look for code that will help me through the login, etc.
>
> use LWP::UserAgent;
>
> Abigail
> --
> sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
> "$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
> *_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
> _::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))

--------------F6D858DA259CF2548AE4014B
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Scott Netterville
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Scott Netterville
n:              Netterville;Scott
org:            Nortel Networks VO
adr:            2350 Lakeside Blvd;;;Richardson;TX;75082;USA
email;internet: knetter@nortelnetworks.com
title:          Member of Scientific Staff
tel;work:       972-685-5247
tel;fax:        972-685-3191
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
version:        2.1
end:            vcard


--------------F6D858DA259CF2548AE4014B--



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

Date: Fri, 5 Feb 1999 22:49:37 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: What's happening with this hash?
Message-Id: <1dmryf7.1qpt85cgqy1hqN@bay2-365.quincy.ziplink.net>

John Moreno <phenix@interpath.com> wrote:

> test();
> 
> sub test {
> my @keys = qw{1 2 3 4};
> my $i;
> my %hash;
> 
> $\="\n";
> 
> foreach $i (@keys) {
>    print $i;
>    $hash{$i}++;
     ^^^^^^^^^^^

$hash{$i} was originally uninitialized.  $hash{$i}++ sets it to 1.

When this loop exits, %hash has four keys; 1, 2, 3, and 4.

The value 1 is associated with each of the fours keys:

  ($hash{1} == $hash{2} == $hash{3} == $hash{4} == 1)


>    for (0..$i) {
>       $hash{$i}{'test'}++;
        ^^^^^^^^^

This is a symbolic reference.  As explained above, every value in %hash
is 1.  Thus, regardless of the value of $i, the above line is equivalent
to:

  $1{'test'}++;

(Note that while $1 is readonly, %1 is not.)


>       print "  $i and ".$hash{$i}{'test'};
>    }
> }
> 
> $i=1;
> $hash{$i++}{'test'}=2;

This sets $1{'test'} to 2.

> $hash{$i++}{'test'}=5;

This sets $1{'test'} to 5.


> $i=1;
> print $hash{$i++}{'test'};

This prints the value of $1{'test'}.

> print $hash{$i++}{'test'};

This also prints the value of $1{'test'}

> 
> }


> If I use strict, I get a error message:
> # Can't use string ("1") as a HASH ref while "strict refs" in use.
> File 'Untitled #2'; Line 17

If $hash{x} is uninitialized, then $hash{x}{y} autovivifies $hash{x} as
a hard reference to an anonymous hash.

But if $hash{x} is initialized, then $hash{x}{y} uses the value of
$hash{x} as a symbolic reference to a named hash.


> I know hashes aren't my strong suit, but I can't figure out what's going
> on. Could someone please tell me what I'm doing wrong?

This is more a problem with references than with hashes.  :-)

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4836
**************************************

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