[10052] in Perl-Users-Digest
Perl-Users Digest, Issue: 3645 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 5 21:06:24 1998
Date: Sat, 5 Sep 98 18:00:20 -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 Sat, 5 Sep 1998 Volume: 8 Number: 3645
Today's topics:
Re: Code to Check for acceptable file type (Jonathan Stowe)
Re: Code to Check for acceptable file type <rootbeer@teleport.com>
Re: Code to Check for acceptable file type (Malcolm Hoar)
FINALLY, THE ANSWER COMES OUT! <kevinbartz@geocities.com>
flock issue (James Stout)
Re: flock issue <rra@stanford.edu>
Re: Hats off to Tom Phoenix (Stefaan A Eeckels)
Re: History of Perl - round 1 (Andre L.)
Re: History of Perl - round 1 <eashton@bbnplanet.com>
Make PERL scripts executable??? <julius@clara.net>
Re: pass on value to subroutine call <jerom@xs4all.nl>
Re: Perl compiler <alf@orion.it>
Re: Problem: Opening Word (ack!) doc w/ OLE scott@softbase.com
Re: reading a file backward (Andre L.)
Re: reading a file backward (Andre L.)
Re: Recommend a good editor <nospam@ifctr.mi.cnr.it>
Redirect problems <ross_bensen@cargill.com>
Re: Redirect problems <rra@stanford.edu>
Re: Redirect problems (Alastair)
Subtotals on forms <arm@home.net>
Re: Subtotals on forms <eashton@bbnplanet.com>
The DEFINITIVE Answer <kevinbartz@geocities.com>
Re: The DEFINITIVE Answer (Ethan H. Poole)
Re: The DEFINITIVE Answer <merlyn@stonehenge.com>
Re: Unreadable Scripts? <alf@orion.it>
Re: Unreadable Scripts? <alf@orion.it>
Re: Why dont people read the FAQs <alf@orion.it>
ZenSearch is still looking for a programmer. <lizpoole@surfsouth.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 05 Sep 1998 21:10:12 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Code to Check for acceptable file type
Message-Id: <35f1a659.34500150@news.btinternet.com>
On Sat, 05 Sep 1998 14:06:09 -0500, Mike wrote :
>@array = ("htm", "html", "shtml"); #array of acceptable file types.
>$string = "index.htm"; #Yield acceptable
>$string2 = "index2.shtml"; #Yield acceptable
>$string3 = "pic.gif"; #yield unacceptable
>How would you check to make sure the file extension in the string is an
>acceptable file type that is stored in an array?
>Thanks.
You could of shown us some code first ey ?
#!perl
#@array = ("htm", "html", "shtml"); #array of acceptable file types.
%extensions = ( "htm" => 1,
"html" => 1,
"shtml" => 1 );
@filenames = qw/index.htm index2.shtml pic.gif/;
for ( @filenames )
{
my ($file,$suffix) = split /\./ ;
print $_," - ",$extensions{$suffix} ? "Acceptable" : "Not
Acceptable","\n";
}
__END__
Whenever you are thinking about checking something against a known
list of other things a hash is almost certainly what you are thinking
about.
of course if all your acceptable file types =~ /s*html?$/; or
something similar then yu could just do that.
/J\
--
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Sat, 05 Sep 1998 21:16:24 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Code to Check for acceptable file type
Message-Id: <Pine.GSO.4.02A.9809051406420.8266-100000@user2.teleport.com>
On Sat, 5 Sep 1998, Kevin Bartz wrote:
> Kevin Bartz wrote in message <6ss5s5$1tm$3@supernews.com>...
> >($filename,$extension)=split(".",$string);
> Sorry, you will have to escape the period. Change the "." to "\."
I can't encourage you enough to try out your suggestions before posting
them. Putting a backslash before the period in that code still won't do
what you want. Try a little harder next time. Thanks!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sat, 05 Sep 1998 21:42:58 GMT
From: malch@malch.com (Malcolm Hoar)
Subject: Re: Code to Check for acceptable file type
Message-Id: <6ssb95$r2$1@nntp1.ba.best.com>
In article <35f1a659.34500150@news.btinternet.com>, Gellyfish@btinternet.com (Jonathan Stowe) wrote:
>#@array = ("htm", "html", "shtml"); #array of acceptable file types.
>
>%extensions = ( "htm" => 1,
> "html" => 1,
> "shtml" => 1 );
>
>@filenames = qw/index.htm index2.shtml pic.gif/;
>
>for ( @filenames )
>{
> my ($file,$suffix) = split /\./ ;
>
> print $_," - ",$extensions{$suffix} ? "Acceptable" : "Not
>Acceptable","\n";
>
>}
>__END__
Fails for "my.index.html"!
--
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| Malcolm Hoar "The more I practice, the luckier I get". |
| malch@malch.com Gary Player. |
| http://www.malch.com/ Shpx gur PQN. |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------
Date: Sat, 5 Sep 1998 14:15:43 -1000
From: "Kevin Bartz" <kevinbartz@geocities.com>
Subject: FINALLY, THE ANSWER COMES OUT!
Message-Id: <6sskfh$gbh$1@supernews.com>
FINALLY, the FINAL answer:
#!/usr/local/bin/perl
print "Content-type:text/html\n\n";
@array=("htm","html","shtml","shtm");
$string="theThing.foolish.nothing.htm";
@IHatePerl=split(/\./,$string);
$extension=$IHatePerl[$#IHatePerl];
$good=0;
foreach $disgusto (@array) {
if ($extension eq $disgusto) {
print "Congratualations... you've given me an excellento file extension!";
$good=1;
}
}
if ($good==0) {
print "Uh-oh! Disgusto! You've given me a completely and utterly disgusting
file extension. We ONLY accept these:\n";
foreach $it (@array) {
print "$it\n";
}
}
Enjoy!
--- Kevin Bartz
Mike wrote in message <35F18BA1.6F00@prtel.com>...
>@array = ("htm", "html", "shtml"); #array of acceptable file types.
>$string = "index.htm"; #Yield acceptable
>$string2 = "index2.shtml"; #Yield acceptable
>$string3 = "pic.gif"; #yield unacceptable
>How would you check to make sure the file extension in the string is an
>acceptable file type that is stored in an array?
>Thanks.
------------------------------
Date: Sun, 06 Sep 1998 00:15:27 GMT
From: itxjcs@unix.ccc.nottingham.ac.uk (James Stout)
Subject: flock issue
Message-Id: <35f1d34e.35365044@news.nottingham.ac.uk>
Hi
I just want to check something.
If I flock a file and then my program crashes or exits unexpectedly,
it shouldn't, I have lots of nice error checking and reporting, but
anyway, if it does, the flock is removed, right?
Is this correct?
Thanks
James Stout
itxjcs@unix.ccc.nottingham.ac.uk
------------------------------
Date: 05 Sep 1998 17:39:00 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: flock issue
Message-Id: <ylsoi6gjmj.fsf@windlord.stanford.edu>
James Stout <itxjcs@unix.ccc.nottingham.ac.uk> writes:
> If I flock a file and then my program crashes or exits unexpectedly, it
> shouldn't, I have lots of nice error checking and reporting, but anyway,
> if it does, the flock is removed, right?
Yup. flock() locking is handled by the kernel, which will clean up
resources left behind by your program when it crashes.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 5 Sep 1998 22:51:22 GMT
From: Stefaan.Eeckels@ecc.lu (Stefaan A Eeckels)
Subject: Re: Hats off to Tom Phoenix
Message-Id: <6ssf9a$1cr$1@justus.ecc.lu>
In article <6sqsie$hgn$1@cyprus.atlantic.net>,
chip@pobox.com (Chip Salzenberg) writes:
>
> But your application of it is religious, not even tangenitally
> Perlian, thus off-topic for this newsgroup. ^^^^^^^^^^^^
Nice. With your permission, I'll adopt that spoonerism ;-)
Take care,
--
Stefaan
--
PGP key available from PGP key servers (http://www.pgp.net/pgpnet/)
___________________________________________________________________
Perfection is reached, not when there is no longer anything to add,
but when there is no longer anything to take away. -- Saint-Exupiry
------------------------------
Date: Sat, 05 Sep 1998 18:54:14 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: History of Perl - round 1
Message-Id: <alecler-0509981854140001@dialup-899.hip.cam.org>
In article <35F195F6.B09A73B@bbnplanet.com>, Elaine -HappyFunBall- Ashton
<eashton@bbnplanet.com> wrote:
> since someone mentioned doing a history of perl i have taken an interest
> in actually doing it. a few others have also expressed an interest in
> helping research and write it sooo...the tentative thesis is 'the
> history of perl as viewed through the sociological and economic forces
> driving its development'.
>
> this may, or may not be the best approach so i'm open to ideas. if you
> have any fun facts, anecdotes, or anything that may be of interest, do
> send them to me. hopefully, we'll do the paper justice.
>
Here's my contribution to your project:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
I hope you'll find a use for those in your paper. :-)
Andre
------------------------------
Date: Sat, 05 Sep 1998 23:22:35 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: History of Perl - round 1
Message-Id: <35F1C563.E63278E@bbnplanet.com>
goodness, people get such a wedgie over the lack of capitals in my
writing. i didn't know geeks were such sticklers for grammar and style.
im imagine that if it amounts to anything it will have a few of those.
e.
------------------------------
Date: Sun, 6 Sep 1998 00:23:00 +0100
From: "Jules" <julius@clara.net>
Subject: Make PERL scripts executable???
Message-Id: <6ssisi$jkr$1@eros.clara.net>
Dear all, I'm just wondering if there's any way to convert a perl script
into a DOS executable? I know you add #!/usr/bin/perl -w to make it run on
UNIX, but what about DOS? I wouldn't want a batch file just to call up
perl.exe feeding it with the script filename.
Please help.
Thanx,
Jules
***There is not enough darkness in the whole world to extinguish the light
of a small candle***
------------------------------
Date: Sun, 06 Sep 1998 00:52:07 +0000
From: jeroen <jerom@xs4all.nl>
To: Duncan Cameron <dcameron@bcs.org.uk>
Subject: Re: pass on value to subroutine call
Message-Id: <35F1DCB7.559BA0B5@xs4all.nl>
Eval works just fine.
Thanks for getting me back on track!
Jerom
Duncan Cameron wrote:
>
> Whoops, didn't read your post correctly!
>
> As well as the idea from Gary Williams, using eval should help. Try
>
> eval $test
>
> Duncan Cameron <dcameron@bcs.org.uk> wrote in article
> <01bdd906$d3791180$0b3c63c3@dns.btinternet.com>...
> > You're dealing with soft references. Without having tried it, I would
> > expect something like
> >
> > &{$afield(26)} to do what you want.
> >
> > HTH
> >
> <Original post snipped>
------------------------------
Date: 27 Aug 1998 23:51:50 +0200
From: Alessandro Forghieri <alf@orion.it>
Subject: Re: Perl compiler
Message-Id: <m390kart3d.fsf@aldebaran.orion.it>
Greetings.
nvp@shore.net (Nathan V. Patwardhan) writes:
[...]
> Not exactly. I think people were just pointing out the lameness of
> plunking a cleartext password into a program and compiling the code in
> hopes of sufficiently protecting the password. We were providing
> information about the *risk(s)* of doing what Lily suggested.
[...]
Again, not exactly.
Lily *also* said something to the effect that the password
wasn't exactly 'precious' and that the people she was trying
to protect it from were not exactly tops in the realm of computer
literacy, but hey, nobody - few actually - was listening by then.
Everybody was by then quoting 'security by obscurity just does not work'
thing. - Sounds like "Just say no" to me...
Few bothered to think: how much security? Who daes she have to protect
the information from?
The 'Security by obscurity' bit must be one of the most abused
cliches being flung around the net (second to 'information wants
to be free', perhaps).
In its original context, it meant "ciphers whose sole claim to
robustness is the secrecy of the algorithm cannot claim to be
robust". These times, it is being quoted as if it meant that any
amount of secrecy in a secure environment is useless if not
counterproductive.
Which is of course, hogwash.
Point: 'security' is a meaningless word unless the context
and extent of the 'secure' envoronment are stated - meaning
secure for how long? Against whom? What is the relative value
that is attached to the information?
Point: security through obscurity does indeed work, every day:
o) childproof medicine containers have a degree of effectiveness;
o) the navajo speakers in WWI were never 'deciphered';
o) trivially, key distribution, passwords, etc. need to be
seceret/obscure, for the whole shebang to hold together;
Point: besides, though not enough to ensure security, obscurity
cannot hurt your secure environment. I see no banks publishing
the plans of their caveau: though that isn't probably their only
line of defense, I do not see anything wrong with that.
And - apart from the suid wrapper discussion - nobody
has come up with the magic wand that would privide rock
hard security for Lily's problem.
Because, IMHO, it comes the time when you just
have to stick a plaintext pwd *somewhere*.
As an example, to automate maintenance tasks on routers - through
telnet, I sometimes have to stick passwords in scripts. I make them
readable & executable just by root. I am not enthused, but I have
yet to come up with something better.
And I am inclined to believe that the alternative are narrow.
Cisco's tacacs+ encrypts all the communications between a router
and a server - however, the key to do so is stored -cleartext -
in a conf file on the server.
Cheers,
Alessandro
--
One standard to rule them all, one standard to find them,
One standard to bring them all, and in darkness bind them.
In the land of Microsoft, where the Shadow lie.
Alessandro Forghieri http://www.orion.it/~alf
------------------------------
Date: 5 Sep 1998 22:30:56 GMT
From: scott@softbase.com
Subject: Re: Problem: Opening Word (ack!) doc w/ OLE
Message-Id: <35f1bba0.0@news.new-era.net>
Charles Sherman (euschsh@am1.ericsson.se) wrote:
> $wd->Documents->Open('FileName:="C:\DOCS\MYDOC.DOC"');
Perl's Win32::OLE does *not* support positional parameters
like VB does. You *can't* use the := syntax. You must
list the parameters in order.
Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more.
------------------------------
Date: Sat, 05 Sep 1998 18:20:57 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: reading a file backward
Message-Id: <alecler-0509981820570001@dialup-899.hip.cam.org>
In article <MPG.105afa8bd91612eb98982a@nntp.hpl.hp.com>, lr@hpl.hp.com
(Larry Rosler) wrote:
[...]
> Now I can think of easy ways of improving my code, for example, by adding
> logic to do backward seeks from the current position instead of simply
> seeking from the beginning (which would make an enormous difference if
> the file were on a sequential medium such as a tape).
[...]
OK, here's a refurbished version that seeks backwards (improvements
welcome). Enjoy -- or not.
#!/usr/local/bin/perl -w
# based on Larry Rosler's code
use strict;
sub print_file_backwards {
my $fh = shift;
my ($i, @pos, @offsets);
my $prev = 0;
# line positions
do { push @pos, tell $fh } while (<$fh>);
# offsets between lines
for ($i = 0; $i <= $#pos; $i++) {
push @offsets, $pos[$i-1] - $pos[$i];
}
@offsets = reverse @offsets;
seek ($fh, 0, 2); # seek to end of file
foreach (@offsets) {
seek ($fh, $prev+$_, 1) or die "Seek error: $!\n";
print scalar <$fh>;
$prev = $_;
}
}
open F, $0
or die "Error opening the file: $!\n";
print_file_backwards *F;
close F;
__END__
HLV,
Andre
------------------------------
Date: Sat, 05 Sep 1998 18:40:01 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: reading a file backward
Message-Id: <alecler-0509981840010001@dialup-899.hip.cam.org>
In article <alecler-0509981820570001@dialup-899.hip.cam.org>, I,
alecler@cam.org (Andre L.) wrote:
[...]
> for ($i = 0; $i <= $#pos; $i++) {
> push @offsets, $pos[$i-1] - $pos[$i];
> }
[...]
Duh... $i should be initialized to 1, not 0, of course. Sorry.
Andre
------------------------------
Date: Wed, 2 Sep 1998 09:11:44 +0200
From: LC's No-Spam Newsreading account <nospam@ifctr.mi.cnr.it>
To: rkprasad@my-dejanews.com
Subject: Re: Recommend a good editor
Message-Id: <Pine.OSF.3.95.980902091022.4052A-100000@poseidon.ifctr.mi.cnr.it>
On Wed, 19 Aug 1998 rkprasad@my-dejanews.com wrote:
>
> I heard of an Editor called "samba" that has the look and feel of a windows
> based IDE but resides in UNIX..
Uh, confusing ?
The "SAMBA" I know (http://lake.canberra.edu.au/pub/samba/samba.html)
is not an editor, but an Unix emulator of the Microsoft SMB protocol, used
to share Unix resources (disks, printers) with NT boxes.
----------------------------------------------------------------------
nospam@ifctr.mi.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
------------------------------
Date: Sat, 05 Sep 1998 18:25:43 -0500
From: Ross Bensen <ross_bensen@cargill.com>
Subject: Redirect problems
Message-Id: <35F1C877.1250A47E@cargill.com>
I am running a script and trying to redirect the output to a file. The
output is in the form of
print "line of text"
I am running the script from an AIX command line:
$myscript >myscript.log
The script is executed only once but all of the output is duplicated in
the log file. Any ideas??
------------------------------
Date: 05 Sep 1998 17:02:16 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Redirect problems
Message-Id: <yl90jyhzw7.fsf@windlord.stanford.edu>
Ross Bensen <ross_bensen@cargill.com> writes:
> I am running a script and trying to redirect the output to a file. The
> output is in the form of
> print "line of text"
> I am running the script from an AIX command line:
> $myscript >myscript.log
> The script is executed only once but all of the output is duplicated in
> the log file. Any ideas??
Does your script fork? If so, do you flush your stdio buffers before
forking? If you don't, your child will get a copy of your stdio buffers
and may print the same things out again.
Set $| to 1 to turn off buffering.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Sun, 06 Sep 1998 00:10:08 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Redirect problems
Message-Id: <slrn6v3ode.ck.alastair@calliope.demon.co.uk>
Ross Bensen <ross_bensen@cargill.com> wrote:
>I am running a script and trying to redirect the output to a file. The
>output is in the form of
>
>print "line of text"
I think You've missed semi-colon off that line.
>I am running the script from an AIX command line:
>
>$myscript >myscript.log
>
>The script is executed only once but all of the output is duplicated in
>the log file. Any ideas??
>
Not unless you post some offending code.
--
Alastair
work : alastair@psoft.co.uk
home : alastair@calliope.demon.co.uk
------------------------------
Date: Sat, 05 Sep 1998 20:55:43 GMT
From: Alan Melton <arm@home.net>
Subject: Subtotals on forms
Message-Id: <35F1A3F7.E762340B@home.net>
I have an ascii comma delimited file with eight fields.
The file is already sorted by skunum.
Is there any way to do a subtotal on a specific field
i.e. $skunum.
Currently the list prints out all the data and certain totals.
I would like to print out a subtotal on $voll if the skunum
is the same.
Example of data file:
30,August,1998,1692,2,81.85,163.70,Discovering Computers/Ltf/Www
30,August,1998,1692,2,81.85,163.70,Discovering Computers/Ltf/Www
31,August,1998,3370,1,37.35,37.35,Dosage Calculations-W/Cd 5th 96 New
31,August,1998,3370,1,37.35,37.35,Dosage Calculations-W/Cd 5th 96 New
31,August,1998,3370,1,37.35,37.35,Dosage Calculations-W/Cd 5th 96 New
31,August,1998,3370,1,37.35,37.35,Dosage Calculations-W/Cd 5th 96 New
^ ^
| |
| |
sku vol
for $filename ("booklt.dat") { # get all filenames in current directory
open(IN, "<$filename"), $filename or die "Cannot read $filename: $!";
while (<IN>)
{
chomp;
# Split the line on the pipe symbol.
($dayy,$monthh,$yearr,$skunum,$voll,$costone,$costtot,$descc) =
split (/\,/);
next unless $skunum;
# Keep a running tab.
$totalVol += $voll;
$totalCost += $costtot;
write;
}
# Select the 'TOTAL' picture.
$FORMAT_NAME = "TOTAL";
# Write out the totals.
write;
# This format 'picture' is for the invioce.
format INVOICE_TOP =
Total
DATE SKU Volume Cost DESC
=============================================================================
.
format INVOICE =
@<< @<<<<<<<<<@<<< @<<<< @### $@###.## @*
$dayy,$monthh,$yearr,$skunum,$voll,$costtot,$descc
.
format TOTAL =
=============================================================================
@##### $@#####.##
$totalVol,$totalCost
.
close IN;
}
1;
------------------------------
Date: Sat, 05 Sep 1998 21:23:44 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Subtotals on forms
Message-Id: <35F1A986.DEBE1350@bbnplanet.com>
one word, database. this won't scale well, which, with books, i imagine
will grow at exponential rates (my book collection does anyway). with a
database, mSQL for example, you are able to select information via
criteria you choose and manipulate it at will, including a subtotal. if
you are tied to this flat file format you should, perhaps, lobby for
said database. i would create an array and increment the vol within
that.
e.
------------------------------
Date: Sat, 5 Sep 1998 12:27:27 -1000
From: "Kevin Bartz" <kevinbartz@geocities.com>
Subject: The DEFINITIVE Answer
Message-Id: <6sse8d$6ff$1@supernews.com>
I am very sorry. Here is the DEFINITIVE answer:
Replace
($filename,$extension)=split(".",$string);
with
($filename,$extension)=split (/\./,$string);
That should do the trick.
--- Kevin Bartz
Kevin Bartz wrote in message <6ss5s5$1tm$3@supernews.com>...
>Use this code:
>
>($filename,$extension)=split(".",$string);
>$good=0;
>
>foreach $disgusto (@array) {
>if ($extension eq $disgusto) {
>print "Congratualations... you've given me an excellento file extension!";
>$good=1;
>}
>}
>
>if ($good==0) {
>print "Uh-oh! Disgusto! You've given me a completely and utterly disgusting
>file extension. We ONLY accept these:\n";
>foreach $it (@array) {
>print "$it\n";
>}
>}
>
>You will need to repeat this code for every string you need to detect, so
>you may want to put the strings in an array and loop through the members.
>Hope this helps...
>
>--- Kevin Bartz
>
>Mike wrote in message <35F18BA1.6F00@prtel.com>...
>>@array = ("htm", "html", "shtml"); #array of acceptable file types.
>>$string = "index.htm"; #Yield acceptable
>>$string2 = "index2.shtml"; #Yield acceptable
>>$string3 = "pic.gif"; #yield unacceptable
>>How would you check to make sure the file extension in the string is an
>>acceptable file type that is stored in an array?
>>Thanks.
>
>
------------------------------
Date: 5 Sep 1998 23:37:28 GMT
From: ehp@gte.net (Ethan H. Poole)
Subject: Re: The DEFINITIVE Answer
Message-Id: <6sshvo$44g$1@news-1.news.gte.net>
[Posted and Emailed] In article <6sse8d$6ff$1@supernews.com>,
kevinbartz@geocities.com says...
>
>I am very sorry. Here is the DEFINITIVE answer:
>($filename,$extension)=split (/\./,$string);
>
>That should do the trick.
>
Ummm.. Nope! Consider the file named "foo.bar.baz" You've detected
$filename=foo $extension=bar, not quite on the mark. There is no rule which
says a filename may have only a single dot (unless you are restricted to the
old 8.3 DOS format).
$FullFileName = "foo.bar.baz";
$FullFileName =~ /(.*)\.([^.]*)$/;
$Filename = $1;
$Extension = $2;
print "Filename = $Filename\n";
print "Extension = $Extension\n";
Would be one possible approach. It basically reads everything from the right
up to the first dot as the extension and the remainder is considered the
filename.
--
Ethan H. Poole | Website Design and Hosting,
| CGI Programming (Perl & C)..
========Personal========= | ============================
* ehp @ gte . net * | --Interact2Day--
http://home1.gte.net/ehp/ | http://www.interact2day.com/
------------------------------
Date: Sun, 06 Sep 1998 00:41:04 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: The DEFINITIVE Answer
Message-Id: <8cn28eul81.fsf@gadget.cscaper.com>
>>>>> "Ethan" == Ethan H Poole <ehp@gte.net> writes:
Ethan> Ummm.. Nope! Consider the file named "foo.bar.baz" You've detected
Ethan> $filename=foo $extension=bar, not quite on the mark. There is no rule which
Ethan> says a filename may have only a single dot (unless you are restricted to the
Ethan> old 8.3 DOS format).
Ethan> $FullFileName = "foo.bar.baz";
Ethan> $FullFileName =~ /(.*)\.([^.]*)$/;
Ethan> $Filename = $1;
Ethan> $Extension = $2;
Ethan> print "Filename = $Filename\n";
Ethan> print "Extension = $Extension\n";
That's dangerous. You don't test the success of the match before
looking at $1. Bad. Very bad.
Nearly always, a match in a void context is a sure sign of a
Programming Bug waiting to happen.
In this case, for a $FullFileName that has no dot, you would get the
*previous* $1 and $2, making your program very confused.
This is perhaps cleaner, and might even be faster:
for my $Full (qw(fred barney.c dino.the.dinosaur.cgi)) {
($base, $ext) = $Full =~ /^ (.*?) (\.[^.]*)? $/sx;
print "Full = $Full, base = <$base>, ext = <$ext>\n";
}
There, try that for an idea.
print "Just another Perl hacker," =~ /(.{1,10})/g;
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 28 Aug 1998 09:18:06 +0200
From: Alessandro Forghieri <alf@orion.it>
Subject: Re: Unreadable Scripts?
Message-Id: <m3u32x8tht.fsf@aldebaran.orion.it>
Greetings.
mgjv@comdyn.com.au (Martien Verbruggen) writes:
[...]
> Then it is still a matter of file permissions. The poster wanted to
> know how to stop people from reading his stuff. Not how to get a false
> sense of security or obfuscation by having a 'compiled' program.
>
> The discussion about why compilation doesn't provide that has been
> here, has been beaten to death.
[...]
That is quite true. And, as those that followed the discussion - or
actually, oh, my, tried it - found out, 'chmod 711' does not quite cut
it, because an interpreter has to be able to *read* the script before
actually executing it. (And there must be a lot of Unix folks, out
there - including my humble self - who knew just by looking that chmod
711 would not work. Yet noone started posting stuff like 'RTFM',
'...have you TRIED IT before posting???' etc. Is there a moral to
this? I honestly don't know.)
Compiling the script of the executable (and *then* chmod it 711) is
therefore a very good way to accomplish that kind of protection -
unless you are inclined to do suid contorsions which are quite devious
anyway, not to mention requiring root privilege.
Yet the same *WRONG* advice (chmod 711) has popped up in this thread...
So:
Factoid 1:
"The discussion about why compilation doesn't provide that
has been here, has been beaten to death" *AND* its conclusion has been
that compilation provides exactly "that". (Then somebody came along and
said that "that" is immoral & evil, but that is another thread, I
guess)
Factoid 2:
There is a number of clpm posters who just love to point
newbies to their operating system documentatuion - after a fair amount
of snide remarks - yet cannot be bothered to try out what they
suggest *BEFORE* they suggest it.
Curiously, the same attitude is vastly despised by the group when:
a)it is exhibited by a newbie
b) it has to do with perl
OTOH, if the perpetrator is not a newbie & speaks about U*X, it is
accepted.
Factoid 3:
"Security by obscurity does not work" is a widely misunderstood
cliche. But I commented on that in another thread.
Cheers,
Alessandro
--
One standard to rule them all, one standard to find them,
One standard to bring them all, and in darkness bind them.
In the land of Microsoft, where the Shadow lie.
Alessandro Forghieri http://www.orion.it/~alf
------------------------------
Date: 28 Aug 1998 09:32:02 +0200
From: Alessandro Forghieri <alf@orion.it>
Subject: Re: Unreadable Scripts?
Message-Id: <m3soih8sul.fsf@aldebaran.orion.it>
Greetings.
mgjv@comdyn.com.au (Martien Verbruggen) writes:
[...]
> 711 means: read, write, execute to owner. execute to group members.
> execute to anyone else.
>
> This clearly means that only the owner of the file can read it. No one
> else (except priveledged accounts, like root).
This is quite right, not to mention educational.
In fact, when someone other than the owner tries to execute a 711
scripts, the following accident happens:
i) the OS finds out about the #!<whatever>/perl magic number
ii) it hands the script to the perl interpreter for action
iii) *BUT* the perl interpreter is running under a UID who does not
have read permissions on the file and everything bombs miserably:
Can't open perl script "foobar.pl": Permission denied
Ouch. If that is what you're after, chmod 700 is quicker.
Cheers,
Alessandro
--
One standard to rule them all, one standard to find them,
One standard to bring them all, and in darkness bind them.
In the land of Microsoft, where the Shadow lie.
Alessandro Forghieri http://www.orion.it/~alf
------------------------------
Date: 26 Aug 1998 10:23:40 +0200
From: Alessandro Forghieri <alf@orion.it>
Subject: Re: Why dont people read the FAQs
Message-Id: <m3yascgnhv.fsf@aldebaran.orion.it>
Greetings.
Arved_37@chebucto.ns.ca (Arved Sandstrom) writes:
[...]
> Larry Wall is an aficionado of the language, and when he mentioned Hubris
> I trust he liked the word, but really just meant confidence. Someone with
> hubris is, by definition, an asshole.
[...]
I cannot - obviously - know what Larry *really* meant.
But, in the classical - Ancient Greek - sense, Arachnis and
Prometheus, among countless others, were guilty of hubrys. Literally,
they were proudly defiant of the Gods (Arachnis thought she could sew
better than anybody else, godesses included; we all know about
Prometheus).
Does that (alone) a asshole make? I don't think so.
Looks to me that the classical meaning fits nicely on the original
Larry's quote.
In the greek world, the 'hubrys ton anthropon' (pride of men) always
provoked the 'fthonos ton theon' (wrath, or revenge, of the Gods) and
consequent retribution.
Of course, we know that the fthonos of the Perl Gods is seldom in short
supply on clpm....;)
Cheers,
Alessandro
--
One standard to rule them all, one standard to find them,
One standard to bring them all, and in darkness bind them.
In the land of Microsoft, where the Shadow lie.
Alessandro Forghieri http://www.orion.it/~alf
------------------------------
Date: Fri, 04 Sep 1998 10:10:11 -0400
From: James T Kendall <lizpoole@surfsouth.com>
Subject: ZenSearch is still looking for a programmer.
Message-Id: <35EFF4C3.7713@surfsouth.com>
ZenSearch is still looking for a programmer.
ZenSearch (http://www.zensearch.com) is now
a non-profit corporation legally registered in the
state of Georgia. We are in need of a Perl programmer
to help take ZenSearch to the next level.
No $$$ upfront, but a seat on the board of directors as well
as a regular salary after we obtain funding.
Thanks for your time
James T Kendall
ceo@zensearch.com
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3645
**************************************