[7725] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1351 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 20 23:07:26 1997

Date: Thu, 20 Nov 97 20:00:21 -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           Thu, 20 Nov 1997     Volume: 8 Number: 1351

Today's topics:
     Re: "perl aware" vi editor? <dickey@clark.net>
     Re: -e switch (Martien Verbruggen)
     Re: 2 quicks questions, really (Tom Harrington)
     Re: 2 quicks questions, really (brian d foy)
     Re: ^D not working (Jeremy D. Zawodny)
     Re: ^D not working <rhodri@wildebst.demon.co.uk>
     Re: Another s/// question <rhodri@wildebst.demon.co.uk>
     Re: Another s/// question <rhodri@wildebst.demon.co.uk>
     Re: Another s/// question (John Moreno)
     Re: Authenticate a user and log him an NT identity (Jeremy D. Zawodny)
     Re: Can't 'make' modules.  "bash: make: command not fou (Faust Gertz)
     Chmod a file within a perl script! <tufgar@golden.net>
     Error 2009, a hard one to solve <gaw29@dial.pipex.com>
     Re: File test operators do not work as advertised!! (Andrew M. Langmead)
     Re: File test operators do not work as advertised!! (Martien Verbruggen)
     Finding the longest common prefix over a list of string (Ken Fox)
     HELP: Perl/DBM/Linux Tutor Consultant Wanted <rosenb10@pilot.msu.edu>
     Re: Last element of an anonymous array (Norman Gaywood)
     MS Acess/OLE/Perl <gkaatz1@nycap.rr.com>
     Re: open/read/close in PERL (Andrew M. Langmead)
     Re: Q: How many elements in a %HASH ? (Andrew M. Langmead)
     Re: sockets <gbarr@pobox.com>
     Re: Text to html perl script (Tushar Samant)
     Re: Text to html perl script (brian d foy)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 21 Nov 1997 00:37:52 GMT
From: "T.E.Dickey" <dickey@clark.net>
Subject: Re: "perl aware" vi editor?
Message-Id: <652l50$njj@clarknet.clark.net>

Martien Verbruggen <mgjv@comdyn.com.au> wrote:
:>>well, that's a shame. nvi is a much better piece of work.

: Please, please please,

: not another religious 'my editor is better than your editor' war.
no.  I was talking about code quality rather than number of features.
(You ought to read nvi and other well-written programs).

-- 
Thomas E. Dickey
dickey@clark.net
http://www.clark.net/pub/dickey


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

Date: 21 Nov 1997 00:49:33 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: -e switch
Message-Id: <652lqt$241$1@comdyn.comdyn.com.au>

In article <34739DD8.812C1DFB@pipeline.com>,
	Joseph Kewish <jsrk@pipeline.com> writes:
> Anyone care to give me an example?

depending slighlty on the operating system and shell (the quoting
might need to be different, this works on tcsh:

perl -we 'foreach( @INC ) { print "$_\n"; }'
perl -we 'for( $i = 0; $i < 10; $i++) { print "$i:"; } print "\n";'

Of course, these are trivial examples.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | You can't have everything, where would
Commercial Dynamics Pty. Ltd.       | you put it?
NSW, Australia                      | 


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

Date: 20 Nov 1997 23:32:37 GMT
From: tph@longhorn.uucp (Tom Harrington)
Subject: Re: 2 quicks questions, really
Message-Id: <652hal$3m05@eccws1.dearborn.ford.com>

Eli the Bearded (usenet-tag@qz.little-neck.ny.us) wrote:
: Tom Harrington <tph@rmi.net> wrote:

: > : 1:\BThis is a test
: > : 2:\BThe time is:\T

: > The backslashes in the text make this one kinda challenging.
: > Keep in mind that "\B" will be seen as an escaped "B", but an
: > escaped "B" has no special meaning, it's just a "B".  The following 

: Huh? I got the impression that perl would *not* be evaluating these.
: Besides, \B is special in regular expressions, so it won't always
: be a "B", sometimes it will be a zero-width assertion that there is
: no word boundary at that point.

I based my statement above on the following:

longhorn{tph:flow_test}: perl5
$_="1:\BThis is a test";
print "$_\n";
$_="2:\BThe time is:\T";
print "$_\n";
^D
1:BThis is a test
2:BThe time is:T

 ...which led me to conclude that the backslashes weren't being seen
as plain text slashes, but were being interpreted as escaping the
following character.  Apparently they are being evaluated, because
the solution I posted was based on that assumption, and it worked.

--
Tom Harrington --------- tph@rmii.com -------- http://rainbow.rmii.com/~tph
       "Ah, Marie, If you can't trust the governments of the world,
                  who can you trust?"  -"Young Einstein"
Cookie's Revenge: ftp://ftp.rmi.net/pub2/tph/cookie/cookies-revenge.sit.hqx


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

Date: Thu, 20 Nov 1997 19:50:57 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: 2 quicks questions, really
Message-Id: <comdog-ya02408000R2011971950570001@news.panix.com>

In article <652hal$3m05@eccws1.dearborn.ford.com>, tph@rmi.net wrote:

>Eli the Bearded (usenet-tag@qz.little-neck.ny.us) wrote:
>: Tom Harrington <tph@rmi.net> wrote:
>
>: > : 1:\BThis is a test
>: > : 2:\BThe time is:\T
>
>: > The backslashes in the text make this one kinda challenging.
>: > Keep in mind that "\B" will be seen as an escaped "B", but an
>: > escaped "B" has no special meaning, it's just a "B".  The following 
>
>: Huh? I got the impression that perl would *not* be evaluating these.
>: Besides, \B is special in regular expressions, so it won't always
>: be a "B", sometimes it will be a zero-width assertion that there is
>: no word boundary at that point.
>
>I based my statement above on the following:
>
>longhorn{tph:flow_test}: perl5
>$_="1:\BThis is a test";
>print "$_\n";
>$_="2:\BThe time is:\T";
>print "$_\n";
>^D
>1:BThis is a test
>2:BThe time is:T
>
>...which led me to conclude that the backslashes weren't being seen
>as plain text slashes, but were being interpreted as escaping the
>following character.  Apparently they are being evaluated, because
>the solution I posted was based on that assumption, and it worked.

your assumption was that the data was evaluated inside double-quotish
sorts of things.  however, the data was read from a file - what you
see is what you get.  your "test" is something completely different.
try it without double-quotish thingys.

this seems to be another situation in which a rush to use double-quotish 
thingys leads to all sorts of confusion.  unless you specifically want
to interpolate something, then don't use the double quotes.

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Fri, 21 Nov 1997 00:14:29 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: ^D not working
Message-Id: <347bd247.247841487@woody.wcnet.org>

[original author automagically cc'd via e-mail]

On Thu, 20 Nov 1997 17:58:29 -0500, comdog@computerdog.com (brian d
foy) wrote:

>In article <652a63$9mi$1@gamera.albany.net>, "Skip Egley" <egley@albany.net> wrote:
>
>>@array = <STDIN>;
>>
>>and perl will keep stuffing array with lines from standard input until a ^D
>>(Control-D). Mine doesn't work. The ^D simply prints a weird character on
>>the screen. It doesn't interrupt the receiving of data from standard input.
>>Am I doing this right? Is there something wrong with my version of perl? I
>>downloaded the latest one for Win95, I believe it was 5.004_02.
>
>^D is a Unix sort of thing.  perhaps that other OS has a different key?  how
>do you normally signal the end of input?

^Z on dos-ish systems will do the trick.

Well, it's not much of a trick.

Jeremy
-- 
Jeremy D. Zawodny                 jzawodn@wcnet.org
Web Server Administrator          www@wcnet.org
Wood County Free Net (Ohio)       http://www.wcnet.org/


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

Date: Thu, 20 Nov 1997 22:41:55 +0000 (GMT)
From: Rhodri James <rhodri@wildebst.demon.co.uk>
Subject: Re: ^D not working
Message-Id: <47ec33202crhodri@wildebst.demon.co.uk>

In article <652a63$9mi$1@gamera.albany.net>,
 Skip Egley <egley@albany.net> wrote:
> Let me try this again. I must not have explained myself well the
> first time.

Evidently the responses weren't well enough explained either :-)

> I'm just learning perl, going through "Teach Yourself Perl in 21 Days".
> According to the book, I can do something as simple as,

> @array = <STDIN>;

> and perl will keep stuffing array with lines from standard input
> until a ^D (Control-D). Mine doesn't work.

That's because your book is wrong, or alternatively your reading of your
book is wrong.  ^D is the correct character to type *ON UNIX* because *ON
UNIX* ^D is regarded *BY THE OS* as the 'end of input stream' indication. 
I believe the equivalent on Win95 is ^Z, but have no proof that it is.

-- 
Rhodri James  *-*  Wildebeeste herder to the masses
If you don't know who I work for, you can't misattribute my words to them

 ... Error: routine Lunchtime is purely virtual


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

Date: Thu, 20 Nov 1997 22:45:04 +0000 (GMT)
From: Rhodri James <rhodri@wildebst.demon.co.uk>
Subject: Re: Another s/// question
Message-Id: <47ec336a14rhodri@wildebst.demon.co.uk>

In article <6527gg$5v8$1@usenet85.supernews.com>,
 Vaughn Fox <vfox@nbnet.nb.ca> wrote:
> I'm new with Perl and am trying to replace an empty space in a
> variable with a "?" and haven't had much luck with the following:

> $variable =~ s/ /?/gi;

> am I on the right track, or is there another way I should go about this?

You are on the right track.  The thing that you haven't noticed is that
"?" is a metacharacter, meaning 'one or none of the preceeding'.  You need
to escape it:

$variable =~ s/ /\?/gi;

(assuming you really want the 'gi' :-)

-- 
Rhodri James  *-*  Wildebeeste herder to the masses
If you don't know who I work for, you can't misattribute my words to them

 ... Error: routine Lunchtime is purely virtual


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

Date: Fri, 21 Nov 1997 01:04:08 +0000 (GMT)
From: Rhodri James <rhodri@wildebst.demon.co.uk>
Subject: Re: Another s/// question
Message-Id: <47ec402560rhodri@wildebst.demon.co.uk>

In article <47ec336a14rhodri@wildebst.demon.co.uk>,
 Rhodri James <rhodri@wildebst.demon.co.uk> wrote:
> In article <6527gg$5v8$1@usenet85.supernews.com>,
>  Vaughn Fox <vfox@nbnet.nb.ca> wrote:
> > I'm new with Perl and am trying to replace an empty space in a
> > variable with a "?" and haven't had much luck with the following:

> > $variable =~ s/ /?/gi;

> > am I on the right track, or is there another way I should go about
this?

> You are on the right track.  The thing that you haven't noticed is
> that "?" is a metacharacter, meaning 'one or none of the
> preceeding'.  You need to escape it:

[I know, I know, following up my own posts.  It just seems appropriate]

 ...except that as brian d foy points out, the '?' is in the substitution
side of the substitution, so doesn't need to be escaped.  Now I'm confused
:-)  When you say you "haven't had much luck with" that substitution, what
exactly do you mean?

-- 
Rhodri James  *-*  Wildebeeste herder to the masses
If you don't know who I work for, you can't misattribute my words to them

 ... Yes, I'll do another Light Stuff soon, honest


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

Date: Thu, 20 Nov 1997 21:12:29 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: Another s/// question
Message-Id: <1d01bw5.188utkrem6utxN@roxboro-187.interpath.net>

Rhodri James <rhodri@wildebst.demon.co.uk> wrote:

]  Rhodri James <rhodri@wildebst.demon.co.uk> wrote:
] >  Vaughn Fox <vfox@nbnet.nb.ca> wrote:
] > > I'm new with Perl and am trying to replace an empty space in a
] > > variable with a "?" and haven't had much luck with the following:
] 
] > > $variable =~ s/ /?/gi; am I on the right track, or is there
] > > another way I should go about
] > > this?
] 
] > You are on the right track.  The thing that you haven't noticed is
] > that "?" is a metacharacter, meaning 'one or none of the
] > preceeding'.  You need to escape it:
] 
] [I know, I know, following up my own posts.  It just seems
] appropriate]
] 
] ...except that as brian d foy points out, the '?' is in the
] substitution side of the substitution, so doesn't need to be escaped.
] Now I'm confused :-)  When you say you "haven't had much luck with"
] that substitution, what exactly do you mean?

Exactly what I was thinking, it works for me.

$variable="this is a test";
$variable =~ s/ /?/gi;
print "$variable\n";

produces

this?is?a?test

-- 
John Moreno


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

Date: Thu, 20 Nov 1997 23:59:34 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: Authenticate a user and log him an NT identity
Message-Id: <3477ce7a.246868387@woody.wcnet.org>

[original author automagically cc'd via e-mail]

On Wed, 19 Nov 1997 18:08:45 -0800, Debasish Biswas <dbiswas@nc.com>
wrote:

>I am writing a web-based admin tool on NT using Perl. I have to
>authenticate the client not only to the admin application but also to
>the operating system, so that the client can get the right
>administrative privileges. In other words I want the scripts to 'run as'
>a privileged user and be able to add users, create directories etc. to
>the NT machine.
>
>How do I do this ? Any help will be appreciated.

Install a second copy of perl.exe. Setup a new file extension which
you want to use on scripts that are run by this second perl.exe (let's
call it admin-perl.exe for fun).

Set the permissions on your scripts (and maybe on the admin-perl.exe,
I can't recall which worked) such that only admins can run them.

Make some sense?

Jeremy
-- 
Jeremy D. Zawodny                 jzawodn@wcnet.org
Web Server Administrator          www@wcnet.org
Wood County Free Net (Ohio)       http://www.wcnet.org/


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

Date: Fri, 21 Nov 1997 00:17:42 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: Can't 'make' modules.  "bash: make: command not found"
Message-Id: <3475d206.3985467@news.wwa.com>

On Wed, 19 Nov 97 21:47:01 -0500, bsa@void.apk.net (Brandon S. Allbery
KF8NH; to reply, change "void" to "kf8nh") wrote:

>Solaris, by any chance?  (Although some other SVR4 variants also have the
>problem, reportedly including SCO v5).
>
>Anyway, the problem on Solaris, SCOv5, etc. is that /usr/ccs/bin needs to be
>added to your PATH.  To the *end* of your PATH, by preference:  

Yup, that was the problem and Zenin's <zenin@best.com> suggestion of
typing:

>PATH=$PATH:/usr/ccs/bin; export PATH

at the shell was just what a unix naive like myself needed.  Thanks.
I've asked my system admin to add it, but at least I've got a way
around it for now.

Thanks once again,

Faust Gertz
Philosopher at Large


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

Date: Thu, 20 Nov 1997 21:59:55 -0500
From: The Tufgars <tufgar@golden.net>
Subject: Chmod a file within a perl script!
Message-Id: <3474F92B.DE0EF898@golden.net>

I'm trying to Make a file that is inaccessible to anyone browsing the
web accessible, when the run my script.  I was thinking of somehow
locking the file with chmod and then unlocking it when a user wanted
it.  Then lock it back up when they were done.  Is this possible?  or is
there and easier way of doing this?



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

Date: Fri, 21 Nov 1997 03:11:27 -0800
From: "Charlie Hope-Lang" <gaw29@dial.pipex.com>
Subject: Error 2009, a hard one to solve
Message-Id: <652uc8$6f9$1@plug.news.pipex.net>

Does anyone know what the following server error means and what can be done
to eradicate it, we are using NT 3.51, Citrix 1.6 SP5 and Oracle Forms.  The
server is a Sequent with 4*p-Pro 200 and 2 Gb RAM.  The swap file is 4 Gb.

Additionally what is the maximum size you can set a swapfile to and does any
one know of any software that will load a server for stress testing.

thanks for any help,  we are really stumped by this one

Charlie




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

Date: Fri, 21 Nov 1997 00:20:22 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: File test operators do not work as advertised!!
Message-Id: <EJyzLy.EDy@world.std.com>

daveisdead@aol.com (DaveIsDead) writes:

>As far as I can figure

>opendir DIR, '/home/foo';
>@dirs = grep -d, readdir DIR;

>should load up @dirs with all of the directories in /home/foo, without the full
>path name.  

Only if you run the script from '/home/foo', or if '/home/foo' happens
to have the same files and directories as the current directory.

readdir() only returns the base file names, not full file path
specifications, and "-d" (and the stat() it is based on) perform its
tests based on the common path rules (file names that start with a
slash are based on the root directory, ones that aren't are based on
the current working directory.)

Essentially, stat() doesn't know what you passed as an argument to
opendir().

@dirs = grep -d, map { "/home/foo/$_" } readdir DIR;

>I've figured out work around, indcluding opening a pipe to read from like so:

>open MYPIPE, 'ls -l /home/foo | grep ^d |';
>(I'll have to parse lines as I read them to get just the dir name)

>or:

>open MYPIPE, 'find /home/foo* * -prune -type d -ls | tail +3 |';

All of these return a full path to the files.
-- 
Andrew Langmead


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

Date: 21 Nov 1997 03:01:43 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: File test operators do not work as advertised!!
Message-Id: <652tin$2mo$1@comdyn.comdyn.com.au>

In article <19971120210001.QAA18755@ladder01.news.aol.com>,
	daveisdead@aol.com (DaveIsDead) writes:
> As far as I can figure
 
> opendir DIR, '/home/foo';
> @dirs = grep -d, readdir DIR;
 
This will only work if you are actually in the directory you're
reading. readdirs will return a list of files/dirs, RELATIVE to
/home/foo.

> should load up @dirs with all of the directories in /home/foo,
> without the full path name.

Exactly, you already had the answer.

Try:

#!perl -w

use strict;

my $dir = '/home/foo';

# Always check return values of opens
opendir(DIR, $dir) or die "Cannot open $dir: $!";

# using the BLOCK version of grep
my @dirs = grep {-d "$dir/$_"} readdir(DIR);

# Whatever you need to do with @dirs here

close(DIR);


> There are also problems with the other file test operators.  -f
> seems to work, -r returns seemingly arbitrary results.  

# ls -al
-rw-r-----   1 notme    staff          0 Nov 21 13:50 bar
-rwxr-x---   1 notme    staff          0 Nov 21 13:50 baz
-r--------   1 mgjv     staff          0 Nov 21 13:47 dick
-rw-------   1 notme    staff          0 Nov 21 13:50 foo
-rwx------   1 mgjv     staff          0 Nov 21 13:47 harry
----------   1 mgjv     staff          0 Nov 21 13:47 tom

# perl5 -e 'print STDOUT join ", ", grep -r, glob "*";'
bar, baz, dick, harry

Seems a good result to me.. Could you post an example of when it
returns 'arbitrary' results?

> -T seems to always evaluate false, except once in a long while.

That most likely means that most files you examine look binary to -T
The entry on -X (perldoc -f -X) explains how -T and -B work.
(maybe you transfered DOS text files in binary mode, which would leave
a bunch of 'odd' characters in there?)

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Little girls, like butterflies, need no
Commercial Dynamics Pty. Ltd.       | excuse - Lazarus Long
NSW, Australia                      | 


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

Date: 21 Nov 1997 01:15:33 GMT
From: fox@pt0204.pto.ford.com (Ken Fox)
Subject: Finding the longest common prefix over a list of strings
Message-Id: <652nbl$kgi1@eccws1.dearborn.ford.com>

The last couple of "what's the best way to do it" questions put
me into a regex hunting mood.  I had a bit of code in a file
browser class which finds the common string prefix in a list of
strings.  Here's the basic algorithm:

  my @words = qw(the thick thesis thoroughly threw thor);

  my $offset = 0;
  my $reference = shift @words;
  my $prefix;

  MATCH: while (1) {
      $prefix = substr($reference, $offset, 1);
      foreach (@words) {
          if (substr($_, $offset, 1) ne $prefix) {
              $prefix = substr($reference, 0, $offset);
              last MATCH;
          }
      }
      ++$offset;
  }

  print "$prefix\n";

When I wrote that I thought it was pretty nice, maybe even elegant.
Here's the best regex-based solution I can come up with:

  (join(',', @words).',') =~ /^(\w*)\w*,(\1\w*,)*$/;

  print "$1\n";

Is there a better one?  And the *big* question, if you had to maintain
the code, which one would you rather look at?  ;)

- Ken

P.S. At first I thought the substr() code would be faster since it
     should (theoretically) do less work.  The regex kicks the snot
     out of the substr() code though.  6.46 secs to 11.58 according
     to Benchmark.pm.  Anybody know how well the regex approach
     scales up?

-- 
Ken Fox (kfox@ford.com)                  | My opinions or statements do
                                         | not represent those of, nor are
Ford Motor Company, Powertrain           | endorsed by, Ford Motor Company.
Analytical Powertrain Methods Department |
Software Development Section             | "Is this some sort of trick
                                         |  question or what?" -- Calvin


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

Date: Thu, 20 Nov 1997 20:58:32 -0400
From: Mark Rosenberg <rosenb10@pilot.msu.edu>
Subject: HELP: Perl/DBM/Linux Tutor Consultant Wanted
Message-Id: <3474DCAF.C6B2B739@pilot.msu.edu>

Hi,

I have inherited some perl code which utilizes dbm structures to build
and operate an event calendar type website. I'd like some help
understanding/porting/modifying the scripts.  I am imagining working on
this using some realtime tools like timbuktu and/or an internet
telephone application. I am figuring it would take about 15-20 hours
total and would like to work on it over the span of a week or two before
the end of the year. I am figuring a 4-6 hour block for you to explore
the code, and then (5)  1-2 hour realtime sessions to walk through the
code and tweek it.

If you are interested, please email me some info about your
perl/dbm/linux experience, your tutoring/teaching experience, your
capacity to work in realtime, your availability, and what you need in
terms of compensation.

Thanks,

Mark Rosenberg
Teacher Education - Michigan State Univ.



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

Date: 21 Nov 1997 10:42:03 +1100
From: norm@turing.une.edu.au (Norman Gaywood)
Subject: Re: Last element of an anonymous array
Message-Id: <652hsb$mc2@turing.une.edu.au>

Terry Michael Fletcher - PCD (tfletche@pcocd2.intel.com) says:
>Norman Gaywood (norm@turing.une.edu.au) so eloquently and verbosely pontificated:
>> How do I find the last element of an anonymous array in the following
>> context. At least, I think I'm asking that question!
>[code with typo-syntax errors deleted]

Opps. Sorry.

>> That seems to work OK.  But, suppose I don't want the first element of
>> each line. I want to do an array slice and write the map part as:
>>            map { TR( $_ ) } (map { td( $_ ) } @data)[1..$#??]
>> But what goes where the ?? is? 

> you've got some syntax errors in there (that i dont want to pick on), but
> the dereferencing you're looking for is:
> 
> @{ $data[$i] }[ 1 .. $#{ $data[$i] } ]   # or, working backwards
> @{ $data[$i] }[ -$#{ $data[$i] } .. -1 ]
> 
> where $i is the index into your list of lists.
> 
> then your statement would look like this:
> 
> map { TR($_) } map { td($_) } @{ $data[$i] }[ 1 .. $#{ $data[$i] } ];

But how do I manage the $i? It needs to be incremented somewhere. But:

map { TR($_);$i++ } map { td($_) } @{ $data[$i] }[ 1 .. $#{ $data[$i] } ];

or

map { TR($_) } map { td($_) } @{ $data[$i++] }[ 1 .. $#{ $data[$i] } ];

are not correct. Am I missing something?

> but be aware that your lists need more than two elements.
>  (the range produces 1,0 for a 1 element list, and 1,1 for a 2 elem.)

Yes, this is a problem which makes the construct a bit messy. I've
gone back to the original:

print table( {-border=>1},
        map { TR( $_ ) }  map { td( $_ ) } @data
      );

because it's nice and clean and easy to understand. I just made sure
that the @data array is in the form I want before getting there.

But! All this is a side issue! My fault for not asking the question
properly. I just asked the question in the context that I came across
the problem. Mark Mielke <markm@nortel.ca> frames my question in a much
better way:

> In perl you can do things like:
>    $hour = (localtime)[2];
> The question as to whether you can say:
>    @all_but_first = (localtime)[1..];
> I can only say... i wish :-) In fact i tried it before in hope or something...
> but it seems the ".." operator is simply that. It's not special when "in array
> element number context" :-) The only way i know of how to do it now is:

So the real answer to the question is no. You can't in general know
what the last element of an array is when subscripting. You have to
keep track of a reference or the name of the array in some way.

I'm sure others must have discussed this before but... Should the syntax
for this be (in perl 6 or whatever):

  @all_but_first = (localtime)[1..-1];

generalising, you can do slices like [1..-3] or [-4..2] which would
pull (2,3) from (1,2,3,4,5).

-- 
Norman Gaywood -- School of Mathematical and Computer Sciences
University of New England, Armidale, NSW 2351, Australia
norm@turing.une.edu.au     http://turing.une.edu.au/~norm
Phone: +61 2 6773 2412     Fax: +61 2 6773 3312


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

Date: 21 Nov 1997 01:01:27 GMT
From: "Glen Kaatz" <gkaatz1@nycap.rr.com>
Subject: MS Acess/OLE/Perl
Message-Id: <01bcf619$adf410c0$0d255c18@glen>

Does anyone have sample code of a Perl using OLE on NT to kick off
MS/Access?

Any/all help will be appreciated.
Thanks,
-Glen Kaatz



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

Date: Fri, 21 Nov 1997 00:07:03 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: open/read/close in PERL
Message-Id: <EJyyzs.806@world.std.com>

Mike Snyder <accu-scan@worldnet.att.net> writes:

>####
>open FILE, "sn.dat";
>read FILE, $buffer,100000;
>close FILE;
>@pairs = split(/&/, $buffer);
>####

>The file is really only about 53000 bytes (not 100000) but it might grow
>in the future. I haven't seen any side effects from trying to read MORE
>bytes than are in the file. It seems to work just fine and $#pairs ends
>up being the correct number of records.

read() will only read until end of file. It returns the number of
bytes read so that the programmer can check for errors.

You might be better off using this common perl idiom:

open FILE, 'sn.dat' or die "Error opening sn.dat: $!\n";
{ 
  local($/) = undef; # slurp entire file with one read
  $buffer = <FILE>;
}

The $/ variable holds the end of record marker for the readline (<>)
operator. It is a newline by default, so that <> returns a line at a
time. When changed to 'undef', it reads an entire file at once. It is
put inside a block and passed to the local() operator so that the
changes in the assignment to $/ are only temporary (until the end of
the block.)

The "or die" expression was added after the open() is because I
couldn't bare to perpetuate a bad example.
-- 
Andrew Langmead


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

Date: Thu, 20 Nov 1997 23:58:12 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Q: How many elements in a %HASH ?
Message-Id: <EJyyL0.364@world.std.com>

G.C.Th.Wierda@AWT.nl (Gerben Wierda) writes:

>Benchmark: timing 100000 iterations of use_array, use_keys, use_loop...
> use_array: 171 secs (129.28 usr  0.67 sys = 129.95 cpu)
>  use_keys:  1 secs ( 0.53 usr  0.02 sys =  0.55 cpu)
>  use_loop: 164 secs (143.39 usr  0.48 sys = 143.88 cpu)

>So:

>sub size_hash {
>	# Pass reference to hash
>	# don't use while inside another each loop!
>	my $hashref = shift;
>	my $n;
>	$n=0;
>	while (($k,$v) = each %$hashref) {
>		$n++;
>	}
>	return $n;
>}

>Usage:
>	$hash_size = &size_hash( \%TEST);

I don't get it. Since "$n = keys %TEST" is so much faster than 
"$n = 0; while(each %TEST) { $n++ }", then why are you trying to wrap
the loop into a subroutine? (Notice since timethese() takes a
reference to a hash as an argument, the order the code snippets are in
when they run are probably not order in which they were written.)

If you did want to hide any of these methods info a subroutine, then
its a great candidate for a function prototype:

sub size_hash (\%) {
# ...
}

$hash_size = size_hash(%TEST);
-- 
Andrew Langmead


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

Date: Thu, 20 Nov 1997 17:06:38 -0600
From: Graham Barr <gbarr@pobox.com>
Subject: Re: sockets
Message-Id: <3474C27E.D8FB586D@pobox.com>

There is a typo in the book, use PeerAddr and LocalAddr instead of
PeerHost and LocalHost

Graham.

Peter Sakalaukus wrote:
> 
> In using the socket examples in the O'Reilly book "Advanced Perl
> Programming", (pages 192-193), I am able to launch the server with
> no problem. When I launch the client though, I get:
> 
> Socket could not be created. Reason: Bad file number
> 
> The client code is simple enough:
> 
> -------------------------------------------------------------------
> 
> use IO::Socket;
> 
> $sock = new IO::Socket::INET (PeerHost => 'some.machine.com',
>                               PeerPort => 8080,
>                               Proto    => 'tcp');
> 
> die "Socket could not be created. Reason: $!\n" unless $sock;
> 
> foreach(1 .. 10)
>   {
>   print $sock "Msg $_: How are you?\n";
>   }
> 
> close($sock);
> 
> -------------------------------------------------------------------
> 
> The sample server is:
> 
> use IO::Socket;
> 
> $sock = new IO::Socket::INET (LocalHost => 'some.machine.com',
>                               LocalPort => 8080,
>                               Proto     => 'tcp',
>                               Listen    => 5,
>                               Reuse     => 1);
> 
> die "Socket could not be created. Reason: $!" unless $sock;
> 
> while($new_sock = $sock->accept())
>   {
>   while(defined ($buf = <$new_sock>))
>     {
>     print $buf;
>     }
>   }
> 
> close($sock);
> 
> -------------------------------------------------------------------
> 
> Any insight would be GREATLY recieved.
> 
> Thanks ...Pete
> 
> sakalauk@coam.usm.edu


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

Date: 20 Nov 1997 17:56:54 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: Text to html perl script
Message-Id: <652io6$98l@shoga.wwa.com>

jeremy@lightningweb.com writes:
>I need a script that can help me convert an entire directory of text files
>to htmls with preconfigured headers and footers.

Firstly, txt2html, as has been suggested, is not a complete solution.
I see from its web page that it converts a single file. (Yes, I know
you specifically said you wanted something more...)

Are you on a Unix system? What do you mean when you say the .docs
"format out as text"? How much HTML do you want in the final product?
Just a <pre> - </pre> slapped on, or much more?

If you tell me this I might be able to give you a program.



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

Date: Thu, 20 Nov 1997 19:53:18 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Text to html perl script
Message-Id: <comdog-ya02408000R2011971953180001@news.panix.com>

In article <652io6$98l@shoga.wwa.com>, scribble@shoga.wwa.com (Tushar Samant) wrote:

>jeremy@lightningweb.com writes:
>>I need a script that can help me convert an entire directory of text files
>>to htmls with preconfigured headers and footers.
>
>Firstly, txt2html, as has been suggested, is not a complete solution.
>I see from its web page that it converts a single file. (Yes, I know
>you specifically said you wanted something more...)

if it can do a single file, then a simple wrapper (perhaps in Perl?)
will make it do as many files as you have disk space for. :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

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

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