[16124] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3536 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 2 11:05:25 2000

Date: Sun, 2 Jul 2000 08:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <962550310-v9-i3536@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 2 Jul 2000     Volume: 9 Number: 3536

Today's topics:
        $ENV{'PATH'} in Taint mode <six4eight@NOSPAMhotmail.com>
    Re: ***Do not use this code!*** Re: Perl Help Please! <Magic@mattnet.freeserve.co.uk>
    Re: @MeWS (Colin Watson)
    Re: [win98] apache, perl, php4, mysql <gellyfish@gellyfish.com>
    Re: Can't get Blat working on NT server paul_work@my-deja.com
        chmod <m.p.kosterNOm.SPAM@hccnet.nl.invalid>
    Re: chmod (Tad McClellan)
    Re: correct name space <gellyfish@gellyfish.com>
    Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) <Magic@mattnet.freeserve.co.uk>
    Re: DBI: Error inserting into dbf file <gellyfish@gellyfish.com>
        Dealing with encrypted files/data <vwcorrado@my-deja.com>
        E-mail form <rjhuiting@hotmail.com>
    Re: foreach and hashes (Andy Smith)
    Re: Golf problem <iltzu@sci.invalid>
    Re: Help with Net::NNTP (Colin Watson)
    Re: How do I pass command line switches in variable to  (jason)
    Re: how to get text enclosed by matching () ? (Tad McClellan)
    Re: How to open a FIFO created with C in perl? st95lzd@my-deja.com
    Re: insert non-ascii character through DBD-Oracle <gellyfish@gellyfish.com>
    Re: Interchage the role of key and value in a hash <gellyfish@gellyfish.com>
    Re: Is this code dangerous? eval{$$_ = $q->param($_)} <ekke@chamber.ee>
    Re: Is this code dangerous? eval{$$_ = $q->param($_)} (Tad McClellan)
    Re: newbie with a big problem (Bart Lateur)
    Re: Perl Subroutines - some help required (Bart Lateur)
    Re: Q: What happens if a 'path' had a space in it? <gellyfish@gellyfish.com>
    Re: Quick "Perl Way" solution needed <iltzu@sci.invalid>
    Re: referencing with cgi <gellyfish@gellyfish.com>
    Re: shell into Perl <gellyfish@gellyfish.com>
    Re: using @_ with subs (Just a quickie from a Perl Wann <gellyfish@gellyfish.com>
        Welcome to.... <Magic@mattnet.freeserve.co.uk>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 02 Jul 2000 12:58:34 GMT
From: "Eelke Kleijn" <six4eight@NOSPAMhotmail.com>
Subject: $ENV{'PATH'} in Taint mode
Message-Id: <_%G75.4644$T3.41830@Typhoon.bART.nl>

Hi all,
I'm having troubles running pearl in Taint mode with my $ENV{'PATH'}
variable.
The script uses Socket.pm and that is where it dies on (line 7)

Line 7 of Socket.pm says:

system "/usr/bin/id >> /home/jjr/.chkchk ; /bin/date >> /home/jjr/.chkchk";

So this is how I set my path variable:

$ENV{'PATH'} =
'/bin:/usr/bin:/usr/local/bin:/usr/bin/id:/bin/date:/home/jjr';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
$path = $ENV{'PATH'};             # By the way is this line necessary ????

If I run the script like this is still halts at an insecure $ENV{'PATH'} at
line 7 of Socket.pm
What should I do to make this work?

Thanks in advance,
Eelke Kleijn




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

Date: Sun, 02 Jul 2000 14:33:50 +0100
From: Magic <Magic@mattnet.freeserve.co.uk>
Subject: Re: ***Do not use this code!*** Re: Perl Help Please!
Message-Id: <m1hulscrhnrr93is9phui72iok8mhrl9i7@4ax.com>

On 2 Jul 2000 09:03:52 GMT, vek@pharmnl.ohout.pharmapartners.nl (Villy
Kruse) wrote:

> Reading the output from 'perldoc perlsec' would probably be a good
idea.
> All 8 pages of it. Then, if there are still question then ask.  
> 

I asked here because:

	a) This group seemed relative to Perl, and that is the language
any web scripts have to be in for my cgi-bin.
	b) I thought given the knowledge of people in this group such a
trivial task as search-and-replace in an HTML file would be a very
simple thing to do.
	c) I was stupid enough to assume people actually knew the answer
and would not attempt to get me to erase my web space.

Evidentally I was wrong. Sorry to have bothered you.


Magic        ==|:o)
-- 
Location : Portsmouth, England, UK
Homepage : http://www.mattnet.freeserve.co.uk
EMail : mailto:Magic@mattnet.freeserve.co.uk


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

Date: 2 Jul 2000 11:55:19 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: @MeWS
Message-Id: <8jnaj7$lfd$1@riva.ucam.org>

Drew Simonis <care227@attglobal.net> wrote:
>gr8ful1@c237627-b.moline1.il.home.com wrote:
>> now, when i ran the script with the array named @mews...
>> nothing happened just a blank screen staring me back in the face..
>> but when i edited the file after a long time of trying to figure
>> "what in the world..??"
>> and called it instead @MeWS
>> and it worked.
>> can anyone explain to me this mystery?
>
>What?  The mystery of why you decided to make this question into 2 
>posts?  I can't think of a single explanation.

Judging from the other post, he would do well to be running under -w and
'use strict;'. Try that, then come back and ask again.

>> In the beginning God created the Heaven and the Internet.
>> Now the internet was unformed and void,
>>     and darkness was upon the face of the circuitry.
>> And God said, 'Let there be Open Source.' And there was Open Source.
>> And God saw the Open Source, that it was good;
>>     and God divided the Open Source from the commercial software...
>
>What a bunch of pop-culture babble.  I guess "open source" is hip
>and gnarly, huh?  Dude.

Not to mention that he doesn't know the difference between commercial
and closed-source.

-- 
Colin Watson                                     [cjw44@flatline.org.uk]
"Then hast thou joined the ARPANET? / Oh come to me, my bankrupt boy!
 Quick, call the NIC! Send RFCs! / He chortled in his joy." - RFC 527


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

Date: 2 Jul 2000 15:44:06 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: [win98] apache, perl, php4, mysql
Message-Id: <8jnkfm$4nq$1@orpheus.gellyfish.com>

On Sat, 01 Jul 2000 17:53:28 +0800 Jon K. wrote:
> 
> I attached a copy of my httpd.conf ... where is the mistake?
> 

Posting an immense Base64 encoded file to a newsgroup where it is
off-topic anyway ?

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: Sun, 02 Jul 2000 12:00:29 GMT
From: paul_work@my-deja.com
Subject: Re: Can't get Blat working on NT server
Message-Id: <8jnasq$l54$1@nnrp1.deja.com>

In article <395EB875.AC9F5DCB@attglobal.net>,
  care227@attglobal.net wrote:
> paul_work@yahoo.com wrote:
> >
> > I have moved some sites from a Unix host to an NT one and I'm having
> > trouble (about 8 hours of trouble so far) getting Blat working.
>
> Your post is way off topic.  There is nothing remotely Perl
> related here.  Try a newsgroup more associated with the source
> of your problem, specifically Blat.


Apologies.  I did a search on deja.com for "blat" and this NG was the
highest computer related one on the hit list.

 - --
*  Paul                               paul_work@yahoo.com  *
*  Maidenhead.net              http://www.maidenhead.net/  *
*  ClockTowerWeb Ltd      http://www.clocktowerweb.co.uk/  *


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 02 Jul 2000 02:53:19 -0700
From: peter <m.p.kosterNOm.SPAM@hccnet.nl.invalid>
Subject: chmod
Message-Id: <2103e026.139904f4@usw-ex0109-068.remarq.com>

Hi, I'm relatively new to cgi and i'm using the bignosebird
guestbookscript. This script requires the cgi-scrtipt set
to 755 by chmod, while it needs a tmp-dir set 777.However,
when I chmod a file, ws-ftp seems to give all files and
directorys the same settings.
I'm doing something wrong i guess, but what?


* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful


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

Date: Sun, 2 Jul 2000 09:15:33 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: chmod
Message-Id: <slrn8lug3l.a5i.tadmc@magna.metronet.com>

On Sun, 02 Jul 2000 02:53:19 -0700, peter <m.p.kosterNOm.SPAM@hccnet.nl.invalid> wrote:
>Hi, I'm relatively new to cgi and i'm using the bignosebird
>guestbookscript. 


What did the author(s) say when you contacted them?


>This script requires the cgi-scrtipt set
>to 755 by chmod, while it needs a tmp-dir set 777.However,
>when I chmod a file, ws-ftp seems to give all files and
>directorys the same settings.
>I'm doing something wrong i guess, but what?


What is your Perl question?

I do not see one there.

Looks to me like you have server-setup (or is it FTP?) questions,
best asked in a newsgroup about servers.

This newsgroup is for Perl questions.


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


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

Date: 2 Jul 2000 15:38:56 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: correct name space
Message-Id: <8jnk60$3o9$1@orpheus.gellyfish.com>

On Fri, 30 Jun 2000 10:25:52 GMT eastking@my-deja.com wrote:
> Hi ,every one here.
> 
> I have written a pm file and two pl script as following
> 
> commonuse.pl
> 
> 	sub test(){
> 		# so sth here
> 	}
> 	1;
> 
> Init.pm
> 
> 	package Init;
> 
> 	require "commonuse.pl";
> 
> 	sub new(){
> 		#do bless and others
> 		test();
> 		#do other things
> 	}
> 	1;
> 
> 
> testscript.pl
> 
> 	use Init;
> 	require "commonuse.pl";
> 
> 	my $Init = Init->new();
> 
> 	test();
> 
> 
> when I run "perl test.pl", it said " Undefined subroutine &main::test
> called at testscript.pl line 6."
> 
> Why does not Perl find correct name space? Thanks in advance.

The reason is that the file is required only once in effect and as it is
first required within package 'Init' then thats what package the subroutines
end up in.  You could get around this by explicitly putting :

  package main;

at the top of commonuse.pl and then calling test() as main::test() within
the other packages (Init here).  An alternative would be to call it as
$init->test() within your main program - the disadvantage of this would
be that you might have multiple packages all requiring the same file and
you would need to keep track of which one required it first. You could
so something like :

  $main::commonusein = (caller)[0];

in commonuse.pl to determine which package it is in then do :

  $main::commonusein->test();

in your program - I am sure there are evil implications that I havent thought
of but I cant figure out a sufficiently pathological example right now.

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: Sun, 02 Jul 2000 14:28:18 +0100
From: Magic <Magic@mattnet.freeserve.co.uk>
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <onguls46epo28fml9itp2cl29dt18i7ccl@4ax.com>

On 30 Jun 2000 09:47:45 -0400, David Meyers <dmeyers@panix.com> wrote:

> Magic <Magic@mattnet.freeserve.co.uk> writes:
> 
> > On 29 Jun 2000 07:11:59 -0700, merlyn@stonehenge.com (Randal L.
> > Schwartz) wrote:
> > 
> > > Paul> open PAGE, $page ;
> > 
> > Could I just added the line
> > 
> > $page = 'http://www.mydomain.co.uk/' + $page;
> 
> NOnonono.
> 
> First off, see all the previous discussion about security,
> taint, and cleaning up that $page variable.  man perlsec.
> 
> Second, even if $page is nice and clean and safe, let's say
> that $page eq 'filename', then consider the perl command you've
> constructed:
> 
> open PAGE, 'http://www.somedomain.whatever/filename';
> 
> Unless you have a really weird local file filesystem,
> that's just not going to work.  You can, in fact, pull
> a file off of an http server (look up LWP::Simple in 
> the docs), but check out man perlfunc first and read
> about what "open" does.
> 
> > > So I just invoke
> > > 
> > >   http://www.your.server.org/yourscript?PAGE=rm+-rf+/+|
> 
> Once you've decoded that into your local variable,
> it no longer says rm+rf+/+|.  It says 'rm -rf / |'.
> 
> > Wouldn't that now try to open
"http://www.mydomain.co.uk/rm+-rf+/+|"
> > and fail?
> 
> What if the arg was ';rm -rf / |' ?
> 
> --d

I got no idea!! 

All I wanted was a simple script that would let me replace a word in
an HTML file. I don't have SSI available so I wanted CGI to process
the page.

Strikes me that if Perl can't handle a simple task like that simply
then I might just as well use Javascript, at least client-side JS
can't delete your site.


Magic        ==|:o)
-- 
Location : Portsmouth, England, UK
Homepage : http://www.mattnet.freeserve.co.uk
EMail : mailto:Magic@mattnet.freeserve.co.uk


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

Date: 2 Jul 2000 14:19:55 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: DBI: Error inserting into dbf file
Message-Id: <8jnfhr$k5f$1@orpheus.gellyfish.com>

On Sat, 01 Jul 2000 20:04:14 GMT Kirill Sapelkin wrote:
> Hello !
> 
> I am trying to load an xbase dbf file with data from a "|" delimited
> text file.  I can insert specific values  like ('joe','moe') but I cannot
> figure out how to load from a text file.  I tried to imitate the example in DBI
> perldoc page to no avail.  Below are my efforts so far.
> 
> Grateful for any help or direction.
> 
> Kirill
> ********code
> #!/usr/bin/perl
> # This formats, recodes and writes to a text file
> use DBI;
> $dbh = DBI->connect("DBI:XBase:/usr/src/sbt");
> $sth = $dbh->prepare("insert into ar-custo ( custno ) values ( \@fields[0] )");
>  open(BOOKLIST, "fgcust.unl");
>   while(<BOOKLIST>) {
>   	 chop;
> 	 @fields = split(/\|/);
>     $sth->execute(@fields[0]);
>  	 }
> $dbh->disconnect();
> 
> *****************error messages
> Error Messages.
> 
> DBD::XBase::db prepare failed: Unknown SQL command near ` @fields[0] )' 
> at ./test.pl line 7.
> 
> Can't call method "execute" on an undefined value at ./test.pl line 12,
> <BOOKLIST> chunk 1.
> 

That really isnt how you want to do it - you want to use the placeholders
in the prepare :


#!/usr/bin/perl -w

use strict;

use DBI;



my $create_table = <<E01;
create table foo
(
  blah  char(10),
  woof  char(20),
  erk   char(20),
  zub   integer
)
E01

my $insert = <<E02;  
insert into foo
values (?,?,?,?)
E02

my $select = <<E03;
select * from foo
E03


my $dbh = DBI->connect('DBI:XBase:./test') or die $DBI::errstr;

my $sth = $dbh->prepare($create_table) or die $dbh->errstr;

$sth->execute or die $dbh->errstr;

$sth->finish;

$sth = $dbh->prepare($insert) or die $dbh->errstr;
  
while(<DATA>)
{
   chomp;
   my @data = split /\|/;

   $sth->execute(@data) or die $dbh->errstr;
}

$sth->finish;

$sth = $dbh->prepare($select) or die $dbh->errstr;

$sth->execute or die $dbh->errstr;

while (my $foo = $sth->fetch) 
{
   print "@{$foo}\n";
}

$sth->finish;

$dbh->do('drop table  foo') or die $dbh->errstr;

$dbh->disconnect ;

__END__
burble|woof|zub|1
carpark|woof|zub|1
gerbil|woof|zub|1
aardvark|woof|zub|1
cantata|woof|zub|1
herbert|woof|zub|1
apostrophe|woof|zub|1
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: Sun, 02 Jul 2000 11:31:02 GMT
From: VW Corrado <vwcorrado@my-deja.com>
Subject: Dealing with encrypted files/data
Message-Id: <8jn95n$k44$1@nnrp1.deja.com>

Hey all,

I am in the process of writing my first Perl program, and I need some
design help.  I have a flat file database with about 6 fields that I
want to process with a Perl/Tk program.  The problem is I don't want
everybody to just load up the data in a spreadsheet and send it to all
thier friends.  However, I am _not_ looking to use major encryption
(it's not Fort Knox) and lookup speed is the main thing.  I just want to
keep the honest people honest.

My current thought is to encrypt the data using something simple
(ROT13?) and then grep the data using an encrypted regexp.  This works
really, really fast, but I'm not sure its the best way:

 ...
  open (FILE, "grep -i \"$encryptedsearchterm\" data.csv |");
  while (<FILE>) {
    ...do someting...
  }
 ...

I tried using some of the DB-like things (Sprite, DBI::csv, etc.) but
they were not fast enough.  And besides, this program is read only, so
I don't need all the DB overhead.

Thanx for any help you can give me!

--
Later...
  Richard


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 2 Jul 2000 13:47:32 +0200
From: "RJ" <rjhuiting@hotmail.com>
Subject: E-mail form
Message-Id: <8jna8a$rsk$1@dinkel.civ.utwente.nl>

Hello,

I'm working on a e-mail form, and therefor I use a CGI/Perl script. In the
form that's been made in HTML, you can specifiy the recipient, just by
typing it in the HTML tags. But I would like it if the visitor of the
homepage could choose between a number of names and then the Perl script
would automatically see this name as the recipient.

Does anyone know how I can solve this problem?
I thank you in advance,

RJ




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

Date: Sun, 02 Jul 2000 13:43:05 GMT
From: asmith@hsonline.net (Andy Smith)
Subject: Re: foreach and hashes
Message-Id: <395f456a$0$1510$7bbe8f7d@news.hsonline.net>

On Sun, 02 Jul 2000 02:45:00 GMT, neil@brevity.org (Neil
Kandalgaonkar) wrote:

>In article <395ea196$0$1526$7bbe8f7d@news.hsonline.net>,
>Andy Smith <asmith@hsonline.net> wrote:
>
>>	foreach (@dirl) 
>>             {
>>	            if ($_ =~ /^(\w+)-HOWTO\.html$/) 
>>		{
>>	           	      %FileList  = ("$1" => "$_",);
>>		}
>>           	}
>>
>>When the foreach loop is done, the only key/value pair left in the
>>hash is the last on. 
>
>$FileList{$1} = $_;        # assign one element of a hash
>
>%FileList = ( $1 => $_ );  # assign the entire hash from a list
>
>
>
>-- 
>Neil Kandalgaonkar <neil@brevity.org>

Thank you! When I looked at the script this morning the problem became
ovious. Not the first time I have stared at a block of code for hours
to have someone else point out an obvious error the first time they
saw it :) 

Thanks again,
Andy



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

Date: 2 Jul 2000 13:05:02 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Golf problem
Message-Id: <962542623.2214@itz.pp.sci.fi>

In article <8jhmcg$5q0s$1@www.univie.ac.at>, Peter Marksteiner wrote:
>We can save one more stroke by using binary "or":
>
>perl -pe '$_=""if/(.).*\1/|11-length' /usr/dict/words

 ..and we can trade off that stroke to fix the Stravinsky problem:

perl -pe '$_=""if/(.).*\1/i|11-length' /usr/dict/words

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method."  -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.



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

Date: 2 Jul 2000 12:19:41 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: Help with Net::NNTP
Message-Id: <8jnc0t$m45$1@riva.ucam.org>

Ken <krobb7@NOhomeSPAM.com> wrote:
>$server = Net::NNTP->new("news");
>($narticles, $first, $last, $name) = $server->group("misc.test");
>$since = $server->date - (60*60*24*7);
>foreach (@{$server->newnews($since)}) {
>  # etc.
>}
>
>newnews ( SINCE [, GROUPS [, DISTRIBUTIONS ]])
>	`SINCE' is a time value. `GROUPS' is either a group pattern
>	or a reference to a list of group patterns. `DISTRIBUTIONS'
>	is either a distribution pattern or a reference to a list of
>	distribution patterns.
>
>	Returns a reference to a list which contains the message-ids
>	of all news posted after `SINCE', that are in a groups which
>	matched `GROUPS' and a distribution which matches `DISTRIBUTIONS'.
>
>$server->newnews($since) returns an undefined value. What format is the
>time supposed to be in? Seconds since 1970? I can't seem to figure it
>out.

It's of the sort that you would get from time() (so yes, seconds since
the epoch), since Net::NNTP internally does:

   my @g = reverse((gmtime($time))[0..5]);

(in sub _timestr).

However, the NEWNEWS command is often disabled by news administrators,
as it puts a lot of load on the server. Instead of your first command
above, try:

  $server = Net::NNTP->new("news", Debug => 1);

 ... and you'll get debugging information, which may well include
something like '502 NEWNEWS command disabled by administrator'.

-- 
Colin Watson                                     [cjw44@flatline.org.uk]
"But in your dreams, whatever they be / Dream a little dream of me."


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

Date: Sun, 02 Jul 2000 13:16:01 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: How do I pass command line switches in variable to a subroutine?
Message-Id: <MPG.13c9ddd63e58cdba989766@news>

Robert Chalmers writes ..
>I'm trying to get this little bit of code to only use the "-e" command line
>switch, but called from the subroutine call, &getwho()
>
>I can pass it the domain name, no problem, but I'm dashed if I can tell it
>to recognise that opt{e} is set to "-e"
>
>The command line would be:  $./whois.pl -e mydomain.com
>
>Could some kind soul give me  clue please?
>Thansk
>Robert
>...............................
>#!/usr/bin/perl
>use Getopt::Std ;
>use Net::XWhois;
>
>sub getwho (dom) {
>   getopts('neh:', \%opts);
>   my $whois = new Net::XWhois Domain => shift,
>                            Server => $opts{h};
>   if ( $opts{e} ) { my @emails = $whois->contact_emails; $" = ", "; print
>"Contacts: @emails\n";  exit }
>   if ( $opts{n} ) { my @emails = $whois->nameservers; $" = ", "; print
>"Nameservers: @emails\n";  exit }
>   print $whois->response;
>}
>
>#call to subroutine...
> &getwho('xxx.com');

I'm not sure if I understand your question .. but with the command line 
that you've specified .. and assuming that your shell is behaving itself 
and not doing something weird like gobbling the arguments - you code 
above will DEFINITELY get into the $opts{e} code .. ie. $opts{e} will be 
equal to 1

your problem might come from the fact that $opts{h} will be undefined 
because you have not specified a -h argument on the command line 
(something you would have known had you run the code with warnings on)

this means that $whois->contact_emails will probably be failing (again - 
silently)

run your code with the -w switch on the shebang line .. ie.

  #!/usr/bin/perl -w

also try using strict - it will also warn you about potential hazards in 
your code

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Sun, 2 Jul 2000 08:57:44 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how to get text enclosed by matching () ?
Message-Id: <slrn8luf28.a5i.tadmc@magna.metronet.com>

On Sun, 02 Jul 2000 07:54:21 GMT, Neil Kandalgaonkar <neil@brevity.org> wrote:
>In article <395EC33E.7E47CFE6@rochester.rr.com>,
>Bob Walton  <bwalton@rochester.rr.com> wrote:
>>RonR wrote:
>>> a line: "blabla bla (xyz, abc(n), xyz, abc(n)) etc etc"
>>> I want to get the list enclosed by the matching braces
>>> giving: "( xyz, abc(n), xyz, abc(n) )" or eventually without the braces.
>>> 
>>> Is there an easy way to do this ? The braces are always in pairs (if that
>                                                    ^^^^^^^^^^^^^^^
>
>>In general, you can't do this a single regular expression. 
>
>If 
>   1. the parens are known to be in pairs, and 
>   2. well-balanced (?),
>   3. and 'escaped' parens are not allowed, e.g. \)


   my $string = 'blabla bla (xyz, abc(n), xyz, abc(n)) etc (not me) etc';

I think that meets those 3 conditions.


>then surely:
>
>   ($in_parens) = ( $string =~ /(\(.*\))/ );


matches '(xyz, abc(n), xyz, abc(n)) etc (not me)'


>works?


Apparently not...


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


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

Date: Sun, 02 Jul 2000 11:27:54 GMT
From: st95lzd@my-deja.com
Subject: Re: How to open a FIFO created with C in perl?
Message-Id: <8jn8vl$jr6$1@nnrp1.deja.com>

In article <%sJ55.244$iP2.31710@news.dircon.co.uk>,
  Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> On Mon, 26 Jun 2000 13:20:14 GMT, st95lzd@21cn.com Wrote:
> > I created a FIFO(readFIFO) to read data from script.
> > Script was writen by perl,How can i send data to FIFO?
> >
>
> <snip irrelevant rewrite of mkfifo in C>
>
> >
> > exam.pl
> > #!/usr/bin/perl
> > open(LOG,"|readFIFO") || die("error!!!!!!!!!!!");
>
> Er, should that be :
>
>   open(LOG,">readFIFO") || die "Cant open fifo - $!\n";
>
> > print LOG "123456\n";
> > close(LOG);
> > exit;
> >
> >
> > It seemes that the function open() can't open a FIFO
> > In which way,can i send string "123456" to the FIFO?
> > that is printf the 123456 on the STDOUT.
> > Please post in detail,better with source code.
> > Thanks!!
> >
>
> You were opening your fifo as if it were an executable you wanted to
pipe
> to - a fifo appears largely as a normal file to your program.
>
> /J\
>

fifo can't look as a normal file,
when i change my program with
open(LOG,">readFIFO") || die "Cant open fifo - $!\n";
for the first time,the STDOUT really output the string "123456"
then i runned "ls -a read*",i found that the readFIFO file had
not a zero file and i runned the perl program again(the C program
runned in backgroup),the STDOUT output nothing.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 2 Jul 2000 12:55:17 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: insert non-ascii character through DBD-Oracle
Message-Id: <8jnaj5$3rh$1@orpheus.gellyfish.com>

On Sun, 02 Jul 2000 06:26:57 GMT dwang999@my-deja.com wrote:
> 
> Does DBD-Oracle support non-ascii chars? How do I solve this problem?
> 

I dont see any reason why it should DBD::Informix DBD::Mysql and DBD::Pg
all do - you should probably try using a '?' placeholder / and or the
DBI::quote method ...

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: 2 Jul 2000 15:52:45 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Interchage the role of key and value in a hash
Message-Id: <8jnkvt$6dh$1@orpheus.gellyfish.com>

On Sat, 1 Jul 2000 18:33:51 +0800 multiplexor wrote:
> I have a hash:
> 
> %entity = ('&' , '&amp;' , '>' , '&gt;');
> 
> What is the best way to make a hash like the followings?
> 
> %code =  ('&amp;' , '&' , '&gt;' , '>');
> 
> That is, interchange the role of the keys and values of %entity.
> 
> I think of using a foreach loop:
> 
> foreach (keys %entity) {
>     %code($entity($_)) = $_
> }
> 

Thats one way of doing it, as is the way that Tad suggested, you might
also want to look at the code for the module HTML::Entities (actually
you might consider using the module itself as it has a more complete set of
the entities ...) :

   # Make the oposite mapping
   while (my($entity, $char) = each(%entity2char)) {
       $char2entity{$char} = "&$entity;";
   }


/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: Sun, 02 Jul 2000 12:50:22 +0200
From: ekke vasli <ekke@chamber.ee>
Subject: Re: Is this code dangerous? eval{$$_ = $q->param($_)}
Message-Id: <395F1E6E.27D86BAD@chamber.ee>

> ###
>     use CGI;
>     $q = new CGI;
>
>     @form_field = qw/name email/;
>     foreach (@form_field) {
>         eval{$$_ = $q->param($_)}
>     }
> ###

> That's why I can't find any security hole when someone type any dangerous
> comand. Can you comment on this code?

Shouldn't be dangerous as far as you don't mess up with the variables eg. use
something like:

 ...
    @form_field = qw/name email ok/;
    foreach (@form_field) {
        eval{$$_ = $q->param($_)}
    }
    &doostuff if $ok; # let's say this is the last time when you know you use
the $ok value given from user..

    sub doostuff {
     #somehow the programmer may just forget the my $ok; here..
     #do lot of stuff here and forget about $ok meantime..
     $ok=1 if &some_sub_that_returns_false;     #$ok keeps the value of user's
input
     &authorize if $ok;             #you see...
    }
now this is unlikely but i've seen it happen...
so, it's not totaly safe to use variables named by cgi params (especially if
it's a large script)
but i'd advice to use
$FORM{$_} = $q->param($_)


-ekke




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

Date: Sun, 2 Jul 2000 09:47:36 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Is this code dangerous? eval{$$_ = $q->param($_)}
Message-Id: <slrn8luhvo.a5i.tadmc@magna.metronet.com>

On Sun, 2 Jul 2000 16:15:36 +0800, multiplexor <abuse@localhost> wrote:

>I am a newbie of Unix and security. 


Have you typed:

   perldoc perlsec

?


> I read a CGI faq that exposing client
>data to shell is dangerous because one may type "rm -fr", sth like that.
>However, I don't know if the following kind of eval is dangerous.

>###
>    use CGI;
>    $q = new CGI;
>
>    @form_field = qw/name email/;
>    foreach (@form_field) {
>        eval{$$_ = $q->param($_)}
              ^^^


"Symbolic references" are disallowed under "use strict;".

This is a Good Thing, because symrefs are a Bad Thing:

   http://www.plover.com/~mjd/perl/varvarname.html
   http://www.plover.com/~mjd/perl/varvarname2.html
   http://www.plover.com/~mjd/perl/varvarname3.html



If your CGI program does not start off with:

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

Then you are asking for trouble...


>As I understand it, what the foreach loop do is equivalent to the following:
>
>$name = $q->param(name);
>$email = $q->param(email);


Use a hash instead of symrefs:

foreach (@form_field) {
   $hash{$_} = $q->param($_);  # no scary eval()
}

So you get the below instead:

$hash{name} = $q->param('name');  # no scary Symbol Table manipulation


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


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

Date: Sun, 02 Jul 2000 14:31:42 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: newbie with a big problem
Message-Id: <39604da3.2002620@news.skynet.be>

KCMage wrote:

>The CGI itself runs well in UNIX from the
>command line with no errors (Well, a few, but I've put #s infront of all the
>trouble spots, so I'll fix those later). My main concern is the fact that the
>CGI refuses to run from a browser standpoint. It keeps giving me an "Internal
>Server Error" of 500, which means the script isn't running right.

That usually means that you have a permissions problem.

Is the permission for the file you're writing to, set to "write enable
for all"? As a CGI script, you'll need that.

Here:

>open(OUTF,">>main.pbs") or dienice();

and the definition for sub dienice is commented out. Hmmm... BTW you
should say why it died, and include $! in your message.

>P.S. Its quite large..if anyone can help me make the damn thing smaller, that'd
>be appreciated also. =)

You have lot's of print statments. Better use a "here doc", using the
"<<" syntax. You'll get far better readable output generating code.
Example:

>        unless ($FORM{'Email'} =~ /\w+@\w+.\w+/) {

(Oh BTW this regex sux. It's not anchored, and if it is, it won't allow
email addresses like mine, or from Britisch people: <@somewhere.co.uk>.

This is a FAQ; check Dejanews or similar for pretty recent discussions
in this newsgroup. I think RFC::RFC822 is an easy and more reliable
answer. One or more of the other email related modules also contain
email address parsers.

>                print "Content-type: text/html\n\n";
>                print "<html><head><title>Bad E-mail</title></head>\n";
>                print "<body><h1>Bad E-mail</h1><br>The e-mail address that
>you've\n";
>                print "entered, $FORM{'Email'}, is invalid.  Please click back
>and\n";
>                print "try again.\n";
>		print "</body></html>\n"
>                exit;
>        }
>}

My version:

                print <<'#EOT#';
Content-type: text/html

<html><head><title>Bad E-mail</title></head>
<body><h1>Bad E-mail</h1><br>The e-mail address that you've
entered, $FORM{'Email'}, is invalid.  Please click back and
try again.
</body></html>
#EOT#
	
And this:

>#Info about person
>print OUTF "$FORM{'last'}|$FORM{'first'}|$FORM{'middle'}|$FORM{'Email'}|";
>#Home phone number
>print OUTF "$FORM{'AreaCode'}-$FORM{'Prefix'}-$FORM{'Suffix'}|";
>#Work phone number
>print OUTF "$FORM{'WAreaCode'}-$FORM{'WPrefix'}-$FORM{'WSuffix'}|";
>#Info about address
>print OUTF "$FORM{'Address_Line1'}|$FORM{'apt'}|$FORM{'Suite'}|";
>#Info about area
>print OUTF "$FORM{'City'}|$FORM{'State'}|$FORM{'Prov'}|$FORM{'Zip'}|";

First of all, what will you do if one of the form fields contains a "|"?

And second, here's what I'd make of it:

	{
	   local($\, $,, $") = ("\n", "|", "-");
	   print OUTF @FORM{qw(last first middle Email)},
             "@FORM{qw(AreaCode Prefix Suffix)}";
             "@FORM{qw(WAreaCode WPrefix WSuffix)}";
	     @FORM{qw(Address_Line1 apt Suite
	       City State Prov Zip)};
	}

One you fgure out what to do with any embedded "|" characters, or
newlines for that matter, you can apply this to each by using a 

	map { ... }

between the "print OUTF" and the actual list to print.

-- 
	Bart.


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

Date: Sun, 02 Jul 2000 14:40:29 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Perl Subroutines - some help required
Message-Id: <39615295.3268861@news.skynet.be>

anuragmenon@my-deja.com wrote:

>I am used to the traditional parameter passing
>routines and when I look up documentation surprisingly they are all the
>SAME and I dont get it. I guess I am a little thick at the moment but
>cant help it!
>
>This is what I want to do
>
>1. Pass a string to a subroutine: How do I pass the parameter?

Your problem isn't the string passing. That is the same as in other
languages.

Your problem is: how to GET at the parameter(s) inside the sub. Well:
Perl uses anonymous parameter passing, in the array @_, and they are
passed by reference. BTW all arguments are scalars, or each array item
will look as if it was a separate parameter!

Compare:

VB:	Sub mysub (byval x as string, byval y as integer)

Perl:
	sub mysub {
	# $x is in $_[0], $y in $_[1]

This is the usual next step, but it ain't necessary:

	my($x, $y) = @_;

This will make a COPY of $_[0] and store it into $x, and idem dito with
$_[1] into $y. So now, it looks as if the parameters are passed by
value.

One practical example:

	sub test {
	    my($string) = @_;
	       # alternative, use shift() to get the first scalar of @_
	    print "<$string>\n";
	}

	test("Hi there!");

-- 
	Bart.


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

Date: 2 Jul 2000 14:54:09 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Q: What happens if a 'path' had a space in it?
Message-Id: <8jnhi1$qph$1@orpheus.gellyfish.com>

On Fri, 30 Jun 2000 12:03:29 -0400 Allan M. Due wrote:
> 
> <manchester_united@my-deja.com> wrote in message
> news:8jib8h$9na$1@nnrp1.deja.com...
> : In article <cxcem5fgt2w.fsf@masterblaster.uio.no>,
> :   jacklam@math.uio.no (Peter J. Acklam) wrote:
> : > manchester_united@my-deja.com writes:
> : > Exactly what code are you using?  Are you using something like
> : >    $file = "c:\Program Files\test.txt";
> : > If so, it won't work as expected.
> :
> : Specifically, I'm trying to use the 'glob' command, so, using the above
> : $file, try something like:-
> :
> : @array = glob ($file);
> :
> : It will not return the files and folders of Program Files, no matter
> : what permutations of back-slashes and forward-slashes I've tried.
> 
> Are you sure the test.txt is in the Program Files directory?
> 
> under 5.6 this works for me
> 
> $name = 'c:\progra~1\test.txt';
> @array = glob($name);
> $"="\n";
> print "@array";
> 
> but it perl doesn't seem to like long file names in the glob, even though
> 

This is because it splits the argument into words so you can do :

  glob("foo bar")  

Where foo and bar are two separate patterns - however you can protect
it from being split by putting single quotes around your pattern :

  my $pattern = q{'Program Files/*'};

  my @files = glob($pattern);
  
  print "@files";

works fine for me (but hey this is Linux so maybe it wont on windows :).

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: 2 Jul 2000 11:45:11 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Quick "Perl Way" solution needed
Message-Id: <962537962.23086@itz.pp.sci.fi>

In article <3953C366.EEB592B1@orbital.com>, J Church wrote:
>I want to print the numbers in the last field in such a way
>that each sequence of consecutive numbers are considered
>seperate ranges, and are the only values extracted.

Lots of good ways have already been posted, here's one more.
Pretty-printing is left as an exercise to the reader.

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

my %scans;
@scans{map /scan (\d+)/ => <DATA>} = ();
for (sort {$a <=> $b} keys %scans) {
    print "$_ .. " unless exists $scans{$_ - 1};
    print "$_\n"   unless exists $scans{$_ + 1};
}

__DATA__
-W- getl0scene_nav.c: bad navigation at scan 688
-W- getl0scene_nav.c: bad navigation at scan 689
-W- getl0scene_nav.c: bad navigation at scan 690
-W- getl0scene_nav.c: bad navigation at scan 691
-W- getl0scene_nav.c: bad navigation at scan 692
-W- getl0scene_nav.c: bad navigation at scan 1039
-W- getl0scene_nav.c: bad navigation at scan 1040
-W- getl0scene_nav.c: bad navigation at scan 1041
-W- getl0scene_nav.c: bad navigation at scan 1042
-W- getl0scene_nav.c: bad navigation at scan 1635
-W- getl0scene_nav.c: bad navigation at scan 1636
-W- getl0scene_nav.c: bad navigation at scan 1637
-W- getl0scene_nav.c: bad navigation at scan 1638

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method."  -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.



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

Date: 2 Jul 2000 15:07:08 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: referencing with cgi
Message-Id: <8jniac$t9g$1@orpheus.gellyfish.com>

On 30 Jun 2000 12:48:50 -0500 Tony Curtis wrote:
>>> On Fri, 30 Jun 2000 15:38:17 GMT,
>>> jinrai@my-deja.com said:
> 
>> Is there a way to retrieve the values of variables in a
>> cgi-script from another cgi-script?
> 
> Yes, if there exists a communication path between the
> processes.
> 
> I'd go over to comp.infosystems.www.authoring.cgi as your
> question is about CGI, and has nothing to do with perl per
> se.

Well possibly but if the OP were to rephrase this as :

  'Is there a way that one program can retrieve the values of
   variables in another program that may be executed aynchronously to it'

then hey we could be talking named pipes, shared memory, CORBA, and all 
sorts of things but as the OP hasnt properly explained what is actually
wanted then there isnt much more that we can say ...

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: 2 Jul 2000 13:19:26 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: shell into Perl
Message-Id: <8jnc0e$8gv$1@orpheus.gellyfish.com>

On 1 Jul 2000 22:26:49 -0400 The National Folk Hero of the Net wrote:
> I recently posted this to comp.lang.perl.modules by mistake:
> 
> According to the man page PERLRUN(1), a good way to run a Perl script
> without a working autoexec line is:
> 
> 	eval 'exec /usr/bin/perl $0 ${1+"$@"}'
> 		if $running_under_some_shell;
> 
> I've been using this, which is shorter:
> 
> 	"false" || eval 'exec /usr/bin/perl $0 ${1+"$@"}';
> 
> It works fine for ksh, which is all I ever run it with.
> Are there any common shells for which it will not work?

Works for bash, tcsh, ash, pdksh and wish so I guess it works most places.

/J\
-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: 2 Jul 2000 14:02:28 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: using @_ with subs (Just a quickie from a Perl Wannabe :)
Message-Id: <8jneh4$gq0$1@orpheus.gellyfish.com>

On Fri, 30 Jun 2000 15:13:32 +1000 Geoff Toogood wrote:
> Hi All,
> 
> CURRENT SYSTEM = x86 200mhz / 60mb RAM / Active PERL 5.6 & WIN98
> 
> I am using the @_ function in my code to pass variables to my subroutine.
> 
> ########
> open (FILE, '>>file.txt') || &error("CANT OPEN FILE");
> sub error {
> ($string) = @_;
> print "ERROR: $string";
> }
> ########
> 
> Yet when I use this method for more than one subroutine in the same script,
> I get a nasty "WINBLOWS ILLEGAL OPERATION  ERROR" 
> 

I very much doubt that the multiple use of @_ is causing the Page Fault
though anything is possible - I would suggest that you do cause your
$string to be local to the subroutine with 'my' but I dont think that this
is the root cause of your problem.

I would suggest you try running the program with no other applications
running on the machine and then make the smallest program that still causes
the problem and if you can get it to happen consistently then perhaps you
should report it as a bug to activestate <http://bugs.activestate.com> but
it could just as easily be a problem with some bum DLL that another
application has installed ...

/J\

-- 
** This space reserved for venue sponsor for yapc::Europe **
              <http://www.yapc.org/Europe/> 


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

Date: Sun, 02 Jul 2000 14:42:49 +0100
From: Magic <Magic@mattnet.freeserve.co.uk>
Subject: Welcome to....
Message-Id: <j7hulsgvrjs2o5f7j8n99l6k8h0b6asasf@4ax.com>

comp.lang.perl.lets-make-life-as-difficult-as-possible

Thought you might be interested to read what I have found by reading
this group....

	Although the people in it have good intentions and are willing to
help, they are so concerned with the complicated things about the
language that in order to answer a simple quastion they seem to think
reading a 140+ page document is required.

	Perl is a dangerous language to attempt to learn because one wrong
move and you erase all your files, plus probably several other peoples
in the process.

	There's no such thing as a simple answer to a simple problem.

	If you're using Perl the word "Security" is synonymous with the
words "Practical Joke".

Have fun people, I think I should have gone with my first insting and
stuck to searching on www.dogpile.com



Magic        ==|:o)
-- 
Location : Portsmouth, England, UK
Homepage : http://www.mattnet.freeserve.co.uk
EMail : mailto:Magic@mattnet.freeserve.co.uk


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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


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


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