[11417] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5016 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 1 12:07:40 1999

Date: Mon, 1 Mar 99 09:02:24 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 1 Mar 1999     Volume: 8 Number: 5016

Today's topics:
    Re: cgi question (Michael Smith)
    Re: Databases & Perl <gellyfish@btinternet.com>
        Do you really need to do 'open(whatever, ..) or die..' <baillie@my-dejanews.com>
    Re: Do you really need to do 'open(whatever, ..) or die <hm@garmisch.net>
    Re: does perl discourage obfuscated code? (was Re: Perl ran@netgate.net
        FAQ 7.10: How do I create a class?   <perlfaq-suggestions@perl.com>
        FAQ 7.11: How can I tell if a variable is tainted?   <perlfaq-suggestions@perl.com>
        FAQ 7.12: What's a closure?   <perlfaq-suggestions@perl.com>
        FAQ 7.13: What is variable suicide and how can I preven <perlfaq-suggestions@perl.com>
        FAQ 7.17: How can I access a dynamic variable while a s <perlfaq-suggestions@perl.com>
        FAQ 7.22: How do I create a switch or case statement?   <perlfaq-suggestions@perl.com>
    Re: Finding the week day. (Nelson E. Ingersoll)
        gethostbyname bug? <haye@cs.cornell.edu>
        grep netstat and display status in html. <cjgebha@enteract.com>
        grep syntax question (KLMN2)
    Re: grep syntax question (Tad McClellan)
    Re: grep syntax question (Randal L. Schwartz)
    Re: grep syntax question (Charles DeRykus)
    Re: Help - regex to extract two fields in "uptime" <baillie@my-dejanews.com>
    Re: Help on CGI!! <rabinv@hotmail.com>
    Re: HELP on socket (Greg Bacon)
    Re: Help! Who can teach me :( (Andre L.)
    Re: Help! Who can teach me :( (Charles DeRykus)
    Re: Help!! <clm@biteme.com>
    Re: Help!! <lembark@wrkhors.com>
    Re: how do I wildcard within eq '***' ? <hm@garmisch.net>
    Re: how do I wildcard within eq '***' ? <hm@garmisch.net>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 1 Mar 1999 16:32:57 GMT
From: smith@io.com (Michael Smith)
Subject: Re: cgi question
Message-Id: <slrn7dlgbe.2hi.smith@dillinger-2.io.com>

On Mon, 01 Mar 1999 02:47:40 -0500, Justin Baugh <baughj@rpi.edu>
wrote:

>When I run my cgi script from a shell, it works fine...when I try to
>execute it from the webserver, I get this in the error logs:
>
>[Mon Mar  1 07:40:40 1999] access to
>/home/mideprov/mideprovince-www/cgi-bin/pdb failed for XXX.XXX.XXX.XXX, 
>reason: attempt to invoke directory as script
>
>And I get a 403 for /cgi-bin/pdb.
>
>The script is within the /cgi-bin/pdb directory...

1) Are you using .cgi as the extension on the script? If not, that
might be the first thing to try changing.

2) Have you been able to run _any_ CGI scripts successfully from
your cgi-bin directory? Are you sure that your system adminstrator
has configured your server in such a way that you are able to do so?

3) Do you know what Web server you are running, and have you read
the CGI documentation for it, especially the troubleshooting info?

Clearly, though, this is not a Perl problem, but a CGI problem, and,
with all respect, you will probably get a better answer if you post
it to comp.infosystems.www.authoring.cgi.

-- 
Michael Smith
smith@io.com     Austin, Texas


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

Date: 27 Feb 1999 21:10:49 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Databases & Perl
Message-Id: <7b9n0p$3m5$1@gellyfish.btinternet.com>

On Sat, 27 Feb 1999 10:59:20 -0500 Todd L. Poole wrote:
> Hello,
> 
> I am pretty new to perl script. I have an application that requires updates
> to an access database. We are running NT server and IIS4.0
> 
> Does anyone know if this is possible? Any help is appreciated!
> 

Of course it is possible.

Depending on your environment you might want to use either:

Win32::ODBC - if you think that your application will only ever run on a
              MS platform.

DBD::ODBC   - If you might be wanting to move your application to another
						  platform at some time.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Mon, 01 Mar 1999 16:12:55 GMT
From: Baillie <baillie@my-dejanews.com>
Subject: Do you really need to do 'open(whatever, ..) or die..'
Message-Id: <7bee9t$m4l$1@nnrp1.dejanews.com>

It seems as if a program will never die at the open line, but rather at the
close line.  Why is that?

i.e.

open(FH, "< $file") || die "can't open $file: $!";
will only complain that the file doesn't exist, but will not die until

close(FH) || die "can't close $file: $!";

I don't get this.  What's the point in setting up to die from the open if it
doesn't work?

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Mon, 01 Mar 1999 17:48:34 +0100
From: Heiko Marschall <hm@garmisch.net>
Subject: Re: Do you really need to do 'open(whatever, ..) or die..'
Message-Id: <36DAC4E2.6EE6FBDC@garmisch.net>

Sure - there is no handle to close if there was no successfully open.
Use "-e":
if (!(-e $FILE)) { die "File doesn4t exist"; }

- Heiko -

> It seems as if a program will never die at the open line, but rather at the
> close line.  Why is that?
> 
> i.e.
> 
> open(FH, "< $file") || die "can't open $file: $!";
> will only complain that the file doesn't exist, but will not die until
> 
> close(FH) || die "can't close $file: $!";
> 
> I don't get this.  What's the point in setting up to die from the open if it
> doesn't work?

-- 
-------------------------------------------------------------------
 Dipl.Phys. Heiko B. Marschall - Geschdftsleitung
 MARSCHALL ELECTRONICS GmbH & Co KG
 hm@garmisch.net  		http://www.garmisch.net
 Phone: +49 8821 943910-0	Kreuzackerstrasse 2
 Fax:   +49 8821 943910-99	D-82467 Garmisch-Partenkirchen


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

Date: 28 Feb 1999 14:06:56 GMT
From: ran@netgate.net
Subject: Re: does perl discourage obfuscated code? (was Re: Perl evangelism)
Message-Id: <7bbii0$ri7$1@remarQ.com>

In <19990227.183452.7J7.rnr.w164w_-_@locutus.ofB.ORG>, Russell Schulz <Russell_Schulz@locutus.ofB.ORG> writes:

>I believe it.  Perl encourages hard-to-read code. 

More like "enables".  As in "co-dependent"...

>that's just the
>way it is, and if you don't apply a strong discipline when writing
>Perl, you're going to be the proud owner of a ton of read-only code.

Ignorance can help,  too  ;-)  Like not knowing (or acting as though you
don't know) about some of the nifty tricks like implicitly-used 
variables.  E.g., even after many years of using awk, I literally don't
even think about eliding the ", $0" in a gsub call, despite its being
"redundant".  I think it's more a matter of "painful experience teaching
good habits" than "strong discipline".  I read about the feature, 
thought "Gee,  there's a land mine waiting to be stepped on",  and 
proceeded to ignore its existence.

>I would guess only APL has ever had a higher reliance on symbols and
>gave a stronger nod towards compactness.

I think APL is helped by the "alien-ness" of its symbol set (although I 
might feel differently if I were Greek...).  It helps create a mental 
"context switch" that encourages thinking in APLish terms.  Contrast 
that with Perl's use of familiar characters in very unfamiliar (to the
newbie) or non-routine (to the experienced programmer who still uses 
them for other purposes on a daily basis) ways.  It makes it harder to 
mentally shift gears,  in much the same way that early attempts to
transliterate APL into standard ASCII did.

The thing that really hammered APL readability was the high cost of 
computer resources,  and the mediocre optimization,  of the mainframe 
systems it got started on.  It could get painfully expensive to give
variables names like "monthly_total" instead of "mttl",  or to split 
code into several lines (and even add comments!) for ease of 
maintenance.

I've been out of touch with APL since leaving mainframes behind almost 
20 years ago.  I wonder if it,  like C,  has "grown up" as declining 
resource costs have made practices like longer,  more-readable names, 
and "unoptimized" code less effective.  Any lurking APL users out there?

Those sorts of "efficiency" concerns shouldn't arise with Perl,  but 
there's still a risk that people will adopt that mindset in the name of 
"rapid development".  So,  yes,  people who haven't developed good 
habits from being forced to deal with their own cryptic "legacy" code do
need some extra discipline until they've gotten that experience.

>if this is the most damaging quote you can supply from Microsoft, then
>you just aren't trying!  :-)

Or maybe Visual BASIC is trying,  but not succeeding.  Certainly anyone
who's used it knows it can be extremely trying...

Ran




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

Date: 27 Feb 1999 13:02:26 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.10: How do I create a class?  
Message-Id: <36d84f52@csnews>

(This excerpt from perlfaq7 - Perl Language Issues 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I create a class?

    See the perltoot manpage for an introduction to classes and objects, as
    well as the perlobj manpage and the perlbot manpage.

-- 
"When you type to Unix, a gnome deep in the system is gathering your
characters and saving them in a secret place."  - Unix 6th edition manual


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

Date: 27 Feb 1999 15:32:28 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.11: How can I tell if a variable is tainted?  
Message-Id: <36d8727c@csnews>

(This excerpt from perlfaq7 - Perl Language Issues 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)

  How can I tell if a variable is tainted?

    See the section on "Laundering and Detecting Tainted Data" in the
    perlsec manpage. Here's an example (which doesn't use any system calls,
    because the kill() is given no processes to signal):

        sub is_tainted {
            return ! eval { join('',@_), kill 0; 1; };
        }

    This is not `-w' clean, however. There is no `-w' clean way to detect
    taintedness - take this as a hint that you should untaint all possibly-
    tainted data.

-- 
	I get so tired of utilities with arbitrary, undocumented,
	compiled-in limits.  Don't you?


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

Date: 27 Feb 1999 18:02:31 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.12: What's a closure?  
Message-Id: <36d895a7@csnews>

(This excerpt from perlfaq7 - Perl Language Issues 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)

  What's a closure?

    Closures are documented in the perlref manpage.

    *Closure* is a computer science term with a precise but hard-to-explain
    meaning. Closures are implemented in Perl as anonymous subroutines with
    lasting references to lexical variables outside their own scopes. These
    lexicals magically refer to the variables that were around when the
    subroutine was defined (deep binding).

    Closures make sense in any programming language where you can have the
    return value of a function be itself a function, as you can in Perl.
    Note that some languages provide anonymous functions but are not capable
    of providing proper closures; the Python language, for example. For more
    information on closures, check out any textbook on functional
    programming. Scheme is a language that not only supports but encourages
    closures.

    Here's a classic function-generating function:

        sub add_function_generator {
          return sub { shift + shift };
        }

        $add_sub = add_function_generator();
        $sum = $add_sub->(4,5);                # $sum is 9 now.

    The closure works as a *function template* with some customization slots
    left out to be filled later. The anonymous subroutine returned by
    add_function_generator() isn't technically a closure because it refers
    to no lexicals outside its own scope.

    Contrast this with the following make_adder() function, in which the
    returned anonymous function contains a reference to a lexical variable
    outside the scope of that function itself. Such a reference requires
    that Perl return a proper closure, thus locking in for all time the
    value that the lexical had when the function was created.

        sub make_adder {
            my $addpiece = shift;
            return sub { shift + $addpiece };
        }

        $f1 = make_adder(20);
        $f2 = make_adder(555);

    Now `&$f1($n)' is always 20 plus whatever $n you pass in, whereas
    `&$f2($n)' is always 555 plus whatever $n you pass in. The $addpiece in
    the closure sticks around.

    Closures are often used for less esoteric purposes. For example, when
    you want to pass in a bit of code into a function:

        my $line;
        timeout( 30, sub { $line = <STDIN> } );

    If the code to execute had been passed in as a string, `'$line =
    <STDIN>'', there would have been no way for the hypothetical timeout()
    function to access the lexical variable $line back in its caller's
    scope.

-- 
Someone who truly understands UNIX not only understands why "rm *"    
screws you, but understands why IT HAS TO BE THAT WAY.


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

Date: 27 Feb 1999 20:32:33 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.13: What is variable suicide and how can I prevent it?  
Message-Id: <36d8b8d1@csnews>

(This excerpt from perlfaq7 - Perl Language Issues 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)

  What is variable suicide and how can I prevent it?

    Variable suicide is when you (temporarily or permanently) lose the value
    of a variable. It is caused by scoping through my() and local()
    interacting with either closures or aliased foreach() iterator variables
    and subroutine arguments. It used to be easy to inadvertently lose a
    variable's value this way, but now it's much harder. Take this code:

        my $f = "foo";
        sub T {
          while ($i++ < 3) { my $f = $f; $f .= "bar"; print $f, "\n" }
        }
        T;
        print "Finally $f\n";

    The $f that has "bar" added to it three times should be a new `$f' (`my
    $f' should create a new local variable each time through the loop). It
    isn't, however. This is a bug, and will be fixed.

-- 
There is no problem so complex that it can't be solved by another level
of indirection --except for too many level of indirection.


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

Date: 28 Feb 1999 06:32:55 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.17: How can I access a dynamic variable while a similarly named lexical is in scope?  
Message-Id: <36d94587@csnews>

(This excerpt from perlfaq7 - Perl Language Issues 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)

  How can I access a dynamic variable while a similarly named lexical is in scope?

    You can do this via symbolic references, provided you haven't set `use
    strict "refs"'. So instead of $var, use `${'var'}'.

        local $var = "global";
        my    $var = "lexical";

        print "lexical is $var\n";

        no strict 'refs';
        print "global  is ${'var'}\n";

    If you know your package, you can just mention it explicitly, as in
    $Some_Pack::var. Note that the notation $::var is *not* the dynamic $var
    in the current package, but rather the one in the `main' package, as
    though you had written $main::var. Specifying the package directly makes
    you hard-code its name, but it executes faster and avoids running afoul
    of `use strict "refs"'.

-- 
    A formal parsing algorithm should not always be used.
		    --D. Gries


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

Date: 28 Feb 1999 19:03:08 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.22: How do I create a switch or case statement?  
Message-Id: <36d9f55c@csnews>

(This excerpt from perlfaq7 - Perl Language Issues 
    ($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)

  How do I create a switch or case statement?

    This is explained in more depth in the the perlsyn manpage. Briefly,
    there's no official case statement, because of the variety of tests
    possible in Perl (numeric comparison, string comparison, glob
    comparison, regexp matching, overloaded comparisons, ...). Larry
    couldn't decide how best to do this, so he left it out, even though it's
    been on the wish list since perl1.

    The general answer is to write a construct like this:

        for ($variable_to_test) {
            if    (/pat1/)  { }     # do something
            elsif (/pat2/)  { }     # do something else
            elsif (/pat3/)  { }     # do something else
            else            { }     # default
        } 

    Here's a simple example of a switch based on pattern matching, this time
    lined up in a way to make it look more like a switch statement. We'll do
    a multi-way conditional based on the type of reference stored in
    $whatchamacallit:

        SWITCH: for (ref $whatchamacallit) {

            /^$/            && die "not a reference";

            /SCALAR/        && do {
                                    print_scalar($$ref);
                                    last SWITCH;
                            };

            /ARRAY/         && do {
                                    print_array(@$ref);
                                    last SWITCH;
                            };

            /HASH/          && do {
                                    print_hash(%$ref);
                                    last SWITCH;
                            };

            /CODE/          && do {
                                    warn "can't print function ref";
                                    last SWITCH;
                            };

            # DEFAULT

            warn "User defined type skipped";

        }

    See `perlsyn/"Basic BLOCKs and Switch Statements"' for many other
    examples in this style.

    Sometimes you should change the positions of the constant and the
    variable. For example, let's say you wanted to test which of many
    answers you were given, but in a case-insensitive way that also allows
    abbreviations. You can use the following technique if the strings all
    start with different characters, or if you want to arrange the matches
    so that one takes precedence over another, as `"SEND"' has precedence
    over `"STOP"' here:

        chomp($answer = <>);
        if    ("SEND"  =~ /^\Q$answer/i) { print "Action is send\n"  }
        elsif ("STOP"  =~ /^\Q$answer/i) { print "Action is stop\n"  }
        elsif ("ABORT" =~ /^\Q$answer/i) { print "Action is abort\n" }
        elsif ("LIST"  =~ /^\Q$answer/i) { print "Action is list\n"  }
        elsif ("EDIT"  =~ /^\Q$answer/i) { print "Action is edit\n"  }

    A totally different approach is to create a hash of function references.

        my %commands = (
            "happy" => \&joy,
            "sad",  => \&sullen,
            "done"  => sub { die "See ya!" },
            "mad"   => \&angry,
        );

        print "How are you? ";
        chomp($string = <STDIN>);
        if ($commands{$string}) {
            $commands{$string}->();
        } else {
            print "No such command: $string\n";
        } 

-- 
Any opinions expressed are my own, and generally unpopular with others.


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

Date: Mon, 01 Mar 1999 02:56:24 GMT
From: ningersoll@codenet.doh.net (Nelson E. Ingersoll)
Subject: Re: Finding the week day.
Message-Id: <36da00e3.338752067@news.codenet.net>

On 23 Feb 1999 22:07:57 GMT, mauro@msan. (Mauro Sanna) wrote:

>Hi.
>Sorry for my bad english, I'm Italian.
>I have a great problem.
>I can't find the week day of a date.
>For example, how can I get the week day of 12/02/1999?
>Thanks.

Get yourself to http://www.cpan.org/ and look for Date-Manip.  It will
do this function for you very simply.  I won't bother to tell you how
since it is well enough documented.  It even works under Perl Win32
from ActiveState.  


- Nelson Ingersoll
  VAX/VMS Grunt
  UNIX Noviate
  Oracle DBA in Training
  Perl programmer by choice.
  Microsoft user cause they FORCED ME!

============================================================
I accept email.  Just remove the '.DOH' from the the return
address.  And, please forgive the subterfuge.  I hate spam;
but love newsgroups.
============================================================


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

Date: Sat, 27 Feb 1999 17:54:43 -0500
From: "Haye Chan" <haye@cs.cornell.edu>
Subject: gethostbyname bug?
Message-Id: <7b9t3l$l5q@blather.cs.cornell.edu>

I am using gethostbyname to get the list of IP addresses for a host. However
the implementation in my version of Perl doesn't seem to be working as
expected. It only gives me one IP address, even if there are more than one
addresses when I check it with nslookup. For example:

($name, $aliases, $addrtype, $length, @addrs) =
gethostbyname("csgate5.cs.cornell.edu");
foreach $addr (@addrs) {
    ($a, $b, $c, $d) = unpack('C4', $addr);
    print "$a.$b.$c.$d\n";
}

Only one address is printed, even though a nslookup of
csgate5.cs.cornell.edu gives me a list of 6 addresses. Can anyone tell me
how can I obtain all 6 addresses without invoking system calls like :
open(FOO, "nslookup csgate5.cs.cornell.edu") ?

I really appreciate it. Thanks.

Haye Chan
haye@cs.cornell.edu




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

Date: Sat, 27 Feb 1999 19:50:03 -0600
From: Chris Gebhardt <cjgebha@enteract.com>
Subject: grep netstat and display status in html.
Message-Id: <36D8A0CB.8551C0BB@enteract.com>

I am a perl newbie trying to have a perl script post a message if
netstat returns a default gateway.
Basically I grep netstat -r for the word default and direct the output
of the file to a file called IP.  Well when I run the perl from the
command line it creates the correct output but when i try it in the
webpage it returns a internal server error and never creates the file.
I have tried almost everything to debug this script but I can not seem
to get any to work.  My limited experience with linux and perl does not
help either.

If someone could provide some help in debugging this script or provide a

easier solution to what I would like to do.  Also any links that would
provide perl html integration would also be of assistance.

Thanks,
Chris Gebhardt


#!/usr/bin/perl
unless (fork){
  exec "netstat -r |grep default >/home/httpd/cgi-bin/IP";
}
wait;

if (-z "IP"){
 print 'Content-type: text/html
 <HTML>
 Not Connected
 </HTML>
 ';

} else {
 print 'Content-type: text/html
 <HTML>
 CONNECTED
 </HTML>';
}

unless (fork){exec "rm -f IP";}
wait;





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

Date: 27 Feb 1999 21:19:09 GMT
From: klmn2@aol.com (KLMN2)
Subject: grep syntax question
Message-Id: <19990227161909.11951.00001742@ng-cg1.aol.com>

Hi -

I am using a search script in Perl which uses grep as:

@results = grep(/$searchstr/,@mydata);

However, whenever I search with this code it is case sensitive.
How do I write it so the search is case insensitive?

Thanks,
Kalman


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

Date: Sun, 28 Feb 1999 02:56:03 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: grep syntax question
Message-Id: <jqsab7.ltf.ln@magna.metronet.com>

Andre L. (alecler@cam.org) wrote:
: In article <m1sobrtqm5.fsf@halfdome.holdit.com>, merlyn@stonehenge.com
: (Randal L. Schwartz) wrote:

: > >>>>> "KLMN2" == KLMN2  <klmn2@aol.com> writes:
: > 
: > KLMN2> I am using a search script in Perl which uses grep as:
: > 
: > KLMN2> @results = grep(/$searchstr/,@mydata);
: > 
: > KLMN2> However, whenever I search with this code it is case sensitive.
: > KLMN2> How do I write it so the search is case insensitive?
: > 
: > First, understand that this is not "grep" syntax... :) From "perldoc
: > perlfunc", grep syntax is something like:
: > 
: >         @results = grep EXPR, @mydata;
: > 

: I don't understand what you see wrong with KLMN2's syntax. Am I missing
: something???


   Yes.

   Randal's comment is not about the grep syntax, but pointing out
   the the Subject: is not correct.

   Getting case-insensitive pattern matching has to do with the
   _regex_ syntax (EXPR), not the grep() syntax.


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


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

Date: 27 Feb 1999 14:43:14 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: grep syntax question
Message-Id: <m1sobrtqm5.fsf@halfdome.holdit.com>

>>>>> "KLMN2" == KLMN2  <klmn2@aol.com> writes:

KLMN2> I am using a search script in Perl which uses grep as:

KLMN2> @results = grep(/$searchstr/,@mydata);

KLMN2> However, whenever I search with this code it is case sensitive.
KLMN2> How do I write it so the search is case insensitive?

First, understand that this is not "grep" syntax... :) From "perldoc
perlfunc", grep syntax is something like:

	@results = grep EXPR, @mydata;

So, given that we've got a regular expression match here for EXPR,
perhaps you might have gotten your clue in "perldoc perlre".

If you're impatient, the answer you want is to attach an /i to the end
of the regular expression.

print join qq" ", grep qq" ", qw"Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Sat, 27 Feb 1999 23:22:36 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: grep syntax question
Message-Id: <F7u69o.n52@news.boeing.com>

In article <19990227161909.11951.00001742@ng-cg1.aol.com>,
KLMN2 <klmn2@aol.com> wrote:
>Hi -
>
>I am using a search script in Perl which uses grep as:
>
>@results = grep(/$searchstr/,@mydata);
>
>However, whenever I search with this code it is case sensitive.
>How do I write it so the search is case insensitive?
>

perldoc perlre and look read the paragraph which
contains the explanation below:

    i   Do case-insensitive pattern matching.


hth,
--
Charles DeRykus


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

Date: Mon, 01 Mar 1999 16:07:51 GMT
From: Baillie <baillie@my-dejanews.com>
Subject: Re: Help - regex to extract two fields in "uptime"
Message-Id: <7bee0e$lo3$1@nnrp1.dejanews.com>

In article <36d978b4.3030207@news.bayarea.net>,
  kag@gaugler.com wrote:
> Hello,
>
> I have a file full of lines of the output from "uptime", from which I would
> like to extract just the time and the 1-minute load average. That is, for
> the line:
>
>   8:00am  up 23 day(s), 21:34,  7 users,  load average: 0.13, 0.08, 0.09
>
> I want to extract:
>
> 8:00am  0.13
>
> note that the leading spaces are also removed.
>
> Can someone tell me the regular expression that would eliminate the unwanted
> characters?
>
> Thanks,
> Ken
>
I'm sure there's probably a better way to do this, but here's one way:

@uparray = split(' ', `uptime`);

print "what you want: $uparray[0] $uparray[9]\n";

>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Sat, 27 Feb 1999 16:11:18 -0500
From: Rabin Vongpaisal <rabinv@hotmail.com>
Subject: Re: Help on CGI!!
Message-Id: <36D85F76.88B00E42@hotmail.com>

Interesting.  Im a newbie, but how do you keep the file open and the
browser opening it?

I might come across a use for this later.  

Any help would be appreciated.
Rabin

news.casema.net wrote:
> 
> Hi,
> 
> I must say I find this an interesting topic since I have been thinking about
> this
> 'problem' as well. If people are interested I have an example where it is
> done
> the way I want to be able doing it :)
> The site is a realtime HTML chat, consisting of 2 frames. The top frame is
> used for entering text to send into the chat etc, and the bottom frame shows
> the text sent by chatter. This bottom page is viewable, but never done
> loading.
> It doesn't reload every x seconds as in most HTML based chats, but the page
> just stays 'open'. How is it done?
> The adress of the chat is : http://www.hotelchat.com/
> I use perl CGI's on a Linux based system.
> 
> Jeroen
>


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

Date: 1 Mar 1999 16:58:41 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: HELP on socket
Message-Id: <7beh01$3gv$1@info.uah.edu>

In article <36DAB931.412DBD68@online.no>,
	Stian Langeland <langels@online.no> writes:
: I would like to communicate between a Visual Basic program on a winX
: machine and perl on a linux machine. Is it possible to make a server
: script in perl  that communicates through Winsock on a linux machine

Please review the example at the end of the IO::Select documentation.

Greg
-- 
A Freudian slip is when you say one thing when you're thinking about a mother. 
    -- Cliff Clavin


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

Date: Sat, 27 Feb 1999 14:59:23 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Help! Who can teach me :(
Message-Id: <alecler-2702991459230001@dialup-554.hip.cam.org>

In article <36D825FB.F92B8E20@hongkong.com>, Aaron Au
<au_aaron@hongkong.com> wrote:

> Please teach me how to do!
> 
> $var1 = "\$a";
> $var2 = "b";
> $var3 = $var1.$var2;
> $var3 = "xyz";  #Actually, I want to assign $ab to "xyz"
> print $ab; #Nothing else!

It looks like you want to use a symbolic reference to $ab and assign 'xyz'
to it, right?

   $v1 = 'a';
   $v2 = 'b';
   $v3 = "$v1$v2";

   $$v3 = 'xyz';
   print $ab;

But you should avoid this and use a hash instead:

  $v1 = 'a';
  $v2 = 'b';
  $hash{ab} = 'xyz';

  print $hash{"$v1$v2"};

You might want to take a look at Tom Christiansen's excellent article,
"FAQ - Using a var as a var name" that he posted recently.

HTH,
Andre


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

Date: Sat, 27 Feb 1999 21:02:20 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Help! Who can teach me :(
Message-Id: <F7tzrw.JCw@news.boeing.com>

In article <36D825FB.F92B8E20@hongkong.com>,
Aaron Au  <au_aaron@hongkong.com> wrote:
>Hi everyone,
>Please teach me how to do!
>
>$var1 = "\$a";
>$var2 = "b";
>$var3 = $var1.$var2;
>$var3 = "xyz";  #Actually, I want to assign $ab to "xyz"
>print $ab; #Nothing else!
>
 
If I understand rightly you'll benefit by reading Tom's
recent FAQ entry: "Using a variable as a variable name"

Look in DejaNews for that title or check for new faq
entries in http://language.perl.com/faq/


Regards,
--
Charles DeRykus


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

Date: Sun, 28 Feb 1999 21:05:49 -0500
From: "Clawed Le Mew" <clm@biteme.com>
Subject: Re: Help!!
Message-Id: <epPXvg4Y#GA.324@nih2naae.prod2.compuserve.com>

The \Q and \E escapes were just what I needed. I'm impressed with what you
can do with just a few lines of code in Perl. Thanks, and sorry for going
overboard posting all those extra lines of the table.

A few tweaks later, I've pretty much got the thing working the way I wanted,
but one more question. What if I wanted to maintain this long table in
Oracle, rather than hard-coded in the program as I have? Is there an
interface available that I can use within Perl to read from Oracle, and if
so, where can I get information about it?

Thanks

Bennett ( b_engel@csi.com )




Jonathan Feinberg wrote in message ...
>"Clawed Le Mew" <clm@biteme.com> writes:
>
>If you'd like to escape all of the meta-characters in a string, you
>may use the quotemeta() function or the "\Q\E" escapes, also
>documented in perlre and perlfunc.
>
>--
>Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
>http://pobox.com/~jdf




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

Date: Sun, 28 Feb 1999 21:41:30 -0600
From: Steven Lembark <lembark@wrkhors.com>
Subject: Re: Help!!
Message-Id: <36DA0C6A.153C2D80@wrkhors.com>

escape the sequences.  can be done for you by perl.  that or
remove them from the input stream before using the s/// section
via substr or another regeular expression.

-- 
 Steven Lembark                                   2930 W. Palmer St.
 Workhorse Computing                             Chicago, IL  60647
 lembark@wrkhors.com                                   800-762-1582
---------------------------------------------------------------------
  The opinions expressed here are those of this company.
  I am the company.
---------------------------------------------------------------------


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

Date: Mon, 01 Mar 1999 17:30:02 +0100
From: Heiko Marschall <hm@garmisch.net>
Subject: Re: how do I wildcard within eq '***' ?
Message-Id: <36DAC08A.5C34E806@garmisch.net>

> > > How do I modify the line below to accept a wildcard before 'aol.com' ? I
> > > want to re-direct AOL users to another URL but, like most ISPs, the front
> > > end changes dynamically. I can't simply put '*.aol' in there. Anyone help?
> > >
> > > if ($ENV{'REMOTE_HOST'} eq 'aol.com') {$HostRedirector =
> > > "http://mydomain.com/aolusers.html}
> >
> > if ($ENV{REMONTE_HOST}=~/.*?\.aol$/i) {...}
>                                    ^
> 
> The $ at the end is wrong -- the address will, presumably, end in
> "aol.com", not just in "aol".

I only made the match for what was requested -> *.aol :-)
I also think that should be *.com ...

 - Heiko -
-- 
-------------------------------------------------------------------
 Dipl.Phys. Heiko B. Marschall - Geschdftsleitung
 MARSCHALL ELECTRONICS GmbH & Co KG
 hm@garmisch.net  		http://www.garmisch.net
 Phone: +49 8821 943910-0	Kreuzackerstrasse 2
 Fax:   +49 8821 943910-99	D-82467 Garmisch-Partenkirchen


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

Date: Mon, 01 Mar 1999 17:43:58 +0100
From: Heiko Marschall <hm@garmisch.net>
Subject: Re: how do I wildcard within eq '***' ?
Message-Id: <36DAC3CE.64444405@garmisch.net>

> I've replaced it with the line you suggested below and ran 'perl -c' on the
> file. It gives the error "/.*?\.aol$/: nested *?+ in regexp at line blah"  .
> Is there something slightly amiss here?
> 
> if ($ENV{REMOTE_HOST}=~/.*?\.aol$/i) {$HostRedirector =
> "http://mydomain/aolusers.html"}
> 
> Also if I wanted to direct UK users to our UK web, how would I wildcard the
> bit before '.uk' within the expression? Many thanks for your help.
> Mig.

 .*? should match everything except \n 0 or more times minimal (means
until the first .aol is found). The "i" is for case-insensitiv (could be
 .AOL or .aol or .Aol) - I think you mean .aol.com so it should be
/.*?\.aol\.com$/
"$" means .aol.com must be matched at the end of the string.
It works also without the "?" because the .aol.com$ is given explicit at
the end.

The match is ok - I tested it ..

So the ".*?" stands for your wildcard "*" and "\.aol" for the rest ->
*.aol (or *.com -> \.com)
You need the "\" ("meta") to let perl not interpret the dot as a
matching command. 

But all this is simple matching - maybe you should read the matching
basics of shell scripting.

- Heiko -
-- 
-------------------------------------------------------------------
 Dipl.Phys. Heiko B. Marschall - Geschdftsleitung
 MARSCHALL ELECTRONICS GmbH & Co KG
 hm@garmisch.net  		http://www.garmisch.net
 Phone: +49 8821 943910-0	Kreuzackerstrasse 2
 Fax:   +49 8821 943910-99	D-82467 Garmisch-Partenkirchen


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

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


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 5016
**************************************

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