[11324] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4924 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 18 03:07:24 1999

Date: Thu, 18 Feb 99 00:00:26 -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           Thu, 18 Feb 1999     Volume: 8 Number: 4924

Today's topics:
        Calling LOCAL CGI Perl script from web browser - possib <bakerb@telusplanet.net>
        Escaping characters <patfong@yoyo.cc.monash.edu.au>
        FAQ 5.5: How can I manipulate fixed-record-length files <perlfaq-suggestions@perl.com>
        FAQ 5.6: How can I make a filehandle local to a subrout <perlfaq-suggestions@perl.com>
    Re: FAQ 5.6: How can I make a filehandle local to a sub <uri@home.sysarch.com>
        FAQ 5.7: How can I use a filehandle indirectly?   <perlfaq-suggestions@perl.com>
        FAQ 5.8: How can I set up a footer format to be used wi <perlfaq-suggestions@perl.com>
        How to pass a parameter to system() from perl script? (Hong)
    Re: How to pass a parameter to system() from perl scrip <kswong@bigpond.com>
        HTML::TreeBuilder - I'm almost there... <jerryp.usenet@connected.demon.co.uk>
        Interprocess Communication using signals jkir@erols.com
        Mail confirmation <ughridk@bbbhotmail.com>
    Re: Need perl programmer <ebohlman@netcom.com>
        Perl Contractor <user@home.com>
    Re: Perl function to reboot NT Server? <greenej@my-dejanews.com>
    Re: perl/tk for win95 renenyffenegger@my-dejanews.com
    Re: String Manipulation (yet another newbie question) <kswong@bigpond.com>
    Re: String Manipulation (yet another newbie question) <ebohlman@netcom.com>
    Re: String Manipulation (yet another newbie question) (Larry Rosler)
        Stumped <wfs-dominion@worldnet.att.net>
    Re: Variable for variable names <tchrist@mox.perl.com>
    Re: WWW Hosting for a site in need of CGI <bcornwell@mail.peds.lsumc.edu>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Thu, 18 Feb 1999 04:35:49 GMT
From: Bill Baker <bakerb@telusplanet.net>
Subject: Calling LOCAL CGI Perl script from web browser - possible?
Message-Id: <36CB8DDA.6DEB052F@telusplanet.net>

If I open a web page on my C: (hard) drive, click on a URL that points
to a CGI Perl script that also resides on my hard drive, will MS
Internet Explorer and/or Navigator be smart enough to invoke that Perl
script and return the resulting web page?

Please copy me in email.

Thanks!
Bill.




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

Date: Thu, 18 Feb 1999 16:24:32 +1100
From: Patrick Fong <patfong@yoyo.cc.monash.edu.au>
Subject: Escaping characters
Message-Id: <Pine.OSF.4.00.9902181622060.22124-100000@yoyo.cc.monash.edu.au>

Hi

Was wondering if someone could tell me more about escaping characters.
Well I think that is related to my problem

the following line gives me errors..


print FIND " <TR VALIGN=top ALIGN=center><TD 
BGCOLOR=#cccc99>$FORM{'filename'}<\/TD><TD 
BGCOLOR=#cccc99>$shortdate<\/TD>";

all of them are on one line of course. We have to escape things like
forward/backward slashes... fullstops... commas... what else?? And why?

P.



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

Date: 17 Feb 1999 21:28:29 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 5.5: How can I manipulate fixed-record-length files?  
Message-Id: <36cb96ed@csnews>

(This excerpt from perlfaq5 - Files and Formats 
    ($Revision: 1.34 $, $Date: 1999/01/08 05:46:13 $)
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/perlfaq5.html
if your negligent system adminstrator has been remiss in his duties.)

  How can I manipulate fixed-record-length files?

    The most efficient way is using pack() and unpack(). This is faster than
    using substr() when taking many, many strings. It is slower for just a
    few.

    Here is a sample chunk of code to break up and put back together again
    some fixed-format input lines, in this case from the output of a normal,
    Berkeley-style ps:

        # sample input line:
        #   15158 p5  T      0:00 perl /home/tchrist/scripts/now-what
        $PS_T = 'A6 A4 A7 A5 A*';
        open(PS, "ps|");
        print scalar <PS>; 
        while (<PS>) {
            ($pid, $tt, $stat, $time, $command) = unpack($PS_T, $_);
            for $var (qw!pid tt stat time command!) {
                print "$var: <$$var>\n";
            }
            print 'line=', pack($PS_T, $pid, $tt, $stat, $time, $command),
                    "\n";
        }

    We've used `$$var' in a way that forbidden by `use strict 'refs''. That
    is, we've promoted a string to a scalar variable reference using
    symbolic references. This is ok in small programs, but doesn't scale
    well. It also only works on global variables, not lexicals.

-- 
"The printing on the t-shirt was not an encrypted message, it was a Perl
script... " (Don Henson, "alt.security.pgp" June 1995)
"You just contradicted yourself there... :-)" (Larry Wall,
"alt.security.pgp" June 1995, answer to Don Henson)


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

Date: 17 Feb 1999 22:28:33 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 5.6: How can I make a filehandle local to a subroutine?  How do I pass filehandles between subroutines?  How do I make an array of filehandles?  
Message-Id: <36cba501@csnews>

(This excerpt from perlfaq5 - Files and Formats 
    ($Revision: 1.34 $, $Date: 1999/01/08 05:46:13 $)
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/perlfaq5.html
if your negligent system adminstrator has been remiss in his duties.)

  How can I make a filehandle local to a subroutine?  How do I pass filehandles between subroutines?  How do I make an array of filehandles?

    The fastest, simplest, and most direct way is to localize the typeglob
    of the filehandle in question:

        local *TmpHandle;

    Typeglobs are fast (especially compared with the alternatives) and
    reasonably easy to use, but they also have one subtle drawback. If you
    had, for example, a function named TmpHandle(), or a variable named
    %TmpHandle, you just hid it from yourself.

        sub findme {
            local *HostFile;
            open(HostFile, "</etc/hosts") or die "no /etc/hosts: $!";
            local $_;               # <- VERY IMPORTANT
            while (<HostFile>) {
                print if /\b127\.(0\.0\.)?1\b/;
            }
            # *HostFile automatically closes/disappears here
        }

    Here's how to use this in a loop to open and store a bunch of
    filehandles. We'll use as values of the hash an ordered pair to make it
    easy to sort the hash in insertion order.

        @names = qw(motd termcap passwd hosts);
        my $i = 0;
        foreach $filename (@names) {
            local *FH;
            open(FH, "/etc/$filename") || die "$filename: $!";
            $file{$filename} = [ $i++, *FH ];
        }

        # Using the filehandles in the array
        foreach $name (sort { $file{$a}[0] <=> $file{$b}[0] } keys %file) {
            my $fh = $file{$name}[1];
            my $line = <$fh>;
            print "$name $. $line";
        }

    For passing filehandles to functions, the easiest way is to preface them
    with a star, as in func(*STDIN). See the section on "Passing
    Filehandles" in the perlfaq7 manpage for details.

    If you want to create many anonymous handles, you should check out the
    Symbol, FileHandle, or IO::Handle (etc.) modules. Here's the equivalent
    code with Symbol::gensym, which is reasonably light-weight:

        foreach $filename (@names) {
            use Symbol;
            my $fh = gensym();
            open($fh, "/etc/$filename") || die "open /etc/$filename: $!";
            $file{$filename} = [ $i++, $fh ];
        }

    Or here using the semi-object-oriented FileHandle module, which
    certainly isn't light-weight:

        use FileHandle;

        foreach $filename (@names) {
            my $fh = FileHandle->new("/etc/$filename") or die "$filename: $!";
            $file{$filename} = [ $i++, $fh ];
        }

    Please understand that whether the filehandle happens to be a (probably
    localized) typeglob or an anonymous handle from one of the modules, in
    no way affects the bizarre rules for managing indirect handles. See the
    next question.

-- 
    Some are born to perl, some achieve perl, and some have perl
    thrust upon them.  


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

Date: 18 Feb 1999 02:12:57 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: FAQ 5.6: How can I make a filehandle local to a subroutine?  How do I pass filehandles between subroutines?  How do I make an array of filehandles?
Message-Id: <x71zjombgl.fsf@home.sysarch.com>

>>>>> "TC" == Tom Christiansen <perlfaq-suggestions@perl.com> writes:

  TC>         @names = qw(motd termcap passwd hosts);
  TC>         my $i = 0;
  TC>         foreach $filename (@names) {
  TC>             local *FH;
  TC>             open(FH, "/etc/$filename") || die "$filename: $!";
  TC>             $file{$filename} = [ $i++, *FH ];
  TC>         }

tom,

could you explain this further? in another thread i was asking for more
documentation about the implied object nature of *FH. here you seem to
be reusing FH but i believe by storing it in the HoL, you get another
handle object with the open call. am i right?

this whole topic of *FH and its implied object nature is unclear to me
and i feel it needs expansion in the docs. in the thread about
read_file, i was surprised that *FH got closed upon exit of its
scope. chris nandor was yelled at me to provide a docs patch but how can
i when i am confused about the very topic. i am asking for more docs on
this from those who can explain it well.

thanx,

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 17 Feb 1999 23:28:36 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 5.7: How can I use a filehandle indirectly?  
Message-Id: <36cbb314@csnews>

(This excerpt from perlfaq5 - Files and Formats 
    ($Revision: 1.34 $, $Date: 1999/01/08 05:46:13 $)
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/perlfaq5.html
if your negligent system adminstrator has been remiss in his duties.)

  How can I use a filehandle indirectly?

    An indirect filehandle is using something other than a symbol in a place
    that a filehandle is expected. Here are ways to get those:

        $fh =   SOME_FH;       # bareword is strict-subs hostile
        $fh =  "SOME_FH";      # strict-refs hostile; same package only
        $fh =  *SOME_FH;       # typeglob
        $fh = \*SOME_FH;       # ref to typeglob (bless-able)
        $fh =  *SOME_FH{IO};   # blessed IO::Handle from *SOME_FH typeglob

    Or to use the `new' method from the FileHandle or IO modules to create
    an anonymous filehandle, store that in a scalar variable, and use it as
    though it were a normal filehandle.

        use FileHandle;
        $fh = FileHandle->new();

        use IO::Handle;                     # 5.004 or higher
        $fh = IO::Handle->new();

    Then use any of those as you would a normal filehandle. Anywhere that
    Perl is expecting a filehandle, an indirect filehandle may be used
    instead. An indirect filehandle is just a scalar variable that contains
    a filehandle. Functions like `print', `open', `seek', or the `<FH>'
    diamond operator will accept either a read filehandle or a scalar
    variable containing one:

        ($ifh, $ofh, $efh) = (*STDIN, *STDOUT, *STDERR);
        print $ofh "Type it: ";
        $got = <$ifh>
        print $efh "What was that: $got";

    If you're passing a filehandle to a function, you can write the function
    in two ways:

        sub accept_fh {
            my $fh = shift;
            print $fh "Sending to indirect filehandle\n";
        }

    Or it can localize a typeglob and use the filehandle directly:

        sub accept_fh {
            local *FH = shift;
            print  FH "Sending to localized filehandle\n";
        }

    Both styles work with either objects or typeglobs of real filehandles.
    (They might also work with strings under some circumstances, but this is
    risky.)

        accept_fh(*STDOUT);
        accept_fh($handle);

    In the examples above, we assigned the filehandle to a scalar variable
    before using it. That is because only simple scalar variables, not
    expressions or subscripts into hashes or arrays, can be used with built-
    ins like `print', `printf', or the diamond operator. These are illegal
    and won't even compile:

        @fd = (*STDIN, *STDOUT, *STDERR);
        print $fd[1] "Type it: ";                           # WRONG
        $got = <$fd[0]>                                     # WRONG
        print $fd[2] "What was that: $got";                 # WRONG

    With `print' and `printf', you get around this by using a block and an
    expression where you would place the filehandle:

        print  { $fd[1] } "funny stuff\n";
        printf { $fd[1] } "Pity the poor %x.\n", 3_735_928_559;
        # Pity the poor deadbeef.

    That block is a proper block like any other, so you can put more
    complicated code there. This sends the message out to one of two places:

        $ok = -x "/bin/cat";                
        print { $ok ? $fd[1] : $fd[2] } "cat stat $ok\n";
        print { $fd[ 1+ ($ok || 0) ]  } "cat stat $ok\n";           

    This approach of treating `print' and `printf' like object methods calls
    doesn't work for the diamond operator. That's because it's a real
    operator, not just a function with a comma-less argument. Assuming
    you've been storing typeglobs in your structure as we did above, you can
    use the built-in function named `readline' to reads a record just as
    `<>' does. Given the initialization shown above for @fd, this would
    work, but only because readline() require a typeglob. It doesn't work
    with objects or strings, which might be a bug we haven't fixed yet.

        $got = readline($fd[0]);

    Let it be noted that the flakiness of indirect filehandles is not
    related to whether they're strings, typeglobs, objects, or anything
    else. It's the syntax of the fundamental operators. Playing the object
    game doesn't help you at all here.

-- 
There's some side effect based on the fact that SIGCHLD isn't sent by
anyone, but is fabricated by the kernel when a child dies.  It's a huge
kludge.  But then, it _is_ SysV. --Chip Salzenberg, aka <chs@nando.net>


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

Date: 18 Feb 1999 00:28:37 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 5.8: How can I set up a footer format to be used with write()?  
Message-Id: <36cbc125@csnews>

(This excerpt from perlfaq5 - Files and Formats 
    ($Revision: 1.34 $, $Date: 1999/01/08 05:46:13 $)
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/perlfaq5.html
if your negligent system adminstrator has been remiss in his duties.)

  How can I set up a footer format to be used with write()?

    There's no builtin way to do this, but the perlform manpage has a couple
    of techniques to make it possible for the intrepid hacker.

-- 
I think I can sum up the difference between *BSD and Linux as follows:
"In Linux, new users get flamed for asking questions in the newsgroups
(or heaven forfend, the wrong newsgroup).  In *BSD the principals
flame each other." --Warner Losh             


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

Date: 18 Feb 1999 05:25:31 GMT
From: yuehong_zheng@yahoo.com (Hong)
Subject: How to pass a parameter to system() from perl script?
Message-Id: <7ag88b$kg5$1@winter.news.rcn.net>


I tried this:

       ...
       $file_name="MYFILE";
       @args=("more", @file_name);
       system(@args);

The problem I am having is that $file_name not get passed to system 
call. Can you tell me what is wrong this code?





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

Date: Thu, 18 Feb 1999 17:07:15 +1100
From: Ka-shu Wong <kswong@bigpond.com>
Subject: Re: How to pass a parameter to system() from perl script?
Message-Id: <Pine.LNX.4.03.9902181701270.197-100000@goose>



On 18 Feb 1999, Hong wrote:

> I tried this:
> 
>        ...
>        $file_name="MYFILE";
>        @args=("more", @file_name);
>        system(@args);
> 
> The problem I am having is that $file_name not get passed to system 
> call. Can you tell me what is wrong this code?

The problem here is that "MYFILE" is assigned to the scalar $file_name,
but the list @file_name is being added to @args.  They are two separate
variables and have nothing to do with each other except for the fact that
they have the same name.
It should have been written:

$file_name="MYFILE";
@args=("more", $file_name);
system(@args);


KS



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

Date: Thu, 18 Feb 1999 06:10:54 +0000
From: Jerry Pank <jerryp.usenet@connected.demon.co.uk>
Subject: HTML::TreeBuilder - I'm almost there...
Message-Id: <JDQF3AAu76y2EwxQ@connected.demon.co.uk>

I'm attempting to use HTML::TreeBuilder to find all text =~/SIZE=4/
remove, manipulate and replace it.

It's taken a while but I've managed to get my &munge_text callback
working for me though I'm having problems with the last part.

How do I get my required text `play' with it and replace it;

I'm pretty sure someone can find a better way to detect the font size as
well.


#!/bin/perl5 -w
use strict;
use HTML::TreeBuilder;
my $h = HTML::TreeBuilder->new;
$h->parse_file("F:/cgi-files/wsa/DW_docs/Environment.htm");
$h->traverse(\&munge_text, 1);

print $h->as_HTML;
print "\nDone";
$h->delete; 
  
sub munge_text {
   my($e, $start) = @_;
   return 1 unless $start;
   my $tag = $e->tag;
   return 1 unless $tag eq 'font';
   if ($e->starttag =~ /SIZE=4/) {
      $e->push_content("\nXx. ITS HERE .xX\n");
   }
}
-- Jerry Pank                             http://www.netconnected.com/
                                        jerryp.usenet@netconnected.com

"If it makes goo on the windshield, we'll call it a bug."
-- Larry Wall


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

Date: Wed, 17 Feb 1999 23:27:33 -0500
From: jkir@erols.com
Subject: Interprocess Communication using signals
Message-Id: <36CB96B5.54AE@erols.com>

I am trying to write a program that spawns other processes by using
fork(). The CHLD signal is trapped and the process id of the child
process is returned from the waitpid function. The program core dumps
intermitently if the function is called like this:
waitpid(-1,&WNOHANG). It also receives the following error message: 
'Argument "CHLD" isn't numeric in entersub at
/usr/local/lib/perl5/aix/5.00404/POSIX.pm line 206.'
If the call to the waitpid is made like this: 'waitpid(-1,0)', the
progrsm doesn't core dump or receive the error message.
The program is running on an AIX machine level 4.3.0, and the PERL
version is 5.00404.  The system supports a non-blocking waitpid. I need
to use the non blocking waitpid so the alternative flag of '0' is not an
option.
Does anybody have a solution to this problem?

Thanks.
Joc
running Perl 5.00404 on an AIX box level 4.4.0.


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

Date: Wed, 17 Feb 1999 23:25:36 -0500
From: "Professeur Alfred" <ughridk@bbbhotmail.com>
Subject: Mail confirmation
Message-Id: <YEMy2.4403$qb4.3565@weber.videotron.net>

I'm making a cgi script with perl which sends e-mail from a Unix server
using Sendmail. I saw that sometimes, e-mails are lost. So, I would like to
be able to verify if the mailing is OK.

Does somebody know how my script can receive a confirmation from Sendmail
that the e-mail is well gone?

Thank you!

Stephane Gauthier

If you want to answer me by e-mail remove the bbb from my address:
ughridk@bbbhotmail.com




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

Date: Thu, 18 Feb 1999 06:41:12 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Need perl programmer
Message-Id: <ebohlmanF7C7wo.6LD@netcom.com>

Chip Harman <charman@clark.net> wrote:
: Can anyone give me a suggestion for finding a perl script programmer to
: do some short-term file 'fixing' in the U.S.?

If you want someone in your own geographic area, I'd suggest you go to 
<URL:http://www.pm.org> and see if there's a Perl Mongers group nearby.  
If so, find out who their contact person is and let them know about your 
needs; the contact person can announce it to the members, and you'll 
likely find someone qualified.



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

Date: Wed, 17 Feb 1999 23:01:30 -0800
From: "John Doe" <user@home.com>
Subject: Perl Contractor
Message-Id: <XgMy2.1327$O4.9887@eagle.america.net>

Looking for Perl contractor in SE US, preferably Atlanta, GA.
$50 per hour, 15 hours/wk guaranteed per week for 6 months.

Please contact Steve Kohler
Ecom Partners, Inc.
678 947 6580
skohler@ecompartners.co




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

Date: Thu, 18 Feb 1999 07:28:47 GMT
From: JAG <greenej@my-dejanews.com>
Subject: Re: Perl function to reboot NT Server?
Message-Id: <7agff9$m89$1@nnrp1.dejanews.com>

In article <7a084j$ltb$1@camel18.mindspring.com>,
  "Georg Buehler" <gbuehler@med.unc.edu> wrote:
> That's just the problem. There _isn't_ a simple command-line in NT to
> reboot. The NT Resource Kit includes a shutdown.exe program for doing a
> command-line reboot, but it's commercial software, part of an expensive
> package and not something I can just download.
>
> I know this sucker exists in a Perl module somewhere, I remember
> experimenting with it several months ago, but I just can't find it.

The perl-ish answer has already been posted, but if you are interested, I can
provide you with a short win32 C program that is almost as good as the NT
Resource Kit SHUTDOWN.EXE. (Almost as good, since it is only implemented for
the local machine, not any machine on the net).

E-mail me if you'ld like the code.

# James Greene - Informatics Consulting - D-79539 Loerrach, Germany
# Internet: www.gucc.org/greene/consult - greene@gucc.org
# PGP Fingerprint: CA88 9BE2 92B3 3162 DF6B  7080 2F9E A97E F25C 5972

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


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

Date: Thu, 18 Feb 1999 06:47:34 GMT
From: renenyffenegger@my-dejanews.com
Subject: Re: perl/tk for win95
Message-Id: <7agd24$kc7$1@nnrp1.dejanews.com>

use activestate's 'perl package manger', to be invoked as
c:\what\ever> ppm install Tk

if you sit behind a firewall or are not connected to the internet on
the target computer, you can download a zip file from
http://www.activestate.com/packages/zips

hth

> Where can I download PERL/TK in a compiled version for WIN95.

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


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

Date: Thu, 18 Feb 1999 17:14:10 +1100
From: Ka-shu Wong <kswong@bigpond.com>
Subject: Re: String Manipulation (yet another newbie question)
Message-Id: <Pine.LNX.4.03.9902181709470.197-100000@goose>



On Thu, 18 Feb 1999 asssi@my-dejanews.com wrote:

[snip]

> what i want to do is this:
> if ($field contains "_1") { etc. etc. etc. }
> 
> so, what comes inside the brackets?

if ($field =~ /_1/) { ... }

Read the section in the Perl manual about regular expressions.


KS



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

Date: Thu, 18 Feb 1999 06:59:08 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: String Manipulation (yet another newbie question)
Message-Id: <ebohlmanF7C8qL.7D1@netcom.com>

asssi@my-dejanews.com wrote:
:       I read a whole lots about how quickly and easily perl can be
: used for search and replace operation. it is described in detail in many
: web sites and tutorials..
:       However what i need to do is much simpler and i couldn't find away
: how to do it.
: i have a variable that may contain or may not contain a sub-string
: somewhere inside.. for example if i have:
: $field = "email_1"

: what i want to do is this:
: if ($field contains "_1") { etc. etc. etc. }

: so, what comes inside the brackets?

A regular expression match operator.  Read perlop to learn how to write 
the match operators, and perlre to learn how to write the regular 
expressions that act as match patterns.

Using regular expressions and match operators is one of the most 
fundamental things in Perl programming.  It really pays to learn them as 
early as possible.  It will probably take you several readings of the 
above documents to get comfortable with pattern matching, but the 
up-front effort will pay off handsomely.



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

Date: Wed, 17 Feb 1999 23:26:35 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: String Manipulation (yet another newbie question)
Message-Id: <MPG.1135607c8fc45666989a54@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7afs18$6eq$1@nnrp1.dejanews.com> on Thu, 18 Feb 1999 
01:57:01 GMT, asssi@my-dejanews.com <asssi@my-dejanews.com> says...
 ...
> i have a variable that may contain or may not contain a sub-string
> somewhere inside.. for example if i have:
> $field = "email_1"
> 
> what i want to do is this:
> if ($field contains "_1") { etc. etc. etc. }
> 
> so, what comes inside the brackets?

Someone else responded with a regex solution.  I think a better approach 
to your particular problem is the 'index' function:

  if (index($field, '_1') >= 0) { ...

(As a habit, use single quotes for string literals unless you want 
interpolation of variables or interpretation of backslash escape 
sequences.)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 18 Feb 1999 04:34:29 GMT
From: "Justin Saul" <wfs-dominion@worldnet.att.net>
Subject: Stumped
Message-Id: <7ag58l$o1i@bgtnsc02.worldnet.att.net>

I fixed earlier problems by moving around code and testing...which is what
you should do. Although it should have worked...oh well.

Here is my new problem that I REALLY cant solve on my own. The error:

Syntax Error line 52, near "TABLE>"
Unterminated <> operator at line 55.

Here are lines ~10-60. The rest of the code does not effect this
section..trust me.

###CODE STARTS NOW###

 if ($form_data{'action'} eq "add" || $ENV{'REQUEST_METHOD'} eq "GET")
    {

# Print out the form

print <<"    end_of_html";
    <HTML><HEAD><TITLE>Download Administration</TITLE></HEAD>
    <BODY>
    <CENTER>
    <H2>Download Administration</H2>
    </CENTER>
    <P>If this does not look familiar please press your back button. Fill in
the information
    asked of you and the program will do the rest.
    </P>

    <FORM METHOD = "POST" ACTION = "/cgi-bin/download_admin.cgi">
    <TABLE>
    <TR>
    <TH ALIGN = "left">Name of File:</TH>
    <TD><INPUT TYPE = "text" NAME = "filename" SIZE = "40"
	       VALUE = "$form_data{'filename'}"></TD>
    </TR><TR>
    <TH ALIGN = "left">Location of File (URL):</TH>
    <TD><INPUT TYPE = "text" NAME = "location" SIZE = "40"
               VALUE = "$form_data{'location'}"></TD>
    </TR><TR>
    <TH ALIGN = "left">Site from which it came:</TH>
    <TD><INPUT TYPE = "text" NAME = "site" SIZE = "50"
               VALUE = "$form_data{'site'}"></TD>
    </TR><TR>
    <TH ALIGN = "left">Comments:</TH>
    <TD><TEXTAREA NAME = "comments" COLS = "60" ROWS = "4">
    $form_data{'comments'}
    </textarea></TD>
    </TR>
    </TABLE>
    <CENTER>
    <INPUT TYPE = "submit" VALUE = "Submit Addition">
    <INPUT TYPE = "reset">
    </FORM>
    <P></P>
    <A HREF = "http://www.5games.com">Back to the Database</A><BR>
    </CENTER>
    </BODY>
    </HTML>
   end_of_html
    exit;
    }




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

Date: 17 Feb 1999 21:15:46 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Variable for variable names
Message-Id: <36cb93f2@csnews>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    zin@clanplaid.net writes:
:I'm a relative perl newbie, and I was wondering if there's any way to have a
:loop act upon a different variable on each iteration.  I was hoping to have an
:array with variable names ($foo, $bar, $etc) and then have a for loop
:to call the different elements of the array within a statement, such as
:"$vararray[$i] = valuexyz;" where $vararray[$i] is actually $foo, so that
:valuexyz goes into $foo.
:
:Is there any way of doing this?

Sure, it gets asked every day.  And the answer is the same: DON'T.

--tom

=head2 How can I use a variable as a variable name?

Beginners often think they want to have a variable contain the name
of a variable.

    $fred    = 23;
    $varname = "fred";
    ++$$varname;         # $fred now 24

This works I<sometimes>, but it is a very bad idea for two reasons.

The first reason is that they I<only work on global variables>.
That means above that if $fred is a lexical variable created with my(),
that the code won't work at all: you'll accidentally access the global
and skip right over the private lexical altogether.  Global variables
are bad because they can easily collide accidentally and in general make
for non-scalable and confusing code.

Symbolic references are forbidden under the C<use strict> pragma.
They are not true references and consequently are not reference counted
or garbage collected.

The other reason why using a variable to hold the name of another
variable a bad idea is that the question often stems from a lack of
understanding of Perl data structures, particularly hashes.  By using
symbolic references, you are just using the package's symbol-table hash
(like C<%main::>) instead of a user-defined hash.  The solution is to
use your own hash or a real reference instead.

    $fred    = 23;
    $varname = "fred";
    $USER_VARS{$varname}++;  # not $$varname++

There we're using the %USER_VARS hash instead of symbolic references.
Sometimes this comes up in reading strings from the user with variable
references and wanting to expand them to the values of your perl
program's variables.  This is also a bad idea because it conflates the
program-addressable namespace and the user-addressable one.  Instead of
reading a string and expanding it to the actual contents of your program's
own variables:

    $str = 'this has a $fred and $barney in it';
    $str =~ s/(\$\w+)/$1/eeg;		  # need double eval

Instead, it would be better to keep a hash around like %USER_VARS and have
variable references actually refer to entries in that hash:

    $str =~ s/\$(\w+)/$USER_VARS{$1}/g;   # no /e here at all

That's faster, cleaner, and safer than the previous approach.  Of course,
you don't need to use a dollar sign.  You could use your own scheme to
make it less confusing, like bracketed percent symbols, etc.

    $str = 'this has a %fred% and %barney% in it';
    $str =~ s/%(\w+)%/$USER_VARS{$1}/g;   # no /e here at all

Another reason that folks sometimes think they want a variable to contain
the name of a variable is because they don't know how to build proper
data structures using hashes.  For example, let's say they wanted two
hashes in their program: %fred and %barney, and to use another scalar
variable to refer to those by name.

    $name = "fred";
    $$name{WIFE} = "wilma";     # set %fred

    $name = "barney";           
    $$name{WIFE} = "betty";	# set %barney

This is still a symbolic reference, and is still saddled with the
problems enumerated above.  It would be far better to write:

    $folks{"fred"}{WIFE}   = "wilma";
    $folks{"barney"}{WIFE} = "betty";

And just use a multilevel hash to start with.

The only times that you absolutely I<must> use symbolic references are
when you really must refer to the symbol table.  This may be because it's
something that can't take a real reference to, such as a format name.
Doing so may also be important for method calls, since these always go
through the symbol table for resolution.

In those cases, you would turn off C<strict 'refs'> temporarily so you
can play around with the symbol table.  For example:

    @colors = qw(red blue green yellow orange purple violet);
    for my $name (@colors) {
        no strict 'refs';  # renege for the block
        *$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
    } 

All those functions (red(), blue(), green(), etc.) appear to be separate,
but the real code in the closure actually was compiled only once.

So, sometimes you might want to use symbolic references to directly
manipulate the symbol table.  This doesn't matter for formats, handles, and
subroutines, because they are always global -- you can't use my() on them.
But for scalars, arrays, and hashes -- and usually for subroutines --
you probably want to use hard references only.
-- 
Living on Earth may be expensive, but it includes an annual free trip
around the Sun.


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

Date: Wed, 17 Feb 1999 20:24:52 -0600
From: "Brent Cornwell, Pediatrics Computer Administrator" <bcornwell@mail.peds.lsumc.edu>
Subject: Re: WWW Hosting for a site in need of CGI
Message-Id: <7ag4qq$14m$2@fox.comm.net>

well, if you're just wanting to TEST your code.... you can find a freeware
web server (i recommend Sambar Server,... www.sambar.com , that is, if
you're running windows 95 or NT on your computer)... and get ActivePerl...
and getting those things set up isn't all that hard....

if you actually want a place to run cgi scripts on a dedicated server, you
can get a FREE account w/ CGI access and TEN Mb, at free.prohosting.com

Brent Cornwell, Computer Support Adminsitrator
Pediatrics Department, LSU Medical


>    I'm presently searching for a hosting site.. but my host right now
>doesn't allow me to make my own CGI's, scared of big bad hackers. What
>should i do? Anyone know a free place to place my CGI's to use them
>remotelly? Or someone willing to host my site?
>
>All i need is a little directory for 5 megs, and i'll redirect it to
there..
>
>WWW with msgboard, chatroom and pop-mail checking...  So the whole things
is
>full of CGI's..
>I'm still lurning Perl.. but since i lurned VB in 2 days.. i guess i can
>lurn Perl in 3 or less.. all i need is to test out my stuff..
>
>It's as if your trying to do grafix without a screen..
>
>Thanks guys..
>
>Reply by mail please..
>boomer@info-internet.net





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

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

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