[17983] in Perl-Users-Digest
Perl-Users Digest, Issue: 143 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 25 14:57:59 2001
Date: Thu, 25 Jan 2001 11:10:18 -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: <980449817-v10-i143@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 25 Jan 2001 Volume: 10 Number: 143
Today's topics:
Possible to UNset a Cookie? <scarroll@sci-design.com>
Re: Possible to UNset a Cookie? (Abigail)
Printing output to a specific print driver lbieg@my-deja.com
Re: Reading from named pipes <Jerome.Abela@free.fr>
REQ: help about tainting in regex <samuele@null.net>
Re: Split string into two arrays (Greg Bacon)
Re: Split string into two arrays (Chris Fedde)
Re: Split string into two arrays gwooddeja@my-deja.com
Re: sprint replaces spaces with tabs in my text nelsonjames@my-deja.com
Re: String comparing? (Mark Jason Dominus)
Re: Type globs <mjcarman@home.com>
Re: unexplained warning ? <Jerome.Abela@free.fr>
Re: unexplained warning ? <joe+usenet@sunstarsys.com>
Re: unexplained warning ? <tore@extend.no>
Re: unexplained warning ? (Mark Jason Dominus)
Re: Using perl to ftp files <randy.galbraith@pegs.com>
What's wrong with this script? <kkk@elrancho.com>
wincvs.org offline? <randy.galbraith@pegs.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 25 Jan 2001 17:30:19 -0000
From: Stuart Carroll <scarroll@sci-design.com>
Subject: Possible to UNset a Cookie?
Message-Id: <t70olbbc8dq275@corp.supernews.com>
I've figured out how to set a cookie, and retreive it - but is it possible
to UNset the cookie?
The script sets a cookie when the user logs in, not a permanent one, just
in RAM, and I want to be able to erase/delete/disable that cookie when the
user logs out. I know the cookie will disappear when the user closes their
browser, but I'd like to be able to get rid of it when they leave the site.
I'm using:
print "Set-Cookie:userid=$userid\n";
to set the cookie. Way simple. And parsing the $ENV var to check for it.
Thanks,
Stuart Carroll
scarroll@sci-design.com
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: 25 Jan 2001 17:43:12 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Possible to UNset a Cookie?
Message-Id: <slrn970pdg.pq7.abigail@tsathoggua.rlyeh.net>
Stuart Carroll (scarroll@sci-design.com) wrote on MMDCCIV September
MCMXCIII in <URL:news:t70olbbc8dq275@corp.supernews.com>:
,, I've figured out how to set a cookie, and retreive it - but is it possible
,, to UNset the cookie?
And what is your excuse to post such an off-topic question in this group?
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
------------------------------
Date: Thu, 25 Jan 2001 16:37:01 GMT
From: lbieg@my-deja.com
Subject: Printing output to a specific print driver
Message-Id: <94pknc$kt2$1@nnrp1.deja.com>
Does anyone know of a way to print output to a specific print driver?
I am trying to generate PDF files from a postscript source file using
Acrobat PrintWriter from Perl on NT.
Thanks!
Loren
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 25 Jan 2001 17:53:17 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: Reading from named pipes
Message-Id: <3A706712.4192AC4B@free.fr>
Richard J Bragg wrote:
> [ failed attempts ]
>
> Is there a method of checking the pipe for data?
This is a faq: "How can I tell whether there's a character waiting on a
filehandle?".
perldoc -q 'character waiting'
> searching perl.com and cpan.org find things that are close but no cigar.
Searching the FAQ is a good idea, too.
Jerome.
------------------------------
Date: Thu, 25 Jan 2001 18:44:18 +0100
From: Samuele Manfrin <samuele@null.net>
Subject: REQ: help about tainting in regex
Message-Id: <3A7065F2.377C2B12@null.net>
Hello,
I have a problem that I cannot solve, related to tainting in regexp. I'm
writing a sw that implements a recursive descent parser for LL(1)
grammars with actions (I think that this will be of interest for a *lot*
of people eheh), but I've found a problem that I cannot solve: it seems
that if tainting is activated, the "g" action in regexp does not works
correctly. This is a snipped example, "taintest.pl", invoked with
"taintest.pl 'area=S::=A{emit(`ls -la`)} A::=b' 'req=b'"
#!/usr/bin/perl -T
# --- part 1 ---
push(@in,@ARGV);
foreach $i (0 .. $#in) {
($key, $val) = split(/=/,$in[$i],2);
# <...snip...>
$in{$key} = $val;
}
# --- end of part 1 ---
# if you use the following line in place of "part 1" above, it works!
# $in{area} = 'S::=A{emit(`ls -la`)} A::=b';
# ----
# but here this b...rd enters in an infinite loop if taint is on
while( $in{area} =~ /([A-Z])::=(.+?)(?=([A-Z]::=|$))/sg ) {
$in{$1}="$2";
# print for debug
print "$1 is equal to $2\n"; }
Just FYI, the regexp explores user's grammar productions, coming from a
<textarea></textarea> tags, e.g.
S::=aA{#a=A1.s+1; S.s=#a; emit("String is #a chars long")}
A::=xA{A.s=A1.s+1} | @{A.s=0}
An action is enclosed in brackets, vars begin with "#", epsilon is "@"
Does someone knows what's wrong? I've deeply read the whole camel book,
the owl book and (I think) all the perldoc documentation about security
and tainting, but I've found no answers. My last hope is in newsgroup
gurus...
Thank you
Samuele - Pisa, Italy
------------------------------
Date: Thu, 25 Jan 2001 16:08:19 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Split string into two arrays
Message-Id: <t70jrjs0lhdua3@corp.supernews.com>
In article <94phtg$i52$1@nnrp1.deja.com>,
<scottpa@my-deja.com> wrote:
: I wonder if anyone could check my code and see if it could be more
: compact. I need to break the following string up into two arrays @parm
: and @type and I wondered if there was a tidier way of doing it?
:
: $_='charparm string dateparm datetime intparm number';
:
: $parm=1;
: foreach $item (@arguments)
: {
: if ($parm) {
: $parm=0;
: push (@parms, $item);
: }
: else {
: $parm=1;
: push (@type, $item);
: }
: }
#! /usr/local/bin/perl -w
use strict;
$_ = 'charparm string dateparm datetime intparm number';
my @parms;
my @type;
{
my @tmp = split;
while (@tmp) {
push @parms => shift @tmp;
push @type => shift @tmp;
}
local $" = "][";
print "\@parms = [@parms]\n",
"\@type = [@type]\n";
}
Enjoy,
Greg
--
Irrationality is the square root of all evil.
-- Douglas Hofstadter
------------------------------
Date: Thu, 25 Jan 2001 16:16:13 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Split string into two arrays
Message-Id: <hjYb6.1303$B9.194910720@news.frii.net>
In article <94phtg$i52$1@nnrp1.deja.com>, <scottpa@my-deja.com> wrote:
>I wonder if anyone could check my code and see if it could be more
>compact. I need to break the following string up into two arrays @parm
>and @type and I wondered if there was a tidier way of doing it?
>
>$_='charparm string dateparm datetime intparm number';
>
>$parm=1;
>foreach $item (@arguments)
>{
> if ($parm) {
> $parm=0;
> push (@parms, $item);
> }
> else {
> $parm=1;
> push (@type, $item);
> }
>}
>
>
>OUTPUT:
>Parm: charparm dateparm intparm
>Type: string datetime number
>
Even and odd arrays?
my @arguments =
split ' ','charparm string dateparm datetime intparm number';
my @parm;
my @type;
@X = ( \@parm, \@type );
for (0..$#arguments) {
push @{$X[$_%2]}, $arguments[$_];
}
print "Parm: ",join(' ',(@parm)),"\n";
print "Type: ",join(' ',(@type)),"\n";
ymmv
chris
--
This space intentionally left blank
------------------------------
Date: Thu, 25 Jan 2001 16:28:46 GMT
From: gwooddeja@my-deja.com
Subject: Re: Split string into two arrays
Message-Id: <94pk7g$kim$1@nnrp1.deja.com>
Use a hash to save parm/type pairs straight from the string:
%parmtype=split(' ',$_);
You may not need 2 arrays at all but if you do you can then do:
@parms=keys(%parmtype);
@types=values(%parmtype);
see perldoc perldata for details of what a hash is and why you might
want to use one.
Graham Wood
In article <94phtg$i52$1@nnrp1.deja.com>,
scottpa@my-deja.com wrote:
> I wonder if anyone could check my code and see if it could be more
> compact. I need to break the following string up into two arrays @parm
> and @type and I wondered if there was a tidier way of doing it?
>
> $_='charparm string dateparm datetime intparm number';
>
> $parm=1;
> foreach $item (@arguments)
> {
> if ($parm) {
> $parm=0;
> push (@parms, $item);
> }
> else {
> $parm=1;
> push (@type, $item);
> }
> }
>
> OUTPUT:
> Parm: charparm dateparm intparm
> Type: string datetime number
>
> Thanks for your time,
> Alan
>
> Sent via Deja.com
> http://www.deja.com/
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 25 Jan 2001 16:09:22 GMT
From: nelsonjames@my-deja.com
Subject: Re: sprint replaces spaces with tabs in my text
Message-Id: <94pj39$jb8$1@nnrp1.deja.com>
Thank you all!
Your use of two unusual character combinations helps too.
Just about every character is used at least once in the two
files I'm processing.
(The big file is over 16Mb and has the long lines).
I appreciate the style and technique comments - I only program
in perl intermittently. (UNIX shell programming more.)
It would be nice if wrap left the spaces as spaces.
In article <Xns903480E16wyzelliyahoocom@203.39.3.131>,
wyzelli@yahoo.com (Wyzelli) wrote:
> nelsonjames@my-deja.com wrote in <94nlvh$11u$1@nnrp1.deja.com>:
>
> >I hope someone knows how to preserve the oringinal
> >spaces in this problem.
> >
> >When I cat my test file into this script, some of the
> >multiple spaces become tab(s). The concept of the
> >file inputed is a prefix of up to 16 chars with spaces
> >padding out whats left, then a wrapped line of text.
> >(The text can be very long.)
> >
> >#!/usr/bin/perl -w
> ># mywrap jnelson@medar.com
> >
> >use Text::Wrap;
> >
> >while (defined($EACH= <STDIN>)){
> > $VARR=sprintf "%-16.16s", $EACH;
> > $EACH=~ s/................//;
> > $EACH=~ s/\,/\,\ /g;
> > $EACH=~ s/\ \ */\ /g;
> > print wrap("$VARR", "$VARR", "$EACH");
> > printf "%s\n", $VARR ;
> >};
> >
> >I piped the output to "od -c" to verify that
> >indeed, tabs were added that were not there
> >before.
> >
>
> The problem is coming from wrap in Text::Wrap. I made the following
> modifications which seems to solve the problem.
>
> #!/usr/bin/perl -w
> # mywrap jnelson@medar.com
> use strict;
>
> use Text::Wrap;
>
> while (defined(my $each= <DATA>)){
> my $varr = substr $each,0,16;
> $varr =~ s/ /#&/g;
> $each = substr $each,16;
> $each=~ s/,/, /g;
> $each=~ tr/ / /s;
> my $string = wrap("$varr", "$varr", "$each");
> $string =~ s/#&/ /g;
> $varr =~ s/#&/ /g;
> print $string;
> printf "%s\n", $varr;
> };
>
> __END__
> 000-0000 ENGINEERING ASSISTANCE REQ'D;; THIS IS A LONNNNNNNG
LINE WHICH
> SHOULD WRAP TEST DRAWING #FIELD 0
> 000-00000000 MFG/ENG/OFFICE
EXPENSEDSUP; 0
> 000-00000000 PORT ITEMS;;
> 000-0000X
DUMMYITEM 0
> 000-0001 FLOPPY DISK-
DSDD360KB;; 6
> 000-0002 14 7/8 X 11 1412TC
GREENBAR 24
> 000-0002 WILLAMETTE #141107
> 000-0003 9 1/2 X 11 9510AJ
WHTCONTINUE 3
>
> Note I also changed the variable names to lower case in accordance
with
> my preference and perlstyle. You may want to read up on
transliteration
> (tr///) and substr.
>
> Also added strict and scoped variables.
>
> HTH
>
> Wyzelli
> --
> #beer v2
> ($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down,
pass it
> around');
> for(reverse(1..100)){$s=($_!
=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
> $_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 25 Jan 2001 18:54:48 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: String comparing?
Message-Id: <3a707678.1903$32f@news.op.net>
In article <94pbc5$poi$1@news.kolumbus.fi>,
wavetable <wavetable@birdmail.com> wrote:
>Is it possible to compare two strings with functions like "contains",
>"starts with", "ends with"?
if (index($haystack, $needle) >= 0) {
# haystack contains needle
}
if (index($haystack, $needle) == 0) {
# haystack starts with needle
}
if (rindex($haystack, $needle) == length($haystack) - length($needle)) {
# haystack ends with needle
}
Now you should look int the on-line documentation for 'index' and
'rindex' and find out what they do.
> (the line contains the line change character,right?).
Normally it does, yes. You may use the 'chomp' function to remove it
if you want.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Thu, 25 Jan 2001 08:53:46 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Type globs
Message-Id: <3A703DFA.9E25FF9C@home.com>
CM wrote:
>
> While aliasing a list into a subroutine I get problems when I
> use 'my' but works allright with 'local'
>
> @foo = ("here's", "a", "list");
> &testsub (*foo);
>
> sub testsub
> {
> local (*printarray) = @_; # THIS DOES NOT WORK IF
> # IF REPLACED BY
> # my (*printarray) = @_;
>
> foreach $element (@printarray)
> {
> print ("$element\n");
> }
>
> }
Tad has already responded to the diagnostic, but I'm wondering why
you're passing a glob? Is there a reason you can pass a normal array or
a reference?
-mjc
------------------------------
Date: Thu, 25 Jan 2001 16:05:52 GMT
From: Jerome Abela <Jerome.Abela@free.fr>
Subject: Re: unexplained warning ?
Message-Id: <3A704DE8.81DB4DDB@free.fr>
Edward D'Flea wrote:
> 35 while (chop($line = <MODULE_MAKEFILE>)) {
> Use of uninitialized value at ./depend3b.pl line 35, <MODULE_MAKEFILE>
You chop() the $line before testing whether it's defined or not. So, at
each EOF on MODULE_MAKEFILE, you get a warning. You should chop() inside
the while, where you know $line is a valid value.
Jerome.
------------------------------
Date: 25 Jan 2001 11:06:19 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: unexplained warning ?
Message-Id: <m3snm7pqf8.fsf@mumonkan.sunstarsys.com>
Edward D'Flea <strawman@plexi.com> writes:
> 35 while (chop($line = <MODULE_MAKEFILE>)) {
Change this to
while (<MODULE_MAKEFILE>) {
chomp( $line = $_ );
I think your original is trying to chop an EOF, which is causing
the warning.
HTH
--
Joe Schaefer
------------------------------
Date: Thu, 25 Jan 2001 18:20:08 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: unexplained warning ?
Message-Id: <MPG.14da7eb7784273e3989862@news.online.no>
In article <3A70458D.EB383D0B@plexi.com>, strawman@plexi.com says...
> 35 while (chop($line = <MODULE_MAKEFILE>)) {
> 36
> 37 if (($line =~ /USES =/) || ($line =~ /REQUIRES =/))
Don't 'chop()' directly; move the 'chop()' inside the 'while'-loop.
You should also consider using 'chomp()' instead of 'chop()';
while (my $line = <MODULE_MAKEFILE>) {
chomp($line);
if ( $line =~ /^[USES|REQUIRES]/ ) {
...
}
}
--
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/
------------------------------
Date: Thu, 25 Jan 2001 18:59:01 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: unexplained warning ?
Message-Id: <3a707774.1919$2dc@news.op.net>
Keywords: bianco, brought, pang, peep
In article <3A70458D.EB383D0B@plexi.com>,
Edward D'Flea <strawman@plexi.com> wrote:
> 35 while (chop($line = <MODULE_MAKEFILE>)) {
Other people have exaplined the real problem, but it may also be worth
pointing out that this will fail if the last line of the file ends
with a '0' character instead of a newline. In that case, $line will
be something like '1234567890', and 'chop' will remove the '0'
character and return it to 'while'. While will interpret the '0' as
'false', and the final line of the file will not be processed.
This sort of problem is the reason that it is almost always correct to
use 'chomp' instead of 'chop'.
>Can anybody out there answer this one. Forgive me if this is a
>fundamental question.
It was an excellent question. Thanks for posting.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Thu, 25 Jan 2001 10:58:47 -0700
From: "Randy Galbraith" <randy.galbraith@pegs.com>
Subject: Re: Using perl to ftp files
Message-Id: <94ppgf$cir$1@freepress.anasazi.com>
Pularis,
I've had great success with Net::FTP
my $ftp;
$ftp = Net::FTP->new($host);
$ftp->login($user, $passwd);
$ftp->binary;
$ftp->put($file_name);
$ftp->quit;
Of course, you will probably want to use eval { } in order to trap errors,
like this...
eval { $ftp = Net::FTP->new($host); }
if (( $@ ) || (!defined($ftp)))
{
warn $@;
# FTP connect has problems...
}
Also, if you run into problems, it can be handy to set the Debug flag, like
this...
$ftp = Net::FTP->new($host, Debug => 1);
Enjoy.
- Randy Galbraith
pularis@my-deja.com wrote in message <940d93$lnb$1@nnrp1.deja.com>...
>Greetings,
> How can I use perl to establish a ftp connection, change directory
>and then put a file on a remote host. I am using a unix machine as the
>sender and a NT server running ftp is the recepient. thanks a much
>
>
>Sent via Deja.com
>http://www.deja.com/
------------------------------
Date: Thu, 25 Jan 2001 20:12:11 +0200
From: "Dan" <kkk@elrancho.com>
Subject: What's wrong with this script?
Message-Id: <94pq50$a5e$1@news.kolumbus.fi>
Could someone please tell me what's wrong with the following script? It's
supposed to add two lines to a file, first the parameter "i" and then the
popup menu's value. Instead it adds a couple of extra empty lines, or if I
remove the linebreak it first writes the parameter and the popup menu's
value when I click submit. After that it only adds the popup menu's value.
I'm totally confused here. I'd be grateful for any help.
#!/usr/local/bin/perl
print ("Content-type: text/html\n\n");
use CGI qw(:standard);
my $c = new CGI;
### READ PARAMETER i ###
if($c->param())
{
$id = $c->param('i');
}
print header;
print start_html('wavetable.net - add plugin');
print (start_form,
"Rating: ",
popup_menu(-name=>'ratenr',
-values=>['5','4','3','2','1']),
submit,
end_form);
if (param()) {
open(OUT,">>ratings.dbn") || die "cannot open ratings.dbn";
print OUT "$id\n", param('ratenr'), "\n";
}
close(OUT);
print end_html;
------------------------------
Date: Thu, 25 Jan 2001 10:40:07 -0700
From: "Randy Galbraith" <randy.galbraith@pegs.com>
Subject: wincvs.org offline?
Message-Id: <94podf$b3g$1@freepress.anasazi.com>
All,
Does anyone here[1] know of the fate of wincvs.org? For the past couple of
days I've been unable to access it.
- Randy Galbraith
[1] I know this isn't a perl specific question, alas, my internal news
server as a limited number of groups.
------------------------------
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 V10 Issue 143
**************************************