[17992] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 152 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 26 18:14:07 2001

Date: Fri, 26 Jan 2001 15:05:16 -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: <980550316-v10-i152@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 26 Jan 2001     Volume: 10 Number: 152

Today's topics:
        'apply' function in perl? tcblue@my-deja.com
    Re: 'apply' function in perl? <tony_curtis32@yahoo.com>
    Re: 'apply' function in perl? (Greg Bacon)
    Re: 'apply' function in perl? <juex@deja.com>
    Re: 'apply' function in perl? <juex@deja.com>
    Re: 'apply' function in perl? (Greg Bacon)
        Automatic return <marekpow@email.hinet.hr>
    Re: Automatic return <juex@deja.com>
    Re: Basic string question nobull@mail.com
    Re: Basic string question <godzilla@stomp.stomp.tokyo>
    Re: Basic string question (James Kufrovich)
    Re: Basic string question <uri@sysarch.com>
    Re: Best way to learn Perl? tgphelps50@my-deja.com
        Calling rsync with "system" does not work (Otto Wyss)
    Re: Calling rsync with "system" does not work <kistler@gmx.net>
    Re: Comparing multiple values (Richard J. Rauenzahn)
    Re: Dealing with x1b character <fty@mediapulse.com>
    Re: Finding unused variables ? (James Kufrovich)
    Re: Form Processing - newbie question <prlawrence@lehigh.edu>
        forms and security (Paul Delahunta)
    Re: forms and security <kistler@gmx.net>
        hash question <todda@xmission.com>
    Re: hash question (Greg Bacon)
    Re: How do you backspace(back delete) on console? (Monte Phillips)
    Re: How valid is $ {$foo} ? (Abigail)
    Re: html link on perl created dynamic webpage <brondsem@my-deja.com>
    Re: Internal counter required: was" Counting elements i (John McNamara)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 26 Jan 2001 19:20:47 GMT
From: tcblue@my-deja.com
Subject: 'apply' function in perl?
Message-Id: <94sim6$87p$1@nnrp1.deja.com>

Hi,
I'v come accross this several times, and finnaly decided to post this
question:  Is there an 'apply' function in perl, similar to the lisp
'apply' func?

Maybe there is a way to do it w/o this fuction, but i haven't figured
out how... basically what i'm trying to do is something like this:

$sum = apply(+, @list_of_numbers);

where it takes a function and applies it to a list, and returns a scalar.

I know there's gotta be some eligant 1 liner that will do this (pref w/o
a loop of somesort)... Please let me... Thanks!

-Patrick T.-
tcblue82@yahoo.com


Sent via Deja.com
http://www.deja.com/


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

Date: 26 Jan 2001 13:39:07 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: 'apply' function in perl?
Message-Id: <87elxq9k84.fsf@limey.hpcc.uh.edu>

>> On Fri, 26 Jan 2001 19:20:47 GMT,
>> tcblue@my-deja.com said:

> $sum = apply(+, @list_of_numbers);

> where it takes a function and applies it to a list, and
> returns a scalar.

Think "map"

    $n = map { $sum += $_ } (1..5);

    print "$sum\n";

    (relies on autovivification of $sum though)

I'm sure there are more exotic ways.

hth
t
-- 
Eih bennek, eih blavek.


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

Date: Fri, 26 Jan 2001 20:15:36 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: 'apply' function in perl?
Message-Id: <t73mn8ubgc3f3@corp.supernews.com>

In article <94sim6$87p$1@nnrp1.deja.com>,
     <tcblue@my-deja.com> wrote:

: Maybe there is a way to do it w/o this fuction, but i haven't figured
: out how... basically what i'm trying to do is something like this:
: 
: $sum = apply(+, @list_of_numbers);
: 
: where it takes a function and applies it to a list, and returns a scalar.

Perl won't let you refer to the addition operator like many functional
languages will.

: I know there's gotta be some eligant 1 liner that will do this (pref w/o
: a loop of somesort)... Please let me... Thanks!

What are you?  Some kinda anti-loopite? :-)  mjd wrote[*] a Perl
version of reduce, and you could use that:

    my @nums = (1, 5, 14, 17, 7, -2);
    my $sum = reduce { $a + $b } 0, @nums;

If only Perl had curried functions... :-)

Greg
-- 
If there be any among us who wish to dissolve the Union or to change its
republican form, let them stand undisturbed, as monuments of the safety
with which error of opinion may be tolerated where reason is left free to
combat it.    -- Thomas Jefferson


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

Date: Fri, 26 Jan 2001 12:44:58 -0800
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: 'apply' function in perl?
Message-Id: <3a71e1ca$1@news.microsoft.com>

"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:87elxq9k84.fsf@limey.hpcc.uh.edu...
> >> On Fri, 26 Jan 2001 19:20:47 GMT,
> >> tcblue@my-deja.com said:
>
> > $sum = apply(+, @list_of_numbers);
>
> > where it takes a function and applies it to a list, and
> > returns a scalar.
> [...]
> I'm sure there are more exotic ways.

A "join" with a subsequent "eval" should work :-)

jue




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

Date: Fri, 26 Jan 2001 13:33:52 -0800
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: 'apply' function in perl?
Message-Id: <3a71ed40$1@news.microsoft.com>

"Greg Bacon" <gbacon@HiWAAY.net> wrote in message
news:t73mn8ubgc3f3@corp.supernews.com...
> What are you?  Some kinda anti-loopite? :-)  mjd wrote[*] a Perl
> version of reduce, and you could use that:
>
>     my @nums = (1, 5, 14, 17, 7, -2);
>     my $sum = reduce { $a + $b } 0, @nums;
>
> If only Perl had curried functions... :-)

Out of curiosity: would it be possible to somehow use closures for this
purpose (or am I way off)?

jue




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

Date: Fri, 26 Jan 2001 22:01:39 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: 'apply' function in perl?
Message-Id: <t73su35bnu9ef1@corp.supernews.com>

In article <3a71ed40$1@news.microsoft.com>,
    Jürgen Exner <juex@deja.com> wrote:

: "Greg Bacon" <gbacon@HiWAAY.net> wrote in message
: news:t73mn8ubgc3f3@corp.supernews.com...
:
: > If only Perl had curried functions... :-)
: 
: Out of curiosity: would it be possible to somehow use closures for this
: purpose (or am I way off)?

Well, sure, but you'd have to do it by hand, and you'd have to play
funny games to get curried versions of builtins like map and grep.

Greg
-- 
 ..I always find it quaint that people who rant and rave against the
silliness of self-reference are themselves composed of trillions and
trillions of tiny self-referential molecules.
    -- Douglas R. Hofstadter


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

Date: Fri, 26 Jan 2001 22:55:21 +0100
From: "MaxyM" <marekpow@email.hinet.hr>
Subject: Automatic return
Message-Id: <94srqf$4rco$1@as121.tel.hr>

Let's say we have two Perl scripts:
One.pl and
Two.pl

The first one, (One.pl) calls the other one, (Two.pl). And Two.pl script is
finished.
The question is, how, or what code write into Two.pl, that automatic return
to caller can be done.
I know how to do it whit a link, but that's very bad solution, because you
have to click every time, when
Two.pl is finished, and I like to do it that way that user don't even know
what's going on in the background.

On the One.pl we have link that points to Two.pl, and I'd like to stay that
way. Only when Two.pl is finished,
automatic return must be done.


Help.







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

Date: Fri, 26 Jan 2001 14:08:56 -0800
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Automatic return
Message-Id: <3a71f578$1@news.microsoft.com>

"MaxyM" <marekpow@email.hinet.hr> wrote in message
news:94srqf$4rco$1@as121.tel.hr...
> Let's say we have two Perl scripts:
> One.pl and
> Two.pl
>
> The first one, (One.pl) calls the other one, (Two.pl). And Two.pl script
is
> finished.
> The question is, how, or what code write into Two.pl, that automatic
return
> to caller can be done.

Well, have you tried it??? How are you calling Two.pl?
Unless you are doing some very weird stuff One.pl will 'wait' until Two.pl
is finished and then resume working.

> I know how to do it whit a link, but that's very bad solution, because you
With a link??? You lost me. Is there a reason you are not using system() or
backticks?

> have to click every time, when
Click? Where do you click in a Perl script? Are you talking about Perl::Tk
or some other GUI?

> Two.pl is finished, and I like to do it that way that user don't even know
> what's going on in the background.
With neither system() nor backticks the user will ever notice that a second
script has been started.

> On the One.pl we have link that points to Two.pl, and I'd like to stay
that
> way. Only when Two.pl is finished,
> automatic return must be done.

Again: system() as well as backticks do exactly that.
If you are looking for something else then you may need to explain your
problem better.

jue




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

Date: 26 Jan 2001 18:52:39 +0000
From: nobull@mail.com
Subject: Re: Basic string question
Message-Id: <u9snm6f8nc.fsf@wcl-l.bham.ac.uk>

Some time ago before our resident troll's recent sebattical I
contradicted someone who said that Godzilla's advice was _always_ wrong,
meaningless or irrlevant.

Since then I've been keeping my eyes-open for an example to prove my
point.

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:

> nesta wrote:
> 
> > Is there a way to divide a string in letters and 
> > put each element into an array ?
> 
> > I'm tried the next:
>  
> > $string = "something "
> > @array = split (/\w/,$string);
>  
> > but @array always is empty.
>  
> Remove your '\w' from your split.
> 
> @Array = split (//, $string);

Clear simple relevant and accurate.  In fact I can only find two
(fairly minor) ways to fault it.  Capitalised variables are considered
poor form in general usage.  The OP said @array, there was no reason
to change this to @Array.

More inportantly it failed to point out that this is explained in the
split() manpage.  There's no point just feeding hungry men fish and
not taking the opportunity to teach them to fish.

> You may test this in two ways....

That was rather a long digresion away from the topic of this thread
explaining printing arrays.  Explaining in moderately accurately.  One
careless mistake (s/maintain/insert/) and forgot to mention $, and $"
but otherwise a resonable explaination. 

However, there was no reason to belive the OP did not already know
about printing arrays.  Indeed since the OP made the mistake of saying
"@array always is empty" the astute reader can actually infer that the
OP did print the array.  If the OP had used so other method to observe
the content of @array then he would not have made this mistake.
 
> You will enjoy better luck with splits
> if you are precise and exact with your
> split delimiter.

Errr, yes: code without mistakes in it works better.  Glad you pointed
that one out.

> In this case, odd as this sounds, you are splitting on nothing.

Another concise, relevant and helpfull comment.

> This should raise a few eyebrows.

A concise, relevant and helpfull comment in a Godzilla post?  I should
say so!

> Do work at avoiding regex like expressions
> for a split and focus on exacting delimiters
> for better reliability and fewer failures.

And you were doing so well.  What, if anything, did that mean?  I
think it meant "more often than not the regex you need in split will
only contain literal characters".  True, maybe, but I can see no
reason why one should "work at avoiding" other regexes.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 26 Jan 2001 12:21:59 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Basic string question
Message-Id: <3A71DC67.78C4D760@stomp.stomp.tokyo>

nobull@mail.com wrote:

> Godzilla! wrote:
> > nesta wrote:

(various snippage)

 
> Some time ago before our resident troll's recent sebattical

If I am truly the troll, why are you trolling me, in this
article and other blatant troll articles of yours?


> In fact I can only find two (fairly minor) ways to fault it.

> More inportantly it failed to point out 


I am not an "it" as you and others state. I am a
female human, a person not too unlike others,
perhaps better than others in a few ways,
certainly worse though, in attitude displayed;
my attitude is real, not a façade like yours
and of other regulars here.

A noticable improvement upon myself is God
having blessed me with being female like Her,
rather than a knuckle dragging hairy backed
slope browed flat toothed pea brained impotent
Neandertal male, like yourself.

Another way I differ from many, especially you,
although my spelling certainly isn't perfect,
my spelling is correct significantly more
than your own cave man cave wall scratchings
lacking even the quality of pictographs
found in a deep dark damp cave in France.

* draws a pictograph of a stickman showing off a very tiny stick *

Moreover, I am able to effectively communicate
with people sans your piece of charcoal and
metamorphic slate stone cave wall.


You, Guttman, Flavell and Foy should meet, get together,
party and all that; peas in pod, real lady charmers.


I will take your comments as compliments issued
by a person lacking in social grace, wittiness
and having a propensity to spread a lot of classic
mule manure, or more fitting for you, a lot of bull,
Mr. Nobull.

Thank you for your kind remarks.

Godzilla!


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

Date: Fri, 26 Jan 2001 22:11:16 GMT
From: eggie@REMOVE_TO_REPLYsunlink.net (James Kufrovich)
Subject: Re: Basic string question
Message-Id: <slrn973tlc.26h.eggie@melody.mephit.com>

On Fri, 26 Jan 2001 10:13:02 -0800, Godzilla! <godzilla@stomp.stomp.tokyo> 
wrote:
[snip]
after setting $string = "something ";
>@Array = split (//, $string);
>print "@Array";
>
>This will print:
>
>s o m e t h i n g  <-- two trailing spaces
>
>A print command for an array without
>quotes will not have spaces, unless
>spaces are included in your elements:
>
>print @Array;
>
>This will print:
>
>something <-- one trailing space

	Erf. Can somebody explain why this is, or point me toward
documentation that would explain it (I can't find any at the moment)?
Thanks

Jamie
-- 
Egg, eggie@REMOVE_TO_REPLYsunlink.net
FMSp3a/MS3a A- C D H+ M+ P+++ R+ T W Z+ 
Sp++/p# RLCT a+ cl++ d? e++ f h* i+ j p+ sm+


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

Date: Fri, 26 Jan 2001 22:28:39 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Basic string question
Message-Id: <x7bssuuewa.fsf@home.sysarch.com>

>>>>> "JK" == James Kufrovich <eggie@REMOVE_TO_REPLYsunlink.net> writes:

  JK> On Fri, 26 Jan 2001 10:13:02 -0800, Godzilla! <godzilla@stomp.stomp.tokyo> 
  JK> after setting $string = "something ";
                                        ^

  >> @Array = split (//, $string);
  >> print "@Array";
  >> s o m e t h i n g  <-- two trailing spaces

  >> print @Array;
  >> something <-- one trailing space

  JK> 	Erf. Can somebody explain why this is, or point me toward
  JK> documentation that would explain it (I can't find any at the moment)?
  JK> Thanks

first, you should always be wary of any posts from moronzilla.

second, notice that $string has a trailing space in it as i marked
above. so interpolating @array will insert another space.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Fri, 26 Jan 2001 20:22:41 GMT
From: tgphelps50@my-deja.com
Subject: Re: Best way to learn Perl?
Message-Id: <94sma6$bo4$1@nnrp1.deja.com>



> Spent last couple of years building well-known e-commerce sites using
> Open Source code. Used a lot of Perl and had to teach jr. programmers
a
> lot about Perl. Found out most effective way was the so-called
Socratic
> method of question/answer. So, put together a website
www.codecity.com
> to explore this approach to teaching Open Source. Hope to get some
> feedback/participation from this group. Hope this is appropriate.

Ever hear of sentences having subject? Thought not. Suggest you learn
English sentence structure. Might get better responses to posts. Hope
this helps.


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 26 Jan 2001 21:23:26 +0100
From: otto.wyss@bluewin.ch (Otto Wyss)
Subject: Calling rsync with "system" does not work
Message-Id: <1env061.1x5k9gj6ddbp2N%otto.wyss@bluewin.ch>

I have written 2 allmost identical scripts (actually just one) which
mirrors a debian server using rsync through the system function. While
the following statement in script "mirrorcheck" works
        @args=("rsync", "-aPv", "$serverdir", "$workfile");
        print "@args\n";
        system (@args);
the following statement in script "mirrorsync"
        @args=("rsync", "-aPv --include-from .listfile", "$serverdir",
"$workdir");
        print "@args\n";
        system (@args);
produces allways the error "illegal option --". 

The complete scripts are available at:
        "http://www.problemlos.ch/otto/mirrorcheck.gz" (3k)
        "http://www.problemlos.ch/otto/mirrorsynch.gz" (3k)

Any comments and/or improvements about my scripts are wellcomed.

I'd like to have a solution where the contents of "$serverdir",
"$workfile" where directly piped to rsync if it's possible and would
appreciate if anybody knows how. Or perhabs the content of the
".listfile" could be piped. The advantage would be after rsync'ing
Packages rsync'ing of the rest would imediatly follow with without
starting rsync each time again.

O. Wyss


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

Date: Sat, 27 Jan 2001 00:41:51 +0100
From: Per Kistler <kistler@gmx.net>
Subject: Re: Calling rsync with "system" does not work
Message-Id: <3A720B3F.B492D32E@gmx.net>

Otto Wyss wrote:
>         @args=("rsync", "-aPv --include-from .listfile", "$serverdir",
> "$workdir");
>         print "@args\n";
>         system (@args);
> produces allways the error "illegal option --".

Either it's all one string for the shell, or then the command and
each option have to be separate scalars, so that perl can start
the command itself and hand over to it each argument. But the line
above mixes up the two methods.

Per.

-- 
Per Kistler, Zurich, Switzerland
------------------------------------------------------------------------


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

Date: 26 Jan 2001 17:53:39 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: Comparing multiple values
Message-Id: <980531618.519340@hpvablab.cup.hp.com>

"John W. Krahn" <krahnj@acm.org> writes:
>"Richard J. Rauenzahn" wrote:
>> 
>> Tore Aursand <tore@extend.no> writes:
>> >In article <94pocs$osn$1@nnrp1.deja.com>, datastar@my-deja.com says...
>> >> ...but what if I want to test if $somevar equals 3,4,8 or 9?
>> >
>> >if ($number =~ /[1|2|3|4]/) {
>> >       ...
>> >}
>> 
>> Umm.. no,
>> 
>> $ perl
>> $number = '40';
>> 
>> if ($number =~ /[1|2|3|4]/) {
>>    print "$number is 1, 2, 3 or 4\n";
>> }
>> 
>> __END__
>> 40 is 1, 2, 3 or 4
>> $
>> 
>> You want $number =~ /^[1|2|3|4]$/) {
>
>BZZZZT! wrong answer.
>
>$ perl -e '$number = "|"; if ($number =~ /^[1|2|3|4]$/) { print "$number
>is 1, 2, 3 or 4\n"; }'
>| is 1, 2, 3 or 4

Argh.  Of course!

This time with real test cases:

$ perl5
foreach(qw(1 2 3 4 5 | a b c 40), "", "1 ") {
   if (/^[1234]$/) {
      print "'$_' is 1, 2, 3 or 4\n";
   } else {
      print "'$_' is NOT 1, 2, 3 or 4\n";
   }
}

__END__
'1' is 1, 2, 3 or 4
'2' is 1, 2, 3 or 4
'3' is 1, 2, 3 or 4
'4' is 1, 2, 3 or 4
'5' is NOT 1, 2, 3 or 4
'|' is NOT 1, 2, 3 or 4
'a' is NOT 1, 2, 3 or 4
'b' is NOT 1, 2, 3 or 4
'c' is NOT 1, 2, 3 or 4
'40' is NOT 1, 2, 3 or 4
'' is NOT 1, 2, 3 or 4
'1 ' is NOT 1, 2, 3 or 4

Rich


-- 
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant     | I speak for me,     |   19055 Pruneridge Ave. 
Development Alliances Lab|            *not* HP |                MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014


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

Date: Fri, 26 Jan 2001 22:15:13 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: Dealing with x1b character
Message-Id: <RFmc6.32550$I9.2306317@news5.aus1.giganews.com>

<hparks@my-deja.com> wrote in message news:94s4u8$qjj$1@nnrp1.deja.com...
> One important correction: the character that is causing me trouble is a
> hex 1A, not 1B, which explains why the file read stops, I think. But
> the problem remains.

Looks like Mark Jason Dominus already answered your question so the problem
does not remain anymore. i.e. look at the binmode() function.

jay



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

Date: Fri, 26 Jan 2001 22:29:03 GMT
From: eggie@REMOVE_TO_REPLYsunlink.net (James Kufrovich)
Subject: Re: Finding unused variables ?
Message-Id: <slrn973umn.26h.eggie@melody.mephit.com>

On 26 Jan 2001 17:05:41 +0100, Jan Willamowius <jan@willamowius.de> wrote:
>I'm looking for a tool that finds unused variables.
[snip]
>Is there a tool that can detect any of those 2 categories ?

	Put '-w' (sans quotes, of course) on the shebang line, which you
should do for every script you write, as well as using the "strict"
pragma, which wont necessarily (I don't think so, anyway) detect unused
variables, but it's a Good Idea anyway. </runon_sentence>

Jamie, making his 3rd post to clpm today. And there was much rejoicing.
[insert sounds of many tomatoes going *splat*]
-- 
Egg, eggie@REMOVE_TO_REPLYsunlink.net
FMSp3a/MS3a A- C D H+ M+ P+++ R+ T W Z+ 
Sp++/p# RLCT a+ cl++ d? e++ f h* i+ j p+ sm+


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

Date: Fri, 26 Jan 2001 12:19:38 -0600
From: "Phil R Lawrence" <prlawrence@lehigh.edu>
Subject: Re: Form Processing - newbie question
Message-Id: <94sf3t$a8s@fidoii.CC.Lehigh.EDU>

[ CC: paul_wasilkoff@ucg.org ]

"PaAnWa" <paul_wasilkoff@ucg.org> wrote:
> > >print FILE "\"$in{'check1'}\",";
> > >print FILE "\"$in{'check2'}\",";
> > >print FILE "\"$in{'check3'}\",";
> > >print FILE "\"\","; #blank field
> > >print FILE "\"\","; #blank field - this makes a total of 5 entries.
> >
   "David Efflandt" <efflandt@xnet.com> wrote:
> > for ($i = 1; $i < 6; $i++) {
> >     print FILE '"', ($in{'check'.$i}) ? $in{'check'.$i} : '', '",';
> > }
>
> Thank you David.  This answers part of my question but I am still int he
> dark as to how I should put the values into the counter in the first
place.
> The user has the choice of over 25 checkboxes but can choose up to 5 - any
> 5.

You will not be putting "values into the counter", but rather into the hash
named %in.  The loop David set up takes care of incrementing the counter.

As far as getting %in populated...  use GCI.pm to read the values of the
check boxes.  Then you can do anything you like with those values, including
storing them in a hash.

Phil R Lawrence




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

Date: Fri, 26 Jan 2001 22:35:34 GMT
From: mustbe@pdelahunta.cjb.com (Paul Delahunta)
Subject: forms and security
Message-Id: <3a71fac4.20562845@news.planet.nl>

Hello,
Maybe someone more experienced could give me some advice on this small
question:

I have this little searchform on a webpage in wich a use enters a
keyword wich I next pass to a regexp in the searchscript unmodified.
The regexp searches the files for the keyword.
 I do this (pass it unmodified to the regexp) so the user can use the
Perl metacharacters to refine his search instruction.  

Is it in any way insecure to do this? Does it increase the
possibilities of misusage? And if so: how?

Thanks in advance,
Paul Delahunta



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

Date: Sat, 27 Jan 2001 00:54:18 +0100
From: Per Kistler <kistler@gmx.net>
Subject: Re: forms and security
Message-Id: <3A720E2A.2857E150@gmx.net>

Hi Paul

I would make it save, even if I would not know in what way
it could be critical. Define what the user is allowed to
do and restrict it the rest.
You may want to quote all metacharacters with: quotemeta()
and then maybe reallow "*" by $a=~s/\\\*/*/g;

Per.

-- 
Per Kistler, Zurich, Switzerland
------------------------------------------------------------------------


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

Date: Fri, 26 Jan 2001 12:06:03 -0700
From: Todd Ahlstrom <todda@xmission.com>
Subject: hash question
Message-Id: <3A71CA9B.FFE9FD38@xmission.com>

I am new to perl, and I am having a problem getting something to work.
I have reread the hash section in the book I am using, but I cannot
figure this out.  I have a hash that contains item, color, and qty
values.  The keys are named item1...item6 color1...color6 qty1...qty6.
What I want to happen is if the value of a qty key is zero, to delete
the corresponding item and color keys.  Example:  qty4's value is 0 then
I would want to delete item4 and color4.  I figured I could do this with
some simple loops, but I can't get it to actually work.  I can get it to
compile and run, but it never deletes the keys I want deleted.  this is
a sample of code I have tried:

for($i=1;  $i<7; $i++){
    if ($hash{qty$i}==0){
    delete $hash{item$i, color$i}; }
}

Being new to perl I was unsure of a few things, if the scope of $i would
extend into the if loop.  I tried declaring $i before the for statement
to deal with this, but it didn't help.  Also, I have been a little
unclear on what quotes to use on the key values in the loops.  I have
tried both single and double, but neither helped.  If I inadvertently
typed a syntax error into this sample code, I apologize. the actual code
I have tried does compile fine, I just need some help deciding how to
make this work properly.
Thank you in advance,
Todd



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

Date: Fri, 26 Jan 2001 19:54:49 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: hash question
Message-Id: <t73lg93o356k94@corp.supernews.com>

In article <3A71CA9B.FFE9FD38@xmission.com>,
    Todd Ahlstrom  <todda@xmission.com> wrote:

:             [...] I have a hash that contains item, color, and qty
: values.  The keys are named item1...item6 color1...color6 qty1...qty6.
: What I want to happen is if the value of a qty key is zero, to delete
: the corresponding item and color keys. [...]
:
: for($i=1;  $i<7; $i++){
:     if ($hash{qty$i}==0){
:     delete $hash{item$i, color$i}; }
: }

I would write it as

    foreach my $i (1 .. 6) {
        if ($hash{"qty$i"} == 0) {
            delete @hash{"item$i", "color$i"};
        }
    }

In your example, you're missing the double quotes around the key
names.  These are necessary because you're creating new strings based
on the value of $i.  Compare the delete statements:

    yours: delete $hash{item$i, color$i};
    mine:  delete @hash{"item$i", "color$i"};

When you see a leading dollar-sign, think "Scalar!".  When you see a
leading at-sign, think "List!"  The leading dollar-sign tells perl to
construct a single key, as though you had written

    delete $hash{ join $;, "item$i", "color$i" };

Using the at-sign, you refer to a hash slice, i.e., a list of key/value
pairs, as though you had written

    delete $hash{"item$i"};
    delete $hash{"color$i"};

Here's a demo program:

    #! /usr/local/bin/perl -w

    use strict;

    my %hash = (
        qty1   => 2,
        color1 => 'blue',
        item1  => 'sky',
        qty2   => 0,
        color2 => 'red',
        item2  => 'fish',
        qty3   => 42,
        color3 => 'green',
        item3  => 'leaf',
    );

    foreach my $i (1 .. 3) {
        if ($hash{"qty$i"} == 0) {
            delete @hash{"item$i", "color$i"};
        }
    }

    foreach my $i (1 .. 3) {
        if ($hash{"qty$i"} != 0) {
            print "Item $i:\n",
                qq[    Qty:   $hash{"qty$i"}\n],
                qq[    What:  $hash{"item$i"}\n],
                qq[    Color: $hash{"color$i"}\n];
        }
    }

If I were you, though, I'd probably use a hash of hashes like

    my %hash = (
        1 => { qty => 2,  color => 'blue',  item => 'sky' },
        2 => { qty => 0,  color => 'red',   item => 'fish' },
        3 => { qty => 42, color => 'green', item => 'leaf' },
    );

Then if you only want to print items in stock, use

    for (sort { $a <=> $b } keys %hash) {
        my $item = $hash{$_};

        if ($item->{qty} > 0) {
            print "Item $_:\n",
                  "    Qty:   $item->{qty}\n",
                  "    What:  $item->{item}\n",
                  "    Color: $item->{color}\n";
        }
    }

Greg
-- 
Why don't you just go down to Hell and work for the Devil?
    -- Hank Hill


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

Date: Fri, 26 Jan 2001 21:31:39 GMT
From: montep@hal-pc.org (Monte Phillips)
Subject: Re: How do you backspace(back delete) on console?
Message-Id: <3a71ec2f.38905242@news.hal-pc.org>

Sisyphus wrote>>>>
Hi,
Seems to me you've already answered the question - which probably
means I
don't understand your question.
As best I can work out, the following demonstrates what you are
looking
for - by using '\b' like you said.
I'll send it anyway.

#!perl -w
use strict;
my $i = 0;
while ($i < 10) {
print "$i\b";
sleep (1);
$i++;
}

Cheers,
Rob


In reply I ducked my head and wrote->>>
First things first, Thank you!<grin>
You were right I had the answer but didn't think it through.  I had
used the \b (win32 machine) but did it within the Run environment of
DZSofts PerlEditor.  That would give me a string 1 2 3 4 with a high
ASCII character between each number.
When I tested your snippet, I went directly to a DOS window to save
time,  voila'.  The number 8 now prints over the 9 then the 7 prints
exactly in the same spot as the 8 etc.  

 Now my sage comment to you in return for the favor.... Never Never,
get old!!!!  arrgh!

Monte



On Fri, 26 Jan 2001 06:17:05 GMT, montep@hal-pc.org (Monte Phillips)
wrote:

>Backspace print using \b is fine except I need to backspace on the
>display screen.  Print a character then backspace over it and print
>another character on the same spot.
>



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

Date: 26 Jan 2001 21:00:39 GMT
From: abigail@foad.org (Abigail)
Subject: Re: How valid is $ {$foo} ?
Message-Id: <slrn973pbn.q5.abigail@tsathoggua.rlyeh.net>

Mark Jason Dominus (mjd@plover.com) wrote on MMDCCV September MCMXCIII in
<URL:news:3a71a39e.3b7b$249@news.op.net>:
__ 
__ In article <slrn972p01.q5.abigail@tsathoggua.rlyeh.net>,
__ Abigail <abigail@foad.org> wrote:
__ >It's an old, undocumented relic from ancient times.
__ 
__ That's what I thought, but I looked, and wasn't able to find anything
__ analogous even as recently as perl 4.0.  Perhaps I missed something?


I once discovered this `feature' by accident, and after I mentioned it
on IRC, I was told by someone who should know (Tom? Randal? Chip?) that
it was an old relic.

But maybe I misremember.



Abigail
-- 
$_ = "\112\165\163\1648\141\156\157\164\150\145\1628\120\145"
   . "\162\1548\110\141\143\153\145\162\0128\177"  and &japh;
sub japh {print "@_" and return if pop; split /\d/ and &japh}


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

Date: Fri, 26 Jan 2001 20:30:11 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: html link on perl created dynamic webpage
Message-Id: <94smo7$c69$1@nnrp1.deja.com>

In article <94sfou$5dn$1@nnrp1.deja.com>,
  davidmonroe@my-deja.com wrote:
> I'm new to Perl and am having difficulty putting a link in a page
that was
> generated by a Perl script.  This is what I have and it does not work.
>
> print "\n<a
href="http://www.atgl.spear.navy.mil/feedback/trnofmod.htm">View
> your submission here</a><br>";

Since you double quote what you are trying to print, you can't have
double quotes within that.  Here are some alternatives:

print "<a href=\"escaped\">asdf</a>";
print '<a href="single quotes">asdf</a>';
print qq~<a href="qq operator">asdf</a>~;
print qq(<a href="qq operator is my favorite">asdf</a>);


>
> Any help would be greatly appreciated.
>
> Dave
>
> Sent via Deja.com
> http://www.deja.com/
>

--
Dave Brondsema


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 26 Jan 2001 22:44:48 GMT
From: jmcnamara@cpan.org (John McNamara)
Subject: Re: Internal counter required: was" Counting elements in an array (foreach)"
Message-Id: <3a71fdcb.2001831@news1.eircom.net>

Ar 26 Jan 2001 15:13:10 GMT, do scriobh
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):

>While this was pretty much agreed upon (I will be corrected if I'm
>wrong), all that remains to do is convince Larry and the Guys that
>it's a good thing and write the patch.  Or propose it for Perl 6,
>which, I'm sure, has been done.

Yes, RFC 120: Implicit counter in for statements, possibly $#. 
http://tmtowtdi.perl.org/rfc/120.html

John McNamara
-- 
"Something tells me we aren't programming in Pascal anymore, Toto."


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

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


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