[29120] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 364 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 20 09:10:16 2007

Date: Fri, 20 Apr 2007 06:09:07 -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           Fri, 20 Apr 2007     Volume: 11 Number: 364

Today's topics:
    Re: Booleans in Perl <rvtol+news@isolution.nl>
    Re: Booleans in Perl <tadmc@augustmail.com>
    Re: Booleans in Perl (Randal L. Schwartz)
    Re: Booleans in Perl <wahab-mail@gmx.de>
    Re: Booleans in Perl <wahab-mail@gmx.de>
    Re: Booleans in Perl (Randal L. Schwartz)
    Re: Booleans in Perl <jurgenex@hotmail.com>
    Re: die problem? <tadmc@augustmail.com>
    Re: die problem? <purlgurl@purlgurl.net>
    Re: FAQ 9.20 How do I send mail? -- PROBLEM SOLVED! <bik.mido@tiscalinet.it>
        Filehandle Pipe Problem? g4173c@motorola.com
    Re: Filehandle Pipe Problem? g4173c@motorola.com
    Re: How to make perl script executable from anywhere on <bik.mido@tiscalinet.it>
    Re: How to make perl script executable from anywhere on <purlgurl@purlgurl.net>
    Re: Newbie queston on Perl and lex. <bik.mido@tiscalinet.it>
    Re: Printing the next line of text of the file <bik.mido@tiscalinet.it>
    Re: Printing the next line of text of the file <bik.mido@tiscalinet.it>
    Re: Printing the next line of text of the file <wahab-mail@gmx.de>
    Re: Printing the next line of text of the file anno4000@radom.zrz.tu-berlin.de
        regex upper and lower case <jpreston@general-steel.com>
    Re: regex upper and lower case <abigail@abigail.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 20 Apr 2007 12:29:50 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Booleans in Perl
Message-Id: <f0abqj.q4.1@news.isolution.nl>

Mirco Wahab schreef:

>   sub true { return 1 }
>   sub false { return 0 }
>   use constant TRUE => true;
>   use constant FALSE => false;

That looks like sub-stacking, but the compiler optimizes it:

$ perl -MO=Deparse -e'
   sub true { return 1 }
   sub false { return 0 }
   use constant TRUE => true;
   use constant FALSE => false;
   $x = TRUE;
   $y = FALSE
'
sub true {
    return 1;
}
sub false {
    return 0;
}
use constant ('TRUE', true());
use constant ('FALSE', false());
$x = 1;
$y = 0;
-e syntax OK



I write such more like:

$ perl -MO=Deparse -e'
  use constant {FALSE => 0, TRUE => !0};
  $x = TRUE;
  $y = FALSE
'
use constant ({'FALSE', 0, 'TRUE', 1});
$x = 1;
$y = 0;
-e syntax OK

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: Fri, 20 Apr 2007 06:47:30 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Booleans in Perl
Message-Id: <slrnf2ha2i.gn9.tadmc@tadmc30.august.net>

David Williams <dw149@acmex.gatech.edu> wrote:
> Small question.
> Why does PERL do the following
>
> $a=FALSE;
> $b=FALSE;
> $c=($a && $b); 
> if($c){
> echo "the expr evaluates to true";
> }
> else{
> echo "the expr evaluates to false;
> }
>
> I always get "the expr evaluates to true";


Because the string 'FALSE' is a true value.

It is a true value because it is not one of the four values that
Perl (not PERL) considers false:

   1) the number zero
   2) the empty string
   3) the undef value
   4) a one character string where the character is the zero digit

> if it is false && false, should it not be false?


FALSE && FALSE _is_ FALSE (which is a true value):

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

my $a=FALSE;
my $b=FALSE;
my $c=($a && $b);

print "\$c is '$c'\n";
-------------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 20 Apr 2007 04:24:24 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Booleans in Perl
Message-Id: <86lkgnuw47.fsf@blue.stonehenge.com>

>>>>> "Mirco" == Mirco Wahab <wahab-mail@gmx.de> writes:

Mirco> package bool;
Mirco>   sub true { return 1 }
Mirco>   sub false { return 0 }
Mirco>   use constant TRUE => true;
Mirco>   use constant FALSE => false;

This is almost never a good idea.

*Somebody* out there will write:

           if (some_func() == TRUE) { ... }

and then get burned when some_func() returns 42 for true, not your
precious "1".

Remember, in Perl, there are many values of true and fewer but still many
values of false.  Stop trying to force Perl's truth model into
a simple boolean space.

print "Just another Perl hacker,"; # the original
-- 
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!

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Fri, 20 Apr 2007 14:07:15 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Booleans in Perl
Message-Id: <f0aaq0$5ub$1@mlucom4.urz.uni-halle.de>

Randal L. Schwartz wrote:
>>>>>> "Mirco" == Mirco Wahab <wahab-mail@gmx.de> writes:
> 
> Mirco> package bool;
> Mirco>   sub true { return 1 }
> Mirco>   sub false { return 0 }
> Mirco>   use constant TRUE => true;
> Mirco>   use constant FALSE => false;
> 
> This is almost never a good idea.
> 
> *Somebody* out there will write:
> 
>            if (some_func() == TRUE) { ... }
> 
> and then get burned when some_func() returns 42 for true, not your
> precious "1".

Oh, I forgot! You are, of course, right. I was blind-
folded, because in php, the following *would* work:

<going into php mode>

     $c = 42;

     if($c == TRUE) {
        echo "$c is TRUE\n";
     }
     else {
        echo "$c is FALSE\n";
     }
</going into php mode>

and its TRUE/FALSE would be a magical
function to the left hand side.

What would be an appropriate idiomatic
approximation in Perl aside from the
obvious

     if( $c ) {
        print "$c is TRUE\n";
     }

(or - why would't be any?)


Regards & Thanks

Mirco


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

Date: Fri, 20 Apr 2007 14:14:04 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Booleans in Perl
Message-Id: <f0ab6q$5uf$1@mlucom4.urz.uni-halle.de>

Dr.Ruud wrote:
> I write such more like:
> 
> $ perl -MO=Deparse -e'
>   use constant {FALSE => 0, TRUE => !0};
>   $x = TRUE;
>   $y = FALSE
> '
> use constant ({'FALSE', 0, 'TRUE', 1});
> $x = 1;
> $y = 0;
> -e syntax OK

OK, I tried to conjure up an overly compli-
cated 'php compatibility framework' ;-)

Yours is much more adequate, but the !0 would
(imho) always evaluate to 1 in Perl, so why
wouldn't one write it.


Regards & Thanks

Mirco


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

Date: Fri, 20 Apr 2007 05:27:53 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Booleans in Perl
Message-Id: <86647rut6e.fsf@blue.stonehenge.com>

>>>>> "Mirco" == Mirco Wahab <wahab-mail@gmx.de> writes:

Mirco> Yours is much more adequate, but the !0 would (imho) always evaluate to
Mirco> 1 in Perl, so why wouldn't one write it.

There's actually no promise of that.  "Boolean-returning" operations are free
to return "any true" for true and "any false" for false, although in practice,
they return a predefined scalar (internally) of "true" and "false", which
look like "1" and "" respectively.  Yes, "false" is not 0, but "".

print "Just another Perl hacker,"; # the original

-- 
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!

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Fri, 20 Apr 2007 12:59:22 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Booleans in Perl
Message-Id: <KO2Wh.7866$F32.2793@trndny02>

David Williams wrote:
> Small question.
> Why does PERL do the following
>
> $a=FALSE;
> $b=FALSE;
> $c=($a && $b);
> if($c){
> echo "the expr evaluates to true";
> }
> else{
> echo "the expr evaluates to false;
> }
>
> I always get "the expr evaluates to true";

Interesting result. I am getting a bunch or compiler errors instead:

String found where operator expected at C:\tmp\t.pl line 6, near "echo "the 
expr
 evaluates to true""
        (Do you need to predeclare echo?)
String found where operator expected at C:\tmp\t.pl line 9, at end of line
        (Missing semicolon on previous line?)
syntax error at C:\tmp\t.pl line 6, near "echo "the expr evaluates to true""
Can't find string terminator '"' anywhere before EOF at C:\tmp\t.pl line 9.

Which version of Perl are you using?

jue






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

Date: Fri, 20 Apr 2007 06:34:42 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: die problem?
Message-Id: <slrnf2h9ai.gn9.tadmc@tadmc30.august.net>

Purl Gurl <purlgurl@purlgurl.net> wrote:
> Tad McClellan wrote:
>
>> Purl Gurl wrote:
>>> g4173c wrote:
>
> (snipped)
>
>>>>    system ("cleatool co -unr -nc $revfilename") || die "Error:
>>>> Couldn't Check Out $revfilename: $!\n";
>
>>>> The system call has a typo for the command. I thought that it should
>>>> have stopped there, however I get this:
>
>>>> Can't exec "cleatool": No such file or directory at ba line 83,
>
>>> Your system call is successful. An error message is returned to
>>> your call, 
>
>> No it isn't.
>
> My presumption is you are not wearing your reading glasses
> rather than your usual habit of lying to readers.


My presumption is that you do not know the difference between
a function's "return value" and "output".


> "Can't exec "cleatool": No such file or directory at ba line 83"

> Nah, this is not a problem


That is output, it is not a return value as you said it was.


>>> no system
>>> error code is returned.
>
>> Yes it is.
>
>>    perl -le '$ret = system "bad"; print $ret'
>
>>    -1
>
> Irrelevant. 


It illustrates that system *does* return an error code.


> All you have accomplished is to exemplify how
> childish are you.


All you have accomplished is to illustrate that you do not know
what you are talking about. Yet again.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 20 Apr 2007 05:44:35 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: die problem?
Message-Id: <-IidnVVyLowmKLXbnZ2dnUVZ_uejnZ2d@giganews.com>

Tad McClellan wrote:

> Purl Gurl wrote:
>> Tad McClellan wrote:
>>> Purl Gurl wrote:
>>>> g4173c wrote:

(snipped)

Your years long persistent habit of adding lies to cover
your previous lies, benefits none.

You are quite the ignorant troll.

Purl Gurl


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

Date: Fri, 20 Apr 2007 12:41:39 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 9.20 How do I send mail? -- PROBLEM SOLVED!
Message-Id: <9u5h23997gf04cl6ruqb3egtt3oapidid8@4ax.com>

On Fri, 20 Apr 2007 03:18:20 -0500, "timdooling"
<timdooling@qconline.com> wrote:

>The quote marks made a difference around the \n, too.  It just comes
>out as '\n' without the quote marks.  But the mail still wasn't sent

To settle down the issue once and forever:

1. Double quotes a.k.a qq// interpretate \n and interpolate;
2. Single quotes a.k.a. q// do neither.

So if you want to print the literal string 'foo@bar', followed by a
newline you can use one of the following (and more, but I'm listing
the most obvious choices):

  print "foo\@bar\n";
  print 'foo@bar', "\n";

If you set $\ suitably and you need several such print()s, you can
save yourself some work and make the code clearer.


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: 20 Apr 2007 05:25:38 -0700
From: g4173c@motorola.com
Subject: Filehandle Pipe Problem?
Message-Id: <1177071938.821425.3230@b58g2000hsg.googlegroups.com>

Hi:

   I have the following code for checking if a file is all ready
checked out for editing. It works if the file is checked out, however
if the file isn't checked out the pipe is closed and I never go into
the while loop. Any ideas what I should change to get this to work?

sub CC_ChkOut {
    my $ccfile = shift (@_);
#
# Check to see if the file is all ready checked out, if not check it
out unreserved.
#
    open (CC, "cleartool lsco -me $ccfile |") or die "Error: Problem
with check file status: $!\n";
    while (<CC>) {
        if (/checkout/) {
            print "All ready checked out...\n";
        }
        else {
            system ("cleartool co -unr -nc $ccfile") == 0 || die
"Error: Couldn't Check Out $ccfile: $!\n";
        }
    }
}

Thanks in advance for any help!!
  Tom



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

Date: 20 Apr 2007 05:58:49 -0700
From: g4173c@motorola.com
Subject: Re: Filehandle Pipe Problem?
Message-Id: <1177073929.326187.177970@l77g2000hsb.googlegroups.com>

D'oh!

sub CC_ChkOut {
    my $ccfile = shift (@_);
#
# Check to see if the file is all ready checked out, if not check it
out unreserved.
#
    open (CC, "cleartool lsco -me $ccfile |") or die "Error: Problem
with check file status: $!\n";
    if (eof(CC)) {
        system ("cleartool co -unr -nc $ccfile") == 0 || die "Error:
Couldn't Check Out $ccfile: $!\n";
    }
    else {
        print "All ready checked out...\n";
    }
    close (CC);
}





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

Date: Fri, 20 Apr 2007 12:30:57 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How to make perl script executable from anywhere on windows?
Message-Id: <nb5h23p6ejeuojvbd6ali6oiudrsqbkf09@4ax.com>

On 19 Apr 2007 21:06:16 -0700, veg_all@yahoo.com wrote:

>I have ActivePerl installed and want to place all my scripts in one
>directory but be able to execute them from anywhere. So if I type perl
>myscript.pl from any directory/folder in windows dos prompt it will
>run.

I just put them in "C:\Programmi\Apps" which is a directory I use for
all standalone programs I use, whether they're perl scripts or not. Of
course I put that directory in the PATH. Notice that AP's installation
program registers the .pl extension, but does not set the PATHEXT env
variable accordingly, so I did that manually. So I put, for example,
coolscript.pl in "C:\Programmi\Apps" and from anywhere at the prompt I
just type

  coolscript foo bar baz


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: Fri, 20 Apr 2007 05:41:27 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: How to make perl script executable from anywhere on windows?
Message-Id: <L5GdnaAR57JiKbXbnZ2dnUVZ_hynnZ2d@giganews.com>

RedGrittyBrick wrote:

> veg_all wrote:

(snipped)


> Note that this has *nothing* to do with perl.exe being on the path or 
> file associations for .pl. The ActiveState installer will already have 
> taken care of both of these. I think the other responder has 
> misunderstood your question.

I am curious.

I provide the precise same information as you, except I provide
greater detail, better explanation, examples and provide research
links, along with cautionary notes.

With your having repeated what I wrote, but to a significantly
lesser degree of quality, why do you understand and I misunderstand?

Appears you are lying to readers just as McClellan lies to readers.

You boys constantly lying to readers, benefits none.

Purl Gurl


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

Date: Fri, 20 Apr 2007 12:35:59 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Newbie queston on Perl and lex.
Message-Id: <6q5h2358fvglgsnev3pnlftcbmfij1lrv3@4ax.com>

On 19 Apr 2007 23:01:54 -0700, somedeveloper@gmail.com wrote:

>1. If my needs are only lexical scanning (and not compiler- and
>interpretor-writing), and
>2. If I'm proficient in Perl and Perl regular expressions,
>
>would I ever need to learn a tool such as f/lex?  Is there anything
>that Perl REs cannot do easily/elegantly which f/lex can, for example?

I don't have the slightest idea. But I know an article that you may be
interested in:

http://www.perl.com/pub/a/2006/01/05/parsing.html


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: Fri, 20 Apr 2007 12:10:48 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Printing the next line of text of the file
Message-Id: <t64h235siu3hftioauofscp5i9k50anp4h@4ax.com>

On 19 Apr 2007 15:37:27 -0700, Nene <rodbass63@gmail.com> wrote:

>I wrote a perl script  that opens a file. I wrote a regex that
>captures $1 $2 and prints it to output. What I want it to do which I
>can't figure out is to print the next line (which has a regex that I
>need to capture as well) under the line that has the the regex but I
>can't figure it out so far. Any help will be greatly appreciated.

  open my $fh, '<', 'somefile' or die "D'oh! $!\n";
  while (<$fh>) {
      if (/$regex/) {
          do_something($1,$2);
          defined(my $next_line=<$fh>) or die "No next line!";
      }
  }


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: Fri, 20 Apr 2007 12:18:53 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Printing the next line of text of the file
Message-Id: <5n4h23hq3v9m0sep14ph856fv5f7juphbl@4ax.com>

On Fri, 20 Apr 2007 02:01:37 -0700, Joe Smith <joe@inwap.com> wrote:

>> for( <$fh> ) {
>>   if( /$rg_1/ ) {
>>     print "$1 $2\n" 
>>     my $next = <$fh>;
>
>Won't work.  for(<$fh>) reads in the entire file, leaving
>nothing for the next <$fh> to read.
>
>Use while(<$fh>), not for(<$fh>).

A side effect of the OP's using C<for> in the first place. OTOH maybe
some of us are thinking of

  for =$fh

already...


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: Fri, 20 Apr 2007 13:47:08 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Printing the next line of text of the file
Message-Id: <f0a9k9$5jd$1@mlucom4.urz.uni-halle.de>

anno4000@radom.zrz.tu-berlin.de wrote:
> Mirco Wahab  <wahab-mail@gmx.de> wrote in comp.lang.perl.misc:
>> Then something like this should work:
>> ...
>>   my $rg = qr/^\w+\s+(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}:\d{2})(?{$flag=0})/;
>>
>>   while( <$fh> ) {
>>      if( /$rg/ ) {
>>        print "$1 $2\n"
>>      }
>>     else {
>>        print unless $flag++
>> ...
> 
> Uh... that won't print anything unless you initialize $flag to false,

I did (didn't I?) - can you spot it?

> and even then it'll work for only one pair of lines.  Simplifying the
> regex still further:
> 
>     my $flag;
>     while ( <DATA> ) {
>         print if $flag;           # the line after a match
>         print if $flag = /xxx/;   # the matching line
>     }

OK, but that a different concept (from mine) and
seems to be overly verbose:

  my $flag = 1;
  my $rg = qr/^\w+\s+(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}:\d{2})(?{$flag=0})/;
  print /$rg/ ? "$1 $2\n" : $flag++ ? '' : $_  while <$fh> ;

;-)

Regards

M.


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

Date: 20 Apr 2007 13:02:00 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Printing the next line of text of the file
Message-Id: <58rru8F2fb9mbU1@mid.dfncis.de>

Mirco Wahab  <wahab-mail@gmx.de> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de wrote:
> > Mirco Wahab  <wahab-mail@gmx.de> wrote in comp.lang.perl.misc:
> >> Then something like this should work:
> >> ...
> >>   my $rg = qr/^\w+\s+(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}:\d{2})(?{$flag=0})/;
> >>
> >>   while( <$fh> ) {
> >>      if( /$rg/ ) {
> >>        print "$1 $2\n"
> >>      }
> >>     else {
> >>        print unless $flag++
> >> ...
> > 
> > Uh... that won't print anything unless you initialize $flag to false,
> 
> I did (didn't I?) - can you spot it?
> 
> > and even then it'll work for only one pair of lines.  Simplifying the
> > regex still further:
> > 
> >     my $flag;
> >     while ( <DATA> ) {
> >         print if $flag;           # the line after a match
> >         print if $flag = /xxx/;   # the matching line
> >     }
> 
> OK, but that a different concept (from mine) and
> seems to be overly verbose:
> 
>   my $flag = 1;
>   my $rg = qr/^\w+\s+(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}:\d{2})(?{$flag=0})/;
>   print /$rg/ ? "$1 $2\n" : $flag++ ? '' : $_  while <$fh> ;

Ah... sneaky code insertions :)  I didn't give the regex more attention
than needed to note it's big.

Code insertions are only there to make it true that "You can do
everything with a regex".

Anno


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

Date: Fri, 20 Apr 2007 07:40:54 -0500
From: "Jerry" <jpreston@general-steel.com>
Subject: regex upper and lower case
Message-Id: <132hd6ffnlv8mfe@corp.supernews.com>

Hi!

I want to make every thing in the line lower case except want is between "".

$ex  = "popups.prompt( \"                 INV_NO_/S\ " + A.INV_NO_ + \"/\" + 
A.S )";

ending result will be

$ex  = "popups.prompt( \"                 INV_NO_/S\ " + a.inv_no_ + \"/\" + 
a.s )";

Thanks,

Jerry




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

Date: 20 Apr 2007 12:52:05 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: regex upper and lower case
Message-Id: <slrnf2hdr5.7ug.abigail@alexandra.abigail.be>

Jerry (jpreston@general-steel.com) wrote on MMMMCMLXXX September MCMXCIII
in <URL:news:132hd6ffnlv8mfe@corp.supernews.com>:
==  Hi!
==  
==  I want to make every thing in the line lower case except want is between "".
==  
==  $ex  = "popups.prompt( \"                 INV_NO_/S\ " + A.INV_NO_ + \"/\" + 
==  A.S )";

That doesn't compile.

==  
==  ending result will be
==  
==  $ex  = "popups.prompt( \"                 INV_NO_/S\ " + a.inv_no_ + \"/\" + 
==  a.s )";



$ex = do {my $i; join '"' => map {++ $i % 2 ? lc : $_} split '"' => $ex, -1};


Abigail
-- 
BEGIN {$^H {q} = sub {pop and pop and print pop}; $^H = 2**4.2**12}
"Just "; "another "; "Perl "; "Hacker\n";


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

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 V11 Issue 364
**************************************


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