[6446] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 71 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 7 14:17:12 1997

Date: Fri, 7 Mar 97 11:00:33 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 7 Mar 1997     Volume: 8 Number: 71

Today's topics:
     "define"-status doesn't follow on assignment? (Doug Elias)
     Re: "indent" for perl <tchrist@mox.perl.com>
     Re: 10 commandments (was re: Which one is the best (pat <tmh@possibility.com>
     Re: 10 commandments (was re: Which one is the best (pat (Mike Heins)
     Re: 10 commandments (was re: Which one is the best (pat (Brian L. Matthews)
     Re: Basic $ENV questions (Nathan V. Patwardhan)
     Re: Basic $ENV questions (Andrew M. Langmead)
     Re: BUG? Please explain this behavior (M.J.T. Guy)
     Re: Debugger and my variables. <tchrist@mox.perl.com>
     Re: Generate Makefile and execute it from PERL <jyves@nortel.ca>
     Re: Getting list of files in a path (Vasudev Dalal)
     help: add a package to perl <jims@ss5mth44.franklin.com>
     Re: How can I use #! w/o knowing where perl lives? <hargrove@sccm.Stanford.EDU>
     Re: How to flush in perl. (Jafar Shameem)
     Re: Interactive drawing alternatives in perl? <skolgan@Helios.goldworks.com>
     NDBM and flock (Chris Nandor)
     Re: Perl timing questions: <tchrist@mox.perl.com>
     Point a socket client at an HTTP server <mstearns@darkwing.uoregon.edu>
     Re: Point a socket client at an HTTP server (Nathan V. Patwardhan)
     Re: Possible bug in regular expression form /\d{x,x}/ (Abigail)
     Re: Reading from a file in an array arbitrary ???? <jstrick@mindspring.com>
     Rounding Numbers in Perl (Dan Davis)
     Re: Simple PERL program - HELP! <david@ti.com>
     string length (Mark Turner)
     Re: string length <tchrist@mox.perl.com>
     Re: string length (Honza Pazdziora)
     Re: Which one is the best (pattern matching) (Bill Kannawin)
     Why are my rand() values so tiny? <ltomlin@ucs.indiana.edu>
     Re: writing to file (Vasudev Dalal)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 07 Mar 1997 13:44:19 -0500
From: elias@telcontar.tc.cornell.edu (Doug Elias)
Subject: "define"-status doesn't follow on assignment?
Message-Id: <s9pn2sfee4c.fsf@telcontar.tc.cornell.edu>



G'day ...


Please tell me what part of the Perl-spec this derives from:

71... perl -w
@a = ("");
pop @a;
@b = @a;
print "\@a: ", defined @a, "\t$#a\n";
print "\@b: ", defined @b, "\t$#b\n";
^D
@a: 1	-1
@b: 	-1

My guess is that @b's lack of definition is due to the lack of
elements in @a on assignment, while @a's definition is retained from
its earlier non-empty incarntation ... but it certainly surprised me,
i would have expected that "definition" would be a property that was
transferred by assignment from a defined (albeit empty) object.
Chapter and verse, please and thanks.

doug
-- 
  __|_        Internet:   elias@tc.cornell.edu
dr _|_)oug    USmail:     Sci.Comp.Support/Cornell Theory Center
  (_|                     737 Rhodes Hall/C.U./Ithaca/N.Y./14853-3801
  (_|__       MaBelle:    607-254-8686   Fax: 607-254-8888
    |         MOOs:       doug/DougE/Strider/Dun'a'dan
        


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

Date: 7 Mar 1997 16:35:42 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: "indent" for perl
Message-Id: <5fpg4u$mjb$2@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    claude@netwoman.rz.unibw-muenchen.de (Claude Frantz) writes:
:Where can I find the "indent" equivalent program for perl 
:source code ?

Ex FAQ qui venit:

    =head2 Is there a pretty-printer (formatter) for Perl?

    There is no program that will reformat Perl as much as indent(1)
    will do for C.  The complex feedback between the scanner and the
    parser (this feedback is what confuses the vgrind and emacs programs)
    make it challenging at best to write a stand-alone Perl parser.

    Of course, if you simply follow the guidelines in L<perlstyle>,
    you shouldn't need to reformat.

    Your editor can and should help you with this.  The perl-mode for
    emacs can provide a remarkable amount of help with most (but not all)
    codes, and even less programmable editors can provide significant
    assistance.

    If you are using to using vgrind program for printing out
    nice code to a laser print, you can take a stab at this using
    CPAN/doc/misc/tips/working.vgrind.entry, but the results are not
    particularly satisfying for more sophisticated code.

    =head2 Where can I get perl macros for vi?

    For a complete version of Tom Christiansen's vi configuration file,
    see ftp://ftp.perl.com/pub/vi/toms.exrc, the standard benchmark file
    for vi emulators.  This runs best with nvi, the current version of
    vi out of Berkeley, which incidentally can be built with an embedded
    Perl interpreter--see CPAN/src/misc .

    =head2 Where can I get perl-mode for emacs?

    Since Emacs version 19 patchlevel 22 or so, there have been both a
    perl-mode.el and support for the perl debugger built in.  These should
    come with the standard Emacs 19 distribution.

    In the perl source directory, you'll find a directory called
    "emacs", which contains a cperl-mode that color-codes keywords,
    provides context-sensitive help, and other nifty things.

    Note that the perl-mode of emacs will have fits with "main'foo"
    (single quote), and mess up the indentation and hilighting.
    You should be using "main::foo", anyway.

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

There is no problem so complex that it can't be solved by another level
of indirection --except for too many level of indirection.


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

Date: Fri, 07 Mar 1997 09:29:25 -0800
From: Todd Hoff <tmh@possibility.com>
Subject: Re: 10 commandments (was re: Which one is the best (pattern matching))
Message-Id: <33205075.ABD@possibility.com>

Devin Ben-Hur wrote:

> 11) Thou shall use use strict;

Jeeze, might as well start using C++ for everything again. 
Why turn perl into the no fun language?

---------------------------------------------------------------------
tmh@possibility.com        | I have no interest in any ship that does
http://www.possibility.com | not sail fast, for I plan to go in 
                           | harm's way. -- J.P. Jones


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

Date: 7 Mar 1997 17:58:34 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: Re: 10 commandments (was re: Which one is the best (pattern matching))
Message-Id: <5fpl0a$nr3@vixen.cso.uiuc.edu>

Todd Hoff (tmh@possibility.com) wrote:
: Devin Ben-Hur wrote:
: 
: > 11) Thou shall use use strict;
: 
: Jeeze, might as well start using C++ for everything again. 
: Why turn perl into the no fun language?
: 

That I disagree with -- I find it more fun to use strict.  Perhaps you
like debugging better than I do, though. 8-)


-- 
Regards,                                                      ___       ___
Mike Heins                          http://www.iac.net/~mikeh|_ _|____ |_ _|
                                    Internet Robotics         | ||  _ \ | |
This post reflects the              Oxford, OH  45056         | || |_) || | 
opinion of my employer.             <mikeh@iac.net>          |___|  _ <|___|
                                    513.523.7621 FAX 7501        |_| \_\   


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

Date: 7 Mar 1997 10:16:49 -0800
From: blm@halcyon.com (Brian L. Matthews)
Subject: Re: 10 commandments (was re: Which one is the best (pattern matching))
Message-Id: <5fpm2h$8mm$1@halcyon.com>

In article <33205075.ABD@possibility.com>,
Todd Hoff  <tmh@possibility.com> wrote:
|Devin Ben-Hur wrote:
|> 11) Thou shall use use strict;
|Why turn perl into the no fun language?

I always use use strict, and still think perl is fun. :-)

Brian
-- 
Brian L. Matthews				Illustration Works, Inc.
	For top quality, stock commercial illustration, visit:
		  http://www.halcyon.com/artstock


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

Date: 7 Mar 1997 18:26:38 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Basic $ENV questions
Message-Id: <5fpmku$b9@fridge-nf0.shore.net>

Eddie Babin (ebabin@cyberenet.net) wrote:

: I guess I'm mistaken but I've seen references to the following which I
: also thought were environment variables:

: HTTP_PROXY_CONNECTION 
: HTTP_REFERER 
: HTTP_USER_AGENT 
[etc snipped]

Read the CGI spec at http://hoohoo.ncsa.uiuc.edu, which I suspect will
answer your questions (i.e. - "where are these variables?").  You must
execute the %ENV script I gave you as a CGI script, BTW.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Fri, 7 Mar 1997 18:57:06 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Basic $ENV questions
Message-Id: <E6osn6.n37@world.std.com>

ebabin@cyberenet.net (Eddie Babin) writes:

>I guess I'm mistaken but I've seen references to the following which I
>also thought were environment variables:

[list deleted]

A process gets every environment variable that its parent process has,
and which ever ones it puts there itself.

These environment varialbes look like ones that an http server would
add to its environment before spawning a child process that will
adhere to the CGI spec.

>From a bourne shell (or compatible shell) prompt, try the following:

#!/bin/sh

perl5 -e 'print map {"old $ENV{$_} $_\n"} keys %ENV'
export NEW_ENV_VAR new_env_var_value
perl5 -e 'print map {"new $ENV{$_} $_\n"} keys %ENV'

>Is there anyway to retrieve these values?  Thanks again for your help.

If the environment variable is there, "keys" will retrieve them.
-- 
Andrew Langmead


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

Date: 7 Mar 1997 17:41:17 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: BUG? Please explain this behavior
Message-Id: <5fpjvt$dst@lyra.csx.cam.ac.uk>

Roderick Schertler  <roderick@argon.org> wrote:
>
>Ditto with 5.003_92.  I don't have any older versions around with which
>to test.  Jim, could you try with 5.003_92?  If not how about posting
>the output of `perl -V' so someone with a similar platform can
>investigate?

Fails in 5.003, mended in 5.003_07.  So yes, it's a known bug which
will be mended in 5.004.


Mike Guy


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

Date: 7 Mar 1997 17:25:13 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Debugger and my variables.
Message-Id: <5fpj1p$opm$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    mlehmann@prismnet.com (Mark A. Lehmann) writes:
:Whenever I try to look at an @array or a %hash which are defined with 'my' in
:a function using the debuggers X or V commands, I get an empty return.
:However, I can print the @array or %hash.  How can I use the X or V commands
:to show me the 'my' variables?

You can't.  You have to use the x or p commands.

    Debbuger> x \%some_hash

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

    I'll say it again for the logic impaired.
		--Larry Wall


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

Date: Fri, 07 Mar 1997 13:04:32 -0500
From: Jean-Yves Levesque <jyves@nortel.ca>
Subject: Re: Generate Makefile and execute it from PERL
Message-Id: <332058B0.6BFE@nortel.ca>

Jean-Yves Levesque wrote:
> 
> I am trying to generate a Makefile from PERL.
> At the end of my perl script, I try to run make depend
> as in the following:
> 
>         my $x=system("gmake depend);
> 

	The solution was to set absoluter path.
	Thanks to all who replied.

Jean-Yves.

-- 
Jean-Yves Levesque (jyves@nortel.ca)	| Idea expressed belong to the
Nortel Technology			| owner and not to the company
P.O. Box 3511, Station C
Ottawa, Canada  K1Y 4H7


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

Date: 6 Mar 1997 03:44:09 GMT
From: vkd0871@omega.uta.edu (Vasudev Dalal)
Subject: Re: Getting list of files in a path
Message-Id: <5flei9$lh4@news.uta.edu>

Hi :

yu177535@yorku.ca wrote:
: Hi, I'm a newbie to Perl and I'm working on a script that needs to get the
: listing of all *.jpg files in a directory.
: 
: @files = (<*.jpg>);

Go to the directory under which you want all the "jpg" files.The u could
say somethng like :
@files = `find . -type f -name "*.jpg"`;

		OR
@files = `find <full path> -type f -name "*.jpg"`;

Vasu
dalal@cse.uta.edu


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

Date: Fri, 7 Mar 1997 16:50:53 GMT
From: Jim Shi <jims@ss5mth44.franklin.com>
Subject: help: add a package to perl
Message-Id: <5fpju6$t62@hideout.emanon.net>



Hi, I want to add a simple package to perl as folows:

 
package Frk;
 
require Exporter;
require DynaLoader;
 
@ISA = qw(Exporter DynaLoader);
 
@EXPORT = qw(gencmp);
 
bootstrap Frk;
 
 
1;
 


when I recompile perl source code, everything is fine, except when 
linking, it says:


        AutoSplitting perl library
 
        Making DynaLoader (static)
 
        Making Frk (static)
gcc-2.7.2.1 -c  -O  -I../..  -I /proj/frankstd/rev3.0/include Frk.c
cp /proj/compress/fdc/stable2.0/tools/resort/bin.sun4/resort.a ../../lib/auto/Frk/Frk.a
ar cr ../../lib/auto/Frk/Frk.a Frk.o && /usr/bin/ranlib ../../lib/auto/Frk/Frk.a
gcc-2.7.2.1    -o perl perlmain.o libperl.a lib/auto/DynaLoader/DynaLoader.a lib/auto/Frk/Frk.a `cat ext.libs` -lnsl -ldbm -ldl -lm -lc -lposix
collect2: ld returned 2 exit status
ld: Undefined symbol 
   _boot_Frk 
*** Error code 1
make: Fatal error: Command failed for target `perl'



what is "_boot_Frk" ? 

jim_shi@franklin.com


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

Date: Fri, 07 Mar 1997 08:47:01 -0800
From: "Paul H. Hargrove" <hargrove@sccm.Stanford.EDU>
Subject: Re: How can I use #! w/o knowing where perl lives?
Message-Id: <33204685.41C67EA6@sccm.Stanford.EDU>

Andrew M. Langmead wrote:
> How about all the variations on
> 
>            #!/bin/sh -- # -*- perl -*- -p
>            eval 'exec perl $0 -S ${1+"$@"}'
>                if 0;
> 
> 
> That are found in the man pages and the camel book?
> 
> Otherwise, do all the systems on which you are trying to run your
> scripts have /bin/env? You could say
> 
>            #!/bin/env perl
> --
> Andrew Langmead

Unfortunately bash version 1.14.17(1) says "sh: --: bad option".
However, /usr/bin/env exists on all the systems I use.

-- 
Paul H. Hargrove               All material not otherwise attributed
hargrove@sccm.stanford.edu     is the opinion of the author or a typo.


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

Date: 5 Mar 1997 21:28:09 GMT
From: jafar@finance (Jafar Shameem)
Subject: Re: How to flush in perl.
Message-Id: <5fkoh9$avp@gein.ge.com>

$|=1 ;

will that help?

Bhasker Allam (abr@wasp) wrote:
: Hi,
: Is there a way in perl to force the output of print to
: to go the screen or file immediately. I want something
: like flush(STDOUT). Thanks in advance.

: Bhasker.

--
http://mville.edu:8000/jafar                  jafar@beavisandbutthead.com

   I got a strong urge to fly
       But I got nowhere to fly to.. fly to.. fly to.. fly to..
                                                  [Pink Floyd - The Wall]


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

Date: Fri, 7 Mar 1997 11:14:58 -0500
From: Serge Kolgan <skolgan@Helios.goldworks.com>
Subject: Re: Interactive drawing alternatives in perl?
Message-Id: <Pine.SOL.3.91.970307105124.26219B-100000@Helios.goldworks.com>

On Fri, 7 Mar 1997, Clay Irving wrote:

> Take a peek at the "Graphics" section of Perl Reference:
>    http://www.panix.com/~clay/perl/query.cgi?graphics+index

this is all great, but not a single module/package mentioned in URL above
supports *interactive* drawing, that is: select primitive (click), draw 
primitive (click), modify... (click-click-click) :)

though the URL itself is worth to put into bookmarks!
Greets,
Serge.
-----------------------------------------------------------------------------
practice your intention



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

Date: Fri, 07 Mar 1997 12:59:04 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: NDBM and flock
Message-Id: <pudge-ya02408000R0703971259040001@news.idt.net>

Does anyobdy have a snippet of code for flock'ing an NDBM database?

I tried the example in the Blue Camel (p. 393), but it NDBM_File doesn't
have the fd() or sync() methods.  I tried just removing the sync and just
giving fd an arbitrary value ('1'), and it seemed to work fine, but I don't
know how it would hold up under heavy use.

Any help is greatly appreciated.

#================================================================
If you're a horse, and someone gets on you, and falls off, and
then gets right back on you, I think you should buck him off
right away.

   --Jack Handey

Chris Nandor                                      pudge@pobox.com
PGP Key 1024/B76E72AD                           http://pudge.net/
Keyfingerprint = 08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6


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

Date: 7 Mar 1997 18:34:45 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl timing questions:
Message-Id: <5fpn45$s6h$1@csnews.cs.colorado.edu>

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

:In comp.lang.perl.misc, 
:    albury@csee.usf.edu writes:
::Can anyone clue me in as to a way to time operations in perl witha
::granularity of less than 1 sec? 

Here, this code should actually work:

=head2 How can I measure time under a second?

In general, you may not be able to.  But if you system supports both the
syscall() function in Perl as well as a system call like gettimeofday(2),
then you may be able to do something like this:

    require 'sys/syscall.ph';

    $TIMEVAL_T = "LL";

    $done = $start = pack($TIMEVAL_T, ());

    syscall( &SYS_gettimeofday, $start, 0)) != -1
                or die "gettimeofday: $!";

        ##########################
        # DO YOUR OPERATION HERE #
        ##########################

    syscall( &SYS_gettimeofday, $done, 0) != -1
            or die "gettimeofday: $!";

    @start = unpack($TIMEVAL_T, $start);
    @done  = unpack($TIMEVAL_T, $done);

    # fix microseconds
    for ($done[1], $start[1]) { $_ /= 1_000_000 }

    $delta_time = sprintf "%.4f", ($done[0]  + $done[1]  )
                                             -
                                  ($start[0] + $start[1] );


--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
"I've decided I don't want to be a manager.  Every time you try to be responsive to your employees, they 
say you're being reactive and not proactive.  And when you try to be proactive, they accuse you 
of being capricious and arbitrary.  So I don't wanna be a manager...  " --Larry Wall


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

Date: Fri, 07 Mar 1997 10:33:51 -0800
From: Michael Stearns <mstearns@darkwing.uoregon.edu>
Subject: Point a socket client at an HTTP server
Message-Id: <33205F8F.1E670F30@darkwing.uoregon.edu>

I would like to create a socket that connects to an HTTP server, but I
can't get it. 

My script (below) gets to at least the line "print "$rawclient\n";" and
then it hangs (but it never dies).

I assume I need to correctly specify the port of the Web server (80?)
but I seem to be missing something. Any help would be appreciated.

Thanks,
Michael Stearns
University of Oregon



#!/usr/local/bin/perl

require 5.002;
use Socket;


$port = 2000;

while (getservbyport ($port, "tcp")) {
$port++;
}

$rawserver = "darkwing.uoregon.edu";

($d1, $d2, $prototype) = getprotobyname ("tcp");
($d1, $d2, $d3, $d4,$rawclient) = gethostbyname ("darkwing");


$clientaddr = pack ("Sna4x8", 2, $port, $rawclient);
$serveraddr = pack ("Sna4x8", 2, 80, $rawserver);
print "$rawclient\n";
socket (HTTP, PF_INET, SOCK_STREAM, $prototype) || die ("no socket");
bind (HTTP, $clientaddr) || die ("Can't bind");
connect (HTTP, $serveraddr) || die ("Can't connect");

print HTTP "GET /~mstearns/index.html HTTP/1.0\n\n" || die ("Didn't hear
anything");
$return=<HTTP> || die ("It's screwed");
print "$return\n";

close (SOCKET);

exit;


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

Date: 7 Mar 1997 18:31:22 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Point a socket client at an HTTP server
Message-Id: <5fpmtq$b9@fridge-nf0.shore.net>

Michael Stearns (mstearns@darkwing.uoregon.edu) wrote:
: I would like to create a socket that connects to an HTTP server, but I
: can't get it. 

(1) Install the LWP modules and run perl with (documented) arguments
    on the command-line.
(2) Read perlipc.pod, and use the client example.
(3) telnet to port 80 of a server, issue a GET request, and you'll
    know what you'll have to output from your client.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Fri, 7 Mar 1997 16:03:24 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: Possible bug in regular expression form /\d{x,x}/
Message-Id: <E6oKLo.C0C@nonexistent.com>

On Fri, 7 Mar 1997 00:16:23 -0500, William J. Sandman wrote in comp.lang.perl.misc:
++ Greetings,
++ 
++ 	I may have found a bug (or then again it could be pilot error)
++ 
++ When I implement a regular expression evaluation of the form:
++ 
++ 	if( @dog =~ /\d{5,5}/){
++ 		do stuff
++ 	}
++ 
++ 	where dog is $dog = 12345; the if evaluates to true.
++ 
++ When $dog is less that 5 digits the if evaluates to false. Since the 
++ upper limit is also 5. If there are more that 5 digits the if SHOULD 
++ evaluate to false. In my applications it is evaluating to true in cases 
++ where the upper limit (second value is either the same as the first of if 
++ different.

Then tell it it shouldn't have more:

if ($dog =~ /^\d{5,5}$/)           # 5 digits, and nothing else.
if ($dog =~ /^\d{5,5}(?!\d)/ ||    # 5 digits not followed by a digit, or
            /[^\d]\d{5,5}(?!\d)/)  # not a digit, 5 digits not
                                   # followed by a digit.
if ($dog =~ /(\d{5,6})/ && $1 !~ /\d{6,6}/) # 5 or 6 digits, but then not 6.

(Note that you want to compare $dog, not @dog).

++ 
++ What's the gig. Am I stoned?(read pilot error).
++ 
++ Community feedback on this is welcom, as I'm fairly comfortable with 
++ Perl, I've always had conceptual problems with regular expressions.
++ 

In that cause, buy the hip owl's book: "Mastering Regular Expressions"
by Jeffrey Friedl. It's a very nice book, and worth its money.



Abigail



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

Date: Fri, 07 Mar 1997 12:04:23 -0500
From: John Strickler <jstrick@mindspring.com>
Subject: Re: Reading from a file in an array arbitrary ????
Message-Id: <33204A97.4864DB4F@mindspring.com>

Douglas Seay wrote:
> 
> R. Evers wrote:
> >
> > Hi guys,
> >
> > I have a question (like everyone who posts to this newsgroup)....
> > I want to read a file into an array.
> > The problem is:
> > I don't want to read all, just a few lines from the file.
> >
> > To clear the problem, the usual codes to read a file into an array will be:
> > open (FILE, "$FileName");
> > @FileArray = <FILE>;
> > close(FILE);
> >
> > The above is what I usual do. However it will be a problem if I want to
> > read a file that contains more than 5000 lines. Imagines how big the array
> > is.
> >
This works for me:

   open(F,$some_file) or die("Oops");
   @stuff[0..9] = <F>;    # read in 1st 10 lines
   print @stuff;

Note that a list of arbitrary numbers can be used as the subscript to
select any lines you
want. I don't, however know whether "<>" is smart enought not to read
the entire file. I 
suspect it is.

--
John Strickler --  Perl/UNIX/C Trainer, Consultant
Jeffersonian Consortium            Voice:     919-682-3401     
HTTP://WWW.JCINC.COM               Facsimile: 919-682-3369


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

Date: 7 Mar 1997 18:26:35 GMT
From: sunny@mem.net (Dan Davis)
Subject: Rounding Numbers in Perl
Message-Id: <5fpmkr$s04@home.mem.net>

Hey

I have what is probobally a very basic question.  I have
been using perl to write some cgi scripts to keep up with
wins and losses for an online gaming leauge.  Everything is
working fine, however I would like to round some of the
scores off to just 2 or 3 significant digits.  The problem
is, I havent been able to find anything in Perl that rounds
floating point numbers.  For that matter, I havent found
anything that will even truncate them.  Am i missing
something here?  

Thanks for any help,
Dan Davis
sunny@mem.net





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

Date: Fri, 07 Mar 1997 11:30:36 -0600
From: "David P. Huff" <david@ti.com>
Subject: Re: Simple PERL program - HELP!
Message-Id: <332050BC.6212@ti.com>

Brian Cohen wrote:
> 
> Hi,
> 
> I was wondering if anybody could help. I would like to make a PERL 
> program that would validate a users password. All passwords would
> be on the PERL program so I don't have to access a database.
> 

This sounds just like the first, example program in the "Llama Book"
Chapter 1. If you don't know what I'm talking about, check out:

  "Learning Perl"
  Schwartz, Randal L.
  1993, O'Reilly & Assoc., Inc.
  ISBN 1-56592-042-2

Regards,

David Huff
Texas Instruments, Inc.
david@ti.com


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

Date: 7 Mar 1997 15:37:14 GMT
From: turnerm@cs.man.ac.uk (Mark Turner)
Subject: string length
Message-Id: <5fpcna$bb9@m1.cs.man.ac.uk>


Hi,

I have misplaced my perl book, and was woundering
if anyone could tell me of a comand to get the
length of the string contained in a variable
$string.

Cheers,


Mark...


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

Date: 7 Mar 1997 17:36:26 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: string length
Message-Id: <5fpjmq$opm$2@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    turnerm@cs.man.ac.uk writes:
:I have misplaced my perl book, 

And you've misplaced the online documentation as well?
This seems, um, unlikely.  It would have been indescribably
faster to look it up yourself than posting this for all
the world to answer.

:and was woundering

Boy, the -ou- thing is even odder in the UK than I realized.

:if anyone could tell me of a comand to get the
:length of the string contained in a variable
:$string.

Geen... I just wonder what one might call a function to find the
length() of a string?  Must be something counterintuitive, like
count_me_all_the_bytes_please().

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

#ifdef USE_STD_STDIO    /* Here is some breathtakingly efficient cheating */
    --Larry Wall, from sv.c in the v5.0 perl distribution


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

Date: Fri, 7 Mar 1997 17:12:55 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: string length
Message-Id: <adelton.857754775@aisa.fi.muni.cz>

turnerm@cs.man.ac.uk (Mark Turner) writes:

> Hi,
> 
> I have misplaced my perl book, and was woundering
> if anyone could tell me of a comand to get the
> length of the string contained in a variable
> $string.

length $string;

:-)

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 7 Mar 1997 10:08:24 -0700
From: kannawin@q.osmre.gov (Bill Kannawin)
Subject: Re: Which one is the best (pattern matching)
Message-Id: <5fpi28$d0o@q.osmre.gov>


In article <5fmr2f$4l99@eccws1.dearborn.ford.com>, cpierce1@cp501.fsic.ford.com (Clinton Pierce) writes:
|> In article <5fkvps$liu@neocad.xilinx.com>,
|> 	stampes@xilinx.com (Jeff Stampes) writes:
|> >Dylan Northrup (northrup@chem.ufl.edu) wrote:
|> >: =:
|> >: =:: Are you trying to start a religion?
|> >: =:
|> >: =:Too late.   ;-)
|> >
|> >: alt.religion.perl anyone?
|> >
|> >the ten commandments:
|> >
|> >1) Thou shall use -w
|> >2) thou shall not ask cgi programming questions
|> >3) Thou shall RTFM
|> >4) Thou shall not try to validate e-mail addresse
|> >5) Thou shall not use perl4
|> >6) Thou shall heed the latro warning
|> >7) Thou shall have a bible handy at all times (Programming Perl, 2nd Ed)
|> >8) Thou shall not write obfuscated code for others to maintain
|> >9) Thou shall check return stati of functions
|> >10) Thou shall use -w
|> >
|> >Do we get to offer up violaters of #2 and #4 as human sacrifice?
|> 
|> No, we make them port the Perl interpreter to COBOL.  Death is too kind.
|> 
we'll end up with    perform varying or die 


-- 
Bill Kannawin (303)844-1479 kannawin@osmre.gov|
Technical Information Processing System       |
US Office of Surface Mining; 1999 Broadway,   |
Suite 3320, Denver, Colorado 80202            |


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

Date: Fri, 7 Mar 1997 12:09:51 -0500
From: Jay Tomlin <ltomlin@ucs.indiana.edu>
Subject: Why are my rand() values so tiny?
Message-Id: <Pine.HPP.3.91.970307114305.20328A-100000@ezinfo.ucs.indiana.edu>

On most machines, using int(rand($int)) after a call to srand() does a
fine job of producing a random integer between 0 and $int. But with a copy
of Perl 5.003 for Solaris that I'm using, the call to int(rand($integer))
always returns zero. So I took off the int() part to see what the numbers
really were... 

	srand;
	for ($i=0; $i<5; $i++) { print rand(10), "\n"; }

yielded this:

	0.000113327987492085
	5.16790896654129e-05
	0.000148466788232327
	0.000116652809083462
	2.94996425509453e-05

I even tried calling srand with seeds other than the default time(), such
as $$ and even (time() ^ ($$ + ($$ << 15)), to no avail.Trying 
int(rand(10000000)) got me integers like 63 and 129. 

Anybody else seen this or have any ideas?

TIA,
-jay 
----------
Jay Tomlin
Office of Overseas Study, Indiana University
http://ezinfo.ucs.indiana.edu/~ltomlin
"When it speaks of music, language is lame."  --George Steiner



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

Date: 6 Mar 1997 03:17:22 GMT
From: vkd0871@omega.uta.edu (Vasudev Dalal)
Subject: Re: writing to file
Message-Id: <5fld02$lh4@news.uta.edu>

mv (nobody@nowhere.com) wrote:
Hello Monty :

: I am working on a cgi that takes the info from a form and writes it to a file.
: 
: open (guestfile, ">> guest.txt");
: 
: How do I have it write to a file in a different directory?

Try using full path names from the ROOT directory. This works for me.

Vasu



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

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

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