[19859] in Perl-Users-Digest
Perl-Users Digest, Issue: 2054 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 2 11:05:35 2001
Date: Fri, 2 Nov 2001 08:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004717108-v10-i2054@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 2 Nov 2001 Volume: 10 Number: 2054
Today's topics:
[OT] Re: Categories and sub categories. <tsee@gmx.net>
Re: apostrophe character in text boxes and mysql (John J. Trammell)
CPAN is down <bart.lateur@skynet.be>
Re: Help modifying a sort routine <tsee@gmx.net>
Re: hi <mark@good-stuff.co.uk>
How to store a table and retrieve items? ississauga@hotmail.com
Re: How to store a table and retrieve items? <spam@thecouch.homeip.net>
How to: If (exactstring) then.. [learning Perl] <emelindjo@hotmail.com>
Re: How to: If (exactstring) then.. [learning Perl] <Laocoon@eudoramail.com>
Re: How to: If (exactstring) then.. [learning Perl] <emelindjo@hotmail.com>
I need some Help (OT)... <carterandcathleen@mediaone.net>
Re: Leftmost SHORTEST (Zilt)
Re: Need help creating a small flatfile DB program <nobody@nowhere.com>
Re: Need help creating a small flatfile DB program <BROWNHIK@Syntegra.Bt.Co.Uk>
Re: Need help creating a small flatfile DB program <Laocoon@eudoramail.com>
Re: Need help creating a small flatfile DB program (Tad McClellan)
Re: newbie: error processing (Arun Kumar U)
Re: Perl in PWS <tim@vegeta.ath.cx>
Perl In Web Pages (Brendan)
Re: Perl In Web Pages <spam@thecouch.homeip.net>
Re: reading flat-file db and replacing a word <bootsy52@gmx.net>
Re: reading flat-file db and replacing a word <BROWNHIK@Syntegra.Bt.Co.Uk>
Re: reading flat-file db and replacing a word (Tad McClellan)
Re: reading flat-file db and replacing a word <tsee@gmx.net>
removing a file extension from list data. <jonathan@unique.com>
Re: removing a file extension from list data. <Laocoon@eudoramail.com>
Re: removing a file extension from list data. <BROWNHIK@Syntegra.Bt.Co.Uk>
Re: removing a file extension from list data. <jonathan@unique.com>
Re: removing a file extension from list data. <bart.lateur@skynet.be>
Re: replacing many patterns at the same time without cr (joe dassin)
Re: Taint problem with BEGIN block (Tad McClellan)
unzipping a password protected zip file.... help <clos@trentu.ca>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 2 Nov 2001 16:26:28 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: [OT] Re: Categories and sub categories.
Message-Id: <9rudrq$8u1$03$2@news.t-online.com>
"John Taylor" <its_mr_impossible@hotmail.com> schrieb im Newsbeitrag
news:9rsma1$leu$1@newsg1.svr.pol.co.uk...
| Thanks for the reply Steffen,
|
| I am using MySQL and DBI. What fieldnames and datatypes would you use? I
am
| thinking:
|
| category_tbl (
| category_id : integer unsigned auto_increment
| parent_id : integer unsigned
| name : varchar(255)
| )
Please reply after the message you are replying to.
Why not use that?
You should be able to do all the operations, that you described, on it.
If you have a fixed number of levels, you could have one table per level of
categories. Maybe that'll make it easier for you to picture the data
structure. Also, the highest level of categories does include actual
products which have a number of other attributes.
I'll stop giving half-cooked advice now. There are people who know more
about db's than I do.
Though I know that there are a lot of people hanging 'round this place who
could help you just fine, I would suggest you look for a more suitable ng to
ask your question. It's not Perl specific and people might not tend to help
you if you post OT.
HTStillH,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Fri, 2 Nov 2001 09:04:38 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: apostrophe character in text boxes and mysql
Message-Id: <slrn9u5dg7.ead.trammell@haqq.el-swifto.com>
On Fri, 02 Nov 2001 15:25:52 +0800, hugo wrote:
>
> How can I have people include the ' character without it causing
> problems for mysql?
>
Use placeholders and bind values. See section "Placeholders and Bind
Values" in the DBI documentation.
--
Isn't it odd that people who object to "foul" language are always the
fucking dickheads that need swearing at? -- Paul Womar
------------------------------
Date: Fri, 02 Nov 2001 15:51:23 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: CPAN is down
Message-Id: <f3g5utsunaed24hm2je93lpgpvb71e2hr4@4ax.com>
It's not REALLY down, but entering any modulke name in the query box on
<http://search.cpan.org> results in an error:
OK
The server encountered an internal error or misconfiguration and
was unable to complete your request.
Please contact the server administrator,
webmaster@chaos.wustl.edu and inform them of the time the error
occurred, and anything you might have done that may have caused
the error.
More information about this error may be available in the server
error log.
The "OK" as the title of the page is very ironic.
--
Bart.
------------------------------
Date: Fri, 2 Nov 2001 16:14:44 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Help modifying a sort routine
Message-Id: <9rudrq$8u1$03$1@news.t-online.com>
[copy of answer to his email]
Hi,
> I really appreciate you taking a look at this for me, As I said before my
> perl knowledge is very limited, in fact almost non existent :(
Well, mine was naught just a year ago. It's still quite limited, but I'm
working on it.
> Are you suggesting I replace my current sort routine by the one you
posted,
> or just a part of it?
Depends. I would suggest you try both, try to understand them, benchmark
them, and then just choose the better one.
No, seriously, you should try to understand them both. Look up any functions
you don't know in perlfunc and maybe reading about some you vaguely know
will help a lot, too.
> I'm sorry to be a real pain.
You shouldn't be, though. People who don't try hard are a pain. Not people
asking for help who have done their homework.
> The original sort routine is taken from a Gossamer Threads script
(Links2),
> so my initial thought was to modify the existing routine based on the same
> sort procedure, bit it appears that I was wrong (which doesnt suprise me
> :)).
I don't know your source and - forgive me - I'm too lazy to do research on
it. I will just try to explain my routine a bit. I will also point out some
"mistakes" or questionable programming style in yours. Keep in mind that
that's subjective.
> I understand the initial part of the original sort routine ie.
> my (@unsorted) = @_;
^ ^
Without the parens is fine.
> my ($num) = ($#unsorted+1) / ($#db_cols+1);
^ ^ ^ ^ ^ ^
Parens enforce list context. They're not necessary here. You may actually
run into some trouble in different context. Another issue: $#array is the
last index of the array. However, you're looking for the number of elements
in an array. That's @array in scalar context. If you're not sure about the
context, you can enforce scalar with scalar();
my $num = @unsorted / @db_cols;
# this is number of data elements divided by number of db_columns.
> my (%sortby, $hit, $i, @sorted);
>
> for ($i = 0; $i < $num; $i++) {
> $sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
> }
> is to establish the the database fields on which the sort is to be
executed
> (I think).
> If I use the sort routine you posted how do I establish the above?
First: Why is %sortby a hash? You're using numbers as keys, so an array
would be more appropriate, right?
Anyway, you need to figure out in which array you have your unsorted data
and what letter you're going to sort it by.
#!/bin/perl
use strict; # always!!!
use warnings; # always!!!
my @ary = ('ABC', 'aBC', 'Ba', 'cc'..'dd');
# I'm just generating some sample data here.
my $sort_by = 'c';
# same goes for this.
# Now as a sub:
my @sorted = sort_link( $sort_by, @ary );
sub sort_link {
my $sort_by = shift;
my @ary = @_;
# get data.
# The following is called a Schwartzian Transform.
# You need to understand map for this. perldoc perlfunc.
# It's all one expression, so we'll read from the end to
# the start (the array assignment).
# Start reading the paragraph 1.
# complete:
@ary = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, lc $_ ] } @ary;
##############
@ary = map { $_->[0] }
3. The sort routine does not modify the data inside the array elements, so
we still need to convert them to their original data. The sorted array that
is returned by sort is passed to another map to transform it. This map puts
the first element of the inner arrays in the place of the inner array as a
whole, so the outer array is not an array of references any more, but a
sorted array of the original data. ->[0] accesses the first element of the
inner arrays, so $_->[0] is the first element of each inner anon array which
is the original data. The array returned by map is assigned to @ary.
sort { $a->[1] cmp $b->[1] }
2. Now, the main array is passed to the sort routine (picture all
expressions in one line!) and sorted by comparing the lower case versions of
the array elements. We did the lc() outside of the sort function because
that would have been called a lot more often. As you know by reading
perlfunc, $a and $b are two elements of the source data (out modifed array)
that are compared. $a and $b actually are array references because that's
what's been passed to the sort routine, so we dereference it with -> and
access the second element [1]. Remember that teh second element is the lower
case data which is what we want to sort by because we want to sort case
insensitively.
map { [ $_, lc $_ ] } @ary;
1. map does something to each element of @ary and returns an array of the
modified elements as you already know after reading perlfunc. What is done
is defined by the code block within {}. The current element is always stored
in $_ by map. This map stores the original data as well as a lower case (lc)
copy of the data in an anonymous array and puts that array in the place of
the original data. So after the map, you have an array that contains
references to anonymous arrays that contain the data as described above.
##############
foreach (@ary) { # iterate over the array.
push @ary, shift(@ary);
# ^ ^ remove one element from the beginning of the array.
# and add it to the end.
last if lc substr($_,0,1) eq $sort_by;
# stop doing this if the lower case version of the first character is
the same
# as the one we're sorting by.
}
return @ary;
}
Please note that the latter part (foreach) won't work if the character
you're sorting by isn't found. The loop will just iterate over the whole
array. Afterwards, it's in the same order as before. You would need a better
routine if you wanted the data to start with the first element
alphabetically *after* the desired one.
HTH,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Fri, 02 Nov 2001 14:33:26 +0000
From: Mark Goodge <mark@good-stuff.co.uk>
Subject: Re: hi
Message-Id: <3BE2AEB6.7608A3A0@good-stuff.co.uk>
hugo wrote:
>
> Hi
>
> I have a perl file with text boxes that users can fill in. The contents
> of the text boxes is stored in a mysql database. This all works fine,
> except when someone puts a apostrophe ' character in a text box e.g.,
> something like:
>
> Company's web site.
>
> When you have something with a ', all entries from all text boxes on the
> perl page are emptied out of mysql, presumably because the ' character
> messes with the INSERT statement and terminates it early. Note that the
> contents of the text boxes are retrieved with perl's param function
> using CGI.pm and stored in variables. Subsequently, these variables are
> used in the mysql INSERT statement when a call is made to the mysql
> database.
>
> How can I have people include the ' character without it causing
> problems for mysql?
It needs to be escaped. Before passing the string to SQL, change all the
instances of ' to \' so that they are passed straight through.
Assuming your input variable is called $input, then this will do it:
$input =~ s/\'/\\'/g ;
It also makes sense to escape anything else that could cause problems
for SQL, such as double quotes.
Mark
------------------------------
Date: Fri, 02 Nov 2001 13:15:09 GMT
From: ississauga@hotmail.com
Subject: How to store a table and retrieve items?
Message-Id: <3be29bfa.3163724@news>
A table has prices for items having width and height,
3 6 8
2 212 229 246
6 230 244 274
9 241 271 291
So if the item is
width=5.9
height=2
price=229
How can the table be stored and prices found when a width and height
is given? I was trying this method but there must be a better way.
If ($width <= 3) && ($height<=2) { $price=212; }
Any solutions??
------------------------------
Date: Fri, 2 Nov 2001 10:42:35 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: How to store a table and retrieve items?
Message-Id: <w9zE7.12913$Bs2.914357@weber.videotron.net>
<ississauga@hotmail.com> wrote in message news:3be29bfa.3163724@news...
>
> A table has prices for items having width and height,
>
> 3 6 8
> 2 212 229 246
> 6 230 244 274
> 9 241 271 291
>
> So if the item is
> width=5.9
> height=2
> price=229
>
> How can the table be stored and prices found when a width and height
> is given? I was trying this method but there must be a better way.
> If ($width <= 3) && ($height<=2) { $price=212; }
What type of data structure is this table stored in ?
>
> Any solutions??
------------------------------
Date: Fri, 2 Nov 2001 12:10:37 +0100
From: "Emping Melindjo" <emelindjo@hotmail.com>
Subject: How to: If (exactstring) then.. [learning Perl]
Message-Id: <9rtuqv$1hkk$1@scavenger.euro.net>
Hi all,
Might be a simple question,..
I want to test the exact content of: ($Category{$line})
if ($Category($line) = "bike" then ...
------------------------------
Date: Fri, 2 Nov 2001 12:10:42 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: How to: If (exactstring) then.. [learning Perl]
Message-Id: <Xns914D7BE3321D5Laocooneudoramailcom@62.153.159.134>
"Emping Melindjo" <emelindjo@hotmail.com> wrote in news:9rtuqv$1hkk$1
@scavenger.euro.net:
> Hi all,
>
> Might be a simple question,..
>
> I want to test the exact content of: ($Category{$line})
> if ($Category($line) = "bike" then ...
perldoc perlop
perldoc perlsyn
if($Category{$line} eq "bike") {
...
}
Lao
------------------------------
Date: Fri, 2 Nov 2001 12:24:38 +0100
From: "Emping Melindjo" <emelindjo@hotmail.com>
Subject: Re: How to: If (exactstring) then.. [learning Perl]
Message-Id: <9rtvku$1lb3$1@scavenger.euro.net>
Thanx, it works !
"Laocoon" <Laocoon@eudoramail.com> wrote in message
news:Xns914D7BE3321D5Laocooneudoramailcom@62.153.159.134...
> "Emping Melindjo" <emelindjo@hotmail.com> wrote in news:9rtuqv$1hkk$1
> @scavenger.euro.net:
>
> > Hi all,
> >
> > Might be a simple question,..
> >
> > I want to test the exact content of: ($Category{$line})
> > if ($Category($line) = "bike" then ...
>
> perldoc perlop
> perldoc perlsyn
>
> if($Category{$line} eq "bike")
>
> ...
>
> }
>
>
> Lao
------------------------------
Date: Fri, 2 Nov 2001 02:39:59 -0500
From: "M. Carter Brown" <carterandcathleen@mediaone.net>
Subject: I need some Help (OT)...
Message-Id: <EqwE7.8$Ai7.1189@eagle.america.net>
I need a few people to help me out.... I need to give out a survey from
my Master's Class.... I'm doing my project on employee / employer benefits.
This isn't anything to complex... Only 16 simple questions. I'm also
donating a $1.00 for each anonymous survey filled out. If you perl
programmers can help out, thanks! If not, then thanks for letting me bother
you.....
Carter
The Survey is here: http://www.mcarterbrown.com/survey.html
Thanks guys and gals!
------------------------------
Date: 2 Nov 2001 07:04:46 -0800
From: zilt@iname.com (Zilt)
Subject: Re: Leftmost SHORTEST
Message-Id: <7e13fafe.0111020704.136fe69@posting.google.com>
> > How do you instruct gawk (or at least perl) to match the leftmost
> > SHORTEST occurance instead of the default longest?
>
> Have you done some research ? This is very clear in the "PERLRE" document:
> [...]
My research has found the answer in a thread with the same subject,
"Leftmost shortest", that gave an example on how to match "ban" in
"banana": /<b.*?>n/.
Ok, I've learnt how to do "stingy" matching in perl, but can this be
done in gawk?
> In summary, you want /<.*?>/
To rephrase, is there a gawk equivalent for /start_expr.*?end_expr/ ?
Thanks!
PS: Logan, thanks for the info; I'm not trying to parse a language,
but rather write a filter to strip various email ads, like /_+\nDo you
Yahoo.*?http.*?\n/
It's a pain in gawk to eliminate text from until the *first* "http"
(because the next http's might contain vaild, non-ad, addresses. E.g.:
___
Do you Yahoo?!
Get your free crap here!
http://www.crap.com
----------- or no separator at all
Join the assembly programming ring at http://www.asmania.com
------------------------------
Date: Fri, 2 Nov 2001 22:37:30 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: Need help creating a small flatfile DB program
Message-Id: <HpwE7.8225$g8.3279@newsfeeds.bigpond.com>
"Robert Valcourt" <rvalcourt@telus.net> wrote in message
news:RJuE7.11572$i4.1113559@news0.telusplanet.net...
> Hey everyone,
>
> I am very new to Perl. My boss has given me the task of creating a small
> "time tracking" program using perl on the web out of a CGI-BIN. What I
need
> it a perl created page that has two text fields, a start and stop button,
a
> description field, and a submit button. Here is what it would do.
>
> When I am given a job, this program would be used to track my labour
hours.
> I would go to this page and hit start. When my job is finished I would
press
> stop. The start and stop time would be shown in the two text fields. EG :
>
> In the first text field : 08:00
> In the second text field : 08:30 ( times just used as an example )
>
> This of course would mean I hit the start button at 8AM and hit the stop
> button at 8:30AM. The page would also have a "work description" textarea
box
> where I could describe the job performed. Once this info has been filled
> out, I would hit submit and the data would be sent to a flatfile text
based
> database. I would like the flatfile database to hold multiple jobs. A
> theoretical "week old" database would look like this:
>
> 08:00 - 08:30 - November 1 - Fixed broken link
> 09:22 - 09:58 - November 2 - Fixed broken link
> 08:05 - 10:47 - November 3 - Fixed broken link
> 04:00 - 05:33 - November 4 - Fixed broken link
>
> This of course means that each time I use the time tracker, and submit the
> info, the info is compiled in the database instead of overwriting old
data.
> Now I am familiar enough with Perl to be able to open and save data to
> files. I am not, however, able to compile data without overwriting the old
> data. I am also not able to create the timer code.
You can open a file for appending and not overwrite it each time using the >
operator.
open OUTFILE, '>fileout.txt'
You can get the time by
($sec, $min, $hr, $dayofmonth, $mo, $yr, $weekday, $dayofyear, $dlDST) =
localtime(time)
gtoomey
------------------------------
Date: Fri, 2 Nov 2001 12:45:09 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: Need help creating a small flatfile DB program
Message-Id: <9ru4nj$pqt$1@pheidippides.axion.bt.co.uk>
> You can open a file for appending and not overwrite it each time using the
>
> operator.
> open OUTFILE, '>fileout.txt'
>
> You can get the time by
> ($sec, $min, $hr, $dayofmonth, $mo, $yr, $weekday, $dayofyear, $dlDST) =
> localtime(time)
>
> gtoomey
>
>
I think you mean the >> operator. the > rewrites the file, the >> appends to
it.
------------------------------
Date: Fri, 2 Nov 2001 14:58:58 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Need help creating a small flatfile DB program
Message-Id: <Xns914D986B2BE5BLaocooneudoramailcom@62.153.159.134>
"Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk> wrote in
news:9ru4nj$pqt$1@pheidippides.axion.bt.co.uk:
>
>> You can open a file for appending and not overwrite it each time using
>> the
>>
>> operator.
>> open OUTFILE, '>fileout.txt'
>>
>> You can get the time by
>> ($sec, $min, $hr, $dayofmonth, $mo, $yr, $weekday, $dayofyear, $dlDST)
>> = localtime(time)
>>
>> gtoomey
>>
>>
>
> I think you mean the >> operator. the > rewrites the file, the >>
> appends to it.
Its _no_ operator here. Don't confuse them with the > (greater than) and the
>> (binary shift) operators.
------------------------------
Date: Fri, 02 Nov 2001 14:39:12 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need help creating a small flatfile DB program
Message-Id: <slrn9u55el.ck7.tadmc@tadmc26.august.net>
Robert Valcourt <rvalcourt@telus.net> wrote:
>
>I am very new to Perl. My boss has given me the task of creating a small
>"time tracking" program using perl on the web out of a CGI-BIN.
Have you seen the many Perl FAQs that mention CGI?
perldoc -q CGI
>that has two text fields, a start and stop button, a
>description field, and a submit button.
That is about HTML, not Perl, so it is off-topic here. There are
newsgroups (comp.infosystems.www.*) about CGI and HTML where you
can ask such questions.
>This of course means that each time I use the time tracker, and submit the
>info, the info is compiled in the database instead of overwriting old data.
>Now I am familiar enough with Perl to be able to open and save data to
>files. I am not, however, able to compile data without overwriting the old
>data.
The Perl FAQs are your friends. Don't ignore your friends:
perldoc -q change
"How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the
beginning of a file?"
>I am also not able to create the timer code.
perldoc -f localtime
or
perldoc -f gmtime
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 2 Nov 2001 04:37:24 -0800
From: u_arunkumar@yahoo.com (Arun Kumar U)
Subject: Re: newbie: error processing
Message-Id: <4afb3ab3.0111020437.2791624@posting.google.com>
> I would like to execute a subroutine when an error occurs in my
> script.
>
> I am familiar with die and warn, but they only seem to print to STDERR
> and I cannot call subroutines from within the die and warn statements.
>
> Is there any way to first execute a subroutine when an error occurs
> and then die or warn?
>
> Specifically, I have statements like these:
>
> or warn "Disconnection failed: $DBI::errstr\n";
>
> I would like to do this:
> or warn addLogMessage("this is the log message");
> and get the script to continue
> or do this:
> or die addLogMessage("this is the log message");
>
> and then die...
>
> is this possible?
>
You'll love this if you are a OO fan:
use Error qw(:try);
try {
## Do your normal stuff here
## on encountering an exception either throw an exception
## or use die()
throw Error::Simple("Something bad happened");
}
catch Error with {
my ($excptn) = shift;
## Perform your exception Handling
## and if needed you can rethrow the exception as showm below
$exceptn->throw("Rethrowing Exception: $exceptn");
};
For this you'll have to use the Error.pm module. You can
download it from CPAN. Yeah, I know I am a bit biased :-)
Best Regards,
Arun
------------------------------
Date: Fri, 02 Nov 2001 12:32:02 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Perl in PWS
Message-Id: <slrn9u54vq.q72.tim@vegeta.ath.cx>
Me parece que gmanon <gmanon@netzero.net> dijo:
> I am trying to run Perl CGI on a MS-PWS in Windows98 and I keep getting this
> error
>
> The specified CGI application misbehaved by not returning a complete set of
> HTTP headers. The headers it did return are:
>
> Can't locate cgi-lib.pl in @INC (@INC contains: D:/Perl/lib D:/Perl/site/lib
> .) at C:\Inetpub\wwwroot\cgi-bin\greet.pl line 5.
>
> I wonder if I have to write the first code line like this:
>
> #!D:/Perl/lib/Perl.exe;
>
> Does anyone here knows how to solve this?
>
> Please thank you
>
> gmanon
Your script apparently uses the cgi-lib.pl library, which is either not
on your computer, or not where perl can find it (ie, not under a
directory mentioned in @INC).
The first line (shebang line) has absolutely _nothing_ to do with @INC.
PWS (like IIS) ignores the first line of your code, so changing it won't
make a difference. Besides, even if a server looks at the shebang line,
it's only to find the perl binary. Since that's an error message from
perl, it's obviously found the binary.
If you have the file cgi-lib.pl on your server, check out:
perldoc lib
perldoc -f require
However, cgi-lib.pl is left-over from Perl4 days, so if you're not
running perl4 (`perl -v` will tell you), use CGI.pm
perldoc CGI
...since it has a cgi-lib compatibility interface and is much safer.
Tim
--
When it comes to broken marriages most husbands will split
the blame -- half his wife's fault, and half her mother's.
------------------------------
Date: 2 Nov 2001 06:42:52 -0800
From: brendandonhue@aol.com (Brendan)
Subject: Perl In Web Pages
Message-Id: <86a94b1e.0111020642.2f3814ad@posting.google.com>
Whenever I run a PERL script, it executes in a DOS windows. Is there a
way to have it execute through a browser window so that it can be part
of my web site?
------------------------------
Date: Fri, 2 Nov 2001 10:40:06 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: Perl In Web Pages
Message-Id: <c7zE7.12885$Bs2.910800@weber.videotron.net>
"Brendan" <brendandonhue@aol.com> wrote in message
news:86a94b1e.0111020642.2f3814ad@posting.google.com...
> Whenever I run a PERL script, it executes in a DOS windows. Is there a
> way to have it execute through a browser window so that it can be part
> of my web site?
That would make it a CGI.
Look into your browser's configuration files to see how you can get it to
execute CGIs for you, and read about CGIs.
------------------------------
Date: Fri, 02 Nov 2001 15:25:35 +0100
From: "Carsten Menke" <bootsy52@gmx.net>
Subject: Re: reading flat-file db and replacing a word
Message-Id: <pan.2001.11.02.15.25.34.514.1633@gmx.net>
On Fri, 02 Nov 2001 01:06:46 +0100, Tad McClellan wrote:
> Devon Perez <hoss@chungk.com> wrote:
>
>>how do i make my program read a flat-file db, replace a certain word and
>>then save it as another file?
>
> Perl FAQ, part 5:
>
> "How do I change one line in a file/
> delete a line in a file/
> insert a line in the middle of a file/ append to the beginning of a
> file?"
>
This is of interest for me, too. But the FAQ doesn't really help. As I
don't want to read the entire file in an array or variable. And I can't
find a tutorial which describes how to solve that in another way. Isn't
there a mehtod using seek, tell to replace or delete an entry in a file?
Would be glad to have a site on the net which describes that in detail.
Carsten
P.S. The problem is not that I have to replace and delete entries at the
same time, it's only replace or delete not both.
------------------------------
Date: Fri, 2 Nov 2001 14:41:54 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: reading flat-file db and replacing a word
Message-Id: <9rubig$1n5$1@pheidippides.axion.bt.co.uk>
"Devon Perez" <hoss@chungk.com> wrote in message
news:h9lE7.372272$ME2.41332196@typhoon.kc.rr.com...
> how do i make my program read a flat-file db, replace a certain word and
> then save it as another file?
>
>
$oldword = 'abc';
$newword = 'def';
open (IFIL, 'infile.txt');
open (OFIL, '>outfile.txt');
while ($lin = <IFIL>)
{
$lin =~ s/$oldword/$newword/g;
print OFIL, $lin;
}
close (OFIL);
close (IFIL);
K Brownhill
------------------------------
Date: Fri, 02 Nov 2001 15:12:40 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: reading flat-file db and replacing a word
Message-Id: <slrn9u5a81.cph.tadmc@tadmc26.august.net>
Carsten Menke <bootsy52@gmx.net> wrote:
>On Fri, 02 Nov 2001 01:06:46 +0100, Tad McClellan wrote:
>
>> Devon Perez <hoss@chungk.com> wrote:
>>
>>>how do i make my program read a flat-file db, replace a certain word and
>>>then save it as another file?
>>
>> Perl FAQ, part 5:
>>
>> "How do I change one line in a file/
>> delete a line in a file/
>> insert a line in the middle of a file/ append to the beginning of a
>> file?"
>>
>
>This is of interest for me, too. But the FAQ doesn't really help.
I think it does help you, you just didn't recognize it :-)
If there is something in the FAQ answer that you don't understand,
you can ask about it here and we'll try and help clarify.
>As I
>don't want to read the entire file in an array or variable.
The FAQ answer gives code that does not read the entire file into
an array (more than one example even). It shows how to do it with
only a single line in memory at any time.
>And I can't
>find a tutorial which describes how to solve that in another way.
The FAQ answer does show "other ways" so I don't know what you
mean there...
>Isn't
>there a mehtod using seek, tell to replace or delete an entry in a file?
Reread the part that starts with:
"(There are exceptions in special circumstances".
If your circumstances are not those special circumstances, then
seek() isn't going to do it for you.
>Would be glad to have a site on the net which describes that in detail.
I fail to see the shortcomings in the FAQ answer that you allude to.
What is wrong with the answer given in the FAQ?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 2 Nov 2001 16:50:51 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: reading flat-file db and replacing a word
Message-Id: <9rufku$opo$05$1@news.t-online.com>
"Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk> schrieb im Newsbeitrag
news:9rubig$1n5$1@pheidippides.axion.bt.co.uk...
|
| "Devon Perez" <hoss@chungk.com> wrote in message
| news:h9lE7.372272$ME2.41332196@typhoon.kc.rr.com...
| > how do i make my program read a flat-file db, replace a certain word and
| > then save it as another file?
| >
| >
|
use strict;
use warnings;
| $oldword = 'abc';
| $newword = 'def';
|
| open (IFIL, 'infile.txt');
| open (OFIL, '>outfile.txt');
Always check the return value of open as Uri suggested in his answer to
another post in this thread.
| while ($lin = <IFIL>)
| {
| $lin =~ s/$oldword/$newword/g;
What if the string to be replaced contains newlines?
| print OFIL, $lin;
| }
|
| close (OFIL);
| close (IFIL);
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m
------------------------------
Date: Fri, 2 Nov 2001 11:46:44 -0000
From: "Jon Fanti" <jonathan@unique.com>
Subject: removing a file extension from list data.
Message-Id: <LIvE7.16$I21.397@news.uk.colt.net>
Hi, I have a script that very simply pulls fields from a filename and puts
them into a list for me. The only problem with this is that the last field
also palls the file extension!
Here is the script (so far):
=========================================
use strict;
my $EOFld = "_-_";
my $extension = ".mp3";
opendir(DIRHANDLE,"/home/jonathan/mp3/")|| die "Error: can not read current
directory";
foreach (grep {/\.mp3?$/i } readdir(DIRHANDLE))
{
(my $artist,my $title) = (split /$EOFld/) [1,2];
chomp ($title);
print "Artist: $artist\n";
print "Title: $title\n";
}
===========================================
When it prints the Title, I also get .mp3 in their! If anybody could point
me in the right direction, that would be great.
Thanks,
Jon.
------------------------------
Date: Fri, 2 Nov 2001 13:05:27 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: removing a file extension from list data.
Message-Id: <Xns914D852C12C57Laocooneudoramailcom@62.153.159.134>
"Jon Fanti" <jonathan@unique.com> wrote in
news:LIvE7.16$I21.397@news.uk.colt.net:
> Hi, I have a script that very simply pulls fields from a filename and
> puts them into a list for me. The only problem with this is that the
> last field also palls the file extension!
>
> Here is the script (so far):
>
> =========================================
> use strict;
use warnings;
> my $EOFld = "_-_";
> my $extension = ".mp3";
>
> opendir(DIRHANDLE,"/home/jonathan/mp3/")|| die "Error: can not read
> current directory";
Include $! in die to see what went wrong
> foreach (grep {/\.mp3?$/i } readdir(DIRHANDLE))
> {
s/.mp3//; # add this
(my $artist,my $title) = (split /$EOFld/) [1,2];
> chomp ($title);
> print "Artist: $artist\n";
> print "Title: $title\n";
> }
>
> ===========================================
>
> When it prints the Title, I also get .mp3 in their! If anybody could
> point me in the right direction, that would be great.
Did you expect not to get .mp3 at the end? Why?
> Thanks,
>
> Jon.
Lao
------------------------------
Date: Fri, 2 Nov 2001 12:12:12 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: removing a file extension from list data.
Message-Id: <9ru2pr$o8k$1@pheidippides.axion.bt.co.uk>
"Jon Fanti" <jonathan@unique.com> wrote in message
news:LIvE7.16$I21.397@news.uk.colt.net...
> Hi, I have a script that very simply pulls fields from a filename and puts
> them into a list for me. The only problem with this is that the last field
> also palls the file extension!
>
> Here is the script (so far):
>
> =========================================
> use strict;
>
> my $EOFld = "_-_";
> my $extension = ".mp3";
>
> opendir(DIRHANDLE,"/home/jonathan/mp3/")|| die "Error: can not read
current
> directory";
> foreach (grep {/\.mp3?$/i } readdir(DIRHANDLE))
> {
> (my $artist,my $title) = (split /$EOFld/) [1,2];
> chomp ($title);
> print "Artist: $artist\n";
> print "Title: $title\n";
> }
>
> ===========================================
>
> When it prints the Title, I also get .mp3 in their! If anybody could point
> me in the right direction, that would be great.
>
> Thanks,
>
> Jon.
>
>
=========================================
use strict;
my $EOFld = "_-_";
my $extension = ".mp3";
opendir(DIRHANDLE,"/home/jonathan/mp3/")|| die "Error: can not read current
directory";
foreach (grep {/\.mp3?$/i } readdir(DIRHANDLE))
{
(my $artist,my $title) = (/.*$EOFld(.*)$EOFld(.*)\.mp3/);
# (my $artist,my $title) = (split /$EOFld/) [1,2];
chomp ($title);
print "Artist: $artist\n";
print "Title: $title\n";
}
Kevin Brownhill
------------------------------
Date: Fri, 2 Nov 2001 12:19:33 -0000
From: "Jon Fanti" <jonathan@unique.com>
Subject: Re: removing a file extension from list data.
Message-Id: <xbwE7.17$I21.366@news.uk.colt.net>
"Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk> wrote in message
news:9ru2pr$o8k$1@pheidippides.axion.bt.co.uk...
> (my $artist,my $title) = (/.*$EOFld(.*)$EOFld(.*)\.mp3/);
Thanks, that worked a treat!
Jon.
------------------------------
Date: Fri, 02 Nov 2001 12:49:17 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: removing a file extension from list data.
Message-Id: <4h55utkd7e3ni7k9lidvd9budj84ludhad@4ax.com>
Jon Fanti wrote:
>{
> (my $artist,my $title) = (split /$EOFld/) [1,2];
> chomp ($title);
> print "Artist: $artist\n";
> print "Title: $title\n";
>}
>
>===========================================
>
>When it prints the Title, I also get .mp3 in their! If anybody could point
>me in the right direction, that would be great.
Do
s/\.mps$//
before processing the filename. You MAY have to make a modifiable copy
of the filename first:
local $_ = $_;
--
Bart.
------------------------------
Date: 2 Nov 2001 07:29:41 -0800
From: lasilasi@hotmail.com (joe dassin)
Subject: Re: replacing many patterns at the same time without cross-interference
Message-Id: <c94426d.0111020729.328c14a1@posting.google.com>
Bart Lateur <bart.lateur@skynet.be> wrote in message news:<tnk3ut0pv9untjtlfacftdpm8so0aal747@4ax.com>...
> joe dassin wrote:
> Try something along the lines of:
> # set up:
> # do it:
> $" = '|';
> $line =~ s/(@searched)/<b
> style="background-color:#$color{lc $1}">$1<\/b>/ig;
Wow. Very nice. I'd never have thought of the {lc $1}...
Thank you VERY much :-)
Joe
------------------------------
Date: Fri, 02 Nov 2001 14:39:14 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Taint problem with BEGIN block
Message-Id: <slrn9u597p.ck7.tadmc@tadmc26.august.net>
BUCK NAKED1 <dennis100@webtv.net> wrote:
>Wyzell wrote:
>> $f is sourced from outside your program
>> so is potentially tainted.
>> $cleanf = $1 if $f =~ m/(a valid pattern here)/;
>Thanks a bunch! I thought that might be the problem, but I had tried a
>regex for $f, and it didn't work. It looks like you have to change $f to
>a new scalar name. If so, that's what I missed.
No, you don't need a newly named variable. In fact the perlsec.pod
manpage shows an example of reusing the same variable:
if ($data =~ /^([-\@\w.]+)$/) {
$data = $1; # $data now untainted
Untainted without introducing a new variable.
>I'm still not sure if I got the regex's to untaint my variables correct
>or not.
Not. :-)
>The way I understand it, is that a variable isn't really
>untainted unless the regex pattern is done correctly to make it secure.
Close, it isn't _properly_ untainted unless the regex pattern is
done correctly.
$f = $1 if $f =~ /(.*)/;
$f is now untainted, but it is still not secure. It was IMproperly
untainted. Taint checking is effectivey disabled by a silly
match such as the above.
Just because it is untainted does not imply that it is secure.
>Furthermore, since I just want directories that consist of 4 digit names
>under "wkdir", I used /(\d{4})/ for my $cleanf regex.
That does not match strings that consist of 4 digit characters.
That matches strings that _contain_ 4 digit chars, like 'foo1234bar'.
You should be anchoring the start and end of your match:
/^(\d{4})$/
> $dir = "wkdir";
> $dir =~ /^([-\@\w]+)$/;
> $dir = $1;
That is not necesary.
$dir is not tainted (because it comes from inside your program),
so there is no need to untaint it.
Only data that comes from outside of your program is marked as tainted.
And you should *never* use the dollar-digit variables unless you
have first tested to ensure that the pattern match succeeded.
Of course it will succeed in the above example, because $dir's
value is hardcoded (which is why it is not tainted in the first place).
> opendir(DIR, $dir) || die "can't opendir $dir: $!";
> my @files = grep { /(\d{4})/ && -d "$dir/$_" } readdir(DIR);
^^^^^^
@dirs would be a much better name, as there can be no files
in the variable named @files!
> closedir DIR;
>
> my $age = time() - 1*3600;
^^
^^
Multiplying by one is not likely to change anything...
> foreach my $f (@files) {
>
> if ( -d $f ) {
First, you are looking in the current directory, you forgot to
paste the directory part onto the file path.
Second, your grep() above has already ensured that the elements
of @files are directories, the test above is redundant (not needed).
> my $stats = stat($f);
perldoc -f stat
"In scalar context, C<stat> returns a boolean value indicating success
or failure"
So $stats contains either a true or false (very likely false,
given that you forgot the directory part again).
> if ($stats->mtime < $age) {
This generates a runtime error.
Please please please test your code before posting it!
(this is yet another example of your "posting history" BTW)
> }
> }
>
>$cleanf = $1 if $f =~ m/(\d{4})$/;
^^
^^
You forgot to anchor to the beginning of the string.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 2 Nov 2001 14:52:36 GMT
From: Chris Los <clos@trentu.ca>
Subject: unzipping a password protected zip file.... help
Message-Id: <3BE2B334.6EC6612B@trentu.ca>
I need to write a script that will unzip a password protected zip
file.... is there a way to do this in perl???
Do i need a special module??
TIA
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.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 V10 Issue 2054
***************************************