[16848] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4260 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 8 11:10:28 2000

Date: Fri, 8 Sep 2000 08:10:15 -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: <968425815-v9-i4260@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 8 Sep 2000     Volume: 9 Number: 4260

Today's topics:
        Passing arrays to a sub routine kelly.carmichael@trx.com
    Re: Passing arrays to a sub routine <rmore1@my-deja.com>
    Re: Passing arrays to a sub routine kelly.carmichael@trx.com
    Re: Passing arrays to a sub routine <aqumsieh@hyperchip.com>
    Re: Passing arrays to a sub routine <rmore1@my-deja.com>
    Re: Perl & NT <livia74@ctimail3.com>
    Re: Regards CGI.pm <camerond@mail.uca.edu>
        website <jpryan@cis.tamu.edu>
    Re: WGET equivalent <jeffp@crusoe.net>
    Re: what is the best way to get the lastest line from a <bowman@montana.com>
    Re: what is the best way to get the lastest line from a <rmore1@my-deja.com>
    Re: what is the best way to get the lastest line from a (Gwyn Judd)
    Re: what is the best way to get the lastest line from a <sariq@texas.net>
        Which module to use, or is there even one out there? <michael.segulja@sgi-lsi.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 08 Sep 2000 14:05:22 GMT
From: kelly.carmichael@trx.com
Subject: Passing arrays to a sub routine
Message-Id: <8parmg$mi6$1@nnrp1.deja.com>

Any help with this would be greatly appreciated!
Here is my code:

my @srcDir = (1,2);
my $srcOutDir = "SEA";

copySrcFiles(\@srcDir,\$srcOutDir);
}

Here is the sub:

sub copySrcFiles(){
    my @srcDir = $_[0];
    my $srcOutDir = $_[1];
}

If I try to print the content of the array, there is only one element
in it. If I print the content of the scalar, it actually contains the
2nd element of the array.

Please shed some light on how to pass arrays and how to use their
content in a sub routine. I have RTFM and I am still stumped!
Thanks in advance!


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


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

Date: Fri, 08 Sep 2000 14:28:14 GMT
From: Rich More <rmore1@my-deja.com>
Subject: Re: Passing arrays to a sub routine
Message-Id: <8pat11$o33$1@nnrp1.deja.com>

In article <8parmg$mi6$1@nnrp1.deja.com>,
  kelly.carmichael@trx.com wrote:
> Any help with this would be greatly appreciated!
> Here is my code:
>
> my @srcDir = (1,2);
> my $srcOutDir = "SEA";
>
> copySrcFiles(\@srcDir,\$srcOutDir);
> }
>
> Here is the sub:
>
> sub copySrcFiles(){
>     my @srcDir = $_[0];
>     my $srcOutDir = $_[1];
> }
>
> If I try to print the content of the array, there is only one element
> in it. If I print the content of the scalar, it actually contains the
> 2nd element of the array.
>
> Please shed some light on how to pass arrays and how to use their
> content in a sub routine.

> I have RTFM and I am still stumped!
Did you: perldoc perlreftut  ???

sub copySrcFiles(){
    my $srcDirRef = $_[0];
    my $srcOutDir = $_[1];
    my @srcDir = @$scrDirRef;

    foreach $dir ( @scrDir )
    {
    }
}

This is not the most elegent way of doing things but, it shows you how
to turn a "reference to an array" into a "regular array" ( with which
you might be more familiar ).




--
=============================
Richard More
http://www.richmore.com/


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


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

Date: Fri, 08 Sep 2000 14:43:13 GMT
From: kelly.carmichael@trx.com
Subject: Re: Passing arrays to a sub routine
Message-Id: <8pattr$pcq$1@nnrp1.deja.com>

In article <8pat11$o33$1@nnrp1.deja.com>,
  Rich More <rmore1@my-deja.com> wrote:
> In article <8parmg$mi6$1@nnrp1.deja.com>,
>   kelly.carmichael@trx.com wrote:
> > Any help with this would be greatly appreciated!
> > Here is my code:
> >
> > my @srcDir = (1,2);
> > my $srcOutDir = "SEA";
> >
> > copySrcFiles(\@srcDir,\$srcOutDir);
> > }
> >
> > Here is the sub:
> >
> > sub copySrcFiles(){
> >     my @srcDir = $_[0];
> >     my $srcOutDir = $_[1];
> > }
> >
> > If I try to print the content of the array, there is only one
element
> > in it. If I print the content of the scalar, it actually contains
the
> > 2nd element of the array.
> >
> > Please shed some light on how to pass arrays and how to use their
> > content in a sub routine.
>
> > I have RTFM and I am still stumped!
> Did you: perldoc perlreftut  ???
>
> sub copySrcFiles(){
>     my $srcDirRef = $_[0];
>     my $srcOutDir = $_[1];
>     my @srcDir = @$scrDirRef;
>
>     foreach $dir ( @scrDir )
>     {
>     }
> }
>
> This is not the most elegent way of doing things but, it shows you how
> to turn a "reference to an array" into a "regular array" ( with which
> you might be more familiar ).
> Yes thank you...guess I should dereference things... :) thanxx!
> --
> =============================
> Richard More
> http://www.richmore.com/
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


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


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

Date: Fri, 08 Sep 2000 14:57:30 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Passing arrays to a sub routine
Message-Id: <7aog1zylr8.fsf@merlin.hyperchip.com>


kelly.carmichael@trx.com writes:

> Any help with this would be greatly appreciated!
> Here is my code:
> 
> my @srcDir = (1,2);
> my $srcOutDir = "SEA";
> 
> copySrcFiles(\@srcDir,\$srcOutDir);
> }
> 
> Here is the sub:
> 
> sub copySrcFiles(){
>     my @srcDir = $_[0];
>     my $srcOutDir = $_[1];
> }
> 
> If I try to print the content of the array, there is only one element
> in it. If I print the content of the scalar, it actually contains the
> 2nd element of the array.

No. This can't be correct. You are passing a reference to an array, and
a reference to a scalar to your subroutine. In your subroutine, you grab
the first argument (which is the reference to your array), and stick it
in a lexical array @srcDir (so this array contains only one element,
which is the reference of your external array).
Then you grab the second argument, which is the reference to the scalar,
and store in another scalar.

Printing those, you should get something like:

	ARRAY(0x80e16b8)
	SCALAR(0x80e16dc)

> Please shed some light on how to pass arrays and how to use their
> content in a sub routine. I have RTFM and I am still stumped!
> Thanks in advance!

Which FM did you read? You should have a look at 'perlsub', 'perlref'
and 'perldsc', which will be very enlightening to you.

The main thing to remember is that arguments to subroutines will be
flattened into one list. Thus if you pass two arrays like this:

	mysub(@array1, @array2);

both arrays will be flattened into one, and then passed into your
subroutine. Inside the subroutine, you can access individual elements
using the @_ special array, but you have no way of knowing the
boundaries of the arrays.

To pass an array to a subroutine, you can either pass it as is, if it is
the only array:

	mysyb(@array);

	sub mysub {
		my @array = @_;
		...
	}

Or you can use reference, as you attempted to do in your example:

	mysub(\@array);

	sub mysub {
		my $arrayref = $_[0];
		my @array    = @$arrayref;
		...
	}

Note that references are scalars. You have to dereference them to get
your data structure back.

--Ala


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

Date: Fri, 08 Sep 2000 14:46:47 GMT
From: Rich More <rmore1@my-deja.com>
Subject: Re: Passing arrays to a sub routine
Message-Id: <8pau4f$pga$1@nnrp1.deja.com>

In article <8parmg$mi6$1@nnrp1.deja.com>,
  kelly.carmichael@trx.com wrote:
> Any help with this would be greatly appreciated!
> Here is my code:
>
> my @srcDir = (1,2);
> my $srcOutDir = "SEA";
>
> copySrcFiles(\@srcDir,\$srcOutDir);
> }
>
> Here is the sub:
>
> sub copySrcFiles(){
>     my @srcDir = $_[0];
>     my $srcOutDir = $_[1];
> }
From 'man perl'
=================
The -w switch produces some lovely diagnostics.

     See the perldiag manpage for explanations of all Perl's
     diagnostics.
==================
For more docs:
perldoc strict
perldoc diagnostics


--
=============================
Richard More
http://www.richmore.com/


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


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

Date: Fri, 08 Sep 2000 21:05:09 +0800
From: TomC <livia74@ctimail3.com>
To: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: Perl & NT
Message-Id: <39B8E405.EE2CCCCE@ctimail3.com>

Thanks a lot.

Brendon Caligari wrote:

> In article <39B88BD5.79F21814@pacific.net.hk>,
>   Brian Leung <brianlk@pacific.net.hk> wrote:
> > Hello all,
> > Is it possible that someone can add user account by perl script in NT
> 4
> > or win 2000?
> > Thanks
> >
> > --
> > Regards,
> >
> > Brian Leung
> >
> >
>
> check the syntax for the NET command.
>
> at the prompt try:
>     c:\> net help user
>
> you should be able to system() it.
>
> Brendon
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.



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

Date: Fri, 08 Sep 2000 09:46:21 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: Regards CGI.pm
Message-Id: <39B8FBBC.687E87AD@mail.uca.edu>

Gwyn Judd wrote:
> 
> I was shocked! How could Ken <kenn_mar@hotmail.com>
> say such a terrible thing:
> >
> >
> >
> >> You'll need to specify absolute paths for your images.  Your problem is
> >> that when you use the bare names, the browser interprets them as relative
> >> to your script's name.
> >
> >I've done that but to no avail. Eg. I've tried "C:\\www\gifs\" in which case
> >CGI.pm prints out C:\www\gifs. I've tried "..\www\gifs\" and still didn't
> >worked. Any other alternatives?
> 
> Well you don't need to do the paths with '\' as the seperator as perl
> will translate them for you. Especially seeing as how '\' in a
> double-quoted string is interpolated as escaping the next character.

Exactly. What he needs if he wants to use backwhacks is
"C:\\www\\gifs\\", but "C:/www/gifs/" is much easier to read (for me). 

Cameron

-- 
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu


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

Date: Fri, 8 Sep 2000 09:57:53 -0500
From: "James Ryan" <jpryan@cis.tamu.edu>
Subject: website
Message-Id: <8paupi$4gt$1@news.tamu.edu>

if anybody really cares, check out this web site that i wrote...  (its in
perl of course)


http://profpages.net

james ryan




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

Date: Fri, 8 Sep 2000 09:15:55 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: WGET equivalent
Message-Id: <Pine.GSO.4.21.0009080914590.23350-100000@crusoe.crusoe.net>

[posted & mailed]

On Sep 8, Chest Rockwell said:

>Is there a perl mod that functions like the WGET command?

perl -MLWP::Simple=getprint -e 'getprint shift' URL

Go to http://search.cpan.org/ to download the LWP bundle of modules.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



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

Date: Fri, 8 Sep 2000 07:39:03 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: what is the best way to get the lastest line from a file?
Message-Id: <JS5u5.694$Ek.2463@newsfeed.slurp.net>


Fu Kai <fukai@asia.com> wrote in message news:39B8B262.AB8214A9@asia.com...
>
> I want to only get the lastest line from a *HUGE* plain text file(about

it is in the docs. hint: look at the seek function.




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

Date: Fri, 08 Sep 2000 13:48:52 GMT
From: Rich More <rmore1@my-deja.com>
Subject: Re: what is the best way to get the lastest line from a file?
Message-Id: <8paqns$lck$1@nnrp1.deja.com>

In article <39B8B262.AB8214A9@asia.com>,
  Fu Kai <fukai@asia.com> wrote:
> hi,
> I want to only get the lastest line from a *HUGE* plain text file
(about
> 20M),
> and i think it is not a efficient way to catch it just read lines one
by
> one,
> so what is the best way to do it? and how?

On Unix: tail -1 file

or if line lenghts don't vary,  use perl's seek() function
perldoc -f seek

--
=============================
Richard More
http://www.richmore.com/


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


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

Date: Fri, 08 Sep 2000 14:43:53 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: what is the best way to get the lastest line from a file?
Message-Id: <slrn8rhup6.8ll.tjla@thislove.dyndns.org>

I was shocked! How could Fu Kai <fukai@asia.com>
say such a terrible thing:
>hi,
>I want to only get the lastest line from a *HUGE* plain text file(about
>20M),
>and i think it is not a efficient way to catch it just read lines one by
>one,
>so what is the best way to do it? and how?

In that case I would open it, seek to the end and then search back till
you find the start of the last line.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Exhilaration is that feeling you get just after a great idea hits you,
and just before you realize what is wrong with it.


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

Date: Fri, 08 Sep 2000 09:48:29 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: what is the best way to get the lastest line from a file?
Message-Id: <39B8FC3D.74ED2DBF@texas.net>

Fu Kai wrote:
> 
> hi,
> I want to only get the lastest line from a *HUGE* plain text file

use File::ReadBackwards;

- Tom


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

Date: Fri, 08 Sep 2000 13:53:53 GMT
From: Michael Segulja <michael.segulja@sgi-lsi.com>
Subject: Which module to use, or is there even one out there?
Message-Id: <8par14$lon$1@nnrp1.deja.com>

I am running my company's intranet server (still in development) on
Mandrake Linux 7.1.  Here's what I want to do:

Schedule a nightly cron job to run a perl script that will connect from
the Linux server to the NT PDC and export the userlist into a text
file.

Execute the same perl script or a different script (don't know if it
would really matter) that will import this userlist.txt file into a
MySql database running on the Linux server.

The next perl script will be a CGI script that will execute when Joe
User connectes to the company help desk system (also under development)
and query the SQL server for the userlist and dynamically enter it into
a web page in a drop down list. I think I know how to do this part.

Is this possible to do while running perl on Linux?  I know I can run
net users /DOMAIN>>c:\somedir\userlist.txt.  I guess I could have some
automated ftp session download the userlist.txt file to the Linux
server, and then have perl take over from there.  I would rather have
it all happen from the Linux server with perl though.  I saw a module
called Win32::NetAdmin and a sample perl script somebody posted on this
newsgroup a couple of weeks ago, but he is running perl on NT.

Can somebody give a clueless guy a clue or two?  I would really
appreciate any help I can get.

Thanks very much,

Michael
SGI Integrated Graphic Systems




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


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

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


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