[11965] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5565 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 4 23:07:18 1999

Date: Tue, 4 May 99 20:00:19 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 4 May 1999     Volume: 8 Number: 5565

Today's topics:
    Re: "learning perl" does not seem to be written well (Damian Conway)
    Re: Always running <walton@frontiernet.net>
    Re: array shuffling (Larry Rosler)
    Re: array shuffling (Larry Rosler)
    Re: How do I hide my source code (was Re: Making execut (Larry Rosler)
    Re: How do I hide my source code (was Re: Making execut <All@n.due.net>
    Re: how do I slurp a file into a string (Larry Rosler)
    Re: I'm new - Please help - Sorting Question <walton@frontiernet.net>
    Re: I'm new - Please help - Sorting Question <walton@frontiernet.net>
    Re: I'm new - Please help - Sorting Question (Bob Trieger)
    Re: I'm new - Please help - Sorting Question (Brian Peisley)
    Re: Limit to number of if statements??? (Larry Rosler)
    Re: Limit to number of if statements??? <design@raincloud-studios.com>
    Re: Limit to number of if statements??? <design@raincloud-studios.com>
    Re: Limit to number of if statements??? (Tad McClellan)
        Newbie having problems getting this script to work... <hawkwynd@adelphia.net>
    Re: Pattern Matching and parsing <ebohlman@netcom.com>
    Re: Pattern Matching and parsing (Tad McClellan)
    Re: Perl 5: The Complete Reference, Martin Brown <ebohlman@netcom.com>
    Re: Perl 5: The Complete Reference, Martin Brown (Tad McClellan)
    Re: perl file "busy"?  how can that be? <walton@frontiernet.net>
    Re: perl file "busy"?  how can that be? <ebohlman@netcom.com>
    Re: Perl with Apache <lyubovi@usa.net>
        piggy-backing ID & psswrd for user <mrichar2@tree.egr.uh.edu>
    Re: Please help me (nobody ever does :( (Tad McClellan)
    Re: sub for re-encoding a url (Sam Holden)
    Re: sub for re-encoding a url (Larry Rosler)
        syswrite() lies elderr@us.ibm.com
    Re: syswrite() lies (Larry Rosler)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 5 May 1999 00:47:39 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: "learning perl" does not seem to be written well
Message-Id: <7go4fb$hvp$1@towncrier.cc.monash.edu.au>

Uri Guttman <uri@sysarch.com> writes:

>my complaint was more about the later part of the relationship with
>manning. they asked for potential reviewer and i said i might help. they
>never followed up on that and it annoyed me. i have heard from others
>about similar behavior from them. so it may not be unsavory (i am
>allowed some perl poetic license) but not professional nor courteous.

Understood, but that's still no indicator of the likely quality of their
publications. Stallman leaps to mind, yet again.

>  DC> Perhaps Uri is aware of other behaviour that was somehow inappropriate,
>  DC> but, checking through dejanews, it's not evident to me.

>the way they did it irritated many others. i will have to go back and
>look at dejanews myself. i don't recall those threads being fun for the
>perl community.

My reading of the entire thread suggested that one or two people were
irritated at the fact that the message was a personalized form-letter,
but not marked as such. The rest were just bemused. And even the
irritated few conceded that the message was not itself obnoxious or
inappropriate.

To this outside reader at least, it seems like a minor breach of
netiquette which was publicly apologized for as soon as the original
poster's far more net-clueful boss explained the problem to him.

Damian


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

Date: Tue, 04 May 1999 22:41:31 -0400
From: Bob Walton <walton@frontiernet.net>
To: Khan <dnkhan@my-dejanews.com>
Subject: Re: Always running
Message-Id: <372FAFDB.EED617B9@frontiernet.net>

Khan, you would probably be better off making your perl script so it runs and
terminates, and schedule the script using cron (see man cron).  That way, the OS
sees to it that the script always gets started, regardless of whether it bombs.
Hopefully, once per minute is fast enough for you.  If not, make your script so
it repeats for a minute and then terminates, and schedule it through cron.  Then
if it dies, you won't be out of business for more than a minute.

Khan wrote:

> Hi,
>    I have a perl script on a unix (solaris) box that is always checking if a
> certain file exists in a directory or not. Besides this , there are other
> things it does which might cause the script to terminate.
>
> How do i ensure in Perl that when this process dies for whatever reason, it
> always gets restarted ? ( somehow emulate the parent child forking concept )
>
> thanks in advance for your help.
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own



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

Date: Tue, 4 May 1999 18:42:44 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: array shuffling
Message-Id: <MPG.119941eecc8513fa9899c1@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7gnsra$357$1@nnrp1.dejanews.com> on Tue, 04 May 1999 
22:37:30 GMT, tvn007@my-dejanews.com <tvn007@my-dejanews.com> says...
> Would some one help me with this problem ? I would really appreciate.

Are we getting near final exams?

 ...
> 1) first set of input is the header as follow:
>   i1  i2  i3  i4  i5  i6  i7  i8  i9  i10
> 
> 2) second set of input is binary number as follow:
>   0   1    1   1   0
> 
> The output should be as follow:
> 
> the first 0 should be assign to i2
> the fisrt 1 should be assign to i5
> the second 1 should be asign to i4
> the third  1 should be asign to i9
> and the second 0 should be asign to i10
> 
> I have to asign i1, i3,i6,i7,i8 to "X"
> 
> The final output should be like this:
> 
> i1  i2  i3  i4  i5  i6  i7  i8  i9  i10
> 
> X   0   X   1   1   X   X   X   1    0

I have no idea what a real problem would look like, or what the binary 
number is, or anything.  This may give you some ideas (and teach you 
about array slices; I hope you have learned them in class already, or 
your teacher will be upset :-):

#!/usr/local/bin/perl -w
use strict;

local $" = '   ';

my @a = qw( X 0 X 1 1 X X X 1 0 );
print map("i$_  " => 1 .. @a), "\n\n@a\n\n";

my @b;
{
  local $[ = 1; # Perl gods, forgive me!
  @b[qw(2 10 4 5 9 1 3 6 7 8)] = ((0) x 2, (1) x 3, ('X') x 5);
}
print map("i$_  " => 1 .. @b), "\n\n@b\n\n";
__END__

The output is:

i1  i2  i3  i4  i5  i6  i7  i8  i9  i10

X   0   X   1   1   X   X   X   1   0

i1  i2  i3  i4  i5  i6  i7  i8  i9  i10

X   0   X   1   1   X   X   X   1   0

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 4 May 1999 18:48:26 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: array shuffling
Message-Id: <MPG.11994344a88a6cda9899c2@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7gnsra$357$1@nnrp1.dejanews.com> on Tue, 04 May 1999 
22:37:30 GMT, tvn007@my-dejanews.com <tvn007@my-dejanews.com> says...
+ Would some one help me with this problem ? I would really appreciate.

Are we getting near final exams?

 ...
+ 1) first set of input is the header as follow:
+   i1  i2  i3  i4  i5  i6  i7  i8  i9  i10
+ 
+ 2) second set of input is binary number as follow:
+   0   1    1   1   0
+ 
+ The output should be as follow:
+ 
+ the first 0 should be assign to i2
+ the fisrt 1 should be assign to i5
+ the second 1 should be asign to i4
+ the third  1 should be asign to i9
+ and the second 0 should be asign to i10
+ 
+ I have to asign i1, i3,i6,i7,i8 to "X"
+ 
+ The final output should be like this:
+ 
+ i1  i2  i3  i4  i5  i6  i7  i8  i9  i10
+ 
+ X   0   X   1   1   X   X   X   1    0

I have no idea what a real problem would look like, or what the binary 
number is, or anything.  This may give you some ideas (and teach you 
about array slices; I hope you have learned them in class already, or 
your teacher will be upset :-):

#!/usr/local/bin/perl -w
use strict;

local $" = '   ';

my @a = qw( X 0 X 1 1 X X X 1 0 );
print map("i$_  " => 1 .. @a), "\n\n@a\n\n";

my @b;
{
  local $[ = 1; # Perl gods, forgive me!
  @b[qw(2 10 4 5 9 1 3 6 7 8)] = ((0) x 2, (1) x 3, ('X') x 5);
}
print map("i$_  " => 1 .. @b), "\n\n@b\n\n";
__END__

The output is:

i1  i2  i3  i4  i5  i6  i7  i8  i9  i10

X   0   X   1   1   X   X   X   1   0

i1  i2  i3  i4  i5  i6  i7  i8  i9  i10

X   0   X   1   1   X   X   X   1   0

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 4 May 1999 17:44:07 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How do I hide my source code (was Re: Making executables from .pl files?)
Message-Id: <MPG.1199342d4e78f11e9899bf@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <r6KX2.2376$612.1296@news.rdc1.ct.home.com> on Tue, 04 May 
1999 22:00:55 GMT, Allan M. Due <All@n.due.net> says...
 ...
> What is it that Larry said?  Oh yea, be consistent.

The Larry said that?!?  Then why didn't he apply it to Perl?  :-)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 05 May 1999 01:11:18 GMT
From: "Allan M. Due" <All@n.due.net>
Subject: Re: How do I hide my source code (was Re: Making executables from .pl files?)
Message-Id: <WUMX2.2454$612.1282@news.rdc1.ct.home.com>

Larry Rosler <lr@hpl.hp.com> wrote in message
news:MPG.1199342d4e78f11e9899bf@nntp.hpl.hp.com...
: [Posted and a courtesy copy mailed.]
:: In article <r6KX2.2376$612.1296@news.rdc1.ct.home.com> on Tue, 04 May
: 1999 22:00:55 GMT, Allan M. Due <All@n.due.net> says...
: ...
: > What is it that Larry said?  Oh yea, be consistent.
:
: The Larry said that?!?  Then why didn't he apply it to Perl?  :-)

Below are the last three points from perlstyle, for whatever reason the last
two have always stuck in my mind.  Perhaps you have to be "the Larry" to see
the constancy in perl <g>.

-Think about reusability. Why waste brainpower on a one-shot when you might
want to do something like it again? Consider generalizing your code.
Consider writing a module or object class. Consider making your code run
cleanly with use strict and -w in effect. Consider giving away your code.
Consider changing your whole world view. Consider... oh, never mind.

-Be consistent.

-Be nice.

AmD

cc'd because it is a Larry thing ;-)




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

Date: Tue, 4 May 1999 18:00:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: how do I slurp a file into a string
Message-Id: <MPG.1199380249b086969899c0@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <x7aevk1krv.fsf@home.sysarch.com> on 04 May 1999 19:24:04 -
0400, Uri Guttman <uri@sysarch.com> says...
 ...
> 	$contents = do{ local( @ARGV, $/ ) = 'joblist.asp' ; <> } ;
> 
> yechhhh! i loaded an asp file!!!
> 
> BTW don't incant that magic code (from abigail) unless you understand
> each and every part of it.

It is charmed and charming.

One (big, to me) problem:  How does one intercept death on failure to 
open the file?  I can't capture it with $SIG{__WARN__} or $SIG{__DIE__}; 
if I use END the message is printed first, and END has a different 
report for $!.

#!/usr/local/bin/perl -w
use strict;

$SIG{__WARN__} = $SIG{__DIE__} = sub { print "in SIG $!\n" };

my $contents = do{ local( @ARGV, $/ ) = 'joblist.asp' ; <> } ;

END { print "in END $!\n" }

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 04 May 1999 21:23:38 -0400
From: Bob Walton <walton@frontiernet.net>
To: news@i-tradeonline.com
Subject: Re: I'm new - Please help - Sorting Question
Message-Id: <372F9D99.CF843786@frontiernet.net>

One possibility would be:

@database=sort byclick <>;
print @database;
sub byclick{
    $a=~/\|([^|]*)$/;
    $aclick=$1;
    $b=~/\|([^|]*)$/;
    $bclick=$1;
    $aclick <=> $bclick;
}

Depending on what you mean by "best", that might qualify.

Chance Houston wrote:

> I'm building a www directory site.  I have all the cgi's in place except for one.
>
> I've written a simple search engine but I want the results to be sorted by the number of clicks a site has recieved.
>
> My database is a text file that looks like this . . .
>
> major_category|sub_category|site_url|site_title|description|feature|graphic|keywords|clickCount
>
> What is the best way to sort my search results by the last item (clickCount)?
>
> A simple answer is all that I'm looking for.
>
> Thanks
>
> Chance Houston



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

Date: Tue, 04 May 1999 21:27:49 -0400
From: Bob Walton <walton@frontiernet.net>
To: news@i-tradeonline.com
Subject: Re: I'm new - Please help - Sorting Question
Message-Id: <372F9E95.FD9701F4@frontiernet.net>

One possibility would be:

@database=sort byclick <>;
print @database;
sub byclick{
    $a=~/\|([^|]*)$/;
    $aclick=$1;
    $b=~/\|([^|]*)$/;
    $bclick=$1;
    $aclick <=> $bclick;
}

Depending on what you mean by "best", that might qualify.

Chance Houston wrote:

> I'm building a www directory site.  I have all the cgi's in place except for one.
>
> I've written a simple search engine but I want the results to be sorted by the number of clicks a site has recieved.
>
> My database is a text file that looks like this . . .
>
> major_category|sub_category|site_url|site_title|description|feature|graphic|keywords|clickCount
>
> What is the best way to sort my search results by the last item (clickCount)?
>
> A simple answer is all that I'm looking for.
>
> Thanks
>
> Chance Houston



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

Date: Wed, 05 May 1999 01:48:51 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: I'm new - Please help - Sorting Question
Message-Id: <7go7a5$1tk$1@birch.prod.itd.earthlink.net>

[ courtesy cc sent by mail if address not munged ]
     
news@i-tradeonline.com wrote:
>I'm building a www directory site.  I have all the cgi's in place except for
> one.
>
>I've written a simple search engine but I want the results to be sorted by the
> number of clicks a site has recieved.
>
>My database is a text file that looks like this . . .
>
>major_category|sub_category|site_url|site_title|description|feature|graphic|key
>words|clickCount
>
>What is the best way to sort my search results by the last item (clickCount)?
>
>A simple answer is all that I'm looking for.
>
>Thanks
>
>Chance Houston
>

PerlFAQ4
        How do I sort an array by (anything?)


HTH,
Bob Trieger
sowmaster@juicepigs.com

PS. There goes my top 10 in "OCR" for this week.



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

Date: Wed, 05 May 1999 02:22:13 GMT
From: brian@helka.mutagenic.org (Brian Peisley)
Subject: Re: I'm new - Please help - Sorting Question
Message-Id: <slrn7ivau3.ef.brian@helka.mutagenic.org>

In comp.lang.perl.misc Chance Houston <news@i-tradeonline.com> writes:

>What is the best way to sort my search results by the last item (clickCount)?
>
>A simple answer is all that I'm looking for.

simple answer:

perldoc -q "how do I sort"

-- 
Brian Peisley
bdp@mutagenic.org


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

Date: Tue, 4 May 1999 17:41:15 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Limit to number of if statements???
Message-Id: <MPG.11993387fd1f5d839899be@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7go0jp$r41$1@fcnews.fc.hp.com> on 4 May 1999 23:41:45 GMT, 
Andrew Allen <ada@fc.hp.com> says...
> Larry Rosler (lr@hpl.hp.com) wrote:
 ...
> :   	&{defined $town_to_builder{$FORM{Key4}} ?
> :              $town_to_builder{$FORM{Key4}} : \&unreferred}};

And wrote better, in a self-followup:

> :   	&{$town_to_builder{$FORM{Key4}} || \&unreferred}};


> Bah! What's wrong with '$town_to_builder{""}=\&unreferred'? Fear of
> undefs is a regurgitory response to too much kid-gloving by the
> nandy-pandy -w! ;)

You are assuming that $FORM{key4} is undefined, which your code would 
catch (less the warning, as you say).  But what if $Form{key4} is 
defined, but $town_to_builder{$Form{key4}} is not defined?  I'd hate to 
blow the program by invoking the null string as a subroutine.

Of course, one can really go paranoid, and add stuff like

    ref($town_to_builder{$Form{key4}}) eq 'CODE' ...

but we're already on our way to madness without that.  We populated the 
hash with coderefs, so let's live without belt-and-suspenders checking.

PS to Uri Guttman:  Andrew is yet another HP Perl hacker from Fort 
Collins, CO (the same location as Jack Applin, whom you pointed at me, 
but with whom I have corresponded already several times).  I wonder if 
Perl hackers run in packs (or Monger groups).  What is the collective 
noun for such -- a mongeries?  (Philologians like TomC will think of 
collections of eels, for example.)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 05 May 1999 02:08:21 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: Limit to number of if statements???
Message-Id: <pKNX2.1510$iu1.1249@news.rdc1.tn.home.com>

>what is the difference between sub{} and \&foo?


One was used by a dufus named CT? WhattIwin? :)

>  CRT> You are using one pre-named form element and evaluating it's
value to
>  CRT> call the matching sub from the hash element. Can it be modified
to work
>  CRT> off the name of the param itself so that virtually any named
button
>  CRT> could be evaluated? I've tried a couple of things but so far
it's eluded
>  CRT> me.
>very easy. just don't check for each possible param. since you didn't
>post any of the form code (please don't!)

Wouldn't think of it. I was certain I was just in the right amount with
the previous post and thought it could only add another dimension to the
discussion on using a hash over if statements.

> i can't code it exactly but
>you make all the buttons have the same name but a unique value. then
you
>just get that value from param('button_name') and dispatch based on
>that.


Ahh... but therein lies the problem. I know it wasn't apparant but those
buttons are *image buttons* which can be used to submit a form. I now
see that I should have pointed that out. My apoligies. (However... that
reply did help me optimize a different script that used standard
buttons... so it was productive)

I get many requests to use image buttons for aesthetic reasons (damn
web) and have come to really favor the hash solution over if statements
in my scripts, so it's somewhat of an ongoing problem to solve. I see it
every day, and know it's slightly inefficient, but have yet to figure
out a way around it.

Image buttons work like maps and return a non-zero value when clicked. I
flip through the $query->param items and test the non-zero button (if
there is one) in the Actions Hash... if so, it goes to the correct sub.

foreach $button($query->param){
  if (defined $actions{$button}){
    &{$actions{$button}};
    return;
  }
}

The problem of one statement is compounded further when a user could
click any one of three 'image buttons' on the same form. (an example of
this might be if someone needed to delete, modify, or clone a record in
a database after selecting the item from a list) The 'value' is for all
practical purposes a random number.

See the problem?

One thought I had for optimization might be a 'prefix' to button names
that wouldn't go through all the items in $query->param, but my second
thought is that it's just one more evaluation to slow things down and I
was better off where I was.

So I guess the Perl-based question is...

When using CGI.pm, how can I determine which image button is clicked by
*name* if the return values are not indicative of the source but the
names are?

Is the loop my only choice?

I'm still an experimenter here, but I've poked at it for a few months
with no progress and this thread just brought it back up in my mind.

Thanks for the reply.. it really did help!

CT




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

Date: Wed, 05 May 1999 02:28:14 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: Limit to number of if statements???
Message-Id: <21OX2.1515$iu1.1477@news.rdc1.tn.home.com>

>The problem of one statement is compounded further when a user could
>click any one of three 'image buttons' on the same form.

>One thought I had for optimization might be a 'prefix' to button names
>that wouldn't go through all the items in $query->param, but my second
>thought is that it's just one more evaluation to slow things down and I
>was better off where I was.


Hmm... but if I *did* prefix the buttons with something like btn_ and
since only one button is returned at a time why am I using the loop in
the first place?

(okay yeah.. dweebs can type in others buttons as a url.. forget that
for know)

CT

Friggin Perl. I'm supposed to be getting proposals for new clients
together and here it has presented me with another challenge that I'm
more interested in solving. :)





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

Date: Tue, 4 May 1999 16:51:40 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Limit to number of if statements???
Message-Id: <skmng7.ic4.ln@magna.metronet.com>

MHCA (info@modularcenter.com) wrote:

: Is there a limit to the length of an if, elsif, else block, or a limit to
: the number of elsif statements?


   No.

   [ well really the answer is yes. It is limited by how much
     memory you have on your computer, not by Perl.
   ]


: The following code worked until I added this one more elsif statement:

: elsif ($FORM{'Key4'} eq "Bronx") {
: # Homeworks Modular Homes - builder_32
: &builder_32;
: }


   Posting programs that are several hundred lines long to
   Usenet is an effective way of getting killfiled.

   It would be in your best interests to refrain from such
   things in the future...



   Your code is crying out to be redone as a dispatch table.

   (surely when you found yourself typing nearly the same
    thing a bazillion times you must have muttered
    "there's got to be a better way to do this" ?
   )

   You might want to refer to perlref.pod if you don't
   understand what's going on below.


---------------------------------
#!/usr/bin/perl -w
use strict;

my %dispatch = (                        # set up the dispatch table
   Albany     =>  \&builder_05,
   Allegany   =>  \&builder_46
);

my %FORM;
$FORM{'Key4'} = 'Albany';


if (exists $dispatch{$FORM{'Key4'}}) {
   &{ $dispatch{$FORM{'Key4'}} };       # call the appropriate routine
}
else {
   &unreferred;
}


sub builder_05 {print "builder_05\n"}
sub builder_46 {print "builder_46\n"}
sub unreferred {print "unreferred\n"}
---------------------------------


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 05 May 1999 01:49:27 GMT
From: "Hawkwynd" <hawkwynd@adelphia.net>
Subject: Newbie having problems getting this script to work...
Message-Id: <HsNX2.381$5g5.3383@server1.news.adelphia.net>

Here's the script, I'm just too new to know what to do next... I know
there's areas of this script that are wrong, and I could use a little help
in this matter:

#! perl

$file_dir = "C:\wp";       # Directory contains random # of text files.

opendir($file_dir, ".") || die("Error: unable to open directory"); # Open
the directory
@myarray = ((join("\n", readdir($file_dir)). "\n"));   # Get all files,
place in @myarray
print (join("\n", readdir($file_dir)). "\n");    # list the files on the
screen
closedir($file_dir);      # Close the dir

foreach (@myarray) {     # One file at a time

open(TEXTF, $myarray) || die("Error: unable to open file $myarray.");  #
Open the file for reading
@buff = <TEXTF>;      # assign to the buffer
close(TEXTF);      # Close file

$myarray = ~s/33_/ /g;     # Remove the 33_ prefix from filename
$myarray = ~s/.txt/ /g;     # Remove the .txt extension from filename

# $buff  = ~s/[\014\015]/ /g;      # Remove hex 14 and 15 from the file

open (WRITEIT, ">$myarray");    # Open a new file, with the new filename
print WRITEIT "$buf";     # Write the file
close (WRITEIT);      # Close the file

print "$myarray completed\n";    # Confirm file is done.
}

print "Done. \n";      # Exit program
exit;












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

Date: Wed, 5 May 1999 02:15:29 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Pattern Matching and parsing
Message-Id: <ebohlmanFB8M9t.2w3@netcom.com>

Greg Waugh <bigbird@pol.com> wrote:
: Hi there!  I was hoping I could get a bit of help with some Perl code to fix
: this little problem.  I have a text file that needs to be split by keywords.
: For example:

: Bob: data data, data data, data data,
: data, data data, data
: Steve: moredata, moredata
: John: differentdata, differetdata, differentdata,
: differentdata, differentdata

[snip]

: Ideally, I'd like it to split by the list of all names ( @names = ("Bob",
: "Steve", "Mark", "John") ) that might or might not appear in the file.  The
: order will most likely remain constant.  So that the final data structure
: would contain (I use an array as an illustration):

: $output[0] eq "Bob: data data, data data, data data, data, data data, data"
: $output[1] eq "Steve: moredata, moredata"
: $output[2] eq "John: differentdata, differetdata, differentdata,
: differentdata, differentdata"

This sort of problem really cries out for a hash:

while (<>) {
  chomp;
  $whose=$1 if s/^(\w+):\s*//;
  $data{$whose}.=$_;
}

This will create a hash whose keys are the names and whose values are the 
lists of data, e.g. $data{Steve} will be "moredata, moredata".  It will 
work regardless of the order of the names, and it will still work even if 
there are multiple non-adjacent entries for the same person.

In production, of course, you'd want to do a little more error checking, 
like dealing with the case of the first data line not having a name on it 
(which will bomb the example code).




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

Date: Tue, 4 May 1999 17:24:29 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Pattern Matching and parsing
Message-Id: <diong7.ic4.ln@magna.metronet.com>

Greg Waugh (bigbird@pol.com) wrote:

: The file will explicitly wrap and is then terminated with a unix \n.  So
: line 2 (data, data..etc) is the beginning of a new line even though it
: referrs to Bob: and should be part of his data.

: Ideally, I'd like it to split by the list of all names ( @names = ("Bob",
: "Steve", "Mark", "John") ) that might or might not appear in the file.  The
: order will most likely remain constant.  So that the final data structure
: would contain (I use an array as an illustration):

: $output[0] eq "Bob: data data, data data, data data, data, data data, data"
: $output[1] eq "Steve: moredata, moredata"
: $output[2] eq "John: differentdata, differetdata, differentdata,
: differentdata, differentdata"


------------------
#!/usr/bin/perl -w
use strict;

{ local $/;
  $_ = <DATA>;  # slurp
}

s/\n([^,:]+,)/$1/g;   # join (some) lines

my @output = split /\n/;

foreach (@output) {
   print "'$_'\n";
}


__DATA__
Bob: data data, data data, data data,
data, data data, data
Steve: moredata, moredata
John: differentdata, differetdata, differentdata,
differentdata, differentdata
------------------


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 5 May 1999 02:01:06 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Perl 5: The Complete Reference, Martin Brown
Message-Id: <ebohlmanFB8LLv.1MB@netcom.com>

Uri Guttman <uri@ibnets.com> wrote:
: <STUPID BOOK>

: To print a hexadecimal or octal number use the printf or use sprintf to
: print a formatted base number to a string:

: printf ("%lo %lx", oct("0755"), oct("0x7f"));
: </STUPID BOOK>

The grammar of this (and of a couple other examples) suggests to me that 
much of the book was written in a language other than English and rather 
poorly translated.



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

Date: Tue, 4 May 1999 17:15:18 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl 5: The Complete Reference, Martin Brown
Message-Id: <61ong7.ic4.ln@magna.metronet.com>

Uri Guttman (uri@ibnets.com) wrote:
: >>>>> "TC" == Tom Christiansen <tchrist@mox.perl.com> writes:

:   TC>  [courtesy cc of this posting sent to cited author via email] In
:   TC> comp.lang.perl.misc, Uri Guttman <uri@ibnets.com> writes: :"Perl:
:   TC> The ImComplete Reference" :guaranteed to teach bad perl or you pay
:   TC> us more money!

:   TC> Thank you for your service.  The publisher should hear this,
:   TC> though.


: another
: great piece of editing by osborne/mcgraw-hill. 


   I looked at half of Chapter 5, and realized I needn't look
   anymore.

      "it's" (possessive) _all over_ the place.

      <quote> expecting to assign the return value two. </quote>
                                                   ^^^
                                                   ^^^ tee hee 
   It isn't even English!
   
   I thought you weren't supposed to use a preposition to
   end a sentence with.

   ??


   <quote> assign a scalar to the reference </quote>

   twilight zone...



   This one head me ROTFL:


<quote>
Anonymous Subroutines

An anonymous subroutine is one that has been defined without a name,
and then assigned to a variable. In it's (sic) simplest form it looks 
like this:

$hw = { print "Hello World\n";};

$hw;

</quote>


   semicolons at end of the block (well it's (not sic) _supposed_ 
                                   to be a block ... 
                                   ... I think)

   no 'sub' keyword

   makes -w noises

   makes 'use strict' noises

   doesn't work (or even compile!)


   Quite a piece of work there...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 04 May 1999 22:30:28 -0400
From: Bob Walton <walton@frontiernet.net>
To: Timothy Larson <larsot2@krypton.mankato.msus.edu>
Subject: Re: perl file "busy"?  how can that be?
Message-Id: <372FAD44.EE129D4C@frontiernet.net>

Timothy, specific information would be in order if you expect a helpful
reply:  what platform, what OS, what version of the OS, what version of
perl, what packages your are using in perl, what are their versions, what is
your web server, what version is the server, how are you calling your perl
script (standard CGI, mod_perl, ...), etc.  The more specific, the better.
One suggestion:  try a minimal perl script, like writing "hi there", and see
if the problem happens to it too.  If not, add pieces of your problem script
until the problem reappears in an effort to narrow it down.

Timothy Larson wrote:

> Greetings!
> I've been all over the web now, trying to find out how a file can be
> busy.  I've seen lots of stuff about multiple processes trying to access
> a file concurrently and how you can work around that, but that's not my
> problem.  My problem is that my Perl script itself is busy when the web
> server hits it.  It's not being hit so often that one process is still
> reading it when another tries, and I don't have it open in any editors,
> so I don't understand what the problem is.  Sometimes I can rename the
> script to something else, and get a few runs out of it, then the error
> might occur again.  Am I the only person this happens to?  It seems to
> be the case.
> Tim



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

Date: Wed, 5 May 1999 02:30:54 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: perl file "busy"?  how can that be?
Message-Id: <ebohlmanFB8MzI.4BJ@netcom.com>

Timothy Larson <larsot2@krypton.mankato.msus.edu> wrote:
: I've been all over the web now, trying to find out how a file can be
: busy.  I've seen lots of stuff about multiple processes trying to access
: a file concurrently and how you can work around that, but that's not my
: problem.  My problem is that my Perl script itself is busy when the web
: server hits it.  It's not being hit so often that one process is still

This can't be true.  The way CGI works is that the server forks off a new 
process on each hit.  Thus even if someone had already invoked your 
script and it was still running, the server would have created an 
entirely new process to run the second invocation.  As far as your script 
is concerned, it doesn't even know that another copy of itself is running 
(which is why if it writes to files or otherwise uses shared resources, 
it needs to make sure it doesn't step on anybody's toes.

: reading it when another tries, and I don't have it open in any editors, 
: so I don't understand what the problem is.  Sometimes I can rename the
: script to something else, and get a few runs out of it, then the error
: might occur again.  Am I the only person this happens to?  It seems to 
: be the case.

Without any more information, this sounds like a server problem rather 
than a Perl problem; you might try reading the FAQs for 
comp.infosystems.www.authoring.cgi and then asking there if you haven't 
already found an answer to your question.



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

Date: Tue, 4 May 1999 21:59:20 -0400
From: "Lyubov Ignatovsky" <lyubovi@usa.net>
Subject: Re: Perl with Apache
Message-Id: <7go8c0$j3h@sjx-ixn10.ix.netcom.com>

Check the first line of your script.  It should contain path
to your Perl executable:
#!c:/perl/bin/perl.exe

Lyubov

Alan Kelly wrote in message
<925807484.22535.0.nnrp-09.9e98357b@news.demon.co.uk>...
>Hi
>
>I have installed Apache for Win32 and enabled SSI as per the instructions
on
>apache.org. However, when I use the #exec command to execute a perl script
I
>get an entry in the error log saying:
>
>    "couldn't spawn child process: <script name>"
>
>Can anyone tell me how to configure Perl with Apache?
>
>
>Many thanks in advance
>
>Al.
>
>PS. Please respond via email (nothing to remove).
>
>




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

Date: 5 May 1999 01:57:58 GMT
From: "Mike" <mrichar2@tree.egr.uh.edu>
Subject: piggy-backing ID & psswrd for user
Message-Id: <01be96ac$322cf120$8f410781@mike.uh.edu>

Hi,   Is there a way using any script language to allow a user from a
specified domain like company.com to get into a restricted website called
pogo.com by somehow bypassing the page that prompts for a username and
password? (.com names are made up of course) 

what I mean is this: the place I work for just bought rights to allow
everyone on our network access to a specific website. Presently, the only
method of access we have to pogo.com is by placing a single link to pogo,
and on that linking page, which is on our intranet, we display the Username
and Password for our employees to type in themselves once they click on the
link. 

So what I would like, is if all our users from company.com could just visit
a page on our website, then attach the username and password to them using
script, then having the script unload the ID & password for the user on the
following pogo.com page, thereby not having to write out the password on
out intranet, nor making the user write down and then type in the password
& ID as they go from our intranet to pogo.com

background info: The pogo.com page is an http:// website (not https://)
and the pogo.com page that prompts for user ID and password uses some kind
of <form> and NOT a gray pop up box like most restricted websites.

Thanks a million for any replies, is this even possible?
Mike



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

Date: Tue, 4 May 1999 14:38:59 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Please help me (nobody ever does :(
Message-Id: <3seng7.ic4.ln@magna.metronet.com>

Genie (gerbenhd@nederlands.com) wrote:

: Subject: Please help me (nobody ever does :(


   You should, perhaps, have a look at:

      http://www.plover.com/~mjd/perl/Questions.html


   Which discusses several reasons why questions sometimes 
   go unanswered.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 5 May 1999 00:28:27 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: sub for re-encoding a url
Message-Id: <slrn7iv45b.kl.sholden@pgrad.cs.usyd.edu.au>

On Tue, 04 May 1999 16:43:40 -0700, Alex Black <enigma@turingstudio.com> wrote:
>sub url_encode {
>    $dirline = ~s/\?/%3f/g;
>    $dirline = ~s/\&/%26/g;
>    $dirline = ~s/\+/%2b/g;
>    $dirline = ~s/([\000-\037\177-\377 ])/"%".sprintf("%2.2x",ord($1))/ge;
              ^^^

I'm pretty positive that doesn't do anything like what you expect it to.

Perl isn't as white space sensitive as Python, but you can't just chuck in
white space wherever you feel like. Especially not in the middle of an
operator.

Do you really want to bitwise negation. I doubt it.

-- 
Sam

I explicitly give people the freedom not to use Perl, just as God gives
people the freedom to go to the devil if they so choose.
	--Larry Wall


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

Date: Tue, 4 May 1999 19:01:27 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: sub for re-encoding a url
Message-Id: <MPG.11994655d914eef89899c3@nntp.hpl.hp.com>

In article <slrn7iv45b.kl.sholden@pgrad.cs.usyd.edu.au> on 5 May 1999 
00:28:27 GMT, Sam Holden <sholden@pgrad.cs.usyd.edu.au> says...
> On Tue, 04 May 1999 16:43:40 -0700, Alex Black <enigma@turingstudio.com> wrote:
> >sub url_encode {
> >    $dirline = ~s/\?/%3f/g;
> >    $dirline = ~s/\&/%26/g;
> >    $dirline = ~s/\+/%2b/g;
> >    $dirline = ~s/([\000-\037\177-\377 ])/"%".sprintf("%2.2x",ord($1))/ge;
>               ^^^
> 
> I'm pretty positive that doesn't do anything like what you expect it to.
> 
> Perl isn't as white space sensitive as Python, but you can't just chuck in
> white space wherever you feel like. Especially not in the middle of an
> operator.
> 
> Do you really want to bitwise negation. I doubt it.

And even after that's fixed, why do you want to hard-code hex values 
into your code?  Include the '?' '&' and '+' into the character class, 
as you did the space.  And don't forget '%'!  Are there any others?

       $dirline =~ s/([\000-\037 %+&?\177-\377])/
            sprintf '%%%.2x', ord $1/ge;
 

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 04 May 1999 17:51:50 -0700
From: elderr@us.ibm.com
Subject: syswrite() lies
Message-Id: <aevktk2h.fsf@us.ibm.com>


A nasty little portability problem.  Works as expected in UNIX.  The value
syswrite returns is _not_ the number of bytes written to a file in NT. 
Some code:

#!/usr/bin/perl

#read some (or all) of input.txt into $srcfiledata
open(SRCFILE,"input.txt");
$srcfilesize=sysread(SRCFILE,$srcfiledata,10000000);  # read at most 10MB
close(SRCFILE);
print "read $srcfilesize bytes\n";

#write 2KB of data
open(OUTFILE,">outfile.txt");
$byteswritten=syswrite(OUTFILE,$srcfiledata,2048);  # write 2KB (hopefully)
close(OUTFILE);

print "Wrote $byteswritten bytes\n";

On UNIX I get (as you'd expect):

root@tuco-on-44["/tucperf/relder/dev"]
%test.pl
read 987687 bytes
Wrote 2048 bytes

root@tuco-on-44["/tucperf/relder/dev"]
%ls -l *.txt      
-rw-rw-r--   1 root     sys       987687 May 04 17:36 input.txt
-rw-rw-r--   1 root     sys         2048 May 04 17:38 outfile.txt

However NT likes to add control Ms to every line of text so that I get more
than a 2048 byte file (2073 bytes) even though it reports it wrote 2048KB.
Does any one know how to stop the mangling of the buffer?  It should just
read in a buffer and write it without scanning the whole thing to add ^Ms
everywhere (if you ask me.)  I'm using 5.005_2 on NT.

Reply via news please.

Thanks,

Rob


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

Date: Tue, 4 May 1999 19:43:14 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: syswrite() lies
Message-Id: <MPG.1199475e88c8e9f89899c4@nntp.hpl.hp.com>

In article <aevktk2h.fsf@us.ibm.com> on 04 May 1999 17:51:50 -0700, 
elderr@us.ibm.com <elderr@us.ibm.com> says...
 ...
> However NT likes to add control Ms to every line of text so that I get more
> than a 2048 byte file (2073 bytes) even though it reports it wrote 2048KB.
> Does any one know how to stop the mangling of the buffer?  It should just
> read in a buffer and write it without scanning the whole thing to add ^Ms
> everywhere (if you ask me.)  I'm using 5.005_2 on NT.

perldoc -f binmode

Do this on both the input and the output filehandles.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

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


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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