[8403] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2020 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 4 12:18:42 1998

Date: Wed, 4 Mar 98 09:00:28 -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           Wed, 4 Mar 1998     Volume: 8 Number: 2020

Today's topics:
    Re: $$ref->{$_} undefined after passing by ref? (Jason Nugent)
        an eval problem <joyot@univ-tln.fr>
    Re: bizzare split problem (Mike Heins)
    Re: bizzare split problem <ajohnson@gpu.srv.ualberta.ca>
    Re: contexts: is there such a thing as array? (Kevin B Cohen)
    Re: Debugging Perl and extensions (Perl gurus please he (Ilya Zakharevich)
    Re: Displaying subdirectories and not filenames <tchrist@mox.perl.com>
    Re: Displaying subdirectories and not filenames (Jason Nugent)
    Re: Duplicating 'tail -n' functionality in Perl <uri@sysarch.com>
        Example for use Win32::NetResource::AddConnection <burkhard.kiesel@med.siemens.de>
        FAQ Re: Using stdout of a script started by perl within (Mike Stok)
        Help with DBD::pNET <ramirez@doc.mssm.edu>
    Re: line number indication in Perl <ajohnson@gpu.srv.ualberta.ca>
    Re: line number indication in Perl <ajohnson@gpu.srv.ualberta.ca>
    Re: perl executable finally mentions FAQ (was Re: Confl (Tom Grydeland)
    Re: Perl on MS Personal Web Server <upsetter@shore.net>
    Re: Perl Scripts for NT server (Curtis)
    Re: Q: Emacs and making it indent perl code <friedman@uci.edu>
    Re: Q: How to (Mike Stok)
    Re: QUIZ: answer and hash slice tutorial <uri@sysarch.com>
        re-populate form <mkisiel@methuentidings.com>
    Re: re-populate form (Mike Stok)
    Re: Retreiving Input from MULTIPLE select <jdporter@min.net>
        SOURCE: Elaborate Example <tchrist@mox.perl.com>
    Re: Summing Up Array Values - How Do I? <jdporter@min.net>
    Re: Summing Up Array Values - How Do I? <uri@sysarch.com>
    Re: The -w switch (was Re: better way to do this?) <upsetter@shore.net>
    Re: The -w switch (was Re: better way to do this?) <zenin@best.com>
    Re: The -w switch (was Re: better way to do this?) <uri@sysarch.com>
        Using stdout of a script started by perl within perl .. <jg@tratech.be>
    Re: What am I doing wrong? <uri@sysarch.com>
    Re: What does this one-liner do? <jdporter@min.net>
    Re: What is PERL? Learn JAVA instead? <jdporter@min.net>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 4 Mar 1998 16:23:18 GMT
From: ap958@chebucto.ns.ca (Jason Nugent)
Subject: Re: $$ref->{$_} undefined after passing by ref?
Message-Id: <6djv5m$nfn$1@News.Dal.Ca>

John Klassa (klassa@aursgh.aur.alcatel.com) wrote:
: On 4 Mar 1998 11:47:12 GMT, Jason Nugent <ap958@chebucto.ns.ca> wrote:
: ->My problem is that I am using the existance of keys in this hash as a
: ->way to prevent an event from taking place.  just to make sure I can
: ->still see the hash inside the foreach loop, I put a print statement
: ->inside it:

: Make sure you use "exists" and/or "defined", depending on what you're
: trying to do, exactly.  Note that they're not the same...

	As far as I can tell, this worked. I'm going to keep feeding it
more tests to be sure, though.  

 unless (exists $ref->{$_}){ do something; }

 is the proper way to do it.  Without exists, it won't work.  Thanks for
your help.  
			Jason

---------------------
Jason Nugent, BSc(Hons)
ap958@chebucto.ns.ca         "Beneath this canvas monochrome 
Certified Web Master           Wrapped in the shroud of this grey home
                              I'll paint a picture all my own
                              I'll paint a picture"
Live to ride,	 
  Ride to Live.	                    -Anacrusis
 	
********************************************************************
The Best Place for Sport on the net! - Sportscience www.sportsci.org
********************************************************************


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

Date: Wed, 04 Mar 1998 17:36:40 +0100
From: JOYOT Pierre <joyot@univ-tln.fr>
Subject: an eval problem
Message-Id: <34FD8318.2C05CD7@univ-tln.fr>

I want to send the result of un eval in a variable

exemple

$pr = "print toto ";
$res=eval $pr;

eval $pr send "toto" in stdout not in $res (normal).

how to put eval stdout in $res ?

thank you.

Pierre JOYOT




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

Date: 4 Mar 98 14:58:02 GMT
From: mikeh@minivend.com (Mike Heins)
Subject: Re: bizzare split problem
Message-Id: <34fd6bfa.0@news.one.net>

[email copy sent]
Matthew.Wickline@usa.net wrote:
> First, here's the little program which will duplicate my problem...
> (the problem follows below)
[over-processing in script deleted]
> I expect the above to print consider each of a b c d e and f as a block....
> but when I run the program, I find that the first three letters all got
> slammed into the first item, and the other letters were handled as I expected.

> Can anyone help me understand why this is happening?
> Do you find the same results on your system?
[snip]

Why all that extra junk?

% perl
my $textstring = <<EOF;
a

b

c

d

e

f

EOF

@bs = split(/\n(?:\s*\n)+/, $textstring);

$i=0;
for (@bs) {
    print "$i='$_'\n";
    $i++;
}
^D
0='a'
1='b'
2='c'
3='d'
4='e'
5='f'

I think you are trying too hard.

Regards,
Mike Heins                          http://www.minivend.com/  ___ 
                                    Internet Robotics        |_ _|____
Just because something is           131 Willow Lane, Floor 2  | ||  _ \
obviously happening doesn't         Oxford, OH  45056         | || |_) |
mean something obvious is           <mikeh@minivend.com>     |___|  _ <
happening. --Larry Wall             513.523.7621 FAX 7501        |_| \_\



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

Date: Wed, 04 Mar 1998 09:52:01 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: bizzare split problem
Message-Id: <34FD78A1.44295B2D@gpu.srv.ualberta.ca>

Matthew.Wickline@usa.net wrote:
> 
> First, here's the little program which will duplicate my problem...
> (the problem follows below)

you could simplify your script as pointed out by Mike H, 
but to answer your question, you don't have a split
problem:

[snip]
> my $textstring = <<EOF;
> a
> 
> b
> 
> c
> 
> d
> 
> e
> 
> f
> 
> EOF
[snip]
> sub break_textarea {
>     my $textarea_string = shift;
>     $textarea_string =~ s/^\s+//sm;
>     $textarea_string =~ s/\s+$//sm;

your problem is here, using the /m modifier means that
^ will match the beginning of string, or the start of 
a logical line(right after a \n)... your first regex above
(to strip leading spaces) will find the first location in the
string that matches '^\s+' which is right after the "a\n", and
because a \n is whitespace (\s) the next \n is removed. Similarly
for the second regex, it won't strip trailing whitespace
from the end of the entire string because it will match earlier,
at the first point it finds where whitespace preceeds a \n, which
is now right after the b "a\nb\n\n", so the \n immediately
following the b is removed. Leaving you with a string that
appears as "a\nb\nc\n\nd\n\nf\n".

hope it helps
regards
andrew


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

Date: 4 Mar 1998 10:53:02 -0500
From: kcohen@julius.ling.ohio-state.edu (Kevin B Cohen)
Subject: Re: contexts: is there such a thing as array?
Message-Id: <6djtcu$r4k@julius.ling.ohio-state.edu>

In article <x71zwjyyjc.fsf@sysarch.com>, Uri Guttman  <uri@sysarch.com> wrote:

>indexing into it. the RHS or LHS is irrelevant. it is the context which
>can be created in many ways on either side of =.
>
>$foo{ 'bar' } = @bar ;

so, the broader question: is it NOT always the LHS that determines the
context in which an operator (bearing in mind that i use "operator"
here in the same loose sense as the blue camel, footnore p. 45, where
"we use the term "operation" loosely to mean either an operator or a
term") is evaluated?  and i ask this for information, not as a
claim--i don't know.

>> @array = /(\w+)(\d+\s)(\w+)/;
>> $thing = join('*', @array);
>> ($one, $two, $three) = /(\w+)(\d+\s)(\w+)/;
>> print "one: $one two: $two three: $three\n";
>> print "$thing\n";
>> 
>> this produces:
>> 
>> one: It two:  three: is
>> It**is
>
>i don't see what point you are making here. you had enough room for 3
>elements in both cases so you got 3 elements, regardless of a value
>being undef.

yes, i did get three elements in the case where the LHS is @array, but
i only got two in the case where the LHS is the list ($one, $two,
$three), didn't i?


kevin









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

Date: 4 Mar 1998 15:33:50 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Debugging Perl and extensions (Perl gurus please help)
Message-Id: <6djs8u$k6i$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Paul Cunnell 
<pcunnell+usenet@csfp.co.uk>],
who wrote in article <34FD1D3A.6F34@csfp.co.uk>:

> Probably. It's hard to say without actually seeing some code. I do know
> that you have to be very careful about what you make mortal when
> constructing
> complex return structures. 

Stop spreading the FUD!  There is nothing simpler: just use _noinc()
variant of newRV_*, and make mortal whatever comes to stack - which
means toplevel thing(s).

Ilya


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

Date: 4 Mar 1998 15:04:11 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Displaying subdirectories and not filenames
Message-Id: <6djqhb$km7$3@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Bob Maillet <bob@cafemedia.com> writes:
:I am currently using opendir but would only like the subdirectories to
:be displayed and not the files which are in the directory I am opening.
:Any ideas?

Get http://language.perl.com/misc/CS-Talk.tar.gz and look in the
sources/iostuff/io-eg file for demos.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com


The secretaries don't understand me.  --Rob Pike


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

Date: 4 Mar 1998 16:28:57 GMT
From: ap958@chebucto.ns.ca (Jason Nugent)
Subject: Re: Displaying subdirectories and not filenames
Message-Id: <6djvg9$nfn$2@News.Dal.Ca>

Bob Maillet (bob@cafemedia.com) wrote:
: I am currently using opendir but would only like the subdirectories to
: be displayed and not the files which are in the directory I am opening.
: Any ideas?

: Bob

	Filter your readdir(DIR) command through a grep statement using
-d.  Something like:

$path = chomp(`pwd`);
my @dirlist = grep { -d "$path/$dir" } readdir(DIR);

should make @dirlist contain only directories.  You could go further than
this and remove . and .. from the returned directories by adding another
condition to the grep statement.

			Hope that helps.

			Jason
---------------------
Jason Nugent, BSc(Hons)
ap958@chebucto.ns.ca         "Beneath this canvas monochrome 
Certified Web Master           Wrapped in the shroud of this grey home
                              I'll paint a picture all my own
                              I'll paint a picture"
Live to ride,	 
  Ride to Live.	                    -Anacrusis
 	
********************************************************************
The Best Place for Sport on the net! - Sportscience www.sportsci.org
********************************************************************


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

Date: 04 Mar 1998 11:34:41 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Duplicating 'tail -n' functionality in Perl
Message-Id: <x7hg5exvmm.fsf@sysarch.com>

Matt Sephton <u5ms@csc.liv.ac.uk> writes:

> I need to get the last few thousand lines of a couple-of-hundred MB
> access_log file, which means that the standard 'tail -3000' command is
> unsuitable with it's limitation of 20k. I have also tried using 'wc -l'
> and then 'calc' and 'sed' to compute the number of lines in the file and
> then to get the last few thousand.
> 
> Is there any way of acieving this in Perl 5? Or does anybody know of a
> version of tail with no buffer size limit ?

GNU tail says it has no buffer limit. try it.

uri

-- 
Uri Guttman                     SYStems ARCHitecture and Software Engineering
uri@sysarch.com                                          Have Perl, Will Hack
http://www.sysarch.com                (781) 643-7504 x*2  FAX: (781) 643-2710
Try the Best Search Engine on the Net -------->  http://www.northernlight.com


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

Date: Wed, 4 Mar 1998 16:49:30 +0100
From: "Burkhard Kiesel" <burkhard.kiesel@med.siemens.de>
Subject: Example for use Win32::NetResource::AddConnection
Message-Id: <6djt1h$1ov$1@med-iss3.med.siemens.de>

Hi there,

is there anyone who has experience with the Win32::NetResource module.
May be it is possible that I can get some examples how to use this.
I just want to connect to a shared drive on a other host.

Thanks in advance


Burkhard





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

Date: 4 Mar 1998 16:39:52 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: FAQ Re: Using stdout of a script started by perl within perl ...
Message-Id: <6dk04o$dg8@news-central.tiac.net>

perlfaq8, distributes with recent perl distributions and available from
http://www.perl.com has a section which starts like this:

       How can I capture STDERR from an external command?

       There are three basic ways of running external commands:

           system $cmd;                # using system()
           $output = `$cmd`;           # using backticks (``)
           open (PIPE, "cmd |");       # using open()

       With system(), both STDOUT and STDERR will go the same
       place as the script's versions of these, unless the
       command redirects them.  Backticks and open() read only
       the STDOUT of your command.
       [...]

If you aren't attached to using system to start the command then the
section suggests several alternatives which offer different advantages.

Hope this helps,

Mike

In article <34FD7F79.7432A1C8@tratech.be>, Jirtme Gonze <jg@tratech.be> wrote:
>-=-=-=-=-=-
>
>Hi,
>
>I'm starting with perl and I would like to retrieve within perl,
>
>the stdout of another script started with the system command.
>
>Is there a solution for that ?
>
>--
>Jirtme Gonze (jg@tratech.be)
>
>Test our Java Web Trading Application at
>
>     http://www.tratech.be/ttfinancialdvp/tradeviewlight
>
>--
>TradeWare Technology S.A.
>Drhve Richelle 159 Box 14
>1410 Waterloo
>
>Til : 32-2-352.07.30
>Fax : 32-2-352.07.31
>
>http://www.tratech.be
>
>
>
>-=-=-=-=-=-
>[Alternative: text/html]
>-=-=-=-=-=-


-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Wed, 04 Mar 1998 10:34:31 -0500
From: "Edwin S. Ramirez" <ramirez@doc.mssm.edu>
Subject: Help with DBD::pNET
Message-Id: <34FD7487.4AC2B7B0@doc.mssm.edu>

Hello,

I am trying to use the DBD::pNET driver to connect a Linux system to an
Oracle database.  I have successfully configured the pNETagent on the
Oracle system and I am able to connect to it from the same machine.
However, when I try to connect from the linux machine, I get an error
message: File is not in Storable format.  It appears that the Storable
module is not producing a compatible byte stream.  Linux is running on a

Pentium 166 and Oracle is on an Alpha 533 running Digital Unix.

Thanks,

Edwin Ramirez



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

Date: Wed, 04 Mar 1998 09:04:53 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: line number indication in Perl
Message-Id: <34FD6D95.D853FAD@gpu.srv.ualberta.ca>

Francky Leyn wrote:
> 
> Hello,
> 
> I'm looking for a way to specify in Perl a line number indication. Does
> this
> exist in Perl, and if so, what is the syntax?

perl supports #line directives in the same format as C, so
you can use -L switch in notangle for the default #line directive
format --- your only problem will be with the first line of
your scripts (the #!/usr/bin/perl notation)...because noweb
inserts the #line directives immediately prior to tangling
out any given code-chunks, your first code chunk (and therefore
your script) will have a #line directive as a first line and
won't the '#!...' won't work properly. You can add a filter to
the notangle pipeline to correct this ... my method was to write
a quick perl script to do the job of notangle (but it doesn't
bother to do the markup stage and so would be unsuitable if you
require complex filters on the tangle side---which I've never
found necessary). I've also got a perl version of the 'finduses'
filter for noweave, which better recognizes perl identifier for
indexing --- contact me if you are interested.

regards
andrew


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

Date: Wed, 04 Mar 1998 09:12:31 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: line number indication in Perl
Message-Id: <34FD6F5F.72FC56D4@gpu.srv.ualberta.ca>

I R A Aggie wrote:
> 
> In article <34FD25F7.97B2C116@esat.kuleuven.ac.be>, Francky Leyn
> <Francky.Leyn@esat.kuleuven.ac.be> wrote:
> 
> + I'm using the literate programming tool noweb to document my Perl
> + programs. http://www.cs.virginia.edu/~nr/noweb/intro.html
> + This allows me to mix Perl code with LaTeX documentation in a single
> + source file.
> 
> Unless there's some reason you need LaTeX, why not use perl's own
> inline documentation, POD?

POD is great for embedding manpages, buts it is extremely
limited for source code documentation in the manner of
literate programming tools, which generally allow for
flexible order of elaboration, and provide means for
generating code-chunk and identifier indexing and
tables of contents... and of course, the full power
of latex so you can have typeset equations, tables
and anything else latex can do depending on your needs.

As Mike Stok said, you can always embed POD into your
literate programs so that the scripts still retain
embedded user documentation.

regards
andrew


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

Date: 4 Mar 1998 15:47:16 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: Re: perl executable finally mentions FAQ (was Re: Conflict in this Newsgroup)
Message-Id: <slrn6fqts4.479.Tom.Grydeland@mitra.phys.uit.no>

On Tue, 3 Mar 1998 14:36:50 +0000,
Russell Schulz <Russell_Schulz@locutus.ofB.ORG> wrote:

> and let's not forget that PGP refuses to run unless it can find the
> manual in the same directory, or it is given a command-line switch
> that is only documented in the manual.

Considering that the pods (as of 5.004_04) take up 1.4 MB, that might
not be such a good idea. Hmmf.

> Russell_Schulz@locutus.ofB.ORG  Shad 86c


-- 
//Tom Grydeland <Tom.Grydeland@phys.uit.no>


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

Date: 4 Mar 1998 15:57:39 GMT
From: Art Cohen <upsetter@shore.net>
Subject: Re: Perl on MS Personal Web Server
Message-Id: <6djtlj$sh@fridge.shore.net>

Steven Savage <badger@infinet.com> wrote:

: I've been wrestling with getting PERL to work on an MS Personal Web 
: Server to demo a PERL search engine.  Does anyone know how to get this to 
: work?  it seems my file associations just aren't enough.

Could you be a little less specific?

--Art

National Ska/Reggae Calendar: www.ziplink.net/~upsetter/ska/calendar.html
        Boston Ska Home Page: www.ziplink.net/~upsetter/ska/index.html



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

Date: Wed, 04 Mar 1998 16:49:35 GMT
From: someguy@knick-knack.com (Curtis)
Subject: Re: Perl Scripts for NT server
Message-Id: <34ff857e.5890755@news.alt.net>

On Wed, 4 Mar 1998 14:52:57 +1000, "NT connection" <nhscott@enternet.com.au>
wrote:

>Hi, does anyone know of a good site to find perl Scripts for doing such
>things as creating users, administering the box, etc.
>
>Thanks
>
>Nick.
>

You might pick up a copy of The Perl Journal   (Issue 8). It has an excellent
article on the Win32:AdminMisc and Win32::NetAdmin modules... Issue 8 is still
in the book stores around here, and the next issue is slated to be released
March 15 (so hurry and get #8). You can also check their website,
http://www.tpj.com/   (they have the programs from each issue available for
download).


-- Curtis (I finally subscribed to TPJ!) Bullock


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

Date: 4 Mar 1998 15:16:14 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: Q: Emacs and making it indent perl code
Message-Id: <6djr7u$3rk@news.service.uci.edu>
Keywords: emacs

[mailed, posted]

[note that this belongs in the emacs groups; followups set accordingly]

In article <19980304074301.CAA27115@ladder02.news.aol.com>,
Brieweb <brieweb@aol.com> wrote:

<Here is another thing I would like to do. I read that there is the
<cperl-mode.el with the perl distribution. Problem is with my GNU emacs on my PC
<running win95 I see all the lisp routines end in .elc . Does that mean they are
<compiled. Do I have to compile it?

byte compiled, and no, you don't >have< to compile it.

Looks like you need to go through the free, interactive documentation 
that came with emacs.  C-h t will put you in a nifty tutorial that
will answer some of your questions.  You might also consider picking
up the ORA book on emacs.

Once you do load cperl-mode, I suggest running C-h m to read the docs for
the mode.

And please do take emacs questions to the emacs group(s)!

Thanks,
Eric
-- 
Eric D. Friedman
friedman@uci.edu


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

Date: 4 Mar 1998 15:21:30 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Q: How to
Message-Id: <6djrhq$83n@news-central.tiac.net>

In article <6djo0k$h2p$1@sun20.ccd.bnl.gov>, Lance <change AT into @> wrote:
>Hi, I have a four-column data file.  I need to abstract the third item from
>the last line.  Is there a simple way to do this?  Thanks in advance.

It depends on the format of your data - for example one way of carving up
a record might be to use split ' ', $record if you know that there aren't
any empty fields and there aren't embedded spaces in the fields.  If the
records have a fixed format then maybe unpack is more suitable.  If you
have a CSV file then maybe a CPAN module or a regex might be the way to
go.

One way to get the last record out of a data file is to read from the
beginning to the end, a record at a time, and remember the last line you
read.  On big files that can be a pain.  If you know the record size you
might consider seeking one record back relative to the end of the file and
grabbing the last record.  If you have an idea of the maximum record size
then it may be worth doing something more elaborate to work back from the
end of the file to find the beginning of the last record.

Without more information on your data it's hard to suggest how to proceed,
solutions which can be whipped up in a couple of minutes and work well on
little files may be inappropriate for multi gigabyte files...

  # example code fragment - not intended to be useful for real work
  $third = (split)[2] while <INPUT>;
  print "third field of last record is $third\n";

is one thing that might work on some format of data file, but would do an
awful lot too much work on big files.

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: 04 Mar 1998 11:10:19 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: QUIZ: answer and hash slice tutorial
Message-Id: <x7ogzmxwr8.fsf@sysarch.com>

aml@world.std.com (Andrew M. Langmead) writes:

> Uri Guttman <uri@sysarch.com> writes:
> 
> >for 0 based use:
> 
> >@foo_to_index{ @foo_array } = ( 0 .. $#foo_array ) ;
> 
> >for 1 based use:
> 
> >@foo_to_index{ @foo_array } = ( 1 .. @foo_array ) ;
> 
> 
> If you are going to worry whether $[ has been altered from its
> default, why not just use it explicitly:
> 
> @foo_to_index{ @foo_array } = ( $[ .. $#foo_array ) ;

i wasn't concerned about $[. in fact i never touch it. this was for
those who need integers values from the keys. some applications want 0
based and some want 1 based. it is not necessarily for indexing into
perl arrays. it could be for external use where 1 basing might be
important.

uri

-- 
Uri Guttman                     SYStems ARCHitecture and Software Engineering
uri@sysarch.com                                          Have Perl, Will Hack
http://www.sysarch.com                (781) 643-7504 x*2  FAX: (781) 643-2710
Try the Best Search Engine on the Net -------->  http://www.northernlight.com


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

Date: Tue, 3 Mar 1998 22:32:16 -0500
From: "mike kisiel" <mkisiel@methuentidings.com>
Subject: re-populate form
Message-Id: <34fcc9f1.0@news.netway.com>

hi there! i'm a very newbie...

after i've written submitted form date to a file via open(xx,
">filename.txt");

how do use this text file as a template to repopulate the form for editing
and resubmitting?

cheers! mike kisiel




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

Date: 4 Mar 1998 16:07:59 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: re-populate form
Message-Id: <6dju8v$dg8@news-central.tiac.net>

If your form is a form submitted over the web and you're using a CGI
script to process it then I would suggest looking at the documentation for
the CGI module which comes as a part of the standard perl distribution
these days.  If you don't have it installed then you can get it from a
comprehensive perl archive network (CPAN) site (or maybe even upgrade your
installation to the latest version which includes both the CGI module and
numerous bug fixes)

Once you have the CGI documentation then look for the word state in it.

Hope this helps,

Mike

In article <34fcc9f1.0@news.netway.com>,
mike kisiel <mkisiel@methuentidings.com> wrote:
>hi there! i'm a very newbie...
>
>after i've written submitted form date to a file via open(xx,
>">filename.txt");
>
>how do use this text file as a template to repopulate the form for editing
>and resubmitting?
>
>cheers! mike kisiel
>
>


-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Wed, 04 Mar 1998 10:20:20 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Retreiving Input from MULTIPLE select
Message-Id: <34FD7133.21E6@min.net>

I have no idea what you're trying to do in this code.
But it has many basic perl errors.

For starters:
1. perl -w; use strict;  
2. legible code style, indentation.
3. use CGI.pm.  It will save you lots of headaches.


(The following is based on code perpetrated by
Burt Lewis:)

open(FILE2,$infile) or die "Can't open $file2: $!\n";
# OFCOL: you try to open $infile, but the error
# message says $file2 ?!?!?
# where do either of these variables come from, anyway?
 
print "Content-type: text/html\n\n";
while (<FILE2>) {

  @list = keys %FORM;
  # valid, but unused.

  foreach $key ( keys %FORM ) {
    print "$key is $FORM{$key}";

    print "$list";
    # Um, where does $list come from?
    # Not from @list, if that's what you were thinking.

    @fields = split /\t/; # splits $_, from FILE2
    $test = "$fields[1]";
    print "$test";
    # Why bother with the quotes?  this works:
    # $test = $fields[1];
    # print $test;

    print "|$key|"; # from keys %FORM

    if ($test == $form{Comm}) {
      # Nope.  You want to compare these as strings,
      # so you have to use eq, not ==.
      # Where does the hash %form come from?
      # You were probably thinking %FORM.  Not the same.
      # And 'Comm'? Don't you mean $key?

      print "<b>You have selected:$test<br>";
    }

    if ($line eq= "") {
      # another line that doesn't compile.
      # eq= is not a perl operator. You meant eq.
      # Actually you probably meant ne, since
      # why would you print a line ONLY if it IS
      # null?
      # Also, where does $line come from?
      # I don't see it used anywhere else.
      # I bet you meant $_, from FILE2.

      print FILE3 "$line";
    }
  }
}

close FILE2;
close FILE3; # when was this ever opened???

#system "rename($outfile,$infile)";
}
# is this the end of some subroutine?
# if so, where's the start?

system passes the string to a shell for execution; that
means it should look just like something you would type
at a command prompt.  Would you type
	rename(foo,bar)
at a shell prompt and expect it to work?


So what you really have (cleaned up) is this:

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

use strict 'refs';

my $infile = 'data.txt';
my $outfile = 'new_data.txt'; # or whatever

open(INFILE,$infile) or die "Can't open $infile: $!\n";

# open the other file for writing:
open(OUTFILE,">$outfile") or die "Can't open $outfile: $!\n";

# if you're sending html to a www client, those dies, if
# one occurs, will be rather unfriendly.
 
print "Content-type: text/html\n\n";

while ( <INFILE> ) {

  my @fields = split /\t/, $_;
  my $test = $fields[1];
  # moved this outside the foreach loop, since
  # it is invariant in that loop.

  my $key;
  foreach $key ( keys %FORM ) {
    # And so, where does %FORM come from?

    if ( $test eq $FORM{$key} ) {
      print "<b>You have selected:$test<br>";
    }

    if ( $_ ne '' ) {
      print OUTFILE $_;
      # still not sure why you do this;
      # copy all (non-null) lines from infile to outfile?
    }
  }
}

close INFILE;
close OUTFILE;

system("rename $outfile $infile");
# is rename really what you want? maybe move, or mv?


After you've learned the perl language, I strongly
suggest you learn how to use the CGI.pm module.
It will take care of multiple selections and so many
other CGI-related issues for you.

Also, if you believe creating a new file and then
copying it over the old one is the best approach for
your application, I would suggest using the File::Copy
module, which provides both copy() and move() operations.

Hope this helps,
John Porter


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

Date: 4 Mar 1998 15:36:49 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: SOURCE: Elaborate Example
Message-Id: <6djseh$nua$1@csnews.cs.colorado.edu>

At http://mox.perl.com/cgi-bin/MxScreen you may find something of interest.  

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
"A ship then new they built for him/of mithril and of elven glass" 
    --Larry Wall in perl.c from the v5.0 perl distribution,
	citing Bilbo from Tolkien's LOTR


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

Date: Wed, 04 Mar 1998 10:48:32 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Summing Up Array Values - How Do I?
Message-Id: <34FD77D0.367D@min.net>

This seems like a FAQ by now...

Here's my solution, posted in this very newsgroup not long ago:

sub add_up {
  my @a = @_;
  while ( $#a ) {
    push( @a, shift(@a) + shift(@a) );
  }
  $a[0];
}

John Porter


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

Date: 04 Mar 1998 11:13:11 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Summing Up Array Values - How Do I?
Message-Id: <x7n2f6xwmg.fsf@sysarch.com>

>>>>> "RS" == Randal Schwartz <merlyn@stonehenge.com> writes:

>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:


  Uri> i agree. i was just showing another way to do it, schwartzian
  Uri> style.

  RS> No.  The "Schwartzian Transform" is specifically a cached-key sort
  RS> identified by a map-sort-map combination.

i do know the idiom. in fact it has been made into a module of sorts
(pun intended)

  RS> It has nothing to do with using map in general in clever (or
  RS> silly) ways.

unless you enforce the correct use of this trademarked name it will get
abused by the public. have your lawyers (and i KNOW you have some)
contact all misusers of the term and threaten them with massive legal
action :-)

uri


-- 
Uri Guttman                     SYStems ARCHitecture and Software Engineering
uri@sysarch.com                                          Have Perl, Will Hack
http://www.sysarch.com                (781) 643-7504 x*2  FAX: (781) 643-2710
Try the Best Search Engine on the Net -------->  http://www.northernlight.com


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

Date: 4 Mar 1998 15:36:38 GMT
From: Art Cohen <upsetter@shore.net>
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <6djse6$6i@fridge.shore.net>

Tom Christiansen <tchrist@mox.perl.com> wrote:
: :	I suggest Apache as well, however I often have to use whatever
: :	the client uses.  

: I am *really* tired of reading "the client made me do it" whinings.

: Does nothing but money matter?  What happened to technical training?
: Has it fallen prey to money-grubbing lackeys without honor or standards?
: Why do you take jobs in brain-dead environments?  Do you just not care,
: or are you that desperate?  

I don't know what you do for money, Tom (besides writing excellent books).
Maybe you do some contract programming, but with your experience and rep,
you're probably able to pick and choose your clients.

The rest of us aren't so lucky. If we don't want to work on a given site
because of the web server, web client, OS, or any other piece of software,
there are a half-dozen other contractors waiting to fill the gap.


: A surgeon who's told by his client that he must cure a minor headache
: by operating using dirty stone tools has the obligation to explain that
: this is a stupid idea from the start to the finish.

: To the professional, the customer is *not* always right.  It is your
: duty to provide sound technical advice.   Why do programming slaves
: just say "Yes, Master, whatever you say, Master" to their managers or
: clients or whatnot?  Why can't technical training count for anything?
: Where have professional integrity and standards gone?

What do you think the client will say if this programmer says "Sorry, but
my professional standards prohibit me from working on your site because
you use Netscape instead of Apache"? Do you seriously think there are many
businesses out there who would respond with "Oh my god, I had no idea this
commerical software was such a piece of crap! We'll change our entire
installation over to Apache immediately just so we can hire *you* as our
Perl contractor!"?

If this guy doesn't want the work, there are plenty of others who do, and
it's hard to convince a brain-dead business type to trade in purchased
commercial software supported by a large corporation for "free" software
supported only voluntarily by people on the net.

: Maybe some people like being mindless slaves, but it's a terrible life.

Well, that's why so many of us would rather contract for such companies
than work for them permanently.

--Art

National Ska/Reggae Calendar: www.ziplink.net/~upsetter/ska/calendar.html
        Boston Ska Home Page: www.ziplink.net/~upsetter/ska/index.html



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

Date: 4 Mar 1998 16:13:15 GMT
From: Zenin <zenin@best.com>
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <889028334.648852@thrush.omix.com>

Tom Christiansen <tchrist@mox.perl.com> wrote:
: I am *really* tired of reading "the client made me do it" whinings.

	It's not a whin, it's a sad fact of life.

: What happened to technical training?

	Good question.

: Has it fallen prey to money-grubbing lackeys without honor or standards?

	Yes.

: Why do you take jobs in brain-dead environments?

	I don't, my company does.  I'm not self-employed and don't have the
	freedom to always dictate my environment.  -Although my company
	does actually bend over backwards to get things set the way they
	should be and I ask for, but alas it is not always possible all the
	time.  This is especially true when working for large (braindead)
	corporations where ordering a box of pencils can take approval from
	5 people in 3 departments and a couple months of lead time.  I'd
	love to never do work for said corporations, however it currently
	is where the bulk of high end work is.	I try to write free
	software when I have time, however both I and my company like to
	eat too.

: A surgeon who's told by his client that he must cure a minor headache
: by operating using dirty stone tools has the obligation to explain that
: this is a stupid idea from the start to the finish.

	Yes, and we do...but they (or more likely the management above them)
	still decides that it would cost too much to by a new set of bronze
	tools.  It's liken to the doctor that wants to help his patient with
	the latest advances in medical research available, but the HMO the
	patient belongs to won't approve it.  Does he just tell the patient
	that he won't help him because the techniques and tools he must use
	aren't the Latest & Greatest?

: To the professional, the customer is *not* always right.

	Rarely right, IMHO which is why they hire outside help to start
	with.  Even if the customer agrees they still oftin deside that
	changing the system would cost too much.

: It is your duty to provide sound technical advice.

	Yes.  It is also my duty to do the best and most reliably work
	despite my sound technical advice being overlooked.  I do not have
	the luxury to say, "Sorry, but your system isn't worthy of my
	talents.  You'll have to change it or hire a lesser programmer.".

: Why do programming slaves just say "Yes, Master, whatever you say,
: Master" to their managers or clients or whatnot?

	We offer the options.  The pros and cons.  In the end, the one with
	the check book makes the choice.

: Why can't technical training count for anything?

	Because then we couldn't have "WebMasters" making $80k and not
	knowing how to build a new module into an Apache server... :-P

: Maybe some people like being mindless slaves, but it's a terrible life.

	Damn shame people sometimes have to do things they do not like,
	isn't it? :-P

-- 
-Zenin
 zenin@best.com


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

Date: 04 Mar 1998 11:23:59 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <x7k9aaxw4g.fsf@sysarch.com>

Tom Christiansen <tchrist@mox.perl.com> writes:

> I am *really* tired of reading "the client made me do it" whinings.
> 
> Does nothing but money matter?  What happened to technical training?
> Has it fallen prey to money-grubbing lackeys without honor or standards?
> Why do you take jobs in brain-dead environments?  Do you just not care,
> or are you that desperate?  
> 
> A surgeon who's told by his client that he must cure a minor headache
> by operating using dirty stone tools has the obligation to explain that
> this is a stupid idea from the start to the finish.
> 
> To the professional, the customer is *not* always right.  It is your
> duty to provide sound technical advice.   Why do programming slaves
> just say "Yes, Master, whatever you say, Master" to their managers or
> clients or whatnot?  Why can't technical training count for anything?
> Where have professional integrity and standards gone?
> 
> Maybe some people like being mindless slaves, but it's a terrible life.

hear! hear!!

i refuse to work on (spit) winblows or NoT systems. i will not sully my
dainty little fingers on them! or give uncle bill any more money that he
deserves. let's swap randal and uncle bill. send bill to jail and give
randal X billions! hell the DOJ may do that if we pray hard enough!
looks like more and more major powers on joining in the fight. uncle
bill is not spending money on lobbyists. why doesn't he just buy the
capital and evict congress!!

uri

-- 
Uri Guttman                     SYStems ARCHitecture and Software Engineering
uri@sysarch.com                                          Have Perl, Will Hack
http://www.sysarch.com                (781) 643-7504 x*2  FAX: (781) 643-2710
Try the Best Search Engine on the Net -------->  http://www.northernlight.com


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

Date: Wed, 04 Mar 1998 17:21:13 +0100
From: "Jirtme Gonze" <jg@tratech.be>
Subject: Using stdout of a script started by perl within perl ...
Message-Id: <34FD7F79.7432A1C8@tratech.be>


--------------6370152441753A69D4B3A3DE
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Hi,

I'm starting with perl and I would like to retrieve within perl,

the stdout of another script started with the system command.

Is there a solution for that ?

--
Jirtme Gonze (jg@tratech.be)

Test our Java Web Trading Application at

     http://www.tratech.be/ttfinancialdvp/tradeviewlight

--
TradeWare Technology S.A.
Drhve Richelle 159 Box 14
1410 Waterloo

Til : 32-2-352.07.30
Fax : 32-2-352.07.31

http://www.tratech.be



--------------6370152441753A69D4B3A3DE
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>

<PRE></PRE>

<PRE>Hi,</PRE>

<PRE></PRE>

<PRE>I'm starting with perl and I would like to retrieve within perl,</PRE>

<PRE>the stdout of another script started with the system command.</PRE>

<PRE>Is there a solution for that ?</PRE>

<PRE></PRE>

<PRE>--&nbsp;
J&eacute;r&ocirc;me Gonze (jg@tratech.be)

Test our Java Web Trading Application at

&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="http://www.tratech.be/ttfinancialdvp/tradeviewlight">http://www.tratech.be/ttfinancialdvp/tradeviewlight</A>

--
TradeWare Technology S.A.
Dr&egrave;ve Richelle 159 Box 14
1410 Waterloo

T&eacute;l : 32-2-352.07.30
Fax : 32-2-352.07.31

<A HREF="http://www.tratech.be">http://www.tratech.be</A></PRE>
&nbsp;</HTML>

--------------6370152441753A69D4B3A3DE--



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

Date: 04 Mar 1998 11:31:09 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: What am I doing wrong?
Message-Id: <x7iupuxvsi.fsf@sysarch.com>

Geert Roovers <etmgero@etm.ericsson.se> writes:

> Hi... in my opinion, the next script should fetch a number form a file,
> increase it, and overwrite the file with this new number. Perl does not
> agrre with me though...
> 
> open(LOGFILE, "+>count.log") || die "Horribly";

use $! in the die message. it will tell you whay the open failed.

> $a = <LOGFILE>;
> print(++$a);
> print LOGFILE ($a);

you have to seek back to the beginning of the file. look up the seek function

> close(LOGFILE)

uri

-- 
Uri Guttman                     SYStems ARCHitecture and Software Engineering
uri@sysarch.com                                          Have Perl, Will Hack
http://www.sysarch.com                (781) 643-7504 x*2  FAX: (781) 643-2710
Try the Best Search Engine on the Net -------->  http://www.northernlight.com


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

Date: Wed, 04 Mar 1998 11:07:29 -0500
From: John Porter <jdporter@min.net>
Subject: Re: What does this one-liner do?
Message-Id: <34FD7C41.B15@min.net>

Uri Guttman wrote:
> 
> assigning an array variable in a scalar context is the only time you get
> the length of the array. array variables are NOT lists.
> 
> @array is an array variable
> ( @array ) is a list with the values of the variable @array
> 
> $foo = @array is the length of @array
> $foo = ( @array ) is the last element of @array

Um, Uri, did you try this code?

The important thing to remember is that a list (stuff in parens)
is a compile-time construct, which propagates its context to its
contents.  In
	$foo = ( @array );
the list, which is the rhs, sees scalar context, so propagates
that to its contents, namely @array.  @array sees scalar context,
so "returns" its length.  This is the case even if you have
	$foo = ( 3, 2, 1, @array );
because the compiler sees a comma operator (several, actually);
and you know what comma operators do.
So $foo gets the count of @array.  Just as in 
	$foo = ( 666, @array, 1 );
$foo gets 1, which is the scalar evaluation of the last item
in the multi-comma operation.

That's where this "Last item in the list" notion comes from:
the freakin' comma operator!

hth,
John Porter


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

Date: Wed, 04 Mar 1998 11:25:49 -0500
From: John Porter <jdporter@min.net>
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <34FD808D.478C@min.net>

Brian Slone wrote:
> 
> I really don't know crap about PERL. How is it different from JAVA?

Perl and Java are essentially the same language.  When you've learned
one, you know them both.
By using different command-line options, you can get either behavior
out of either compiler.

> Which one is better?

As I say, they are basically the same; but Pure Java has as slight
advantage in most areas (compilation speed, executable size, ease
of use, platform-independence, etc.)

> What can I use it for?

Both of these languages are really only suitable for web site
development.  If you need to do heavy duty data processing,
you should probably look at C++ or SQL.

John Porter, TPFIC


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

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

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