[7323] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 948 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 29 16:08:27 1997

Date: Fri, 29 Aug 97 13:00:21 -0700
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, 29 Aug 1997     Volume: 8 Number: 948

Today's topics:
     Attachment with Sendmail? <webmaster@webmagic.de>
     Re: Can You Title Case A String ?. (brian d foy)
     Crash in Perl for Win32 5.003_07 (and older versions to <peterv@valkieser.nl>
     Re: crypt... does it work with shadow passwd (Aaron Sherman)
     Re: disappearing values in DBM files <fawcett@nynexst.com.spam-me-not>
     gethostbyaddr or some such... (Michael Budash)
     Re: Getting next byte of scalar <dennis.kowalski@daytonoh.ncr.com>
     Help - Displaying text files!!! <Masked@Masked.Masked>
     Re: Help: Perl (brian d foy)
     Re: How can I print the size of a file???? (Ronald L. Parker)
     Re: I have to ASK <zenin@best.com>
     ipc socket as 0_NONBLOCK <pellja@wwc.edu>
     Re: My counter counts, but too munch (Aaron Sherman)
     Re: Out of memory problem (Ronald L. Parker)
     Pushing output in CGI kchadha@hotmail.com
     Questions about passing by reference. <peterv@valkieser.nl>
     Re: Questions about passing by reference. (Jot Powers)
     renaming long files with WIN32 Perl <matthewg@bu.edu>
     using frames along with CGI.pm <yinso@u.washington.edu>
     Re: Where is the FAQ?  Not at "www.perl.com"! <ramon@ramonc.icix.net>
     Re: Win32::EventLog problem <dave@turfpit.demon.co.uk>
     Re: Win32::EventLog problem <dave@turfpit.demon.co.uk>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 29 Aug 1997 21:30:27 +0200
From: Bernhard Naahs <webmaster@webmagic.de>
Subject: Attachment with Sendmail?
Message-Id: <34072353.4A87@webmagic.de>

Hello everybody,

ich wish to setup a CGI Script (Perl) wich can send a download request
via eMail. (Like that one Matt Wright uses on his Site). Anyone knows
how to do this, or where ich can find a Script like this.

Thanks in advance and greetings from Germany,

Bernhard
eMail: webmaster@webmagic.de


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

Date: Fri, 29 Aug 1997 14:24:37 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Can You Title Case A String ?.
Message-Id: <comdog-ya02408000R2908971424370001@news.walrus.com>

In article <33FA1362.195F@athena.lbl.gov>, Shawn Gordon <sgordon@athena.lbl.gov> wrote:

>Andy Marr wrote:
>> 
>> I have a string "THIS IS A STRING" and I want to
>> format it to "This Is A String". (Cap at the start of each word).
>> 
>> Is there a command in Perl to do this ? , or do I have to split the
>> string again and change to lower case and upper case the first letter ?
>
>How about:
>
>#!/usr/bin/perl
>$string = "THIS IS A TEST";
> 
>$string =~ s/\b(\w+)\b/"\L\u$1"/eg;
>print $string,"\n";

this has undesired side effects.  consider:

#!/usr/bin/perl
$string = "this isn't a test";
 
$string =~ s/\b(\w+)\b/"\L\u$1"/eg;
print $string,"\n";

__END__

This Isn'T A Test


someday someone will fix the FAQ regarding this :)

-- 
brian d foy                                  <comdog@computerdog.com>


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

Date: Fri, 29 Aug 1997 19:38:28 +0200
From: Peter de Vroomen <peterv@valkieser.nl>
Subject: Crash in Perl for Win32 5.003_07 (and older versions too)
Message-Id: <34070914.4EE5BBFF@valkieser.nl>

Hello People,

I have a program written in Perl for win32 5.003_07 which crashes when I
try to read from a file.

Most of the time Perl quits with a 'Error: Runtime exception', but
sometimes it even quits with a general protection fault.

This seems to be a problem with Perl itself (I just open the file and
try to read it), so I don't think publishing the complete code (which is
pretty elaborate, and pretty unfinished) right now will do any good.
This is the subroutine where things go wrong however:

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

sub merge_file
{
    *HTMLPage = shift;
    $LineNo = shift;
    $Offset = shift;
    $FileName = shift;

        # Get line chopped up.
    $Curr = substr( $HTMLPage[$LineNo], 0, $Offset );
    $Rest = substr( $HTMLPage[$LineNo], $Offset );

        # Kill line.
    splice( @HTMLPage, $LineNo, 1 );

    open( MERGEFILE, "<" . $FileName ) || cgi_error( "Couldn't open file
'" . $FileName . "'.", __LINE__, 1 );
    while( <MERGEFILE> )
    {
            # Parse variables, which we can use for some niceties.
        $Curr .= parse_variables( $_ );
        splice( @HTMLPage, $LineNo, 0, $Curr );
        $Curr = "";
        $LineNo++;
        if( eof( INFILE ))
        {
            splice( @HTMLPage, $LineNo, 0, $Rest );
        }
    }
    close( MERGEFILE );
}

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

The crash occurs in the line with 'while( <MERGEFILE> )'. When I step
through the code with the debugger the program crashes right after
executing this statement. When I run it without debugging (I added some
print's) it crashes after reading 2 or 3 lines (it seems to read the
file allright though).

@HTMLPage is a simple flat array of sting.
$LineNo is an index in the array.
$Offset is the offset in an element of the array where we have to split
the line.
$FileName is a string containing a filename.

The filename is:
'd:\home\htdocs\hv_generate\templates\hoogovens\header.scr'.

Maybe the path is too long?

Has anyone ever had the same problem before, and does anyone have a
workaround?

I'm using Perl for Win32 5.003_07 build 307 (I've tried older builds to,
same problem) under Windows NT 4.0 (with service pack 3 installed).

Please reply in the newsgroup, _and_ to peterv@valkieser.nl, as I don't
look in the newsgroup regularly (I'm just too busy at the moment), but I
think this might interest other people as well.

Thanks in advance,

Peter
-- 
Peter de Vroomen (e-mail: peterv@valkieser.nl), Software Engineer,
Valkieser Solutions, 's Gravelandseweg 80a, 1217 EW Hilversum,
The Netherlands, +31-(0)35-6714300, fax: +31-(0)35-6714333


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

Date: 29 Aug 1997 13:58:20 -0400
From: ajs@lorien.ajs.com (Aaron Sherman)
Subject: Re: crypt... does it work with shadow passwd
Message-Id: <5u72js$7pn@lorien.ajs.com>

Andrew Kerr <kerr@cs.uregina.ca> wrote:
>: > Sure it'll work.  You just have to read use /etc/shadow instead of
>: > /etc/passwd as the location of the crypt()ed string.  Which means you
>: > have to be root.
>: > 
>: Better if you use getpwnam and friends.  You'll get the password if
>: you've got the priveleges and your code will be more portable!
>
>
>Well, two problems... 1. This is meant to be used via a webpage, so no
>root, cause I'm not letting perl run as root.
>2.  What is friends???  I know getpwnam and am using it, but haven't seen
>or read anything on friends.
>

First off, in your original text, crypt has nothing directly to do with
/etc/passwd, but I assume that the reply above was addressing what you
really meant.

Second, from the perlfunc manpage:


       getpwnam NAME

       getpwuid UID

       getpwent

       setpwent

       endpwent

               These routines perform the same functions as their
               counterparts in the system library.  Within a list
               context, the return values from the various get
               routines are as follows:

                   ($name,$passwd,$uid,$gid,
                      $quota,$comment,$gcos,$dir,$shell) = getpw*

These are getpwnam's friends.

			-AJS


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

Date: 29 Aug 1997 13:55:56 -0400
From: Tom Fawcett <fawcett@nynexst.com.spam-me-not>
To: Aymeric Duclert <duclert@genset.fr>
Subject: Re: disappearing values in DBM files
Message-Id: <8jvi0oq3f7.fsf@nynexst.com.spam-me-not>

Aymeric Duclert <duclert@genset.fr> writes:
> I have a problem of disappearing (key,value) pairs using the Berkeley DB
> library.
> I'm using this library through perl5.
>  
> Here is a simple programm where the key "key1" is changed several times
> and is lost at the end, while a new key "key11" appears ...
>  
> ------------------------------------------------------------------------
> #!/nfs/share/bin/perl
> use Fcntl;
> use DB_File;
> &Fill("short");
> &Fill("long");
> &Fill("short");
>  
> sub Fill
> {
>         my($arg) = shift;
>         tie %hash, "DB_File","toto",O_CREAT|O_RDWR,511,$DB_HASH;
>         if ($arg eq "short") {
>                 $hash{"key1"} = "A";
>         } elsif ($arg eq "long") {
>                 $hash{"key1"} = "A" x 10000;
>         }
>         $hash{"key2"} = "BBBB";
>         @keys = keys(%hash);
>         print "keys : @keys\n";
>         print "length of key1 : " . length($hash{"key1"}) . "\n\n";
>         untie %hash;
> }
> ------------------------------------------------------------------------
> Here is the suprising output :
>  
> keys : key1 key2
> length of key1 : 1
>  
> keys : key2 key1
> length of key1 : 10000
>  
> keys : key2 key11
> length of key1 : 0
>  
> And if the programm is run several times, the result is even more
> suprising : a hash with several identical keys !
> ------------------------------------------------------------------------

If you change the number 10000 to 1000, the strange behavior goes away.
I suspect you're exceeding DB_File's maximum key length and it's
corrupting the database in some way.  

Seems like it should issue an error.

-Tom


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

Date: Fri, 29 Aug 1997 12:30:31 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: gethostbyaddr or some such...
Message-Id: <mbudash-2908971230320001@d49.pm8.sonic.net>

If I have an IP address (e.g., mine right now: 208.201.224.62) and I'd
like to get the actual host name (e.g., mine right now:
d49.pm8.sonic.net), how would I do it in perl? Would I use perl's
gethostbyaddr function? Anybody?

Response by email as well as this newsgroup preferred - I'm kinda in a hurry!

TIA,
                _____________________________
                       Michael Budash, Owner
                     Michael Budash Consulting
                           707-255-5371
                   http://www.sonic.net/~mbudash
                         mbudash@sonic.net
                _____________________________


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

Date: Fri, 29 Aug 1997 11:42:59 -0400
From: Dennis Kowalski <dennis.kowalski@daytonoh.ncr.com>
Subject: Re: Getting next byte of scalar
Message-Id: <3406EE03.7DD3@daytonoh.ncr.com>

Dennis Kowalski wrote:
> 
> I am porting a C program to Perl.
> 
> The program looks at each byte of an input record.
> 
> I am doing the following in Perl.
> 
> $byte = substr($buff,$indx,1);
> 
> $indx is incremented to get to the next byte.
> 
> The $buff scalar has some binary data fields in it.
> 
> Most of the time $byte is set to the right value but sometimes
> it gets set to 1.
> 
> One of the values that does this is a hex ac in $buff.
> 
> There are probably others too.
> 
> If substr has a problem with certain hex values, is there another way
> to extract a byte from a scalar when the byte may be any binary value
> of hex 00 to hex ff ?
> 
> Thank You


-----------------
THANK YOU ALL
-----------------

This is just to let everyone know how the problem was solved.

Instead of using substr to get the next byte of the scalar, I now
do the following

@bytes = split //,$record;

This creates an arry of bytes with all of the record in it

Then to access a byte, I do this

$ch = shift @bytes;

Many Thanks to Tom Phoenix for the solution and to others who responded 
also


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

Date: 29 Aug 1997 18:54:18 GMT
From: "Masked" <Masked@Masked.Masked>
Subject: Help - Displaying text files!!!
Message-Id: <01bb95da$f9ff7c20$5f867dc2@cathalmc>

Hi. I'm new to Perl so please put up with my (perhaps silly?) question.
What I want to know is how do I write a script that will read from a text
or html file and then output it to the screen? I'd be delighted if you
could give me some sample code!

Please reply to me via email - cmccarthy@ccl.ie

Many thanks!
Cathal McCarthy


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

Date: Fri, 29 Aug 1997 15:19:33 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Help: Perl
Message-Id: <comdog-ya02408000R2908971519330001@news.walrus.com>

In article <5tkp3t$26b$1@nnrp.cs.ubc.ca>, q8e192@ugrad.cs.ubc.ca (Henry Avatar Chan) wrote:

>Question 1)
>How do you make CONSTANTS in Perl.
>I remember seeing a cool example of how
>someone make a reference to 3.14 to PI
>or something.

#!/usr/bin/perl

*PI = \3.141592654;

$PI = 2.7182818;

print $PI;

__END__

# Modification of a read-only value attempted.
File 'Untitled'; Line 5

>Question 2)
>How do I direct  STDERR and STDOUT in Perl
>programmatically.  
>I'm looking for the C equivalent to something
>like freopen

see the perl FAQ at <URL:http://www.perl.com> for several examples :)

-- 
brian d foy                                  <comdog@computerdog.com>


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

Date: Fri, 29 Aug 1997 18:35:05 GMT
From: ron@farmworks.com (Ronald L. Parker)
Subject: Re: How can I print the size of a file????
Message-Id: <34071625.22055859@207.126.101.82>

On Fri, 29 Aug 1997 13:38:55 +0100, Gary Colman
<SPAMFREEcolmang@ms.com> wrote:

>time() - (-M $fullFilename) * 86400

Careful!  Not all days have 86400 seconds!  October 26 of this year is
a good example.

--
Ron Parker
Software Engineer
Farm Works Software       Come see us at http://www.farmworks.com
For PGP public key see http://www.farmworks.com/Ron_Parker_PGP_key.txt


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

Date: 29 Aug 1997 19:07:03 GMT
From: Zenin <zenin@best.com>
Subject: Re: I have to ASK
Message-Id: <5u76kn$ld$1@nntp2.ba.best.com>

COWBYS <cowbys@aol.com> wrote:
> I am looking for the FTP.pm module, I know what CPAN is and Ive been there,
> my understanding was that i could go there and download modules, Ive gone
> into "modules", "by module" and I dont see any  ".pm" files, Isnt there an
> easier way of 
> obtaining a particular ".pm" file from somewhere.
	Many (now most?) modules are not completely contained within a
	single, platform indepent Foo.pm file.  Net::FTP is part of the
	libnet library collection.  You need to download and install
	that (libnet) package.

	You can find it in the modules/by-module/Net/ directory of your
	local CPAN.  Look for a tar file called libnet-1.*.tar.gz

-- 
-Zenin
 zenin@best.com


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

Date: Fri, 29 Aug 1997 12:00:01 -0700
From: James Pellow <pellja@wwc.edu>
Subject: ipc socket as 0_NONBLOCK
Message-Id: <34071C31.A80@wwc.edu>

Hi all,

I have perl 5.004 and I am working on remote communications between two
linux boxes (2.0.30 slackware 3.3).  I have sucessfully created a socket
connection in perl and it seems to work ok.  So here is the problem:  I
need the program to be able to check the socket for data and if nothing
is present to continue on to the next line.  Currently the socket seems
to be set up in blocking mode.  I have read the source code for
Socket.pm and IO::Socket.pm and the man pages for the linux system calls
and it talkes about setting the socket up as O_NONBLOCK.  Is it possible
to do this in perl.  Thanks for your help.


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

Date: 29 Aug 1997 14:12:31 -0400
From: ajs@lorien.ajs.com (Aaron Sherman)
Subject: Re: My counter counts, but too munch
Message-Id: <5u73ef$7ro@lorien.ajs.com>

Lozano Mosterin, Jesus <lozano@opalo.etsiig.uniovi.es> wrote:

>I want to count the "0" chars in various strings of lengh 7,
>related to string position. I'm using this and sometimes works
>as expected, others don't, counting one ocurrence more in the
>seventh position
>
>
>for ($j=0;$j<7;$j++) {  $stat[$j]++ if ($j == index($temp,"0",$j)); }

I don't know what's going wrong there, but I have to wonder if this
wouldn't be faster:

	$tmp2 = substr($temp,0,7);
	$stat[length($`)]++ while $tmp2 =~ /0/g;

That will allow perl to skip over non-zeros faster.

			-AJS


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

Date: Fri, 29 Aug 1997 18:36:32 GMT
From: ron@farmworks.com (Ronald L. Parker)
Subject: Re: Out of memory problem
Message-Id: <3408169c.22174590@207.126.101.82>

On Fri, 29 Aug 1997 08:17:36 -0700, Tom Phoenix
<rootbeer@teleport.com> wrote:

>On Fri, 29 Aug 1997, Daniel Mills wrote:
>
>> I running the following simple script on on a VMS machine and get
>> an "Out of Memory" error whenever the input file is very large (> 10M).
>
>What version of Perl are you running? Many memory leaks from previous
>versions have been plugged in 5.004_03.
>
>> open(TXT,"cbgnl\$dump:dot.sgm");
>
>It doesn't waste any memory to check the return value from open. :-)
>
>> undef $/;
>> while(<TXT>){
>
>Are you really needing to read the entire file into memory at once? If
>your application can do so, it's more polite to process it line-by-line. 
>
>> 	while(/\d+\s/gs){
>
>I don't think that the /s option adds anything there. 
>
>Hope this helps!
>
>-- 
>Tom Phoenix           http://www.teleport.com/~rootbeer/
>rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
>Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
>

--
Ron Parker
Software Engineer
Farm Works Software       Come see us at http://www.farmworks.com
For PGP public key see http://www.farmworks.com/Ron_Parker_PGP_key.txt


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

Date: Fri, 29 Aug 1997 14:51:16 -0600
From: kchadha@hotmail.com
Subject: Pushing output in CGI
Message-Id: <872883778.16200@dejanews.com>

Hi,

This is a very simplied version of
my program:

$| = 1;

for ($i=0;$i<5;$i++)
{
	sleep(5);
	print "wait ";
}

Now the problem is that it prints all "wait wait wait"
together instead of waiting 5 secs before each.

Howvever, if I say print "wait <br>", it pushes
the output every 5 secs.

My questions is that can I avoid putting the
<br> or <p> and just get the output to
print on the same line after every 5 secs-
basically I need to prevent the buffering. I
got suggestions to make it a nph- script, but that
doesn't work.

Please e-mail your replies to kchadha@hotmail.com


Thanks !

K.Chadha

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Fri, 29 Aug 1997 19:39:32 +0200
From: Peter de Vroomen <peterv@valkieser.nl>
Subject: Questions about passing by reference.
Message-Id: <34070954.5CEB2AF0@valkieser.nl>

Hello People,

I have some questions about passing variables around using references.

In my program I try to pass array's and hash-tables by reference as much
as possible, because I presume passing a reference to a large array is
much faster than passing the array itself (passing them to a subroutine
that is..).

I want to create an array inside a function and then pass the reference
to the array to the caller. I don't want to create a global array, and
creating a 'my' array is one of the most stupid things I could do, so I
create a local variable, and pass the reference back to the caller.
Consider the following code:

-------------------------
sub create_array
{
    local @ar;

    $ar[0] = "0";
    $ar[1] = "1";

    return \@ar;
}

*foo = create_array;
-------------------------

This is possible, and seems to work, but is it valid? @ar is created as
a local variable, but a local variable only differs from a global
variable by its scope, isn't it? I'd think @ar still exists somewhere in
memory when the subroutine create_array is exited. This would not be
true if I had declared @ar as a 'my' variable.

I'd like to make the parallel with a static variable in C (as this is my
main programming-language).

Next example... What if I wanted to use @foo as a parameter for another
function, like this (I won't recite the above subroutine..):

-------------------------
sub print_element
{
    *bar = shift;
    my $element = shift;

    print $bar[$element], "\n";
}

*foo = create_array;
print_element( \@foo, 1 );
-------------------------

This is also possible, and seems to work, but is this valid too? My
first reaction was to declare @bar as a 'my' variable (my *bar = shift).
This doesn't seem possible (why not, I'm passing a reference, isn't
it?). But not giving the variable a scope at all declare's it as a
'my'-variable, isn't it? Declaring @bar as a 'local' variable works
also, but then @bar wouldn't be garbage-collected when print_element is
exited (I would expect....).

Now the BIG question (it's getting trickier)... What if I wanted to
_add_ new elements to the array, like so:

-------------------------
sub add_elements
{
    *bar = shift;

    push @bar, "2";
}

*foo = create_array;
add_elements( \@foo );
print_element( \@foo, 2 );
-------------------------

This also seems to work (print_element prints 2). I didn't declare @bar
as 'local' in add_elements, so where is the element going to? The
original array (@ar) was declared local, are new elements going to go to
the right place to? Or will the new element be put in the 'my' address-
space (which will be marked for garbage-collection after add_elements is
exited), creating an internal reference (in Perl) to an invalid piece of
memory?

Ok, this mail is getting a trifle long, so I'll try to condense these
questions:

Can I treat references in Perl as I would treat pointers in C? When I
pass a reference, am I just passing an address to some kind of memory?
Can Perl become confused about where to allocate the memory for new
elements in an array passed by reference (and does this count for
hash-tables too)? If I pass a variable by reference to a subroutine, and
this subroutine passes the same variable by reference to another
subroutine, will this work?

I ask these questions because I have a Perl program which keeps
crashing, and I'm not sure I did things right.

Thanks in advance,

PeterV
-- 
Peter de Vroomen (e-mail: peterv@valkieser.nl), Software Engineer,
Valkieser Solutions, 's Gravelandseweg 80a, 1217 EW Hilversum,
The Netherlands, +31-(0)35-6714300, fax: +31-(0)35-6714333


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

Date: 29 Aug 1997 19:42:36 GMT
From: news@bofh.com (Jot Powers)
Subject: Re: Questions about passing by reference.
Message-Id: <5u78nc$2r9$1@gazette.corp.medtronic.com>

In article <34070954.5CEB2AF0@valkieser.nl>, Peter de Vroomen wrote:
>Hello People,
>
>I have some questions about passing variables around using references.

First thing you probably want to do is to go ahead and read the
perlref (perl references) page.  Try perldoc perlref.

>In my program I try to pass array's and hash-tables by reference as much
>as possible, because I presume passing a reference to a large array is
>much faster than passing the array itself (passing them to a subroutine
>that is..).

I believe this is correct.  It also has other benefits.  You want
to look at perlsub for some of them.

>
>I want to create an array inside a function and then pass the reference
>to the array to the caller. I don't want to create a global array, and
>creating a 'my' array is one of the most stupid things I could do, so I
>create a local variable, and pass the reference back to the caller.

Ok, now I seem to recall that local variables, are really global variables.

[Checks Camel real quick]

pg 108:  '...local variables, which are really global variables in
disguise.'

So, go head and use a my'd array.

>sub create_array
>{
>    local @ar;

     my @ar;
>
>    $ar[0] = "0";
>    $ar[1] = "1";
>
>    return \@ar;
>}
>
>*foo = create_array;

Eek.  C-geek!  ;)

You want $foo.  Here is my version of yours.

#!/usr/local/bin/perl -w
use strict;
 
my $foo;
 
$foo = &create_array();
 
print "foo->[0]: $foo->[0]. foo->[1]: $foo->[1]\n";
sub create_array {
        my @ar;
 
        $ar[0] = 'A';
        $ar[1] = 'B';
 
        return \@ar
}
node127% perl /tmp/test.pl
foo->[0]: A. foo->[1]: B

>This is possible, and seems to work, but is it valid? @ar is created as
>a local variable, but a local variable only differs from a global
>variable by its scope, isn't it? I'd think @ar still exists somewhere in
>memory when the subroutine create_array is exited. This would not be
>true if I had declared @ar as a 'my' variable.

So, no, I don't believe the * is valid, and yes, you can use a my'd 
array.

>I'd like to make the parallel with a static variable in C (as this is my
>main programming-language).

I never would have guessed.   ;)

>Next example... What if I wanted to use @foo as a parameter for another
>function, like this (I won't recite the above subroutine..):
>
>-------------------------
>sub print_element
>{
>    *bar = shift;
>    my $element = shift;
>
>    print $bar[$element], "\n";
>}
>
>*foo = create_array;
>print_element( \@foo, 1 );

Make the following changes:

sub print_element {
 
        my $bar = shift;
        my $element = shift;
 
        print $bar->[$element] . "\n";
}

print_element( $foo,1);

I think you have this off by one sort of thing.  $foo is the
reference to the original my'd array.  You can then simply pass
$foo as if it were a scalar, and then do the dref.

>Now the BIG question (it's getting trickier)... What if I wanted to
>_add_ new elements to the array, like so:
>
>-------------------------
>sub add_elements
>{
>    *bar = shift;
>
>    push @bar, "2";
>}

sub add_elements {
 
        my $bar = shift;
 
        push @{$bar}, 'C';
}

>Can I treat references in Perl as I would treat pointers in C? When I
>pass a reference, am I just passing an address to some kind of memory?
>Can Perl become confused about where to allocate the memory for new
>elements in an array passed by reference (and does this count for
>hash-tables too)? If I pass a variable by reference to a subroutine, and
>this subroutine passes the same variable by reference to another
>subroutine, will this work?

Ok, I'll stick my final version, which I kept adding to as you
came up with more questions, after my sig.  

I'm not sure this is the best way to do things as I haven't
had to pass by ref a bunch, but if I'm wrong, one of the
gooroos will correct me.

>I ask these questions because I have a Perl program which keeps
>crashing, and I'm not sure I did things right.

Try these changes.  Hope that helps.

-- 
Jot Powers  news@bofh.com
Unix System Administrator
"Sometimes you just have to grab the bull by the tail and face the situation."


#!/usr/local/bin/perl -w
use strict;

my $foo;

$foo = &create_array();
&add_elements($foo);
&print_element( $foo,2);

print "foo->[0]: $foo->[0]. foo->[1]: $foo->[1]\n";
sub create_array {
 	my @ar;

	$ar[0] = 'A';
	$ar[1] = 'B';
	
	return \@ar
}

sub print_element {

	my $bar = shift;
	my $element = shift;

	print $bar->[$element] . "\n";
}

sub add_elements {

	my $bar = shift;

	push @{$bar}, 'C';
}


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

Date: Fri, 29 Aug 1997 14:53:07 -0400
From: Matthew Glogowski <matthewg@bu.edu>
Subject: renaming long files with WIN32 Perl
Message-Id: <34071A93.4DCE72@bu.edu>

is there any way to rename long file names and directories in win32 perl
under NT?

thanks,

-matt


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

Date: Fri, 29 Aug 1997 12:49:16 -0700
From: Y Chen <yinso@u.washington.edu>
Subject: using frames along with CGI.pm
Message-Id: <Pine.OSF.3.96.970829120815.29242A-100000@saul1.u.washington.edu>

hi, I faced a weird problem that I cannot solve with CGI.pm v2.36, &
perl5.004.

I am trying to use CGI along with frames, i.e., creating forms in one
frame and then having its result show up in a different frame. codes are
right here:

 #!/usr/local/bin/perl5.004

 use CGI ":all :any";
 my $q = new CGI;
 my $self = $q->url;
 my $window;

 # determine the frame to display
 if (!$q->param('w')) { 
	$window = 0; # display the framesets
 } else {
	$window = $q->param('w');
 }
 &showWindows ($window);

 # the main sub routine
 sub showWindows {
	my $win = $_[0];
	
	print header;
	SWITCH: {
		if ($win == 0) { # print the framesets
			print title ("CGI.pm & Frame Sample"), "\n";
			print frameset ({'rows'=>'30%, *'}, "\n",
				frame ({'src'=>"$self?w=1", 'name'=>'one'}), "\n",
				frame ({'src'=>"$self?w=2", 'name'=>'two'}), "\n",
			), "\n";
			last SWITCH;
		}
		if ($win == 1) { # print the first 
			print start_html, "\n";
			print $q->startform(-action=>"$self?w=2",
					-target=>'two',
			);
			print b ('Type something: ', 
				$q->textfield (-name=>'type'), 
			), "\n";
			print $q->endform;
			print end_html, "\n";
			last SWITCH;
		}
		if ($win == 2) {
			print start_html, "\n";
			if (!$q->param('type')) {
				print h3 ('This is the original text.'), "\n";
			} else {
				print h3 ("You type: $q->param('type')."), "\n";
			}
			print end_html, "\n";
			last SWITCH;
		}
		$nothing = 1;
	}
 }

Things seem fine.  I can type in the url, and it will give me a page with
two frames, the top one with a textfield in it, and the bottom one says
that "This is the original text."  However, when I type something in the
textfield and press enter, it will behave wildly.  The target works right,
it generate pages in frame 'two', but instead of generating the intended
page (w=2), it generates w=0 (becomes a nested frame) in the frame 'two',
and then display w=1 in the nested frame 'one'; but it doesn't display any
thing in the nested frame 'two'.  nothing I do can get it to work (if I
type in url?w=2&type=Cool, then it will display the right page that says: 
"You type: Cool.").

If anyone knows anything about this behavior, plz post to this message.
any help is appreciated.  Plz Cc me, too :)

Thanks in advance,


yin-so





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

Date: Fri, 29 Aug 1997 15:22:53 -0400
From: Ramon Castillo <ramon@ramonc.icix.net>
Subject: Re: Where is the FAQ?  Not at "www.perl.com"!
Message-Id: <3407218D.26CB@ramonc.icix.net>

John Desmond Curry wrote:
> 
> Thursday, August 28, 1997
> 
> Dear Perl gurus :
> 
> I am a newbie, so please have patience!  I have spent hours
> trying to find the Perl FAQ at the various places that previous
> messages on this newsgroup (comp.lang.perl.misc) have said that
> it is at, including "www.perl.com", but none of them exist.  So,
> where is it?
> 
> Be seeing you.
> 
> John Curry
> 
> mailto:jdcurry@primenet.com
> 
> http://www.primenet.com/~jdcurry/
> 
> "I propose we leave math to the machines and go play outside." -- Calvin

It's sound weird www.perl.com should work I just visited it.

anyway You can try with any CPAN mirror :

ftp:ftp.digital.com/pub/plan/perl/CPAN/doc/FAQs/FAQ/html/index.html 

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

use Hart::WithBrain;
while ($god->bless == $Internet && $Perl == $Cool){
       $Be = "Happy";
       $Live = "Love";
       $Hack = "Fun";
}      #  RC          ray@icix.net


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

Date: Fri, 29 Aug 1997 19:12:48 GMT
From: "David Richards" <dave@turfpit.demon.co.uk>
Subject: Re: Win32::EventLog problem
Message-Id: <01bcb4af$71d0d840$0101010a@turfpit>

James

>     Open Win32::EventLog( $EventLog, $LogName, $ComputerName );

Reverse the order of $LogName and $Computername.  The documentation does
not match the code in eventlog.pm.

David

James D. Murray <jdm@oreilly.com> wrote in article 
> I have just installed Perl for Win32 from ActiveWare (5.003_07 
> Build 306) on my WinNTW4 system and I an experiencing an error 
> in the EVENTLOG.PM module. The following program:
> 
>     use Win32::EventLog;
>     my $EventLog;
>     my $LogName = 'System';
>     my $ComputerName = 'PPRO';
> 
> produces the following error:
> 
>     Modification of a read-only value attempted 
>       at D:\PERL\LIB\WIN32\EVENTLOG.PM line 81.



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

Date: Fri, 29 Aug 1997 19:17:29 GMT
From: "David Richards" <dave@turfpit.demon.co.uk>
Subject: Re: Win32::EventLog problem
Message-Id: <01bcb4b0$1900ae10$0101010a@turfpit>

James

Try

http://www.inforoute.cgs.dr/leberre1/

for excellent and accurate Eventlog & Registry documentation for Perl for
Win32.

David 

> Build 306) on my WinNTW4 system and I an experiencing an error 
> in the EVENTLOG.PM module. The following program:
>     Open Win32::EventLog( $EventLog, $LogName, $ComputerName );
> 
> produces the following error:
> 
>     Modification of a read-only value attempted 
>       at D:\PERL\LIB\WIN32\EVENTLOG.PM line 81.



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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.  

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 948
*************************************

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