[18666] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 834 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 4 11:10:41 2001

Date: Fri, 4 May 2001 08:10:20 -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: <988989020-v10-i834@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 4 May 2001     Volume: 10 Number: 834

Today's topics:
    Re: Installing Module (advice for new coder) <kristoffer@bastad.com>
    Re: Installing Module (advice for new coder) <hillr@ugs.com>
        link management script <ringo@ringo.net.ru>
    Re: Multi dimensional array dimensions <iltzu@sci.invalid>
    Re: One-liner matching woes... <admin@salvador.venice.ca.us>
    Re: prevent empty message being sent? <bart.lateur@skynet.be>
    Re: Problem with the subroutine (closure?) for the "sor (EED)
    Re: Problem with the subroutine (closure?) for the "sor <joe+usenet@sunstarsys.com>
    Re: Problem with the subroutine (closure?) for the "sor (EED)
    Re: Problem with the subroutine (closure?) for the "sor (EED)
    Re: Problem with the subroutine (closure?) for the "sor <ren@tivoli.com>
    Re: Recursing a directory tree <jfreeman@tassie.net.au>
    Re: Removing attributes <hamel@hotmail.com>
        Rename subdirectories and files <a.b.horne@exeter.ac.uk>
        Simple question <Waarddebon@chello.nl>
    Re: Simple question <joe+usenet@sunstarsys.com>
    Re: Simple question <bowman@montana.com>
    Re: Simple question <bart.lateur@skynet.be>
    Re: Simple question <jfreeman@tassie.net.au>
    Re: Simple question (Tad McClellan)
    Re: sub z {return } print ((($x,$y)=z) ? "yes:$x,$y\n"  <iltzu@sci.invalid>
    Re: untaint help <jfreeman@tassie.net.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 4 May 2001 16:01:07 +0200
From: "Kristoffer Malvefors" <kristoffer@bastad.com>
Subject: Re: Installing Module (advice for new coder)
Message-Id: <qByI6.3108$vR1.9971@nntpserver.swip.net>

Yes, I would need some info on that as well...

Kristoffer Malvefors


"Dave Atherfold" <david115@home.com> wrote in message
news:3AF1EF54.D84B4BA5@home.com...
> First post to comp.lang.perl.misc.
>
> My web host uses NT Servers:
>
> I wanted to use DBI module, but this was not installed on my hosts
> server. I was advised to upload this module myself, and address it with
> the 'require' instead of the 'use' command.
>
> I am receiving errors when using this module that indicate I have not
> installed it correctly.
>
> Could someone please point me to somewhere where I can find more
> documentation on how to install modules on a Windows machine ( without
> using PPM ) Could not find at ActiveState.
>
> Thanks
>
> Dave




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

Date: Fri, 04 May 2001 07:12:54 -0700
From: Ron Hill <hillr@ugs.com>
Subject: Re: Installing Module (advice for new coder)
Message-Id: <3AF2B8E6.45B52B5@ugs.com>

Dave Atherfold wrote:
> 
[snipped]

> Could someone please point me to somewhere where I can find more
> documentation on how to install modules on a Windows machine ( without
> using PPM ) Could not find at ActiveState.
> 
To compile the DBI module on WNT you will need a c compiler (nmake)
get the module from www.cpan.org extract the tar file then
run perl makefile.pl this will produce

D:\DBI-1.14>perl makefile.pl

*** You are using a perl with experimental threading enabled!
*** You should be aware that using multiple threads is unstable
*** are should NOT be done in production environments.
DBI thread mutex protection is enabled

*** Note:
    The optional PlRPC-modules (RPC::PlServer etc) are not installed.
    If you want to use the DBD::Proxy driver and DBI::ProxyServer
    modules, then you'll need to install the RPC::PlServer,
RPC::PlClient,
    Storable and Net::Daemon modules. The CPAN Bundle::DBI may help you.
    You can install them any time after installing the DBI.
    You do *not* need these modules for typical DBI usage.

Optional modules are available from any CPAN mirror, in particular
    http://www.perl.com/CPAN/modules/by-module
    http://www.perl.org/CPAN/modules/by-module
    ftp://ftp.funet.fi/pub/languages/perl/CPAN/modules/by-module

Checking if your kit is complete...
Looks good
Writing Makefile for DBI

    Remember to actually *read* the README file!
    Use  'make' to build the software (dmake or nmake on Windows).
    Then 'make test' to execute self tests.
    Then 'make install' to install the DBI and then delete this working
    directory before unpacking and building any DBD::* drivers.

    Windows users need to use the correct make command.
    That may be nmake or dmake depending on which Perl you are using.
    If using the Win32 ActiveState build then it is recommended that you
    use the ppm utility to fetch and install a prebuilt DBI instead.

go from there!!
Hope this helps

Ron


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

Date: Fri, 4 May 2001 15:07:21 +0400
From: "ringo" <ringo@ringo.net.ru>
Subject: link management script
Message-Id: <3af28d65@news.ptt.ru>

link management script

Please, can you help me!
I need cgi script that counts hits sent to my site , aswell as hits out from
my site. And can sorted links by hits sent to me.  I want links can be
displayed anywhere on my page i want.
I`ve got one big problem: i havent enough money to pay for the script, so
please, can anybody help me to find the script free of charge!
Or  if you`re a webmaster i can pay for the script by sending you some
traffic from my site to yours.

Please , help me. Drop me a line and we should have a deal!
ringo@ringo.net.ru




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

Date: 4 May 2001 14:08:01 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Multi dimensional array dimensions
Message-Id: <988984747.841@itz.pp.sci.fi>

In article <chrI6.926$po.26152@typhoon.sonic.net>, John Nolan wrote:
>Ilmari Karonen <iltzu@sci.invalid> wrote:
>
>:   sub foo { $_[0] .. $_[1] }
>:   print scalar foo(0, 5), "\t toggle off\n";
>:   print        foo(0, 5), "\t print '012345'\n";
>:   print scalar foo(0, 0), "\t still turned off\n";
>:   print scalar foo(5, 0), "\t toggle on\n";
>:   print        foo(0, 5), "\t print '012345'\n";
>:   print scalar foo(0, 0), "\t still turned on\n";
>
>What part of the source code should I look at, in order
>to learn what is really going on here?

No need to read the source.  The "perlop" manual page is what you want.

Briefly, the ".." operator has two roles: In list context it produces a
range of values, while in scalar context it's a boolean flip-flop.  The
funny part is that each such operator really must be able to do both at
the same time, since the context may vary at runtime.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: Fri, 4 May 2001 06:59:46 -0700
From: Salvador Peralta <admin@salvador.venice.ca.us>
Subject: Re: One-liner matching woes...
Message-Id: <9cubu4$2od$1@persian.noc.ucla.edu>

Paul Boardman quoth:

Thanks for the advice, Paul.  I should've known better regarding the 
global expression but I didn't know one could use END in perl the 
same way that you can in awk, and I very much appreciate the input on 
implicit use of $_.  

regards,

Salvador

> You can simplify the one-liner by using $_ implicitly.  e.g. $x++ if
> /\.NET/;$y++ if /GPL|OSS|Open Source/i;

> You can enclose the code that you want to be executed in an END
> block. This is only run on termination of the script (I apologise if
> my terminology is a bit off, but the gist is there).
> 
> so your script becomes perl -ne '$x++ if /\.NET/;$y++ if
> /GPL|OSS|Open Source/i;END{print "MS: $x\n OS: $y\n"}'
> 
> to do multiple matches on a single line you could try using a while
> m//g;
> 
> e.g. perl -ne '$x++ while m/\.NET/g;$y++ while m/GPL|OSS|Open
> Source/gi;END{print "MS: $x\n OS: $y\n"}'



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

Date: Fri, 04 May 2001 11:43:46 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: prevent empty message being sent?
Message-Id: <ac55ft0hejjcohtbg4mivmfg6881jk3ccf@4ax.com>

Bing Du wrote:

>In the following snippet of code, if RESULT is closed normally, then the
>stuff printed to it can get sent out.  What if the script aborts before
>close(RESULT), so RESULT will still be closed, but this time, an empty
>message will be sent to user@tamu.edu.
>How should I do to prevent empty message being sent?
>
>open(RESULT,"|/usr/sbin/mailx -s 'a test message' user\@tamu.edu");
># print stuff to RESULT
>close(RESULT);

Eh, don't open a pipe to mailx until you're sure it's going to be a
valid message?

There's an SMTP command, RSET, which you can use to cancel a message, if
you find out there's something wrong. I doubt if mailx makes this
available to external control, but some SMTP modules might.

-- 
	Bart.


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

Date: Fri, 04 May 2001 15:04:17 +0200
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <3AF2A8D1.528921B@eed.ericsson.se>

Ren Maddox wrote:
> I would very much suspect that your patterns are not matching.
> Actually, it is certainly true that your patterns are not matching.
> Add some printing of $path to verify that it really ends with "PATH"
> or "STAT".
> 
> Your strategy is sound, so it should be fine once you get the patterns
> to match.

Thanks for your replies, but still it doesn't work.
I have written a simple test script (please don't be 
scared by its size - it's just the data init.):

#!/opt/local/perl-5.6.0/bin/perl -w

use strict;
use vars qw ($hohref $sort);
use Data::Dumper;

sub sort_sub ($$)
{
    my $path   = shift;
    my $hohref = shift;

print "<PRE>PATH=$path,\$a=$a,\$b=$b\n", Dumper ($hohref), '</PRE>';

    if ($path =~ /\/(\w+)$/)                 # sort by string in PATH_INFO
    {
        return sub { $hohref -> {$a} -> {$1} cmp $hohref -> {$b} -> {$1} };
    }

    return sub { $a cmp $b };                # sort by %$hohref keys
}

$hohref = {
        'SHS' => {
                   'PATH' => 'SHS/SHS_ANT',
                   'STAT' => 'ok'
                 },
        'LSS' => {
                   'PATH' => 'LSS/LSS_ANT',
                   'STAT' => 'ok'
                 },
        'CHS_ACCOUNTING' => {
                              'PATH' => 'CHS/CHS_ANT/ACCOUNTING_CRT',
                              'STAT' => 'ok'
                            },
        'MSS' => {
                   'PATH' => 'MSS/MSS_ANT',
                   'STAT' => 'ok'
                 },
        'XXX' => {
                   'PATH' => 'LSS',
                   'STAT' => '*_CNT not found'
                 },
        'MDS' => {
                   'PATH' => 'MDS/MDS_ANT',
                   'STAT' => 'ok'
                 },
        'MSS_GMSC' => {
                        'PATH' => 'MSS_GMSC/MSS_ANT',
                        'STAT' => 'ok'
                      },
        'MMS' => {
                   'PATH' => 'MMS/MMS_ANT',
                   'STAT' => 'ok'
                 },
        'TCS' => {
                   'PATH' => 'TCS/TCS_ANT',
                   'STAT' => 'ok'
                 },
        'TSS' => {
                   'PATH' => 'TSS/TSS_ANT',
                   'STAT' => 'ok'
                 },
        'YYY' => {
                   'PATH' => 'yyy/xxx/zzz',
                   'STAT' => 'dir not found'
                 }
          };

$sort = sort_sub ('/PATH', $hohref);
#$sort = sort_sub ('/STAT', $hohref);
    
for my $key (sort $sort keys %$hohref)
{
    printf "%20s %20s\n", $hohref -> {$key} -> {STAT},
                          $hohref -> {$key} -> {PATH};
}


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

Date: 04 May 2001 09:30:06 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <m3pudp2qe9.fsf@mumonkan.sunstarsys.com>

"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:

>     if ($path =~ /\/(\w+)$/)                 # sort by string in PATH_INFO
>     {
>         return sub { $hohref -> {$a} -> {$1} cmp $hohref -> {$b} -> {$1} };
                                           ^^                          ^^

Like $a and $b, $1 is a global, so it not evaluated until the closure is 
*executed*. Since you need it to be evaluated at compile time, stuff it in 
a lexical first:

  if ($path =~ /\/(\w+)$/) {
    my $match = $1;
    return sub { $hohref->{$a}->{$match} cmp $hohref->{$b}->{$match} };
  }

HTH
-- 
Joe Schaefer    "You can't depend on your eyes when your imagination is out of
                                           focus."
                                               --Mark Twain


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

Date: Fri, 04 May 2001 15:56:17 +0200
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <3AF2B501.8D3A43E@eed.ericsson.se>

Joe Schaefer wrote:
> 
> "Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:
> 
> >     if ($path =~ /\/(\w+)$/)                 # sort by string in PATH_INFO
> >     {
> >         return sub { $hohref -> {$a} -> {$1} cmp $hohref -> {$b} -> {$1} };
>                                            ^^                          ^^
> 
> Like $a and $b, $1 is a global, so it not evaluated until the closure is
> *executed*. Since you need it to be evaluated at compile time, stuff it in
> a lexical first:
> 
>   if ($path =~ /\/(\w+)$/) {
>     my $match = $1;
>     return sub { $hohref->{$a}->{$match} cmp $hohref->{$b}->{$match} };
>   }

Thank you, it has finally explained what happens to me.
I didn't realize, that sub { ... } evaluates only the
lexical (and not dyn.) variables during the compile time.


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

Date: Fri, 04 May 2001 16:35:05 +0200
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <3AF2BE19.65F47999@eed.ericsson.se>

nobull@mail.com wrote:
> > and I also suspect that $a and $b are undefined anyway...
> 
> This is another problem.  $a and $b are package variables providing
> sort_sub() is defined in the same package as the call to sort()
> there's no problem.
> 
> If you want sort to use a comparison routine in another package then
> see thread "Using a comparison routine in another package" from last
> November or more recently "efficient comparators (namespaces for $a and
> $b)" a few weeks ago.

Thanks but your solution looks really dirty :-(

I think I will drop my idea with the sorting subroutine - 
it won't make my script more readable (as I hoped first)


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

Date: 04 May 2001 09:03:26 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <m3bsp9jjo1.fsf@dhcp9-172.support.tivoli.com>

On Fri, 04 May 2001, eedalf@eed.ericsson.se wrote:

> Thanks for your replies, but still it doesn't work.
> I have written a simple test script (please don't be 
> scared by its size - it's just the data init.):

So close.... you fixed your previous problem, but introduced a new
one.


> sub sort_sub ($$)
> {
>     my $path   = shift;
>     my $hohref = shift;
> 
> print "<PRE>PATH=$path,\$a=$a,\$b=$b\n", Dumper ($hohref), '</PRE>';

(BTW, $a and $b don't have a value at this point, so printing them is
just going to give warnings.)

>     if ($path =~ /\/(\w+)$/)                 # sort by string in PATH_INFO
>     {
>         return sub { $hohref -> {$a} -> {$1} cmp $hohref -> {$b} -> {$1} };

Remember, only *lexical* variables are captured in the closure.  $1 is
very much *not* a lexical variable.  Add a lexical variable, and your
set:

      if (my($key) = $path =~ m|/(\w+)$|) {
          return sub { $hohref->{$a}{$key} cmp $hohref->{$b}{$key} };
      }

>     }
> 
>     return sub { $a cmp $b };                # sort by %$hohref keys
> }

Hope that gets you going!

-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 04 May 2001 21:38:19 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: Recursing a directory tree
Message-Id: <3AF294AB.8CE38F3F@tassie.net.au>



Dave Bailey wrote:

> On Thu, 03 May 2001 16:15:25 +1000, Jfreeman <jfreeman@tassie.net.au> wrote:
> >[Posted to perl.misc and CC Author]
> >
> >Arun Horne wrote:
> >
> >> Does anyone have some simple code to recurse a directory tree please?? Best
> >> regards Arun Horne.
> >
> >Here you are:
> >
> >#!usr/bin/perl -w
> [...]
> >sub find_dirs {
> >
> >    my $path = shift;
> > my @dirs;
> > opendir (DIR, $path) || die "Unable to open directory $path: $!\n";
> > my @files = readdir DIR;
> > close DIR;
> > for (@files) {
> >  next if m/^\.{1,2}/; # skip the dot files
>
> You don't want to do that.  For example, my home directory has 253
> subdirectories which begin with "." (recursively counting subdirs
> of my dot-directories):
>
> [dave@sydney dave]$ find . -type d | grep "\.\/\." | wc
>     253     292    7549
> [dave@sydney dave]$
>
> The poster's question has been answered many, many times on this
> newsgroup.  There is no need to waste time answering it again,
> especially incorrectly.

If the argument is that you should really have:

>  next if m/^\.{1,2}$/; # skip the dot files

So that you only skip the . and .. files fine.

If you don't understand that the . dir is simply a reference to the current dir
and the .. dir is a reference to the directory one level above the current dir
 .....

Which directory will list with this?

dir .\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.   (ls ./././././././././././././.)

James

>
>
> --
> Dave Bailey
> davidb54@yahoo.com



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

Date: Fri, 4 May 2001 09:42:21 -0400
From: "Philippe Hamel" <hamel@hotmail.com>
Subject: Re: Removing attributes
Message-Id: <tf5cdig2522k7d@corp.supernews.com>

Well, I did give you an idea of what my problem is.  I'm trying to remove an
attribute from an entry.  No, there's no error message to parse, because
there's no code to give an error.  That's the same reason why there's no
code included in my post.  I'm not getting an error trying to remove an
attribute with faulty code, I just plain don't know how to do it.

Using Net::LDAP's "delete" function, I'm able to remove an entry, but not an
attribute.  Can an attribute be removed using that function or is there
another one?

I'm sure there's a way to do it, since I'm using an LDAP browser that can do
just that.  Too bad I don't have access to the code of the browser.

Thank you.

--
Philippe Hamel
Bureau :
Courriel : phamel@logisil.com
Tel : (514)866-5493 poste 419
Maison :
Courriel : philippe.hamel@apiiq.qc.ca

"Jon Ericson" <Jonathan.L.Ericson@jpl.nasa.gov> wrote in message
news:864rv1lrea.fsf@jon_ericson.jpl.nasa.gov...
> "Philippe Hamel" <hamel@hotmail.com> writes:
>
> > I'm trying to delete attributes from an LDAP entry using perl and
associated
> > modules.  I've figured out how to remove whole entries, but if I just
want
> > to delete attributes from an entry, how do I do that?
>
> I don't know the first thing about LDAP (except that I once got
> Netscape mail to search the jpl.nasa.gov LDAP server).  I know even
> less how the protocol works.  I don't know the name of the perl module
> that speaks LDAP.  You didn't give me any perl code to work with.  You
> didn't give me an error message to parse.  You didn't give me any
> hints as to what your problem is.  I see you cross-posted to an LDAP
> group, but this is pretty much off-topic there too (unless there is
> something about the protocol that makes deleting attributes
> impossible).  Please consider posting some code.
>
> Jon




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

Date: Fri, 04 May 2001 15:59:45 +0100
From: Arun Horne <a.b.horne@exeter.ac.uk>
Subject: Rename subdirectories and files
Message-Id: <9cug54$1ujv7$1@athena.ex.ac.uk>

Hi I want to rename an entire directory tree in one go such that:

all whitespace is replaced by _'s
each word in the filename is correctly capitalised, i.e. HeLLo becomes
Hello and jOb -> Job

Can anyone provide me with such code?

Regards

--
Arun Horne
Please replace NOSPAM with @ in address to reply


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

Date: Fri, 04 May 2001 12:49:24 GMT
From: "Waarddebon" <Waarddebon@chello.nl>
Subject: Simple question
Message-Id: <ozxI6.108388$eL4.29851194@Flipper>


I want to check if a variable is ok by comparing them with 2 values.

if ($x=10)
or
if ($x=23){print"ok";}

How do I replace the or command ?




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

Date: 04 May 2001 09:15:32 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Simple question
Message-Id: <m3u2312r2j.fsf@mumonkan.sunstarsys.com>

"Waarddebon" <Waarddebon@chello.nl> writes:

> I want to check if a variable is ok by comparing them with 2 values.
> 
> if ($x=10)
> or
> if ($x=23){print"ok";}
> 
> How do I replace the or command ?

Just do it:

  if (10 = $x or 23 = $x) { print "ok"; }

but be sure you are really "testing" $x, not "assigning" to it :-)


If you really mean to use "elsif" here, see

  % man perlsyn

for help with Perl's flow control features.

-- 
Joe Schaefer         "Everything that can be invented has been invented."
                                               -- Charles H. Duell


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

Date: Fri, 4 May 2001 07:26:32 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: Simple question
Message-Id: <24yI6.158$Tf2.1623@newsfeed.slurp.net>


"Joe Schaefer" <joe+usenet@sunstarsys.com> wrote in message > Just do it:
>
>   if (10 = $x or 23 = $x) { print "ok"; }
> but be sure you are really "testing" $x, not "assigning" to it :-)

of course, if you are really 'testing' it, you might want to use the '=='
operator rather than the assignment '=' operator. And you might want to read
the docs on the difference of 'or' and '||'





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

Date: Fri, 04 May 2001 13:30:36 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Simple question
Message-Id: <vib5ft0eqq8o97i9cps99j4qfhmjf4iq8p@4ax.com>

Waarddebon wrote:

>I want to check if a variable is ok by comparing them with 2 values.
>
>if ($x=10)
>or
>if ($x=23){print"ok";}
>
>How do I replace the or command ?

First of all, you want either "==" or "cmp", not "=".

Second, loose the second "if", and roll the two conditions into one:

	if($x==10 or ^$x==23) { print"ok"; }

And  finally, your question is a FAQ. And no, Perl has no special syntax
for this kind of situation. You can use a hash, or use grep(), or even a
regex, and Damian Conway can come and tell you of great hopes for the
future, with his proposed keyword "any".

But unless you have many more values to test against than just two, I
just wouldn't bother.

-- 
	Bart.


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

Date: Sat, 05 May 2001 00:16:08 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: Simple question
Message-Id: <3AF2B9A8.D5D73E57@tassie.net.au>



Joe Schaefer wrote:

> "Waarddebon" <Waarddebon@chello.nl> writes:
>
> > I want to check if a variable is ok by comparing them with 2 values.
> >
> > if ($x=10)
> > or
> > if ($x=23){print"ok";}
> >
> > How do I replace the or command ?
>
> Just do it:
>
>   if (10 = $x or 23 = $x) { print "ok"; }

Joe is being mean. Just for that I will avoid saying you really need to get a
book and learn a few really incredibly basic concepts (whoops I just did) an
give you a quick run down:

First the comparitive operators ie the ones that answer the question what is the
relationship of a to b and return a true/false response are

For strings ie 'ABBA' "G'Day g'day, and how ya goin, wadaya know, strike a
light!"

eq        for equals, returns true is the strings on each side are the same
ne        not equal
lt         less than returns true is the strings on left side less than string
on right ('aa' lt 'abracadabra' evaluates true
gt        greater than
le        less than or equal
ge         guess

For numbers

==        for equals
!=         for not equals
<           less than returns true is the number on left side less than number
on right
>
<=
>=


= is the assignment operator. IT PLACES THE VALUE ON THE RIGHT INTO THE VARIABLE
ON THE LEFT. It does not compare anything.

> if ($x=10)
> or
> if ($x=23){print"ok";}

What your code does is assign (NOT COMPARE)  the value 10 into $x (returning a
true value if it succeeds which it will). It then generates a syntax error
because the syntax of an if statement is

if (condition) {
    DO SOMETING
}

Alternatively you may have

if (condition) {
    DO SOMETING
} else {
    DO OTHER THING
}

Presuming you want to find out if the variable $x has previously been assigned
and therefore now holds either ot the values 10 or 23 you want any of the
following statements:

print "OK\n" if ($x == 10 or $x ==23 );

if ($x == 10 or $x ==23 ) {print "OK\n";}

if ($x == 10 or $x ==23 ) {
    print "OK\n";
}

if ($x == 10 or $x ==23 ) {
    print "OK\n";
} else {
    print "Oh no \$x does not contain the values 10 or 23!\n";
}

if ($x  =~ m /^(?:10|23)$/) {print "OK\n";}


A full script, showing you the use of a while loop  might look like

#!/usr/bin/perl

while  ($x != 10 and $x !=23 ) {
    print "Guess either of my favourite numbers to escape ";
    $x = <>;
}
print "You guessed one!\n";


Get a book.

James


>
>
> but be sure you are really "testing" $x, not "assigning" to it :-)
>
> If you really mean to use "elsif" here, see
>
>   % man perlsyn
>
> for help with Perl's flow control features.
>
> --
> Joe Schaefer         "Everything that can be invented has been invented."
>                                                -- Charles H. Duell



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

Date: Fri, 4 May 2001 08:27:15 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Simple question
Message-Id: <slrn9f5813.3nm.tadmc@tadmc26.august.net>

Waarddebon <Waarddebon@chello.nl> wrote:
>
>I want to check if a variable is ok by comparing them with 2 values.
                                        ^^^^^^^^^


You are not doing any comparisons in the code below!

You are making assignments.


>if ($x=10)
>or
>if ($x=23){print"ok";}
>
>How do I replace the or command ?


You don't.

You instead delete the first close parenthesis, the second
open parenthesis and the second "if".    :-)

   if ( $x==10 or $x==23 ) {print "ok"}



(spaces are not a scarce resource. Feel free to use as many as you
 like to make your code easier to read.
)

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 4 May 2001 14:16:19 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: sub z {return } print ((($x,$y)=z) ? "yes:$x,$y\n" : "no\n")
Message-Id: <988985417.1404@itz.pp.sci.fi>

In article <slrn9f04db.3ts.tjla@thislove.dyndns.org>, Gwyn Judd wrote:
>
>and it still prints "yes". It is true that evaluating a list in scalar
>context evaluates to the last item, and an array in list context
>evaluates to the number of items. This is evaluating a list assignment
>in scalar context which appears to be different again.

s/a list in scalar/expressions separated by commas in scalar/

Sorry for being pedantic, but there's still no such thing as a list in
scalar context.  Just keeping the facts straight here.

Oh, also s/array in list/array in scalar/ of course.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: Fri, 04 May 2001 23:27:25 +1000
From: Jfreeman <jfreeman@tassie.net.au>
Subject: Re: untaint help
Message-Id: <3AF2AE3D.245183C7@tassie.net.au>



Paul wrote:

> Hi,
>
> I am having a problem with untainting. The error message I get is the
> following:
>
> Insecure dependency in open while running with -T switch at
> /usr/local/lib/perl5/5.6.0/Net/FTP.pm line 445.
>
> which comes from the following lines of code:
>
> foreach $temp_file (@output_arr) {
> #    $temp_file = &untaint($temp_file);
>     $ftp->get("$temp_file","$RESTORE_DIR/$y.$temp_file") or die "Can't fetch
> $temp_file: $!\n";
>     $y++;
>   }
>
> I am running the perl script with -Tw option and perl gets upset when I do
> ftp->get. Please note the commented line where I do the untaint of temp
> file. I guess I need to untaint the file I am writing to at local host. But
> I am not sure how to do that. Any help would be appreciated.

Perl's idea of tainted data is basically anything not hard coded in the program.
To quote the camel book 'you may not use data derived from outside your program
to affect something else outside your program.'

When your ftp object calls its get sub with the specified args the open call
within that sub is using arguments that are flagged as tainted. Either one or
both of $temp_file  $RESTORE_DIR must be tainted.

Presumably the data in @output_arr and therefore $temp_file is tainted - ie it
has come from user input or an external file. To simply untaint this (shotgun
approach) replace your commented out call to a non specified untaint subroutine
(hard to see what you are (not) doing there!) with:

($temp_file) = $temp_file  =~ m/(.*)/;

This will untaint $temp_file, however it kinda defeats the purpose of taint
checking as it checks nothing about what is in $temp_file. It could be that if
$temp_file is raw user input it contains the string "; rm -rf * ;"

Be careful unless you are 100% sure that $temp_file contains a trusted value -
Perl it seems is not.

I presume that somewhere above the code posted is a line like:

use constant $RESTORE_DIR  => 'usr/local/apache/data/restore_dir';

or

my $RESTORE_DIR = 'usr/local/apache/data/restore_dir';

If  $RESTORE_DIR is hard coded then it should remain untainted.

You may also need to secure your PATH with a

$ENV{PATH} = 'usr/my/safe/path';

although you are not showing any path problems in you post.

Suggest you check out the  Camel book and perldocs.

Cheers

James


>
> Thanks in advance.
>
> Paul



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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 834
**************************************


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