[25075] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7325 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 27 18:10:53 2004

Date: Wed, 27 Oct 2004 15:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 27 Oct 2004     Volume: 10 Number: 7325

Today's topics:
        browser output <nospam@nospam.com>
    Re: browser output <toreau@gmail.com>
    Re: browser output <lwt0301@bellsouth.net>
    Re: browser output <segraves_f13@mindspring.com>
    Re: browser output <nospam@nospam.com>
    Re: browser output <uguttman@athenahealth.com>
    Re: browser output <spamtrap@dot-app.org>
    Re: browser output <lwt0301@bellsouth.net>
    Re: browser output <spamtrap@dot-app.org>
    Re: browser output <notvalid@email.com>
    Re: browser output <nospam@nospam.com>
    Re: browser output <flavell@ph.gla.ac.uk>
    Re: browser output <nospam@nospam.com>
    Re: browser output <segraves_f13@mindspring.com>
    Re: browser output <uguttman@athenahealth.com>
    Re: browser output <spamtrap@dot-app.org>
    Re: browser output <mjcarman@mchsi.com>
    Re: browser output <spamtrap@dot-app.org>
    Re: browser output <abigail@abigail.nl>
    Re: Common file operations <bik.mido@tiscalinet.it>
        Compress::Zlib vs. external gzip call (odigity)
        dynamic regex (Machoq)
    Re: dynamic regex <someone@example.com>
        FAQ 8.35: How do I close a process's filehandle without <comdog@panix.com>
    Re: Finding the size of a rather complicated hash-struc ctcgag@hotmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 27 Oct 2004 14:47:39 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: browser output
Message-Id: <1098902904.105121@nntp.acecape.com>

afternoon,

I use the following in all my scripts:

print $q->header();
print $out;
exit;

And sometimes in place of the first line I have used
print "Content-type: text/plain\n\n";

Sometimes after everything appears to be working fine, I no
longer get output to my browser (windows platform) after
running the script I get the dialog asking me if I would like to
SAVE/OPEN this document.  Opening it makes a quick DOS
window, and examining the results of save with a text editor,
shows me the text of my output.

If this were C I would almost think I am corrupting something
from the CGI module, but that seems harder to do  in Perl.

I looked with the FAQ, and from perldoc even went
here:  http://www.webthing.com/tutorials/cgifaq.html but
have been unable to find my answer.  Any pointers in the
right direction would be appreciated.

Thanks ahead




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

Date: Wed, 27 Oct 2004 21:03:58 +0200
From: Tore Aursand <toreau@gmail.com>
Subject: Re: browser output
Message-Id: <pan.2004.10.27.19.03.57.517246@gmail.com>

On Wed, 27 Oct 2004 14:47:39 -0400, daniel kaplan wrote:
> I use the following in all my scripts:
> 
> print $q->header();
> print $out;
> exit;

Don't 'exit()' from CGI-scripts.  IMO, don't 'exit()' from any scripts; if
you need to, you are probably doing something wrong somewhere.

> Sometimes after everything appears to be working fine, I no longer get
> output to my browser (windows platform) after running the script I get
> the dialog asking me if I would like to SAVE/OPEN this document.

Sounds to me like the web server isn't executing the script.  This isn't a
Perl problem, AFAIKS.


-- 
Tore Aursand <toreau@gmail.com>
"The trouble with programmers is that you can never tell what a
 programmer is doing until it's too late." (Seymour Cray)


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

Date: Wed, 27 Oct 2004 15:12:22 -0400
From: Laura <lwt0301@bellsouth.net>
Subject: Re: browser output
Message-Id: <10nvsuqiotoqv6b@news.supernews.com>

Tore Aursand wrote:

> On Wed, 27 Oct 2004 14:47:39 -0400, daniel kaplan wrote:
>> I use the following in all my scripts:
>> 
>> print $q->header();
>> print $out;
>> exit;
> 
> Don't 'exit()' from CGI-scripts.  IMO, don't 'exit()' from any scripts; if
> you need to, you are probably doing something wrong somewhere.

exit is good for testing code when you don't want the rest of the script to
run.

goto is the one you should never ever use.  no need for it ever.  why do
they say 'never use goto!' and then put it in the language anyway?

> 
>> Sometimes after everything appears to be working fine, I no longer get
>> output to my browser (windows platform) after running the script I get
>> the dialog asking me if I would like to SAVE/OPEN this document.
> 
> Sounds to me like the web server isn't executing the script.  This isn't a
> Perl problem, AFAIKS.
> 
> 



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

Date: Wed, 27 Oct 2004 19:31:31 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: browser output
Message-Id: <nISfd.11073$ta5.10826@newsread3.news.atl.earthlink.net>

"daniel kaplan" <nospam@nospam.com> wrote in message
news:1098902904.105121@nntp.acecape.com...
> afternoon,
>
> I use the following in all my scripts:
>
> print $q->header();
> print $out;
> exit;
<snip>

Try the following, in place of what you are now using:

print header, start_html, $out, end_html;
--
Bill Segraves




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

Date: Wed, 27 Oct 2004 15:34:01 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: browser output
Message-Id: <1098905686.814197@nntp.acecape.com>

"Tore Aursand" <toreau@gmail.com> wrote in message
news:pan.2004.10.27.19.03.57.517246@gmail.com...
> Sounds to me like the web server isn't executing the script.  This isn't a
> Perl problem, AFAIKS.

my apologies for leaving out that, the script ran fine.  it's purpose was to
sned out emails, and it did, so i knew it ran.  plus the fact that if i
looked at the results of clicking SAVE....it was simply a text file the
output i wanted to go to the browser...

with regards to your EXIT comment, if i hear correctly , just make sure your
script is at the bottom of the file (subroutines on top) and just let it run
through?




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

Date: Wed, 27 Oct 2004 15:41:49 -0400
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: browser output
Message-Id: <m3zn28x81u.fsf@linux.local>

>>>>> "L" == Laura  <lwt0301@bellsouth.net> writes:

  L> goto is the one you should never ever use.  no need for it ever.
  L> why do they say 'never use goto!' and then put it in the language
  L> anyway?

ding! ding! ding! we have another winna!!

ever heard of perl's magic goto?

uri


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

Date: Wed, 27 Oct 2004 15:42:42 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: browser output
Message-Id: <s8mdnZKZK5SvZ-LcRVn-1A@adelphia.com>

daniel kaplan wrote:

> print $q->header();

> And sometimes in place of the first line I have used
> print "Content-type: text/plain\n\n";

These are not equivalent - the default MIME type when you call header() 
without args is text/html. To get text/plain, you'd need to specify that:

print $q->header('text/plain');

> Sometimes after everything appears to be working fine, I no
> longer get output to my browser (windows platform) after
> running the script I get the dialog asking me if I would like to
> SAVE/OPEN this document.

One possibility is that MS thinks they know better than you do what your 
content is. IE is known to ignore the specified MIME type under some 
circumstances, looking at the extension in the URL instead.

Another of IE's bugs is that if you specify text/plain and your output 
has some HTML tags in it, the MIME type will be ignored and the output 
will be displayed as HTML anyway.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Wed, 27 Oct 2004 15:43:25 -0400
From: Laura <lwt0301@bellsouth.net>
Subject: Re: browser output
Message-Id: <10nvup29ondms4c@news.supernews.com>

Bill Segraves wrote:

> "daniel kaplan" <nospam@nospam.com> wrote in message
> news:1098902904.105121@nntp.acecape.com...
>> afternoon,
>>
>> I use the following in all my scripts:
>>
>> print $q->header();
>> print $out;
>> exit;
> <snip>
> 
> Try the following, in place of what you are now using:
> 
> print header, start_html, $out, end_html;
> --
> Bill Segraves

#! /usr/bin/perl
use warnings;
use strict;
use CGI q(:standard);
$out = "Hello, World";
print header, start_html, $out, end_html;

look at http://stein.cshl.org/WWW/software/CGI/
it's like a whole book's worth of CGI programming info for free from the
author no less.



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

Date: Wed, 27 Oct 2004 15:52:11 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: browser output
Message-Id: <15SdnTZBEMn2YeLcRVn-uw@adelphia.com>

daniel kaplan wrote:

> with regards to your EXIT comment, if i hear correctly , just make sure your
> script is at the bottom of the file (subroutines on top) and just let it run
> through?

It doesn't matter where subroutines are. Why would you think it does?

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Wed, 27 Oct 2004 20:06:53 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: browser output
Message-Id: <xdTfd.834$zx1.39@newssvr13.news.prodigy.com>

Laura wrote:

> goto is the one you should never ever use.  no need for it ever.  why do
> they say 'never use goto!' and then put it in the language anyway?

No. You should never use goto unless you know why. I regularly use the:

	goto &subroutine;

form. Quite useful.

--Ala


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

Date: Wed, 27 Oct 2004 16:07:04 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: browser output
Message-Id: <1098907670.275280@nntp.acecape.com>

"Sherm Pendley" <spamtrap@dot-app.org> wrote in message
news:15SdnTZBEMn2YeLcRVn-uw@adelphia.com...

> It doesn't matter where subroutines are. Why would you think it does?

because without the "exit" command, my server error log complained....which
i no longer have any since using the exit.




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

Date: Wed, 27 Oct 2004 21:09:50 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: browser output
Message-Id: <Pine.LNX.4.61.0410272058060.18459@ppepc56.ph.gla.ac.uk>

On Wed, 27 Oct 2004, Sherm Pendley wrote:

Nothing to do with Perl - but you *did* bring it up -

> IE is known to ignore the specified MIME type under some
> circumstances,

Indeed it is, unfortunately... contrary to mandatory requirements
of RFC2616.

> looking at the extension in the URL instead.

URLs don't have "extensions".  The whole point of inventing URLs was 
to dissociate them from the specific details of file naming on this or 
that platform.  Attempts to renege on that are presumably attempts to 
subvert the open nature of the WWW.

Nothing personal, you understand: but I do think this distinction 
needs pointing up, if the issue is going to be mentioned at all.

Actually, the situation is worse, and far more complicated, than that.  
http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp

And it will be different again (but of course will still not conform 
to the mandatory requirements of the interworking protocol - that 
would be too much to hope) after XP SP2 is applied.

all the best


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

Date: Wed, 27 Oct 2004 16:10:25 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: browser output
Message-Id: <1098907870.687454@nntp.acecape.com>

"Uri Guttman" <uguttman@athenahealth.com> wrote in message
news:m3zn28x81u.fsf@linux.local...

> ding! ding! ding! we have another winna!!
>
> ever heard of perl's magic goto?
>

am pretty sure she was refering to "goto LABEL".

to quote "beginning Perl"  ...if you see it in anyone else's Perl, you can
laugh heartily at them.  so am guessing she meant,
to quote "perlfunc " ...The author of Perl has never felt the need to use
this form of goto (in Perl, that is--C is another matter).


why bother putting it there then is what i believe she meant.




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

Date: Wed, 27 Oct 2004 20:13:14 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: browser output
Message-Id: <ujTfd.9601$5i5.3174@newsread2.news.atl.earthlink.net>

"Laura" <lwt0301@bellsouth.net> wrote in message
news:10nvup29ondms4c@news.supernews.com...
> Bill Segraves wrote:
>
> > "daniel kaplan" <nospam@nospam.com> wrote in message
> > news:1098902904.105121@nntp.acecape.com...
> >> afternoon,
> >>
> >> I use the following in all my scripts:
> >>
> >> print $q->header();
> >> print $out;
> >> exit;
> > <snip>
> >
> > Try the following, in place of what you are now using:
> >
> > print header, start_html, $out, end_html;
> > --
> > Bill Segraves
>
> #! /usr/bin/perl
> use warnings;
> use strict;
> use CGI q(:standard);
> $out = "Hello, World";
> print header, start_html, $out, end_html;
>
> look at http://stein.cshl.org/WWW/software/CGI/
> it's like a whole book's worth of CGI programming info for free from the
> author no less.
>

Laura,

Please re-read my response, interpreting it literally. My statement
suggested the OP replace the code fragment he posted with the code fragment
I posted. Naturally, we expect the OP would have used something similar to
the complete script that you posted. If the OP has not been following your
advice, he has not provided enough code to show that to be the case.

Unfortunately, you missed the most important points of the Op's post, i.e.,
those that deal with, let us say, Content-Length: problems. After lunch,
I'll post a complete script for the OP that solves those problems.

Cheers.
--
Bill Segraves




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

Date: Wed, 27 Oct 2004 16:13:52 -0400
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: browser output
Message-Id: <m3oeinyl4v.fsf@linux.local>

>>>>> "dk" == daniel kaplan <nospam@nospam.com> writes:

  dk> "Uri Guttman" <uguttman@athenahealth.com> wrote in message
  dk> news:m3zn28x81u.fsf@linux.local...

  >> ding! ding! ding! we have another winna!!
  >> 
  >> ever heard of perl's magic goto?
  >> 

  dk> am pretty sure she was refering to "goto LABEL".

she didn't say that so i won't assume it. there are uses for that as
well.

typical cult coder. goto is not 'needed' but it does have its uses. but
that is beyond laura's vision. she needs to learn much more before she
can make claims like that.

uri




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

Date: Wed, 27 Oct 2004 16:35:25 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: browser output
Message-Id: <46adneeEa_UTmx3cRVn-qw@adelphia.com>

daniel kaplan wrote:

> "Sherm Pendley" <spamtrap@dot-app.org> wrote in message
> news:15SdnTZBEMn2YeLcRVn-uw@adelphia.com...
> 
>>It doesn't matter where subroutines are. Why would you think it does?
> 
> because without the "exit" command, my server error log complained....which
> i no longer have any since using the exit.

Okay, let me rephrase that then. ;-)

It doesn't *normally* matter where subroutines are, and exit() is not 
*normally* needed. In your script, adding the exit() was an effective 
workaround, but the lack of an exit() was not the core problem. (It's a 
subtle difference, I know.)

So, instead of using the workaround, in my opinion you'd be better off 
solving the problem at its source instead.

What were the complaints that appeared in the error log?

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Wed, 27 Oct 2004 15:02:23 -0500
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: browser output
Message-Id: <clousn$9421@onews.rockwellcollins.com>

Laura wrote:
> 
> goto is the one you should never ever use.  no need for it ever. why 
> do they say 'never use goto!' and then put it in the language anyway?

There *are* occasions when goto is necessary, just like there are
occasions when using symbolic references is necessary. Both situations
are very rare, but it does happen.

That said, Perl has three flavors of goto, which are not all the same:

    goto LABEL
    goto EXPR
    goto &NAME

The first two are the traditional "jump to someplace else" that's
generally considered bad. goto &NAME is very different: it replaces the
current subroutine with the one referenced. While the first two forms
are shunned, the third is quite common (e.g. in an AUTOLOAD).

-mjc


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

Date: Wed, 27 Oct 2004 17:05:13 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: browser output
Message-Id: <st-dnU6c9-EXkB3cRVn-tw@adelphia.com>

Alan J. Flavell wrote:

> Nothing personal, you understand: but I do think this distinction 
> needs pointing up, if the issue is going to be mentioned at all.

No offense taken - you're right. In fact, the root of this design flaw 
in IE is that MS failed to make that very distinction, and chose to 
assign meaning where none was supposed to exist.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: 27 Oct 2004 21:56:40 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: browser output
Message-Id: <slrnco06co.3ac.abigail@alexandra.abigail.nl>

Alan J. Flavell (flavell@ph.gla.ac.uk) wrote on MMMMLXXV September
MCMXCIII in <URL:news:Pine.LNX.4.61.0410272058060.18459@ppepc56.ph.gla.ac.uk>:
__  On Wed, 27 Oct 2004, Sherm Pendley wrote:
__  
__  Nothing to do with Perl - but you *did* bring it up -
__  
__ > IE is known to ignore the specified MIME type under some
__ > circumstances,
__  
__  Indeed it is, unfortunately... contrary to mandatory requirements
__  of RFC2616.
__  
__ > looking at the extension in the URL instead.
__  
__  URLs don't have "extensions".  The whole point of inventing URLs was 
__  to dissociate them from the specific details of file naming on this or 
__  that platform.  Attempts to renege on that are presumably attempts to 
__  subvert the open nature of the WWW.


Well, that has been happening ever since Marc Andreessen implemented
the IMG element in the Mosaic browser. Years before Microsoft realized
the internet was there to stay.



Abigail
-- 
perl -wlpe '}{$_=$.' file  # Count the number of lines.


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

Date: Wed, 27 Oct 2004 22:47:56 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Common file operations
Message-Id: <bf10o090o6rc71s5usu1472qv8tp5vclus@4ax.com>

On Tue, 26 Oct 2004 19:36:00 -0300, "Shmuel (Seymour J.) Metz"
<spamtrap@library.lspace.org.invalid> wrote:

>>I don't trust you! (Minimal) examples?
>
>If you don't trust me, then what's the point of giving you examples?

Hmmm, maybe I should apologize... but I think you misunderstood the
sense of my cmt: it was intended ironic, sarcastic maybe, but
certainly not offensive. If, inadvertently, it was, then I apologize.

What I meant is that at all effects what you (not too clearly)
described seemed a good task for glob(). To be precise there's no
reason why it shouldn't work. If for any reason it didn't work for me,
then I'd suspect about me having done something wrong, however deeply
hidden the error may be, rather than blaming glob(). So I *could*
trust you, provided that you show me/us a possibly minimal example
exhibiting the allegedly wrong behaviour.

>>Also, see 'perldoc -q glob'.
>
>"No documentation found"

D'Oh! I'm sorry to inform you that your perl installation is broken...

>>Then just use File::Find.
>
>I will if what I wanted doesn't exist.

Sorry, but I think that you didn't clearly say what it is that you
want. You named what I think to be an OS/2 system call, but I think
that most of us won't be that familiar with it anyway, so if only you
could express it also more verbosely...

>>Ever heard about regexen?
>
>No.

Yes, you did!

>>Then glob() should do.
>
>No.

WHY?!?

>>Again, you should show some actual example proving that it doesn't.
>
>I might, for someone who isn't prejudiced. Why should I bother for
>someone who already has made up her mind?

Side note: s/her/his/;

However the point was that, quite opposite to your assumption, I could
*not* make make up my mind because of lack of information. That
information are lacking... well, on this yes: I've made up my mind!
;-)

>>  perldoc -f glob
>
>No documentation found for "perlfunc"

D'Oh! I'm sorry to inform you that your perl installation is broken...

>>  perldoc File::Glob
>
>I don't see anything there that wan't already in my de3ad tree.

Care to expand?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 27 Oct 2004 14:52:51 -0700
From: ofer@netapt.com (odigity)
Subject: Compress::Zlib vs. external gzip call
Message-Id: <de652f7.0410271352.67c0a5c6@posting.google.com>

I'm writing a script that needs to run in as fast a time as possible. 
Every minute counts.  The script crawls a tree of gzipped files
totalling about 30gb.  Originally I was calling open() with "gzip
$file |", but I hate making external calls - it requires a fork, and
you have very limited communication with the process for catching
errors and such.  I always like using perl functions and modules when
possible over external calls.  However, I wanted to make sure I
wouldn't take a performance hit before switching to Compress::Zlib.

I picked one of the bigger files (75mb) and ran some benchmarking on
it, comparing Compress::Zlib to an exernal call to the gzip utility. 
Here's the code:

#!/usr/bin/perl -w
use strict;
use Benchmark  qw( cmpthese );
use Compress::Zlib;
use IO::File;

my $file = 'sample.gz';

print "warming up the file...\n";
system( "zcat $file > /dev/null" );

print "starting comparison...\n";
cmpthese( 3, {
  'ext_gzip'      => \&ext_gzip,
  'compress_zlib' => \&compress_zlib,
});


sub ext_gzip
{
  my $fh = IO::File->new( "gzip -cd $file |" ) or die( "could not gzip
-cd '$file' for reading: $!" );
  my $lines = 0;
  while ( defined(my $line = $fh->getline()) ) {
    $lines++;
  }
  $fh->close();
  print "ext_gzip: $lines lines\n";
}


sub compress_zlib
{
  my $gz = gzopen( $file, 'rb' ) or die( "could not gzopen '$file' for
reading: $!" );
  my $line;
  my $lines = 0;
  while ( ( my $bytes = $gz->gzreadline( $line ) ) > 0 ) {
    die( $gz->gzerror ) if ( $bytes == -1 );
    $lines++;
  }
  $gz->gzclose();
  print "compress_zlib: $lines lines\n";
}

Here's the output:

warming up the file...
starting comparison...
compress_zlib: 15185003 lines
compress_zlib: 15185003 lines
compress_zlib: 15185003 lines
            (warning: too few iterations for a reliable count)
ext_gzip: 15185003 lines
ext_gzip: 15185003 lines
ext_gzip: 15185003 lines
            (warning: too few iterations for a reliable count)
              s/iter compress_zlib      ext_gzip
compress_zlib   68.6            --          -23%
ext_gzip        52.8           30%            --

Now, this wasn't the best possible benchmarking test, but I still
think I am justified in being concerned.

Any help in either a) interpreting these results, b) suggesting better
benchmarking methods, c) explaining why Compress::Zlib is slower than
gzip, and most importantly, d) how to improve performance, would be
appreciated.

-ofer


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

Date: 27 Oct 2004 11:21:37 -0700
From: saket.raizada@pepperweed.com (Machoq)
Subject: dynamic regex
Message-Id: <a55c6a86.0410271021.10f70b74@posting.google.com>

I need to take as variable 2 things
a) The pattern to match
b) Match settings like global, case insensitivity etc..

 so i want to have a program like

 $str = "Japh" ;
 $pat = "JA" ;
 $key = "gi" ;#global match, case insensitive
 print "Voila!" if ($str =~ /$pat/$key); 

 this errors with Scalar found where operator expected at test.pl
 Any alternatives ?


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

Date: Wed, 27 Oct 2004 18:58:39 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: dynamic regex
Message-Id: <zdSfd.20677$9b.16201@edtnps84>

Machoq wrote:
> I need to take as variable 2 things
> a) The pattern to match
> b) Match settings like global, case insensitivity etc..
> 
>  so i want to have a program like
> 
>  $str = "Japh" ;
>  $pat = "JA" ;
>  $key = "gi" ;#global match, case insensitive
>  print "Voila!" if ($str =~ /$pat/$key); 
> 
>  this errors with Scalar found where operator expected at test.pl
>  Any alternatives ?

Modifiers like i can be included in the pattern itself:

my $key = 'i';
my $pat = "(?$key:JA)";


However using modifiers like g would require you to use eval():

print 'Voila!' if eval "$str =~ /$pat/$key";



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 27 Oct 2004 22:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 8.35: How do I close a process's filehandle without waiting for it to complete?
Message-Id: <clp5uk$olf$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

8.35: How do I close a process's filehandle without waiting for it to complete?

    Assuming your system supports such things, just send an appropriate
    signal to the process (see "kill" in perlfunc). It's common to first
    send a TERM signal, wait a little bit, and then send a KILL signal to
    finish it off.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: 27 Oct 2004 18:12:00 GMT
From: ctcgag@hotmail.com
Subject: Re: Finding the size of a rather complicated hash-structure
Message-Id: <20041027141200.502$y2@newsreader.com>

Fred <na@na.no> wrote:
> Hi group
>
> Ok, so I've got a rather complicated hash-structure that I'd like to find
> the size of. Size in consumed bytes of memory. Just because I'm curious.
> And I've done the obligatory searches for finding sizes of stuff, and I'm
> not much the wiser. Exept I've come to understand that there isn't any
> bult-in functionality to do this for such structures.


The Tie::Cache module has code that tries to do this, but as of version
0.17, it was wildly inaccurate for nested structures with numbers or small
strings as the final data elements.  I tweaked it some to make it better,
but was never happy enough with the changes to submit them to the author as
an improvement.  If your interested, I could go back and look into it
again.


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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