[24894] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7146 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 16 09:06:48 2004

Date: Thu, 16 Sep 2004 06:05:15 -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           Thu, 16 Sep 2004     Volume: 10 Number: 7146

Today's topics:
    Re: $| (undocumented) magic? <Joe.Smith@inwap.com>
    Re: $| (undocumented) magic? (T. Ogawa)
    Re: Best place to learn perl? <shawn.corey@sympatico.ca>
        CGI.pm textfield problem drove me crazy (wana)
    Re: CGI.pm textfield problem drove me crazy <mark.clements@kcl.ac.uk>
    Re: different behaviour when accessing HD or USB storag (PilotMI80)
        Exporting variables from a hash pmak@aaanime.net
    Re: Exporting variables from a hash <noreply@gunnar.cc>
    Re: Exporting variables from a hash (Anno Siegel)
    Re: Exporting variables from a hash <nobull@mail.com>
    Re: Exporting variables from a hash (Peter Scott)
        https - lwp - postini <weiner@knightstalker.net>
    Re: killing a "nobody's" process and its group <1usa@llenroc.ude.invalid>
    Re: Newbie Question <spamtrap@dot-app.org>
    Re: Newbie Question <someone@example.com>
    Re: Newbie Question (J. Romano)
    Re: Passing a regex reference through a hashed value to nobull@mail.com
    Re: Perl send args to other perl file. <Joe.Smith@inwap.com>
    Re: preserving back references (ie $1, $2...) <nobull@mail.com>
        Simple problem (Jayashree)
    Re: Simple problem <josef.moellers@fujitsu-siemens.com>
    Re: Simple problem <noreply@gunnar.cc>
    Re: Simple problem (Anno Siegel)
    Re: Speicherkosnum <clandos@yahoo.com>
    Re: Why this Regex not working? <mark.clements@kcl.ac.uk>
    Re: Why this Regex not working? (Anno Siegel)
    Re: Why this Regex not working? <someone@example.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 16 Sep 2004 07:42:21 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: $| (undocumented) magic?
Message-Id: <wtb2d.202005$Fg5.180836@attbi_s53>

Michele Dondi wrote:

>>Nothing is ever "stored" in $|, just like nothing is ever "stored" in a
>>tied variable.  $| is like a tied variable, but on an internal level.
>>When you set $| to a true value, the internals turn off buffering for the
>>currently selected filehandle, and when you read $|'s value, Perl checks
>>to see if the currently selected filehandle has buffering on or off.  $|
>>is just a placeholder.
> 
> 
> I don't want to argue on this particular topic, especially since I
> guess we both know what we're talking about, and I'm still thanking
> you for your knowledgeable explanation. However it's obvious that even
> if technically "nothing is ever stored" in $|, it maintains a
> knowledge of its current status, which is what I meant...

linux% perl -MDevel::Peek -e '$a=2;Dump $a'
SV = IV(0x8139674) at 0x8139b80
   REFCNT = 1
   FLAGS = (IOK,pIOK)
   IV = 2

linux% perl -MDevel::Peek -e '$|=2;Dump $|'
SV = PVMG(0x8154fc8) at 0x8139b80
   REFCNT = 1
   FLAGS = (GMG,SMG,pIOK)
   IV = 2
   NV = 0
   PV = 0
   MAGIC = 0x813b028
     MG_VIRTUAL = &PL_vtbl_sv
     MG_TYPE = PERL_MAGIC_sv(\0)
     MG_OBJ = 0x8139bd4
     MG_LEN = 1
     MG_PTR = 0x813bc68 "|"

linux% perldoc perlguts | grep -i magic


	-Joe


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

Date: 16 Sep 2004 01:33:05 -0700
From: hydroxide@inorbit.com (T. Ogawa)
Subject: Re: $| (undocumented) magic?
Message-Id: <da01153a.0409160033.79797da0@posting.google.com>

Ala Qumsieh <notvalid@email.com> wrote in message news:<B1_1d.21323$7W3.102@newssvr29.news.prodigy.com>...
> Sherm Pendley wrote:
> > Also, JAPHs as sigs tend to give a bad impression of the language to 
> > those who've never seen any other Perl. They promote the idea of an 
> > insular community that delights in writing obscure code that's difficult 
> > for newbies and outsiders to grok.
> 
> They're just jealous because they can't write any valid Python program 
> in just four lines (/me ducks and runs for cover).
Well we can't write _any_ valid program in four lines, but we can
manage a JAPy or 30.  Some of them are even unreadable.

http://www.python.org/cgi-bin/moinmoin/JustAnotherPythoneer

-T.


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

Date: Thu, 16 Sep 2004 08:05:05 -0400
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: Best place to learn perl?
Message-Id: <vhf2d.7366$lb5.943131@news20.bellglobal.com>

Page wrote:

> my $pscript = @{$struct->{treemap}->[0]->{pscript}}[0];
> 

Or you can say: my $pscript = $struct->{treemap}->[0]->{pscript}->[0];

> I appear to be on the right track.  The trouble I'm having now is when I try 
> to use $pscript and [0] contains no value.  When that happens I get 
> something like "HASH(0x1d82e20)" which I don't know what it means.
> 
> When I use Dumper, it shows a value of null.  To be precise it shows:
> 'pscript' => [ {} ],
> 
> How do I get it to return the null string ("") instead of this strange HASH value?

There is no null string. $pscript is a reference to an ARRAY, which 
contains one element an empty HASH. No strings or scalars.

	--- Shawn



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

Date: 16 Sep 2004 00:54:42 -0700
From: ioneabu@yahoo.com (wana)
Subject: CGI.pm textfield problem drove me crazy
Message-Id: <bf0b47ca.0409152354.57d62806@posting.google.com>

I was going crazy over this stupid thing because the second text field
wouldn't display $a.  I had to put in -force=>1 for it to work.  Is
that normal?  I thought I had a bad CGI.pm, but Dr. Stein's examples
ran fine on my system.  I scrutinized his simple examples so closely
and couldn't find what I was doing wrong.  Of course, the examples I
was looking at didn't involve displaying a result in a textfield.

#!/usr/bin/perl 
use CGI ':standard';
$a = "";
if (param)
{
        @a = param('horse');
        $a = join (',',@a);
        $b = param('tuna');
        $c = param('cow');
        $a = "$a, $b, $c.";
}
print header;
print start_html({-bgcolor=>'pink',-title=>'poop'});
print start_form;

print
radio_group({-name=>'tuna',-value=>['rug','carpet','tile','wood'],-rows=>2}),
checkbox_group({-name=>'horse',-value=>['dog','cat','pig','turkey'],-rows=>2}),
textfield({-name=>'cow'}),
textfield({-name=>'chicken',-value=>$a,-force=>1}),
,submit({-name=>'enter'});

print end_form,end_html;


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

Date: Thu, 16 Sep 2004 13:41:58 +0200
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: CGI.pm textfield problem drove me crazy
Message-Id: <41497c07@news.kcl.ac.uk>

wana wrote:
> I was going crazy over this stupid thing because the second text field
> wouldn't display $a.  I had to put in -force=>1 for it to work.  Is
> that normal?  I thought I had a bad CGI.pm, but Dr. Stein's examples
> ran fine on my system.  I scrutinized his simple examples so closely
> and couldn't find what I was doing wrong.  Of course, the examples I
> was looking at didn't involve displaying a result in a textfield.
> 
> #!/usr/bin/perl 
> use CGI ':standard';
> $a = "";
> if (param)
> {
>         @a = param('horse');
>         $a = join (',',@a);
>         $b = param('tuna');
>         $c = param('cow');
>         $a = "$a, $b, $c.";
> }
<snip>
it may have something to do with what the passed parameters are (try 
dumping Vars() somewhere), but...

1) your variable names aren't very helpful
2) you haven't reduced this problem to its smallest possible size before 
posting
3) you haven't produced any output for us to scrutinize

so there isn't a lot for us to go on.

Mark


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

Date: 16 Sep 2004 00:29:37 -0700
From: pilotmi80@hotmail.com (PilotMI80)
Subject: Re: different behaviour when accessing HD or USB storage
Message-Id: <9b14a223.0409152329.60ec9b9b@posting.google.com>

Joe Smith <Joe.Smith@inwap.com> wrote in message news:<GeU1d.438135$%_6.292304@attbi_s01>...
> PilotMI80 wrote:
> 
> > When trying to access a USB key with : 
> > 
> > foreach(<$path/*>)
> > (or any combination of quotes )
> 
> That is guaranteed to fail if $path contains spaces in the name,
> like "e:/My Files".  As you've seen, readdir() does not have
> that problem.
> 	-Joe

thanks for your try, i have to be a bit more precise so you can answer
well


By "any combination of quotes", I meant white spaces were not the pb
cause I actually use "$path"/* :

For my tests I copied part of the hierarchy so that replacing the
drive letter has no incidence on the structure.

if $path is c:/foo, it works ok but if $path is f:/foo, it doesn't. 
I guess there's a pb with the buffering with the key.
(I use Perl 5.6)

I can keep on with opendir but the con is that I need a global handle
for each.

thx


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

Date: 16 Sep 2004 02:04:15 -0700
From: pmak@aaanime.net
Subject: Exporting variables from a hash
Message-Id: <cibkuf$r4i@odak26.prod.google.com>

Let's say I have this:

my %data = (id => 'pmak', name => 'Philip Mak', level => 50);
magic_function(\%data);

What could I put for magic_function() such that it'll have this effect,
based on the keys and values of the hash passed to it:
my $id = 'pmak';
my $name = 'Philip Mak';
my $level = 50;



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

Date: Thu, 16 Sep 2004 11:13:44 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Exporting variables from a hash
Message-Id: <2qt3vaF139b62U1@uni-berlin.de>

pmak@aaanime.net wrote:
> Let's say I have this:
> 
> my %data = (id => 'pmak', name => 'Philip Mak', level => 50);
> magic_function(\%data);
> 
> What could I put for magic_function() such that it'll have this
> effect, based on the keys and values of the hash passed to it:
> my $id = 'pmak';
> my $name = 'Philip Mak';
> my $level = 50;

     sub magic_function {
         my $href = shift;
         my $id = $href->{id};
         my $name = $href->{name};
         my $level = $href->{level};

         # do stuff now
     }

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 16 Sep 2004 09:27:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Exporting variables from a hash
Message-Id: <cibman$95m$2@mamenchi.zrz.TU-Berlin.DE>

 <pmak@aaanime.net> wrote in comp.lang.perl.misc:
> Let's say I have this:
> 
> my %data = (id => 'pmak', name => 'Philip Mak', level => 50);
> magic_function(\%data);
> 
> What could I put for magic_function() such that it'll have this effect,
> based on the keys and values of the hash passed to it:
> my $id = 'pmak';
> my $name = 'Philip Mak';
> my $level = 50;

No way.

A sub cannot declare lexical variables in the scope of its call.

Simply use the hash and access "$data{ id}" instead of "$id", etc.

If that is inconvenient, what you can do is

    my ( $id, $name, $level) = @data{ qw( id name level)};

but that's neither magic nor a sub.  In particular, it doesn't try
to extract the names of program variables from the data in the hash.
The latter is impossible with lexicals and inadvisable with package
variables.

Anno


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

Date: Thu, 16 Sep 2004 10:57:51 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Exporting variables from a hash
Message-Id: <cibnqs$pat$1@sun3.bham.ac.uk>



pmak@aaanime.net wrote:
> Let's say I have this:
> 
> my %data = (id => 'pmak', name => 'Philip Mak', level => 50);
> magic_function(\%data);
> 
> What could I put for magic_function() such that it'll have this effect,
> based on the keys and values of the hash passed to it:
> my $id = 'pmak';
> my $name = 'Philip Mak';
> my $level = 50;

You would have to use a source filter.

But do _not_ do it.



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

Date: Thu, 16 Sep 2004 12:13:56 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: Exporting variables from a hash
Message-Id: <8sf2d.24557$%S.1523@pd7tw2no>

In article <cibkuf$r4i@odak26.prod.google.com>,
 pmak@aaanime.net writes:
>Let's say I have this:
>
>my %data = (id => 'pmak', name => 'Philip Mak', level => 50);
>magic_function(\%data);
>
>What could I put for magic_function() such that it'll have this effect,
>based on the keys and values of the hash passed to it:
>my $id = 'pmak';
>my $name = 'Philip Mak';
>my $level = 50;

Just to show how unwise this is, here's what it would take to
literally satisfy your request:

sub magic_function {
  use Filter::Simple sub {
    s/^\s*magic_function\s*\(\s*\\\s*%(\w+).*?;/my \$id = \$$1\{id\};/mg
  };
  BEGIN { import() }
}
my %data = (id => 'pmak', name => 'Philip Mak', level => 50);
magic_function(\%data);
print "id = $id\n";

Extension to handle the other variables is left as an exercise
for the reader.  It also requires that all the keys be
explicitly named.  But this is sick; don't do it.

Why would you ask for this in the first place?  If you're
going to write code containing $id, for example, why not write
$data{id}, or, if you're going to repeatedly refer to that
and want to save space, write my $id = $data{id} and then go 
on to use $id?

More importantly, why would you want to create something that 
has unpredictable side effects, so that if one day a new key 
gets added to the hash that happens to match a variable you're 
already using, your program will fail in some bizarre way?

If the equivalent of %data in the real code is a long
expression you don't want to type repeatedly, then just make
a reference to it:

        my $hr = \%blahblahblah...
        ... $hr->{id} ...

When you see a variable in your program you want to have a 
fighting chance of figuring out where it came from.

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/


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

Date: Thu, 16 Sep 2004 08:24:06 -0400
From: "Knight Stalker" <weiner@knightstalker.net>
Subject: https - lwp - postini
Message-Id: <5eidnWunnJoDHtTcRVn-sQ@gwi.net>

Looking for a little help with postini and ezcommand in the postini system.
The code I have is working fine for verifing authentication, but I receive
different responses from a web browser as compared to what I receive with a
perl script.

script is as follows:

use LWP::UserAgent;
use PSTNCrossAuth;

$secret = 'secret';
$auth = new PSTNCrossAuth( $secret );
$user = 'user@somewhere.com';

$authString = $auth->authString( 'user@somewhere.com' );

$address = $auth->checkString( $authString, $secret );

#  $authString =~ s/+/%2B/g;


print "AUTH STRING: $authString\n";
print "ADDRESS: $address\n";

my $ua=LWP::UserAgent->new;
$ua->timeout( 600 );

my $reqobj = $ua->post(
'https://xxxxxx.postini.com/exec/remotecmd?$auth=$authString&cmd=adduser%20$
user' );
if( ${$reqobj}{_msg} ne 'OK' )
{
    print "\nerror posting data: ${$reqobj}{_msg}\n";
    exit 1;
}

my $results = ${ $reqobj }{_content};
print $results;
exit 1;


has anyone used ezcommand with perl to update postini?

thanx,




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

Date: 16 Sep 2004 13:01:13 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: killing a "nobody's" process and its group
Message-Id: <Xns95665BC226989asu1cornelledu@132.236.56.8>

Henry Law <lawshouse.public@btconnect.com> wrote in
news:k19dk0tuu9a5mr2m6qv13tedmidarbpotg@4ax.com: 

> On 13 Sep 2004 17:03:16 GMT, "A. Sinan Unur"
> <1usa@llenroc.ude.invalid> wrote:
> 
>>Federico <es@yahoo.fedeabascal> wrote in
>>news:ci4f36$cgr$1@nsnmrro2-gest.nuria.telefonica-data.net: 
>>
> ...
>>> 'kill(-9, PID)' it is able to kill it.
>>
>>That is gibberish.
>>

You misquoted. The OP's original sentence was:

<blockquote>
The problem is that none kill -9, $cgi_pid or kill $cgi_pid, or kill... 
whatever is able to kill the processes. But if I run as root user a 
simple perl -e 'kill(-9,PID)' it is able to kill it.
</blockquote>

Now, pray tell me, is it or is it not able to kill whatever 'it' is. 
Sherm has since explained how to interpret this to me but without that I 
would forever not know the intended meaning. 

>> Your problem (whatever it is) is not a Perl problem. 
>  ...
>> you should be asking the question (in a more intelligible manner) in
>> the appropriate forum.
> 
> The reasoning behind your post is, of course, correct.  But the
> unkindness in what you have written is breathtaking.

Let's not overdo it please.
 
> The OP plainly has something other than English as his first language
> and is doing his best.

I plainly have something other than English as my first language and I am 
trying to do my best. Having learned a couple of other languages than my 
own, let me tell you that fully forming sentences is not a hard task so 
long as one sticks with simple structures. IMNSHO, choosing not to write 
in not in fully formed sentences, dropping vowels, etc, are indicators of 
lack of respect for the people one expects to receive help from.

> Does your position as an English-speaking über-mensch living in the 
> land of the free give you the right to put him down like that?

So, you mean, I cannot be an über-mensch unless my native language is 
English. I am very disappointed. 

> How hard would it have been to write
> 
>      "This is not a Perl problem.  Killing processes is done
>      by the operating system so you should ask in the newsgroup
>      for the operating system in which Apache is running"

Feel free to write that if that is how you would like to spend your time. 
On the other hand, I do not remember the OP mentioning anything about 
Apache.

Have a nice day.

Sinan.


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

Date: Thu, 16 Sep 2004 06:43:54 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Newbie Question
Message-Id: <6ZCdnR92PfL289TcRVn-hQ@adelphia.com>

tim wrote:

> I have to parse through a file for a pattern and if the pattern
> matches, the preceding two and succeeding lines until a blank line is
> encountered need to be redirected to another file. This has to be done
> multiple times until EOF.
> 
> I have figured out the pattern matching and file redirection part. Can
> anyone give hints regarding how to capture the preceedng two lines
> after the pattern matches.

If you're using while(<>) to loop through the file a line at a time, you 
could keep a rolling buffer that contains the previous two lines read.

At the end of your loop, push() the current line onto the end of the 
buffer, and if the buffer has more than two lines in it, shift() the 
first one off the beginning.

By the way, you should think about your subject lines - this wasn't a 
question about newbies.

sherm--

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


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

Date: Thu, 16 Sep 2004 10:55:26 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Newbie Question
Message-Id: <yie2d.33709$KU5.17711@edtnps89>

tim wrote:
> 
> I have to parse through a file for a pattern and if the pattern
> matches, the preceding two and succeeding lines until a blank line is
> encountered need to be redirected to another file. This has to be done
> multiple times until EOF.
> 
> I have figured out the pattern matching and file redirection part. Can
> anyone give hints regarding how to capture the preceedng two lines
> after the pattern matches.

perl -00ne'print /^ ( .*\n .*\n .* pattern (?s: .* ) ) \z/mx' yourfile


John
-- 
use Perl;
program
fulfillment


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

Date: 16 Sep 2004 05:46:32 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: Re: Newbie Question
Message-Id: <b893f5d4.0409160446.28ad58d1@posting.google.com>

audi_nfl@yahoo.com (tim) wrote in message news:<43eba941.0409151836.3c8fdf51@posting.google.com>...
> 
> I have to parse through a file for a pattern and if the pattern
> matches, the preceding two and succeeding lines until a blank line is
> encountered need to be redirected to another file. This has to be done
> multiple times until EOF.
> 
> I have figured out the pattern matching and file redirection part. Can
> anyone give hints regarding how to capture the preceedng two lines
> after the pattern matches.

Dear Tim,

   I just create an array called @pastLines, that holds the past lines
encountered, whether they matched or not.  I always trim it to just
two lines (so I don't have to store everything).  When a match is
encountered, I print out the @pastLines.

   Here is a small program that does what you want:


#!/usr/bin/perl -w
use strict;
my @pastLines;
while (<>)
{
   shift @pastLines  if (@pastLines > 2);
   if (m/MATCH/ .. m/^$/)
   {
      print @pastLines  if m/MATCH/;
      print $_;
   }
   push @pastLines, $_;
}
__END__


   Now save it to a file (you can call it something like
"2before.pl"), replace the pattern m/MATCH/ with whatever you want
your pattern match to be, and then call it with a command like:

      perl 2before.pl input.txt

and you'll see that the lines two before the match all the way to the
blank line are printed.

   This also prints the final blank line.  If you don't want that
blank line, replace the line:

      print $_;

with:

      print $_  unless m/^$/;

   I hope this helps, Tim.

   -- Jean-Luc


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

Date: 16 Sep 2004 05:24:21 -0700
From: nobull@mail.com
Subject: Re: Passing a regex reference through a hashed value to the right side of s///g
Message-Id: <4dafc536.0409160424.1b462152@posting.google.com>

"John W. Krahn" <someone@example.com> wrote in message news:<Qv%1d.35949$XP3.18660@edtnps84>...
> Brian McCauley wrote:
> > Yes! Yes! Yes! This is wonderfull.  I'm so happy to see this.
> 
> Are you being ironic?

Only slightly.

Since I'm giving a Lightning talk tomorrow here at YAPC about how
commonly this quesiton comes up in comp.lang.perl.misc I had been
hoping to be able to say that the question had actually been posted
during the conference.


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

Date: Thu, 16 Sep 2004 07:17:51 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Perl send args to other perl file.
Message-Id: <z6b2d.98813$3l3.61109@attbi_s03>

ilksen wrote:

> Hello all, 
> Can i send vars from file1.pl to file2.pl and display or read the
> sended vars in file2.pl?

In general, you cannot send variables from one perl script to another.
Instead, send the values that were in the variables.
The receiving script will use @ARGV;

> File2
> -----------------------------
> #!/usr/local/bin/perl
> if(@hello){
> print "Value: @hello\n";
> } else { print "Nothing received\n";}

   if(@ARGV) {
     print scalar(@ARGV)," arguments received: @ARGV\n";
   } else {
     die "No command line arguments detected\n";
   }

	-Joe


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

Date: Thu, 16 Sep 2004 11:53:31 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: preserving back references (ie $1, $2...)
Message-Id: <cibr38$qvc$1@sun3.bham.ac.uk>



Eric Amick wrote:
> On Wed, 15 Sep 2004 00:34:57 GMT, "John W. Krahn" <someone@example.com>
> wrote:
> 
> 
>>rob wrote:
>>
>>>Does anyone know of a way to preserve that back reference so you can
>>>continue to access parts of a sting with out having to parse them out
>>>into separate scalar variables?
>>
>>You mean something like this.  :-)
>>
>>my $string = 'a,b;c,d;e,f';
>>if ( $string =~ /([a-z,]+);([a-z,]+);([a-z,]+)/ ) {
>>  print "START_3\n";
>>  print "$1\n";
>>  { local $_ = $1;
>>    local ( $1, $2, $3 );
> 
> 
> The capture variables are already block scoped, so the second local()
> really isn't necessary.

The capture variables are not really block scoped or localized as per 
ordinary globals.

The value of $1 is magically the first capture of the last regex 
evaluation in the current stack frame or a parent stack frame.

But it's still the same variable.

'foo' =~ /(.*)/;
my $r1 = \$1;
{
   'bar' =~ /(.*)/;
   print "$1 $$r1\n"; # bar bar
}
print "$1 $$r1\n"; # foo foo



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

Date: 16 Sep 2004 01:01:52 -0700
From: jayyuba@yahoo.com (Jayashree)
Subject: Simple problem
Message-Id: <3bdadfd0.0409160001.6bf48e53@posting.google.com>

I am a newbie to perl and its regular expression. I would like to know
the regular expression which would allow me to match anything in a
string except for "textarea" or "script" within an angle bracket

string = "abracadabra<this should match><textarea><script><textarea
abracadabra>"

In the above string it should match 
<this should match>
<textarea abracadabra>
and not match
<textarea>
<script> and ofcourse the beginning abracadabra

Thanks in advance,
Jayashree


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

Date: Thu, 16 Sep 2004 11:04:18 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Simple problem
Message-Id: <cibkpd$scm$1@nntp.fujitsu-siemens.com>

Jayashree wrote:
> I am a newbie to perl and its regular expression. I would like to know
> the regular expression which would allow me to match anything in a
> string except for "textarea" or "script" within an angle bracket
>=20
> string =3D "abracadabra<this should match><textarea><script><textarea
> abracadabra>"
>=20
> In the above string it should match=20
> <this should match>
> <textarea abracadabra>
> and not match
> <textarea>
> <script> and ofcourse the beginning abracadabra

What do you mean by "should match"?
Usually you match an entire line (or parts thereof) and extract the=20
interesting portions. So: what exactly do you want to do with the line?
If you are interested in the various parts, you might want to have a=20
look at "split":

#! /usr/bin/perl
use warnings;
use strict;

my $string =3D "abracadabra<this should match><textarea><script><textarea=
>=20
abracadabra>";
my @f =3D split(/<textarea>|<script>/, $string);
print join("\n", @f);

Note that this will extract the empty string between "<textarea>" and=20
"<script>".
You can avoid this if you use
my @f =3D split(/(<textarea>|<script>)+/, $string);

HTH,

Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Thu, 16 Sep 2004 11:03:01 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple problem
Message-Id: <2qt3b0F133o19U1@uni-berlin.de>

Jayashree wrote:
> I am a newbie to perl and its regular expression. I would like to
> know the regular expression which would allow me to match anything
> in a string except for "textarea" or "script" within an angle
> bracket

     perldoc perlrequick

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 16 Sep 2004 09:13:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Simple problem
Message-Id: <ciblgg$95m$1@mamenchi.zrz.TU-Berlin.DE>

Jayashree <jayyuba@yahoo.com> wrote in comp.lang.perl.misc:

Your subject "Simple problem" is at once vacuous and annoying.  If you
can't solve it, don't tell us it's simple!

> I am a newbie to perl and its regular expression. I would like to know
> the regular expression which would allow me to match anything in a
> string except for "textarea" or "script" within an angle bracket
> string = "abracadabra<this should match><textarea><script><textarea
> abracadabra>"
> 
> In the above string it should match 
> <this should match>
> <textarea abracadabra>
> and not match
> <textarea>
> <script> and ofcourse the beginning abracadabra

This isn't simple, it's impossible.

A regex match must be definite.  It isn't enough to decide whether
a match occurs, but it must say where it occurs and how many characters
are involved.  So where in the string "abracadabra" is the place where
/<textarea>|<script>/ isn't contained, and for how many characters
isn't it contained?

The answer is, your regex would have to match every substring that
isn't exactly one of "<textarea>" or "<script>".  That are a lot
of substrings, including strings like "match><textar", "textarea>",
and so on.  A single regex simply won't do it.

You could first extract the parts that are enclosed in <> and
then de-select the unwanted matches, as in

    print "$_\n" for grep ! /<textarea>|<script>/, /(<.*?>)/g;

but that isn't a single regex, and it will break easily on more
complicated HTML.

What you really should do is get yourself an HTML parser from CPAN
and use that.

Anno


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

Date: Thu, 16 Sep 2004 09:16:20 +0200
From: "Peter Kramer" <clandos@yahoo.com>
Subject: Re: Speicherkosnum
Message-Id: <41493dc9$0$299$4d4ebb8e@read.news.de.uu.net>

Sorry, I didnt see it, its english.

I have some memory leaks in this program. When I fork with W2k and open a db
connection, make some db actions, and exit the child, almost 2 mb of ram are
gone.
If  I open it in the parent process everything is going normal, but all
db-handles are not forked, so the child can not use the db.
Peter




"Peter" <clandos@yahoo.com> schrieb im Newsbeitrag
news:4147f9c0$0$290$4d4ebb8e@read.news.de.uu.net...
> Hallo,
>
> folgendes Script kosnumiert Speicher en mass und ich habe keine Ahnung
> warum.
> Leider lässt sich eine DBI Datenverbindung nicht forken, sodass ich
> innerhalb des Childs jedesmal eine Connection öffne.
> Allerdings ist es so, das der Speicher nicht mehr freigegeben wird
> Hat jemand eine Idee?
>
>
>
>
> use DBI;
> while()
> {
>
>  if ($pid =fork()) #parent
>  {
>
>   wait();
>
>  }
>  else # child
>  {
>
>   my $dbh = &dbopen;
>   print "write data $dbh\n";
>   &dbwrite($dbh);
>   &dbclose($dbh);
>   exit;
>
>  }
> }
>
>
> sub dbopen
> {
>
>  my $dsn = 'DBI:mysql:max:server';
>  my $db_user_name = 'max';
>  my $db_password = 'min';
>  my ($id, $password);
>
>  return DBI->connect($dsn, $db_user_name, $db_password);
>
>
>
> }
>
> sub dbclose
> {
>  my $dbh = shift;
>  $dbh->disconnect()
> }
>
> sub dbwrite
> {
>  my $dbh = shift;
>  $dbh->do("select * from test");
> }
>
>
>




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

Date: Thu, 16 Sep 2004 09:48:19 +0200
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Why this Regex not working?
Message-Id: <41494543$1@news.kcl.ac.uk>

Looking wrote:
> $s='sadf content= "this is what i want " asd " sdf " adfa  " sdf';
> $s =~ s/.*content=.*?["|'](.*)?["|'].*/$1/si;
> #$s =~ s/.*content=.*?["|']([^"|']*)["|'].*/$1/si;
> print "$s\n";
> 
> The scond regex works. I wonder why the first regex not working?
> I am trying to get whatever is between the first pair of "" or '' after
> content=. It is parsing the header file of HTML pages.
> 
> The first regex gave me this:
>  "this is what i want " asd " sdf " adfa
> 
> But I need this:
> this is what i want
You may want to check out HTTP::Headers rather than doing this yourself.

With this regex

(this won't work for readers using proportional fonts)

$s =~ s/.*content=.*?["|'](.*)?["|'].*/$1/si;
                                ^

The problem is that in order to do a non-greedy match the question mark 
should be immediately adjacent to the * ie you need to remove the 
brackets or put the ? inside the brackets. Also, you don't need the | 
(pipe symbol) inside [] character classes.

regards,

Mark





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

Date: 16 Sep 2004 07:49:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why this Regex not working?
Message-Id: <cibgil$44r$1@mamenchi.zrz.TU-Berlin.DE>

Looking <adsense@whitehouse.com> wrote in comp.lang.perl.misc:
> $s='sadf content= "this is what i want " asd " sdf " adfa  " sdf';
> $s =~ s/.*content=.*?["|'](.*)?["|'].*/$1/si;
                         ^         ^
Do you actually want to allow | besides " and ' for quotes?  I think
you have conflated character class notation and alternation.

> #$s =~ s/.*content=.*?["|']([^"|']*)["|'].*/$1/si;
> print "$s\n";
> 
> The scond regex works. I wonder why the first regex not working?
> I am trying to get whatever is between the first pair of "" or '' after
> content=. It is parsing the header file of HTML pages.

Better use a real HTML parser.

> The first regex gave me this:
>  "this is what i want " asd " sdf " adfa
> 
> But I need this:
> this is what i want

Simple.  /.*/ is greedy, it matches the longest string it can while
still having the rest of the pattern match.  So it picks up everything
until the last " or ' in the line.  The question mark in /(.*)?/
serves no purpose.  You probably meant to put it inside the parentheses:
/(.*?)/.  In that position the match will be non-greedy.

Anno


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

Date: Thu, 16 Sep 2004 10:31:57 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Why this Regex not working?
Message-Id: <xYd2d.33695$KU5.12198@edtnps89>

Looking wrote:
> $s='sadf content= "this is what i want " asd " sdf " adfa  " sdf';
> $s =~ s/.*content=.*?["|'](.*)?["|'].*/$1/si;
> #$s =~ s/.*content=.*?["|']([^"|']*)["|'].*/$1/si;
> print "$s\n";
> 
> The scond regex works. I wonder why the first regex not working?

That is because *, + and ? are greedy and will match as many characters as 
possible so (.*) will match everything to the end until the last ", | or ' 
character.  (Why are you trying to match the | character?)  You probably want 
something like:

$s =~ s/.*content=.*?(["'])([^\1]*)[\1].*/$2/si;


John
-- 
use Perl;
program
fulfillment


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

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


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