[13817] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1227 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 30 00:05:47 1999

Date: Fri, 29 Oct 1999 21:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <941256313-v9-i1227@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 29 Oct 1999     Volume: 9 Number: 1227

Today's topics:
    Re: Card shuffling (Kragen Sitaker)
    Re: Card shuffling (Kragen Sitaker)
    Re: create hash for db index?? (Martien Verbruggen)
    Re: How come no interface to mmap? (Chris Fedde)
    Re: How the heck does this regex match? (Martien Verbruggen)
    Re: How the heck does this regex match? <jeffp@crusoe.net>
    Re: It is always like this here? <ltl@rgsun40.viasystems.com>
    Re: It is always like this here? (Martien Verbruggen)
    Re: Perl and Excel (David Foster)
    Re: perl double-split <randys@NOSPAMamigo.net>
        perl programs help <bchung@ci.south-el-monte.ca.us>
    Re: Perl script to check OS system (Martien Verbruggen)
    Re: regex match with empty string <ltl@rgsun40.viasystems.com>
    Re: Reinventing the wheel (Steve Morris)
    Re: shtml / perl problem <randys@NOSPAMamigo.net>
    Re: simplifying a script <jeffp@crusoe.net>
    Re: slow txt processing problem (Kragen Sitaker)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 30 Oct 1999 03:03:49 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Card shuffling
Message-Id: <petS3.8642$23.482660@typ11.nn.bcandid.com>

In article <380EF5A6.7F2A05CD@ife.ee.ethz.ch>,
Alex Rhomberg  <rhomberg@ife.ee.ethz.ch> wrote:
>The other problem is still that if I know all permutations the number
>generator can produce, I need to see only very few cards to know all of
>them

Well, in principle this is true.  If you have, say, a PRNG with a
64-bit seed, you can just make a table of the first six cards generated
by all 2^64 seeds, or whichever cards you see, and look up the given
six cards to see which of the combinations are possible.

In reality, making a 18446744073709551616-entry table is difficult.
That's why 56-bit DES with known plaintexts is still somewhat hard to
crack.

In reality, many PRNGs use 32-bit seeds, so the table attack may be
feasible.

In reality again, many PRNGs are simple linear things, the sort of
thing that mystical Real Cryptographers can crack in their sleep.  So
even if it's a 64-bit-seed PRNG, it might be possible to simply
*calculate* from the first six cards what the next card could be.

Another question, though: assuming the sequence has only 32 bits of
entropy, all 32 of which are present in every output, is it guaranteed
by the Fisher-Yates shuffle that all 32 bits will show up in the first
few cards?  This is prompted by your '20 cards all in one place'
comment.  Maybe it just so happens that there are only 2^10
possibilities for the first six cards, but 2^32 possibilities for the
deck as a whole.  This might be enough to prevent practical cheating.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Thu Oct 28 1999
12 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: Sat, 30 Oct 1999 03:20:30 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Card shuffling
Message-Id: <2utS3.8668$23.482466@typ11.nn.bcandid.com>

In article <slrn814f85.fji.abigail@alexandra.delanet.com>,
Abigail <abigail@delanet.com> wrote:
>Kragen Sitaker (kragen@dnaco.net) wrote on MMCCXLI September MCMXCIII in
><URL:news:XkoP3.22432$E_1.1219502@typ11.nn.bcandid.com>:
>// 
>// Well, I believe professional dealers are required to shuffle the deck
>// six times, enough for every card to be able to be anywhere in the deck,
>// but not enough to stack it very well.  [I can't remember what the
>// number is, though.]
>// 
>// Ideally, every card getting shuffled -- except for the last two or
>// three -- contributes one bit of entropy, because it's equally likely to
>// be the left or right card.  If this is the case, we have about 50 bits
>// of entropy per shuffle, so we only need one shuffle to do better than
>// rand(), and five shuffles to do things perfectly.  [This suggests
>// something is wrong with my reasoning, because we know it takes six --
>// right?  Or does it?]
>
>Well, not quite. For such a shuffle, it would impossible for instance
>for the top card to end up as the bottom card after only one shuffle.
>And while it's true that as long as you have two stacks, there's an
>about equal chance the next card will come from the left or right stack,
>cards that are in the right stack will show up in the shuffled stack
>in the same order; same for cards in the left stack. Hence, I would not
>say "50 bits of entropy".
>
>Take for instance a shuffle with 4 cards. Have A and B in the left deck,
>and C and D in the right. You can only get 6 different decks from that:
>      A B C D
>      A C B D
>      A C D B
>      C A B D
>      C A D B
>      C D A B
>while 4! == 24.

That's lg 6, or about 2.58 -- almost three -- bits of entropy, which is
almost one bit per card.  Obviously the last card contributes no
entropy, and sometimes the last few cards contribute none, because
there are no cards left in the other hand when they fall down.  So
you'd expect a little less than 3 bits of entropy.  That's what I said
in the text quoted above; either I am missing something you said, or
you were missing what I said.

For four cards, you need two shuffles to get the requisite lg 24, or
4.58, bits of entropy you need.  (You actually get about 5.16, some of
which gets discarded.)

It seems to me that you should be able to calculate exactly how many
bits of entropy you get shuffling N cards in the idealized manner
discussed above by using the binomial distribution.  Each card
contributes exactly one bit, except when there are no cards left in the
other hand, in which case it contributes no bits.  The number of
different ways the shuffle can go such that there are exactly N
shoo-in, zero-contribution cards at the end of the shuffle should be
calculatable by the binomial theorem, right?  So sum the entropy of
each family of shuffles, from 1 shoo-in card to an entire hand full of
shoo-in cards, and you have your answer.  Right?  Something seems wrong
with this to me.

On a somewhat related note, using perfect faro shuffles, in which only
one bit of entropy is added per shuffle because the cards alternate
perfectly, you need lg N shuffles to get the top card to any position
N deep or less in the deck.  This is apparently a skill practiced by
some magicians of mathematical inclination.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Thu Oct 28 1999
12 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: 30 Oct 1999 01:49:52 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: create hash for db index??
Message-Id: <slrn81kjrq.j4s.mgjv@wobbie.heliotrope.home>

[If you hadn't removed the attribution, maybe you would have spelled
Abigail's name correctly.]

On Sat, 30 Oct 1999 01:01:27 GMT, Shmooth <shmooth@yahoo.com> wrote:
> >
> > Perhaps if you need to do something with Oracle, you would have to
> > make yourself familiar with it?
> >
> 
> it's called overstatement, Abiguile.  Most programmers I know are
> familiar with _it_...

And most programmers I know wouldn't dream of not using the RDBMS they
are working with to create unique indexes. That's part of the database's
job.  Besides, if they're in a database table, they already have a
unique key.

Abigail was entirely correct to point out to you that before working
with a database system, you should at least familiarise yourself with it
a bit.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Hi, Dave here, what's the root
Commercial Dynamics Pty. Ltd.   | password?
NSW, Australia                  | 


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

Date: Sat, 30 Oct 1999 01:29:30 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: How come no interface to mmap?
Message-Id: <_RrS3.138$F3.189653504@news.frii.net>

In article <FJz3EH.n10@news.boeing.com>,
Keith Michaels <krm@sdc.cs.boeing.com> wrote:
>I need to read a large random access database of fixed length records.
>In the old days I would use mmap with C for efficiency.  What is the
>counterpart in perl?  Why isn't there an mmap package?
>

There is an interface to mmap listed in CPAN.  Does that not meet your
needs?

chris



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

Date: 30 Oct 1999 01:59:36 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: How the heck does this regex match?
Message-Id: <slrn81kke2.j4s.mgjv@wobbie.heliotrope.home>

On Thu, 28 Oct 1999 20:15:25 +1000,
	Douglas Garstang <dgarstan@nsw.bigpond.net.au> wrote:
> #!/usr/bin/perl
> 
> $a = "[ sdt_shel ]";
> $b = "dtlogin";

- You should be a bit careful using $a and $b. Unfortunately, Perl uses
  these internally in sorts.

> if ( $b =~ $a ) {

This is equivalent to:

	if ($b =~ /[ sdt_shel ]/) {

As you probably know. And a quick browse of the regexp documentation
that comes with perl shows:

# man perlre
(or perldoc for people on systems without man)
[snip]
           []  Character class
[snip]
       You can specify a character class, by enclosing a list of
       characters in [], which will match any one character from
       the list.
[snip]

So. The regular expression you provide asks for a match of a single
character that is either ' ', 's', 'd', 't', '_', 'h', 'e' or 'l'.

And since 'dtlogin' contains more than one of those, it returns true
(because of the d actually: leftmost longest match).

> *is blown away*
> 
> How can this be true?
> 
> (something to do with the []'s getting in the way?)

*nod*

I suggest you read the documentation a bit.

Just as an aside: Are you trying to do a remote login and recognise the
prompt or something? If so, are you aware of the Net::Telnet module,
available from CPAN (http://www.cpan.org/)?

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd.   | Then things get worse.
NSW, Australia                  | 


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

Date: Fri, 29 Oct 1999 21:59:50 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: How the heck does this regex match?
Message-Id: <Pine.GSO.4.10.9910292156500.2694-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 28, Douglas Garstang blah blah blah:

> $a = "[ sdt_shel ]";
> $b = "dtlogin";
> 
> if ( $b =~ $a ) {
>         print "YES\n";
> }

If we make this non-variable-dependent, we get:

  if ("dtlogin" =~ /[ sdt_shel ]/) { print "YES\n"; }

[] signify a character class; that is, the previous example matches if any
of the characters, ' ', s, d, t, _, s, h, e, l, or ' ' are in the string.
Remove duplicates, and you'd have:

  if ("dtlogin" =~ /[ sdt_hel]/) { ... }

Surely, "dtlogin" has the characters t, d, and l.  So it matches.  Perhaps
you want:

  if ($b =~ /\Q$a/) { ... }

or

  $a = quotemeta("[ sdt_shel ]");
  if ($b =~ $a) { ... }

For more info, read:

  perldoc perlre
  perldoc -f quotemeta

-- 

  MIDN 4/C PINYAN, USNR, NROTCURPI
  jeff pinyan      japhy@pobox.com
  perl stuff       japhy+perl@pobox.com
  CPAN ID: PINYAN  http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/



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

Date: 30 Oct 1999 03:36:39 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: It is always like this here?
Message-Id: <7vdp47$qkh$1@rguxd.viasystems.com>

Martien Verbruggen <mgjv@wobbie.heliotrope.home> wrote:
:>On 29 Oct 1999 17:50:44 GMT,
:>	William <bivey@teamdev.com> wrote:
:>> Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid> wrote in article
:>> <000b8d9b.40a12527@usw-ex0101-001.remarq.com>...

[snip long (and mostly true and informative) discussion of how 
things got to be the way they are on clpm]

:>> I've found that, while the cluelessness is just as high,
:>> the newbie-toasting is less pronounced in newsgroups
:>> devoted to creating applications. Don't know why,
:>> just my observation.

:>Again, it's not that, really. It's the total clash of cultures that is
:>fairly unique to the perl newsgroups. Most of the oldies here were here
:>befire the Web was invented,or at least before it became commercially
:>attractive. Most of the newbies here have found Usenet through the
:>'Messenger' button on Netscape (or whatever the thing is called).

:>The people here aren't really nasty. It's just a reaction against what
:>they see as pollution, laziness, and rudeness. They expect newbies to
:>realise that they should read the Usenet introduction, and to first get
:>some basic understanding of programming. It's not much to ask, but it
:>won't happen. This discussion, and many like it, has been here. Many,
:>many many times. I keep promising myself that Iwon't get drawn into yet
:>another one, but here I am.

I am tired of seeing the nastiness defended.  I've seen lots of
explanations for it and I won't disagree with any of these analyses
of why people (regulars) behave the way they do in c.l.p.m, but I
don't buy any defense of the nastiness as a constructive force with a
rational motive behind it.

It is simple rudeness.  It serves no constructive purpose to the people
who read it (unless it is written well and provides entertainment ;-).

It is a human failing.  I know better (an especially difficult lesson
learned over many years) and yet still occasionaly say something that
makes someone else feel bad when I know I shouldn't.  I can come up
with all kinds of excuses why it is in that persons best interest or
it is in my best interest, but it is just a rationalization.  There
is always a better way.  (Not that I always take the better way; hey,
I'm only human too.)

If you like, think Machiavelli (sp?).  Being nice (or at least
seeming to be nice) is better because it is more effective.  The
rudeness serves no constructive purpose.  The clueless will actually
respond better to polite pointers.

Read my sig.  It would seem to be apropo.  :-)

-- 
// Lee.Lindley   /// I used to think that being right was everything.
// @bigfoot.com  ///  Then I matured into the realization that getting
////////////////////   along was more important.  Except on usenet.


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

Date: 30 Oct 1999 04:01:10 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: It is always like this here?
Message-Id: <slrn81kri2.jvv.mgjv@wobbie.heliotrope.home>

On 30 Oct 1999 03:36:39 GMT,
	lt lindley <ltl@rgsun40.viasystems.com> wrote:

> It is a human failing.  I know better (an especially difficult lesson
> learned over many years) and yet still occasionaly say something that
> makes someone else feel bad when I know I shouldn't.  I can come up
> with all kinds of excuses why it is in that persons best interest or
> it is in my best interest, but it is just a rationalization.  There
> is always a better way.  (Not that I always take the better way; hey,
> I'm only human too.)


Which was partly, although not explicitly stated, my point. I,
personally, try to be nice to new posters. However, I don't always
succeed. Most people here probrbaly try to be nice to new posters.
However, they don't always succeed. And for some people the 'not always'
is more often than for others.

Note that I wasn't _defending_ that behaviour, of which I am guilty too,
I'm just explaining it as I see it, and I don't even know why :).
Because next week, someone will post a question to this group, not
having read a single article, and especially not this thread, and they
won't understand why they get grumpy answers. They'll take it
personally, and here we go again.

Anyway, I _wish_ it would stop. But experience shows that it won't.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd.   | no excuse - Lazarus Long
NSW, Australia                  | 


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

Date: 29 Oct 1999 22:08:11 -0400
From: dfoster@panix.com (David Foster)
Subject: Re: Perl and Excel
Message-Id: <7vdjub$2p7$1@panix.com>

In <P2kS3.6282$hK6.316007@monger.newsread.com> scott@aravis.softbase.com (Scott McMahan) writes:

>Asquith (asquith@macconnect.com) wrote:
>> Looking for a 100% Perl module that can take an Excel file and convert it 
>> variously delimited files or open the Excel file, convert it, and pipe it
>> downstream.  I'm developing an application on Solaris and Linux and need to
>> interface transparently to Excel files sitting on the NFS.

>You're not going to find it.

Never say never. 

I haven't tried it, but the laola OLE::Storage package contains a module
that's supposed to do exactly this.

http://wwwwbs.cs.tu-berlin.de/~schwartz/pmh/

-- 
-- 
 David Foster            |  I am a camera with its shutter open
 dfoster@panix.com       |  quite passive, recording not thinking
 finger for PGP key      |              -- Christopher Isherwood


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

Date: Fri, 29 Oct 1999 20:45:18 -0600
From: "Randy Smith" <randys@NOSPAMamigo.net>
Subject: Re: perl double-split
Message-Id: <381a082c@news.amigo.net>

If at first you don't succeed, cheat.

First, $data = <FH> only reads one line.You can read the entire file, line
by line, by doing @data = <FH>; Now each line of the file is an element in
@data.
Now you can do something like @stuff = split (",", $data[0]); to get the
data from a line.

EX:
# you can, of course, do this from STDIN just replace
# FH with STDIN and lose the open and close.
open (FH, "myFile");
my @data = <FH>;
close FH;
foreach my $line (@data)
{
    my @line_stuff = split (",", $line);
    # do stuff with the data here
}

You can get the double array thing by replacing the foreach loop with this
for (my $i; $i < scalar @data; $i++)
{
    @data[$i] = [split (",", @data[$i])];
}

Now you can access things as $data[0][43374].

Have fun,
Randy

Daniel Heiserer <daniel.heiserer@bmw.de> wrote in message
news:3819A159.55C6D670@bmw.de...
> Hi,
>
> assume I read a file into a variable in perl:
>
> undef $/;
> $data=<>;
>
> I know how I can split the $data (according the lines) into field @Tmp
> using
> @Tmp=split('\n',$data);
>
> But assume I read a table, or comma separated file:
>
> #-----------file------------
> me,you,karl,mary,joan
> 23,3455,34543,2343,34
> #-----------file------------
>
> and I want to split it into a file using TWO separators:
> "\n" for the "lines" and "," for the columns and the resultant
> should be a double-indexed field @Tmp2:
>
> @Tmp2=howtosplit_doubles('\n',',',$data);
>
> So $Tmp2[1][1]=3455
>
> How could that be done in a that simple and similar way??????
>
> I know perl can do that easily. ;-)
>
> Any hints?
>
> Thanks daniel
>
>
> mailto:daniel.heiserer@bmw.de




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

Date: Sat, 30 Oct 1999 04:46:24 -0800
From: b chung <bchung@ci.south-el-monte.ca.us>
Subject: perl programs help
Message-Id: <381ADA8F.4CEB582E@ci.south-el-monte.ca.us>

Help -  I am looking for someone that can write a perl script.

The requirements are:  Perl1.pl calls perl2.pl with username and
password.
Perl2.pl returns  the record of data for username and associate field
names by
finding the matching username/password record in the file.
Then in Per1.pl, display the record with the field names on a web page
(i.e. fullname = jack smith, address=1464 w street ave )
note: the special character in the record must stay in the record in the
return trip.
Perl1.pl  has a  'require ossd.cfg'  line.
Perl2.pl  has a  'require  ospd.cfg' line.
ossd.cfg and ospd.cfg  have the same variables in them and obviously
the  content
is different.

If you are interested, please email me ,Betty Chung at bc99@pacbell.com
and give me
some idea of the cost and time needed.


This is my attempt:

#perl1.pl
#!/usr/local/bin/perl

$search_field="username";
$search_for="alan";
$pa = "perl perl2.pl search_for=$search_for |";
$co=0;
open (LIST_OF_FILES, $pa);
while ($filename = <LIST_OF_FILES>){
@out = $filename;
#print "processing ",$filename;
$out[$co] = $filename;
$co = $co+1;
open (MY_FILE_HANDLE, $filename);
while (<MY_FILE_HANDLE>) {
   process information in line of file by using ,$_
}
}

print $out[0];


($fieldn,$fieldc) = split(/\n/, $out[0]);
print "$fieldn\n";
print "$fieldc\n";

print $fieldns[2];
print $fieldnc[2];

print "test\n";
-------------------------------------------------------------------
#perl2.pl
#!/usr/bin/perl

use CGI qw (:standard);
use CGI::Carp qw(fatalsToBrowser);

 $search_field="username";
 $config="ossd.cfg";
unless(require $config){
  $config="database.cfg";
}

$q = new CGI;
  $search_for = $q->param(search_for);

$f = join("~", @fields);

&search_database($search_for);

$ff = $results[0];

 print $ff;

exit;

sub search_database{

  my $search_for = $_[0];
  open(DB, $database) or die "Error opening file: $!\n";
    while(<DB>){
      if($search_field =~ /all/i){
        if(/$search_for/oi){push @results, $_};
      } else {
        ($key,@field_vals) = split(/\|/, $_);
        if($field_vals[$search_field] eq $search_for){push @results,
$_};
      } # End of else.
    } # End of while.
  close (DB);

 } # End of search_database subroutine.





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

Date: 30 Oct 1999 01:46:03 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: Perl script to check OS system
Message-Id: <slrn81kjkl.j4s.mgjv@wobbie.heliotrope.home>

On Fri, 29 Oct 1999 18:01:45 -0700,
	Hai Do <hdo@ea.com> wrote:
> Hello,
> 
> I want to write a Perl script that check the OS without calling the system
> command such as 'uname' on Unix. It will dectect both Unix and Windows and
> return the platform name. Is there any Perl built-in command or module to
> check the OS? Please help.

OS name (which seems to be the only thing you need)
# perl -le 'print $^O'
# perl -MEnglish -le 'print $OSNAME'

You could have a look at how CGI.pm does it as well.

Others as well
# perl -e 'use Config qw(config_vars); config_vars(qw(osname archname osvers))'

# perldoc perlvar
# perldoc Config

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: 30 Oct 1999 02:22:25 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: regex match with empty string
Message-Id: <7vdkp1$ov8$1@rguxd.viasystems.com>

Sam Holden <sholden@pgrad.cs.usyd.edu.au> wrote:
:>On 29 Oct 1999 02:35:22 GMT, lt lindley <ltl@rgsun40.viasystems.com> wrote:
:>>Oh darn.  I'm quoting somebody in here with ":>>" but I lost
:>>the attribution.    Xah is ":>"
:>>
:>>Xah Lee <xah@best.com> wrote:
:>>

Uh, Sam.  I guess it was your lines that I failed to attribute correctly.
But you responded to my answers to Xah as if they were directed at
you.  This is now hopelessly muddled. Probably best to just drop it.
Actually, it was probably best to drop it before we even started, yet
here we are.  :-)

Sorry for the confusion.  

-- 
// Lee.Lindley   /// I used to think that being right was everything.
// @bigfoot.com  ///  Then I matured into the realization that getting
////////////////////   along was more important.  Except on usenet.


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

Date: 30 Oct 1999 03:15:36 GMT
From: morris@rahul.net (Steve Morris)
Subject: Re: Reinventing the wheel
Message-Id: <7vdnso$9mm$1@samba.rahul.net>

In article <1415c574.a0e37bb4@usw-ex0101-006.remarq.com>,
	david.lane@mantech.com <david.laneNOdaSPAM@mantech.com.invalid> writes:
> Greetings,
> 
> I suspect someone out there has already done this and can help me out.
> 
> I am trying to take a directory output (from NetWare's NDIR command) and
> transpose it so that I can shove it into a database.  Once I get it
> 
> What I want to get rid of is the formating crap (Files, size and the
> underline) between the directory name and the files.  I also want to
> tack on the directory name to the files listing so that in general I
> have:
> 
> file, size, date, user, directory
> 
> I can get as far as the regex to pull out the directory name and put
> that in a variable for appending, but I cannot skip or get rid of the
> next two lines.  With 500 pages of this stuff to sort through, I really
> want to do this in an automated fashion.
> 
> Any thoughts?
> 
> Thanks,
> 
> DAVID
> 

What you need to do is test if a regex matches for the directory lines
and only use the data if it does. Assuming I unwrapped your line wraps
properly and line wraps don't do me in, this appears to work.


#!/usr/bin/perl -w
#file, size, date, user, directory
my $dirname="NO DIRECTORY";

while(<DATA>){
	$dirname=$1 if m#^([\w\\/:]+)\*\.\*$#;
	if( my @a= m#^([\w.]+)\s+o?\s+([,\d]+)\s+([\d/]+)\s+([\d:ap]+)\s*([\w.]+)#){
		push @a,$dirname;
		print join( " ",@a),"\n";
	}
}




__DATA__
CORP_02/SHARES:SPC\PROJECTS\MARKETI0\NUTRIVIL\*.*
Files                      Size Last Update     Owner
----------------- ------------- --------------- -------------------------
MANUAL6.DOC     o       477,696  4/03/98 12:04p MScott.Alexandria.ISDN...
NUORDERF.DOC    o        12,288  3/17/98 10:53a MScott.Alexandria.ISDN...
MANUAL.DOC      o       484,864  4/03/98 12:05p MScott.Alexandria.ISDN...
NUTACTIV.DOC            527,360  2/26/98  8:49a MScott.Alexandria.ISDN...

 

Hope it helps.

Steve


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

Date: Fri, 29 Oct 1999 20:29:38 -0600
From: "Randy Smith" <randys@NOSPAMamigo.net>
Subject: Re: shtml / perl problem
Message-Id: <381a0484@news.amigo.net>

Your error log should have a reason for the failure. It sounds like the Perl
is OK but your SSI is baked. Take a look at your error log and see where
that goes.

Randy

<newsmf@bigfoot.com> wrote in message news:7vahcg$i15$1@nnrp1.deja.com...
> Hi -
>
> I've shtml-enabled a directory called "/exampledir"
>
> test.shtml in that directory calls the script test.pl using
> <!--#include virtual = "/cgi-bin/test.pl" -->
>
> However, I get
> [an error occurred while processing this directive]
>
> If I run test.pl directly via www.mydomain.com/cgi-bin/test.pl it
> executes all right (i.e. doing the redirect it's supposed to do).
>
> How do I get test.pl to work when it is invoked through the shtml page
> at www.mydomain.com/emampledir/test.shtml ?
>
> Thanks a lot for helping.
>
> Cheers,
>
> Marc.
>
> Here's test.pl:
>
> #!/usr/bin/perl -w
> # test.pl
>
> $url = "http://www.perl.com/CPAN/";
>         print "Location: $url\n\n";
>         exit;
>
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

Date: Fri, 29 Oct 1999 21:13:01 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: simplifying a script
Message-Id: <Pine.GSO.4.10.9910292105570.2694-100000@crusoe.crusoe.net>

On Oct 29, Abigail blah blah blah:

>        my @table_data = map {"bobbhtml/TableData${_}.txt"} 1 .. 11;

This might be a bit nit-picky, but I bring up two points:

  1.  useless { and } around _ in $_
  2.  map in block format is slower than map in list format (here)

Explained with the following benchmark:

  use Benchmark qw( timethese );
  timethese(100_000, {
    'block' => q{
      my @table_data = map {"bobbhtml/TableData${_}.txt"} 1 .. 11;
    },
    'block2' => q{
      my @table_data = map {"bobbhtml/TableData$_.txt"} 1 .. 11;
    },
    'list' => q{
      my @table_data = map "bobbhtml/TableData${_}.txt", 1 .. 11;
    },
    'list2' => q{
      my @table_data = map "bobbhtml/TableData$_.txt", 1 .. 11;
    },
  });


  Benchmark: timing 100000 iterations of block, block2, list, list2...
       block: 38 wallclock secs (39.31 usr +  0.00 sys = 39.31 CPU)
      block2: 37 wallclock secs (38.07 usr +  0.00 sys = 38.07 CPU)
        list: 38 wallclock secs (38.52 usr +  0.00 sys = 38.52 CPU)
       list2: 41 wallclock secs (37.97 usr +  0.00 sys = 37.97 CPU)


Again, this might be nitpicking it *just a little*.  But then again, I'm
an adolescent bastard.

-- 

  MIDN 4/C PINYAN, USNR, NROTCURPI
  jeff pinyan      japhy@pobox.com
  perl stuff       japhy+perl@pobox.com
  CPAN ID: PINYAN  http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/



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

Date: Sat, 30 Oct 1999 04:01:04 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: slow txt processing problem
Message-Id: <44uS3.8729$23.493805@typ11.nn.bcandid.com>

In article <7vcope$qsa$1@pegasus.csx.cam.ac.uk>,
M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
>Kragen Sitaker <kragen@dnaco.net> wrote:
>>
>>If you really mean =~ instead of eq in the above if, you may be out of
>>luck.
>>
>>Depending on parts of your code either you or I deleted, using eq or a
>>hash might also avoid all the XXA crap.
>
>And even if =~ is *really* what you want (I also have doubts), you can
>still avoid the antics by suitably quoting your regex, for example
>using \Q or quotemeta.

\Q or quotemeta won't make \ in carparts.txt match XXA in the input
data.  Did he put the XXA stuff in the input data with a bunch of
s///'s too?  I deleted that part of the code before writing the above,
and my newsreader won't let me look while I'm writing an article.

Presumably XXA in the input data is \ somewhere down the line, but
possibly it's before he gets hold of it.

-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Thu Oct 28 1999
12 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 1227
**************************************


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