[19227] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1422 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 1 14:05:35 2001

Date: Wed, 1 Aug 2001 11:05:08 -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: <996689107-v10-i1422@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 1 Aug 2001     Volume: 10 Number: 1422

Today's topics:
        <br> and <b> substitution <sb26@ukc.ac.uk>
    Re: active state and CGI? <joe.lindquist@usa.alcatel.com>
        Anonymous Subroutines and shared vars? <a@b.c>
    Re: couldn't get sysseek/syswrite combination to overwr nobull@mail.com
    Re: Data Interchange Format <jeff@vpservices.com>
        fd_set typemap <gtm@oracom.com>
    Re: Help with an array and foreach (Helgi Briem)
    Re: how to find free disk space (Win32) (Gary E. Ansok)
    Re: join lines ? <mjcarman@home.com>
    Re: join lines ? <godzilla@stomp.stomp.tokyo>
    Re: join lines ? <godzilla@stomp.stomp.tokyo>
    Re: join lines ? <ren@tivoli.com>
    Re: newbe question splitting a string into two differen <Tassilo.Parseval@post.rwth-aachen.de>
    Re: newbe question splitting a string into two differen <uri@sysarch.com>
        perl ticker tape script?? <dfreake@nauyak.com>
    Re: question on Here documents <strawSPAM_BEGONEman@plexi.com>
    Re: question on Here documents (Randal L. Schwartz)
    Re: question on Here documents <strawSPAM_BEGONEman@plexi.com>
    Re: question on Here documents <mjcarman@home.com>
    Re: question on Here documents <ren@tivoli.com>
    Re: question on Here documents nobull@mail.com
    Re: Regex Question... <ren@tivoli.com>
    Re: RegExp (Gary E. Ansok)
    Re: Script works on PWS but not IIS? <carlos@plant.student.utwente.nl>
    Re: Search statments -> SQL -> DBI <joe.lindquist@usa.alcatel.com>
    Re: Toke::Parser woes... (Eric Bohlman)
        unlocking a directory (James Schandua)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 1 Aug 2001 19:03:58 +0100
From: "Steve Booth" <sb26@ukc.ac.uk>
Subject: <br> and <b> substitution
Message-Id: <9k9g75$p7o$1@athena.ukc.ac.uk>

Hi,
I'm not sure if this is a good way of doing it but I'm trying to replace <b>
and <br> tags with codes.  The codes are stored in %hash1 and the HTML file
is stored in $toFormat.  I have tried the code below but it only works if
the tag is the only thing on a line.
i.e:
<br>            will be converted
<br><br>      will not be converted

Thanks for any help,
Steve Booth

-----------

$toFormat =~ s! (<(.+)>) ! $hash1{$2} || $1 !gexi;

  BEGIN {
        %hash1 = (
        'br' => '=!=br=?=!==br=?=',
        'b' => '=!=b=?='
        );
    }




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

Date: Wed, 1 Aug 2001 10:19:09 -0500
From: "Joe Lindquist" <joe.lindquist@usa.alcatel.com>
Subject: Re: active state and CGI?
Message-Id: <9k96le$n1o$1@auds955.usa.alcatel.com>

to install the CGI module into Win32 Activestate Perl, go to the command
prompt, and type:

'ppm'  ##This executes the Perl Package Manager.  Once in the manager, type:
'install CGI' ##this will install the most current CGI.pm into your Perl
Interpreter.  Type:
'exit'  ##This will exit PPM.  In each script, include the line:
'use CGI;'  It's that easy.

I would recommend Apache web server to test your scripts.  It's relatively
easy to use, and set up.  Plus it's free, and very commonly used.

Joe



zawy <zawy@yahoo.com> wrote in message
news:3b680af3.88400616@news.mindspring.com...
> How do I use active state and cgi?  I mean, how do I use Perl on my
Windows
> machine to accept form data from a browser and return output to the
> browser?




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

Date: Wed, 01 Aug 2001 10:50:55 -0700
From: BCC <a@b.c>
Subject: Anonymous Subroutines and shared vars?
Message-Id: <3B68417F.8043898F@b.c>

Hi,

I am porting my scripts to mod_perl, and am getting the 'Variable $foo
will not stay shared' warning.  After reading perldiag, it suggests to
use anonymous subroutines to cure the problem.

My script is structured somewhat like this:

## Params for cgi
my $q = new CGI;
my $a = $q->param("param1");
my $b = $q->param("param2");
my $c = ...etc, etc. (there are about 15 of these)

## Test for which sub is needed
$a eq "something" ? mySub1("pass", "in", 4, "args")
                  : mySub2("pass", "in", 4, "args");

## The subroutines
sub mySub1 {
  my ($arg1, $arg2, $arg3, $arg4) = @_;
  ## do a LOT of stuff, USING $a, $b, $c, etc, etc.
}

sub mySub2 {
  ## blah blah
}

So that when I call mySub1, I get the warning.  So it would seem I have
a choice, I can either rewrite these as anonymous subroutines, or
explicitly pass in my cgi params everytime I call the sub.  The latter
sounds cleaner to me, and I can do this, but it seems rather painful as
there are a lot of params.  Would a hash be best to pass all the cgi
params in to my sub?  Or an array...?

Which method is prefered in this situation, and would it be possible to
see an example?

Thanks!
Bryan


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

Date: 01 Aug 2001 18:38:24 +0100
From: nobull@mail.com
Subject: Re: couldn't get sysseek/syswrite combination to overwrite a line.e
Message-Id: <u9d76f8yun.fsf@wcl-l.bham.ac.uk>

srinivasanbala@netscape.net (Balaji) writes:

> I am not sure this can be done.but by checking perl.com I am
> trying.Please guide me on this. Thanks.
> 
> My methodology like this.
>
> I am taking a form input and convert to params and then I have printed
> to a file called "Results.dat" , like below
> 
> Mike,38,Male,Engineer,Texas,Austin,USA,08/01/01,10:56.

This does not look like a fixed-length record to me.  You cannot
therefore usefully overwrite a record.  

For correct methodology for replacing variable length record see FAQ:
"How do I change one line in a file...?"
 
> later if I want to overwrite austin to dallas(this information is also
> submitted via the same form only), I am trying to use the following
> info.

In general not all cities have 6 character names.

> for this to happen, I have split the "Results.dat" and compared with
> input PARAMS and found which line is to be changed and construct a
> newline based on new info and use sysseek to bring the pointer to
> start and use syswrite overwrite that line.

Why sysseek() and syswrite() not seek() and print() ? 

> syntax check is also ok.

You have forgotten to enable warnings and strictures and so most
checks are dissabled.  For example you have not allowed Perl to draw
your attension to the fact that you have mistyped one of your variable
names.

It is considered very rude to come here and ask for help if you
haven't accepted all the help that Perl itself has to offer.

>     ## counting number of characters read so far
>    $linesRead = $linesRead + length($readLine);

Incidently using a variable called $linesread (or $linesRead) to hold
a count of the number of _characters_ read is obfuscation.

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


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

Date: Wed, 01 Aug 2001 09:36:18 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Data Interchange Format
Message-Id: <3B683002.E053F9F0@vpservices.com>

Bart Lateur wrote:
> 
> Robert Goff wrote:
> 
> >I've looked and looked, but I haven't found code that will parse a DIF
> >file, the DIF that is produced by spreadsheet programs and FileMaker
> >Pro, specificially.  Any suggestions?  Thanks.
> 
> Write your own DIF parser? You can get info on the file format on
> Wotsit, <http://www.wotsit.org/download.asp?f=dif> (2k ZIP file,
> containing 6k of text).
> 
> Note to Jeff Zucker: perhaps another candidate for DBD::Anydata (former
> DBD::RAM)?

Yep, I thought of that.  But I had a look at DIF and it seems like quite
a mess though still a good candidate for an AnyData plug-in.  I'll stick
it on the list after Mail/Mbox and DBM which, in my mind have a bit of
priority.  But if anyone else wants to give it a shot, I'd be glad to
help out.

-- 
Jeff



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

Date: Wed, 01 Aug 2001 13:25:38 +0000
From: Glenn MacGregor <gtm@oracom.com>
Subject: fd_set typemap
Message-Id: <3B680352.74942099@oracom.com>


--------------AB2D3BFA860ED2BDEC2000A5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi All,

I am writing a perl module based on a c lib I write.  I am using XS
(h2xs) to do this.  I have a function in the c lib that I need to
implement in the perl module, that function takes as an argument fd_set
*, does anyone know how to translate an fd_set * or fd_set from c to
perl?

    Thanks


--

Glenn MacGregor

Director of Services
Oracom, Inc.
http://www.oracom.com

Tel. +1 978.557.5710 Ext. 302
Fax  +1 978.557.5716



--------------AB2D3BFA860ED2BDEC2000A5
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi All,
<p>I am writing a perl module based on a c lib I&nbsp;write.&nbsp; I am
using XS (h2xs) to do this.&nbsp; I have a function in the c lib that I
need to implement in the perl module, that function takes as an argument
fd_set *, does anyone know how to translate an fd_set * or fd_set from
c to perl?
<p>&nbsp;&nbsp;&nbsp; Thanks
<br>&nbsp;
<pre>--&nbsp;

Glenn MacGregor

Director of Services
Oracom, Inc.
<A HREF="http://www.oracom.com">http://www.oracom.com</A>

Tel. +1 978.557.5710 Ext. 302
Fax&nbsp; +1 978.557.5716</pre>
&nbsp;</html>

--------------AB2D3BFA860ED2BDEC2000A5--



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

Date: Wed, 01 Aug 2001 16:23:56 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: Help with an array and foreach
Message-Id: <3b682cab.805900333@news.isholf.is>

On Tue, 31 Jul 2001 21:57:55 +0100, "Scott Porter"
<scott@nospamthankx.here.there.org.co.uuk> wrote:

>In article <3B66B038.5C0E8012@stomp.stomp.tokyo>, "Godzilla!"
><godzilla@stomp.stomp.tokyo> wrote:
>>> Godzilla! wrote:
>> I can easily surmise the end of your right index finger is heavily
>> calloused from reading and, your brain is still infant soft and tender.
>
>Translation: "Waaaaahhhh! No fair, no fair - you made me look
>stooopid!!!! Waaaaahhhh!"

Not so. Godzilla has no problem making herself look
stupid without any help from me or anybody else.
I think she is running on some kind of Auto-Stupid.

Regards,
Helgi Briem




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

Date: 1 Aug 2001 16:56:47 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: how to find free disk space (Win32)
Message-Id: <9k9ccf$fkd@gap.cco.caltech.edu>

In article <b65eb2a6.0108010241.119537fd@posting.google.com>,
John Stumbles <jstumbles@bluearc.com> wrote:
>Is there a module? Or some fairly portable way to do this? On windoze
>even grepping `dir` for 'bytes free' fails if the disk is empty :-(

For Windows, there's Win32::DriveInfo, available from CPAN.

I've used $bytes_free = Win32::DriveInfo::GetDiskFreeSpaceEx('g:')
successfully in the past.

-- Gary Ansok


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

Date: Wed, 01 Aug 2001 10:29:16 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: join lines ?
Message-Id: <3B68204C.DE7F5A74@home.com>

Tim wrote:
> 
> I am reading lines from input file.
> 
> The lines has the following format:
> 
> line "line1" = "001\
>                 010\
>                 11";
> line "line2" = "111\
>                 011\
>                 1";
> 
> I would like to have the output as follow:
> 
> line "line1" = "0,0,1,0,1,0,1,1";
> line "line2" = "1,1,1,0,1,1,1";

#!/usr/bin/perl -w
use strict;

$/ = ";\n";

while (<DATA>) {
    # strip continuation chars/linefeeds
    s/\\\n//g;
    # strip whitespace caused by continuations
    s/(\d)\s+(\d)/$1$2/g;
    # split data and join by commas.
    s/(\d{2,})/join(',', split('', $1))/e;
    print "$_";
}

__DATA__
line "line1" = "001\
                010\
                11";
line "line2" = "111\
                011\
                1";


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

Date: Wed, 01 Aug 2001 09:24:09 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: join lines ?
Message-Id: <3B682D29.D9053A0B@stomp.stomp.tokyo>

Godzilla! wrote:
 
> Tim wrote:
> > Godzilla! wrote:
> > > Tim wrote:
 
  (snipped)

>   local ($");
 
> Localize and null the array list separator to avoid
> a need to foreach loop print elements; no spaces.
 

> sub Clean_Up
>  {
>   local ($/) = ";";
>   local ($");


>     print "$line_title", @Array, "\";\n\n";


I need to amend my code although it works fine. There
is a bit of inefficiency incorporated. 

My use of  local ($")  can be removed based upon the
syntax I use for my print statement.

An alternative is to leave my  local ($")  and change
my print statement to,

print "$line_title@Array\";\n\n";

This was my original intent for my print statement.
However, I neglected to change my print statement
during stage development and script finalization.

Either or, your choice; both work fine.


Godzilla!


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

Date: Wed, 01 Aug 2001 09:31:44 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: join lines ?
Message-Id: <3B682EF0.A66D51A@stomp.stomp.tokyo>

Michael Carman wrote:
 
> Tim wrote:

(snipped)

> > The lines has the following format:

> > line "line1" = "001\
> >                 010\
> >                 11";
> > line "line2" = "111\
> >                 011\
> >                 1";

> > I would like to have the output as follow:

> > line "line1" = "0,0,1,0,1,0,1,1";
> > line "line2" = "1,1,1,0,1,1,1";
 
> #!/usr/bin/perl -w
> use strict;
 

This code of yours will not work, not by fault of
your own. The orginating author has changed his
parameters in a subsequent article. This data
he presented and you use, is not the correct data.
Between those two articles of his, perhaps you can
ascertain what he truly wants to do, if he doesn't
again change his parameters.


Godzilla!


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

Date: 01 Aug 2001 12:28:15 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: join lines ?
Message-Id: <m37kwnd70w.fsf@dhcp9-161.support.tivoli.com>

On 31 Jul 2001, tvn007@hotmail.com wrote:

> The lines has the following format:
> 
> line "line1" = "001\
>                 010\
>                 11";
> line "line2" = "111\
>                 011\
>                 1";
> 
> I would like to have the output as follow:
> 
> line "line1" = "0,0,1,0,1,0,1,1";
> line "line2" = "1,1,1,0,1,1,1";

Here is another solution:

#!/usr/bin/perl
use strict;
use warnings;
$/=qq/";\n/;
while(<DATA>) {
  s/\\\n\s*//g;
  s/(\d)(?=\d)/$1,/g;  
  print;
}
__DATA__
line "line1" = "001\
                010\
                11";
line "line2" = "111\
                011\
                1";
__END__


-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 01 Aug 2001 18:27:22 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: newbe question splitting a string into two different variables
Message-Id: <3B682DEA.5050308@post.rwth-aachen.de>

Anno Siegel wrote:

>According to Tassilo von Parseval  <Tassilo.Parseval@post.rwth-aachen.de>:
>
>
>>What is an undefined length? In Perl diction the length of an array is 
>>undefined, when it is 0.
>>
>
>Ahem.  What Perl diction would that be?  The length of an unassigned
>array is zero, and it would be misleading to call it anything else.
>Even when you "undef @x" (which is rarely the right thing to do),
>it is 0 in scalar context.
>

I better should have written an array is undefined when its length is zero.

>
>>                         That is, even an anonymous array (or list) 
>>could have an undefined length:
>>
>
>No Perl array has an undefined length -- "defined scalar @x" is
>always true.
>

Going along with the above said, this should be "anon array ... could be 
undefined".

In the moment I wrote this last post of me, I was sort of sensing 
there'd be something fishy about it. People here are just too competent 
as though it could have passed unnoticed. ;-)


Tassilo



-- 
Are we THERE yet?  My MIND is a SUBMARINE!!




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

Date: Wed, 01 Aug 2001 18:01:57 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: newbe question splitting a string into two different variables
Message-Id: <x7u1zrzmjw.fsf@home.sysarch.com>

>>>>> "TvP" == Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> writes:

  TvP> I better should have written an array is undefined when its
  TvP> length is zero.

that still is wrong. undef @array is very different than @array = ().

the former deletes all storage associated with the array. the latter
only sets its length to 0, while its storage is still kept for reuse
(assuming you stuff it with data).

  >> No Perl array has an undefined length -- "defined scalar @x" is
  >> always true.

  TvP> Going along with the above said, this should be "anon array ... could be 
  TvP> undefined".

it still doesn't make any difference. anon or named arrays ALWAYS have a
defined length. the scalar holding an array ref can be set to undef, but
then you don't even have an array any more, let alone its length.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


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

Date: 1 Aug 2001 15:21:41 -0350
From: Douglas <dfreake@nauyak.com>
Subject: perl ticker tape script??
Message-Id: <Xns90F09BDF32460dfreakenauyakcom@209.128.1.3>

Can a ticker tape script be written using only perl?
If anyone has done this I would sure like to take a look!

Thanks.

Doug


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

Date: Wed, 01 Aug 2001 11:08:15 -0400
From: Edward Little Titan/SRC x4621 <strawSPAM_BEGONEman@plexi.com>
Subject: Re: question on Here documents
Message-Id: <3B681B5F.DED48C96@plexi.com>

Edward Little Titan/SRC x4621 wrote:

> Is it possible to call a member function in a here document to provide a
> value?
>
> For instance, assume $object is a referance to an object:
> ...
>
> my $text = << "END_HERE"
>
> yadayadayada
> yadayadayada
> yadayadayada
> The value is: $object->getValue()
> yadayadayada

Sorry I  mistakingly sent the message before I was done. To continue:

yadayadayada
END_HERE


When I try to do the above: The reference value (hex) is entered in the
here document. Like this:
ClassName=HASH(0x4a4828)->getValue()


Is there a way around this?




Thanks for the help.





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

Date: 01 Aug 2001 08:15:07 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: question on Here documents
Message-Id: <m17kwnu804.fsf@halfdome.holdit.com>

>>>>> "Edward" == Edward Little Titan/SRC x4621 <strawSPAM_BEGONEman@plexi.com> writes:

Edward> Edward Little Titan/SRC x4621 wrote:
>> Is it possible to call a member function in a here document to provide a
>> value?
>> 
>> For instance, assume $object is a referance to an object:
>> ...
>> 
>> my $text = << "END_HERE"
>> 
>> yadayadayada
>> yadayadayada
>> yadayadayada
>> The value is: $object->getValue()
>> yadayadayada

Edward> Sorry I  mistakingly sent the message before I was done. To continue:

Edward> yadayadayada
Edward> END_HERE


Edward> When I try to do the above: The reference value (hex) is entered in the
Edward> here document. Like this:
Edward> ClassName=HASH(0x4a4828)->getValue()


Edward> Is there a way around this?

Right under your nose.  Always look in the FAQ first, before posting
here.

    $ perldoc -q expand function calls string

    =head1 Found in /usr/lib/perl5/5.00503/pod/perlfaq4.pod

    =head2 How do I expand function calls in a string?

    This is documented in L<perlref>.  In general, this is fraught with
    quoting and readability problems, but it is possible.  To interpolate
    a subroutine call (in list context) into a string:

        print "My sub returned @{[mysub(1,2,3)]} that time.\n";

    If you prefer scalar context, similar chicanery is also useful for
    arbitrary expressions:

        print "That yields ${\($n + 5)} widgets\n";

    Version 5.004 of Perl had a bug that gave list context to the
    expression in C<${...}>, but this is fixed in version 5.005.

    See also ``How can I expand variables in text strings?'' in this
    section of the FAQ.

    =head2 How do I expand tabs in a string?

    You can do it yourself:

        1 while $string =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;

    Or you can just use the Text::Tabs module (part of the standard perl
    distribution).

        use Text::Tabs;
        @expanded_lines = expand(@lines_with_tabs);

    =head2 How can I expand variables in text strings?

    Let's assume that you have a string like:

        $text = 'this has a $foo in it and a $bar';

    If those were both global variables, then this would
    suffice:

        $text =~ s/\$(\w+)/${$1}/g;  # no /e needed

    But since they are probably lexicals, or at least, they could
    be, you'd have to do this:

        $text =~ s/(\$\w+)/$1/eeg;
        die if $@;			# needed /ee, not /e

    It's probably better in the general case to treat those
    variables as entries in some special hash.  For example:

        %user_defs = ( 
            foo  => 23,
            bar  => 19,
        );
        $text =~ s/\$(\w+)/$user_defs{$1}/g;

    See also ``How do I expand function calls in a string?'' in this section
    of the FAQ.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 01 Aug 2001 11:26:13 -0400
From: Edward Little Titan/SRC x4621 <strawSPAM_BEGONEman@plexi.com>
Subject: Re: question on Here documents
Message-Id: <3B681F95.A99F4067@plexi.com>

>

OK. Thanks.
Will be more thorough next time.





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

Date: Wed, 01 Aug 2001 11:08:11 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: question on Here documents
Message-Id: <3B68296B.ED820B03@home.com>

Edward Little Titan/SRC x4621 wrote:
> 
> Is it possible to call a member function in a here document to
> provide a value?
> 

Yes. See the perlfaq4 entry "How do I expand function calls in a
string?"

-mjc


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

Date: 01 Aug 2001 12:19:21 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: question on Here documents
Message-Id: <m3bslzd7fq.fsf@dhcp9-161.support.tivoli.com>

On 01 Aug 2001, merlyn@stonehenge.com wrote:

>     $ perldoc -q expand function calls string

Despite continual desire to have it function this way, the -q option
does not process multiple arguments.

>     =head1 Found in /usr/lib/perl5/5.00503/pod/perlfaq4.pod
> 
>     =head2 How do I expand function calls in a string?

[snip]

>     =head2 How do I expand tabs in a string?

[snip]

>     =head2 How can I expand variables in text strings?

[snip]

These results are just from searching for "expand".  (It does, of
course, take a regex, but writing order-independent multi-word regexen
is a pain: "(?=.*expand)(?=.*function)(?=.*calls).*string".)

-- 
Ren Maddox
ren@tivoli.com


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

Date: 01 Aug 2001 18:43:00 +0100
From: nobull@mail.com
Subject: Re: question on Here documents
Message-Id: <u98zh38ymz.fsf@wcl-l.bham.ac.uk>

merlyn@stonehenge.com (Randal L. Schwartz) writes:

>     $ perldoc -q expand function calls string

>     If you prefer scalar context, similar chicanery is also useful for
>     arbitrary expressions:
> 
>         print "That yields ${\($n + 5)} widgets\n";

Please note: this is wrong.  See thread following the last time the FAQ
bot posted this FAQ.

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


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

Date: 01 Aug 2001 12:05:58 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Regex Question...
Message-Id: <m3k80nd821.fsf@dhcp9-161.support.tivoli.com>

On 1 Aug 2001, tommyumuc@aol.com wrote:

> I have a series of about 500 .dbf files that I need to merge
> together into one large file that is sorted and neatly formatted.
> For example, in the below partial file, I have: 

I'm not familiar with .dbf files, so if there is anything special
about them that bears on this problem or solution, then I'm missing
it.

> $myVar=<<"FILE"; 
> 1 5C162810001H51Delaware Bay 188 
> 2 92C162810001H51Delaware Bay 44 3 204
> C162810001D85Killen Pond State Park 8 4 207
> C162810001D85Killen Pond State Park 8 
> FILE 
> 
> $myVar =~ s/\\W+//egs; #works 

For what definition of "works"?  With two "\"-s, it does nothing to
this input.  Assuming that is just a typo, them it removes all of the
non-word characters, which happens to be all of the white-space in
this input.  If you really mean white-space, use \s instead of \W.
But with the white-space gone, how do you distinguish the first three
fields?  The second field obviously varies in length and presumably
the first one does as well.

In addition, the /e and /s modifiers have no effect here.  (Well, the
/e produces a bunch of warnings when warnings are enabled as they
should be.)

> $myVar =~ s/\n//egs; #doesn't work 

Works for me (with the same issues as above for /e and /s).  Perhaps
you have a DOS-formatted file that has \r\n at the end of each line.
Wise use of \s can make this problem disappear.

> I've tried getting rid of instances of more than 2 spaces in the file,
> which worked well, but I can't seem to get rid of the newline
> characters in the same fashion. What I would like this file to
> become ultimately (and I realize that after I have stripped the
> newline characters, this is still a few lines of code away) is this
> exactly:
> 
> 1 5 C1628 10001 H51 Delaware Bay 188
> 2 92 C1628 10001 H51 Delaware Bay 44 
> 3 204 C1628 10001 D85 Killen Pond State Park 8
> 4 207 C1628 10001 D84 Killen Pond State Park 8

Well, making a few additional assumptions about the format, this
works:

#!/usr/bin/perl
use strict;
use warnings;
my $myVar=<<FILE;
1 5C162810001H51Delaware Bay 188
2 92C162810001H51Delaware Bay 44 3 204
C162810001D85Killen Pond State Park 8 4 207
C162810001D85Killen Pond State Park 8
FILE

while ($myVar =~ /(\S+)\s+(\d+)\s*(\w{5})(\w{5})(\w{3})(.*?)\s*(\d+)/g) {
  print "$1 $2 $3 $4 $5 $6 $7\n";
}      
__END__

If extra newlines can fall in other places (between fields), then
simply inserting \s* as appropriate can handle that.  One of the big
assumptions here is that the second field can only be digits and the
third field starts with a letter.

I hated having to use the $1, $2, etc. variables here, but I needed
the pattern match to be in scalar context to get the proper behavior
for /g.  Ah... the "answer" just came to me.  Use this instead:

my @fields = $myVar =~ /(\S+)\s+(\d+)\s*(\w{5})(\w{5})(\w{3})(.*?)\s*(\d+)/g;
print join(" ", splice @fields, 0, 7), "\n" while @fields;

> After I have it in this format, I've already created the script to
> merge the files (which I have tested, and works fine--I run this
> script on the directory where I have the files I would like to merge
> and then just redirect it into a .dat file--this script took only a
> few minutes to write and once handled 16 million records in only 20
> minutes):
> 
> #!/usr/bin/perl
> 
> opendir (DH, 'other_blocks')  ||  die "Cannot open:  $!";

Should include the name of the directory in the error message.

>    while ($file=readdir DH) { 
>    next if (-d "other_blocks/$file");
>    if (! open (F, "other_blocks/$file") ) {  
>       warn "Cannot search: $!";

Should include the name of the file in the error message.

>       next;
>    } 
>    while(<F>)  {
>       $_ =~ s/ /0/g;
>       $st = substr($_, 1,2);	
>       $cou = substr($_, 3, 3);
>       $cen = substr($_, 6, 6);
>       $block = substr($_, 12 ,4);
>       $land = substr($_, 91, 14);
>       $pop = substr($_, 117, 6);

I usually prefer a single unpack instead of a string of substr
extractions.  Of course, I'm not sure your substr() values make much
sense.  You start at 1 instead of 0.  Later, you skip to 91 and then
again to 117.  This doesn't seem to match the above output data.

>       if ($st == '02') {
>          print "$st$cou$census$block\t$land\t$pop\n";
>       }
>       elsif ($st == '15') {
>          print "$st$cou$census$block\t$land\t$pop\n";
>       }
>       elsif ($st == '72') {
>          print "$st$cou$census$block\t$land\t$pop\n";
>       }

These all seem to do the same thing.

>       else {
>          print "Incorrect values!\n";
>       }
>    }
> } 
> 
> 
> I appreciate any suggestions anyone may have--thank you.

I hope that helps.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 1 Aug 2001 16:35:48 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: RegExp
Message-Id: <9k9b54$eoe@gap.cco.caltech.edu>

In article <a6150edd.0107312153.73e61abb@posting.google.com>,
Gerfried Ranner <ranner@gmx.net> wrote:
>I am a VB programmer using some RegExp's.
>As you are familiar with RE, I am posting here ;o)

Since this is a Perl newsgroup, we'll tell you how we'd do it
using Perl.

>I try to get the source-page of a frame definition 
>in a html file.
>
>Such a definition can look like this:
><FRAME name="test1" src="http://www.altavista.com">
>My RegExp pattern is:
>strPattern = "(\<FRAME\s+.*src\s*\=\s*[\""|\']?)(.*)([\""|\']?.*\>)"
>
>THIS WORKS! 
>But it returns the whole string, and I would like
>to have http://www.altavista.com to be returned, only.
>
>Do you know how to extract this information by using RE?
>I think it has something to do with "back references"!?

In Perl, you'd use $2 to get the part of the string matched by the
second set of parentheses.

Actually, though, that's a *very* bad way to try to get the source-page
string.  Even using your RE and data as-is, the closing quote gets 
included in $2.  Running it on real HTML data, even something as simple as
<FRAME src="http://www.altavista.com" name="test1">
will match something very different from what you want.  Using .*?
instead of .* will help, but it won't solve all the problems.

You really want to use an HTML parser, like Perl's HTML::Parser or
HTML::TokeParser.  A regular expression can do this job only when your
input data has several restrictions on it (no "src=" or ">" in the name 
could be just two, for example).  

I know -- I've written an similar routine using Perl regexps, and while 
it worked in all the common cases, I was never happy about it because I 
never knew when some (legal) HTML would come in that would cause something 
to be skipped or mis-matched.

Even trying to document what input might lead to problems was a learning
experience.  (The next version had a real parser in it.)

-- Gary Ansok


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

Date: Wed, 1 Aug 2001 17:59:38 +0200
From: "carlos" <carlos@plant.student.utwente.nl>
Subject: Re: Script works on PWS but not IIS?
Message-Id: <9k991a$d8s$1@dinkel.civ.utwente.nl>

because:
Can't Open e:/Inetpub/wwwroot/Edtech/iei/guestbook/guestbook.html:
Permission denied

"Alex" <samara_biz@hotmail.com> wrote in message
news:c7d9d63c.0108010534.50dae317@posting.google.com...
> Hi,
>
> I am trying to install Matt Wright's guestbook script on a website on
> a IIS webserver. When I try to run it I get the following error
> message:
>
> ----------
> CGI Error
> The specified CGI application misbehaved by not returning a complete
> set of HTTP headers. The headers it did return are:
>
> Can't Open e:/Inetpub/wwwroot/Edtech/iei/guestbook/guestbook.html:
> Permission denied
> ----------
>
> I only have ftp access to the IIS webserver. At first I thought that
> the problem is in write permission on guestbook.html. I have a PWS
> webserver installed on my local machine. When I install the script
> there, it runs just fine! It doesn't even matter whether
> guestbook.html has write permission enabled or not. I tried really
> hard to model the same problem, but I couldn't.
>
> I'm very confused... Why does the script run on PWS, but wouldn't run
> on IIS?
>
> Any help is very appreciated. I searched for the solution to this
> problem for hours, but can't seem to come up with anything on my own,
> that's why I'm posting this here.
>
> Thanks again,
>
> Alex




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

Date: Wed, 1 Aug 2001 11:01:45 -0500
From: "Joe Lindquist" <joe.lindquist@usa.alcatel.com>
Subject: Re: Search statments -> SQL -> DBI
Message-Id: <9k995b$f7i$1@auds955.usa.alcatel.com>

I just finished a similar script.  It restricts the user to 'and', 'or',
'not', but with minor modification could accept virtually any syntax.  It
defaults to 'or' if no operator is given, and gives grouping precedence to
'and'.  The script has been working well so far.

You can see that you will need to modify the SQL clauses a bit, but the
logic is here.

SCRIPT FOLLOWS:

###########################################################################
##################  Parse Array @fields and Generate SQL  #################
###########################################################################
sub generate_SQL()
{
$sqlstatement = "SELECT Summary FROM Knowledge WHERE (";

  my $disqualifier = "";
  my $i = 1;
  if ($#fields == 0){
    $sqlstatement = "$sqlstatement"." SolutionText LIKE '%@fields[0]%'";
  }
  while ($i <= $#fields){
    ####################################  AND
    if (@fields[$i] =~ /and/i){
      if (($i != 1)&&(!(@fields[$i-2] =~ /not/i))){
         $sqlstatement = "$sqlstatement"." OR"
      }
      $sqlstatement = "$sqlstatement"." (SolutionText $disqualifier LIKE
'%@fields[$i-1]%'";
      while (@fields[$i] =~ /and/i){
        $sqlstatement = "$sqlstatement"." AND SolutionText $disqualifier
LIKE '%@fields[$i+1]%'";
        $i += 2;
      }
      $sqlstatement = "$sqlstatement".")";
    }
    #################################### OR
    elsif (@fields[$i] =~ /or/i){
      if (($i == 1)||(@fields[$i-2] =~ /not/i)){
        $sqlstatement = "$sqlstatement"." SolutionText $disqualifier LIKE
'%@fields[$i-1]%'";
      }
      if (!(@fields[$i+2] =~ /and/i)){
        $sqlstatement = "$sqlstatement"." OR SolutionText $disqualifier LIKE
'%@fields[$i+1]%'";
      }
      $i += 2;
    }
    #################################### NOT
    elsif (@fields[$i] =~ /not/i){
      $disqualifier = "NOT";
      if ($i == 1){
        $sqlstatement = "$sqlstatement"."SolutionText LIKE '%@fields[0]%'";
      }
      if (@fields[$i+2]){
        $i += 2;
      }
      else{
        $i++;
      }
      $sqlstatement = "$sqlstatement"." AND (";
    }
    ####################################  ELSE
    else{
      if ($i == 1){
        $sqlstatement = "$sqlstatement"."SolutionText LIKE
'%@fields[$i-1]%'"
      }
      if (@fields[$i-2] =~ /not/i){
        if (!(@fields[$i+1] =~ /and/i)){
          $sqlstatement = "$sqlstatement"."SolutionText $disqualifier LIKE
'%@fields[$i-1]%' OR SolutionText $disqualifier LIKE '%@fields[$i]%'";
        }
        else{
          $sqlstatement = "$sqlstatement"."SolutionText $disqualifier LIKE
'%@fields[$i-1]%'";
        }
      }
      elsif (@fields[$i-1] =~ /not/i){
        if (!(@fields[$i+1] =~ /and/i)){
          $sqlstatement = "$sqlstatement"."SolutionText $disqualifier LIKE
'%@fields[$i]%'";
        }
      }
      elsif (!(@fields[$i+1] =~ /and/i)){
        $sqlstatement = "$sqlstatement"." OR SolutionText $disqualifier LIKE
'%@fields[$i]%'";
      }
      $i++;
    }
  }
  if ($disqualifier){
    $sqlstatement = "$sqlstatement".")";
  }
  $sqlstatement = "$sqlstatement) AND (ExpDate IS NULL Or ExpDate>=Date())";
  $sqlstatement = "$sqlstatement AND (Verified=TRUE)";
  $sqlstatement = "$sqlstatement AND (Public=TRUE)";
  $sqlstatement = "$sqlstatement GROUP BY Summary";
}

Good luck, and enjoy,
        Joe Lindquist




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

Date: 1 Aug 2001 15:17:49 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Toke::Parser woes...
Message-Id: <9k96it$8bc$1@bob.news.rcn.net>

Salvador <speralta@fidm.com> wrote:
> #!/usr/bin/perl

Missing -w
Missing "use strict;"

>       
>   use HTML::TokeParser;
>   use File::Find;
>   find(\&parse_dir, "c:/test/parser");

>    sub parse_dir{
>       # parse and output tagged text 
>       $filename = $File::Find::name;
>       if($filename =~ /\.txt$/) {
>          $parser=HTML::TokeParser->new(\$filename);

You're telling the parser to parse the file's *name*, rather than its 
*content*.  Take off that backslash; if the argument to new is a *string*, 
it's taken as the name of a file to open and parse.  If the argument is a 
string *reference*, it's taken as HTML content to parse.

>          while (my $token = $parser->get_tag("B")) 
>           { 
>            my $text = $parser->get_trimmed_text("/B");
>           }  

You need to declare $text *outside* the loop, since you're going to use 
its value later.

>         print "$filename\n"; 
>         if ( $text != NULL ){
>           print $text;
>         } else {
>           print "Null value found";
>         }

Because of the scoping error above, $text here refers to the *global* 
variable $text, which you've never set.  If you had used strict, perl 
itself would have informed you of this problem.

There's no predefined constant "NULL" in Perl.

>        }
>     }


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

Date: 1 Aug 2001 10:22:10 -0700
From: js4864@txmail.sbc.com (James Schandua)
Subject: unlocking a directory
Message-Id: <8b99fa9.0108010922.20b14ff5@posting.google.com>

I have an issue as follows:

I have had the Unix admin use directory level security to lock the
directory in which my webpage files are held. When the user enters a
username and password, I need the information to validate through a
SQL Server 7 DB. How can I send the username and password to the DB,
have them validate, and then let the users see the rest of the site
only after logging in.


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

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


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