[31049] in Perl-Users-Digest
Perl-Users Digest, Issue: 2294 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 24 21:09:54 2009
Date: Tue, 24 Mar 2009 18:09:11 -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 Tue, 24 Mar 2009 Volume: 11 Number: 2294
Today's topics:
Re: How to use a variable as regular expression? <tzz@lifelogs.com>
Re: How to use a variable as regular expression? <tadmc@seesig.invalid>
Re: i have a question <tzz@lifelogs.com>
Re: Read File and Output to new format sln@netherlands.com
Re: Read File and Output to new format <tadmc@seesig.invalid>
Re: Read File and Output to new format <Ansher.M@gmail.com>
Re: Read File and Output to new format <Ansher.M@gmail.com>
Re: regex question: extended [^...] concept? <wl@gnu.org>
rolling frame (3) <mstep@podiuminternational.org>
Roulette, was rolling frame (seriously OT) <unclebob@tnglwood.demon.co.uk>
Re: translating memcache php code to perl <jcharth@gmail.com>
what is the return value type of !1 ? <meshulum@gmail.com>
Re: what is the return value type of !1 ? (Tim McDaniel)
Re: what is the return value type of !1 ? <meshulum@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 24 Mar 2009 13:14:00 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to use a variable as regular expression?
Message-Id: <86ab7akcuv.fsf@lifelogs.com>
On Mon, 23 Mar 2009 08:35:42 -0700 (PDT) SamL <slsamliu@gmail.com> wrote:
S> I want to use a variable as a regular expression because I want user
S> to be able to specify the regular expression in command line.
S> Basically I want something like this:
S> perl -e '$pattern='s/a/b/'; $x='a'; $x=~$pattern; print $x;'
S> where user can modify $pattern at runtime.
S> Of course the above does not work. I am wondering if there is some
S> mechanism in perl allowing me to do that. For example, something like
S> eval in ksh.
Be careful, if the user can type any regular expression, they can
execute plenty of Perl code. I think Perl 6 will have better support
for what you want (I'm not sure, it's been a while since I read the
relevant docs), but with Perl 5 you have to do the due dilligence
yourself.
Ted
------------------------------
Date: Tue, 24 Mar 2009 15:25:20 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: How to use a variable as regular expression?
Message-Id: <slrngsigdg.q7u.tadmc@tadmc30.sbcglobal.net>
Ted Zlatanov <tzz@lifelogs.com> wrote:
> On Mon, 23 Mar 2009 08:35:42 -0700 (PDT) SamL <slsamliu@gmail.com> wrote:
>
> S> I want to use a variable as a regular expression because I want user
> S> to be able to specify the regular expression in command line.
^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^
> S> Basically I want something like this:
>
> S> perl -e '$pattern='s/a/b/'; $x='a'; $x=~$pattern; print $x;'
>
> S> where user can modify $pattern at runtime.
>
> S> Of course the above does not work. I am wondering if there is some
> S> mechanism in perl allowing me to do that. For example, something like
> S> eval in ksh.
>
> Be careful, if the user can type any regular expression, they can
> execute plenty of Perl code.
They already have command line access, so users can already
execute plenty of Perl code.
:-)
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 24 Mar 2009 13:10:25 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: i have a question
Message-Id: <86eiwmkd0u.fsf@lifelogs.com>
On Mon, 23 Mar 2009 16:06:57 +0000 Ben Morrow <ben@morrow.me.uk> wrote:
BM> Quoth Tad J McClellan <tadmc@seesig.invalid>:
>>
>> You should use single quotes unless you need one of the two extra
>> things that double quotes gives you.
BM> I used to think that, until http://markmail.org/message/e4i3ngej24an7uch
BM> convinced me otherwise. The section on double-quoting starts about a
BM> third of the way down (search for 'politically-correct Bowdlerization').
I firmly believe that whichever quotes you use, you'll find out later it
was the wrong kind because the code, requirements, or data has changed.
It's "Murphy's" Law, I guess.
Ted
------------------------------
Date: Tue, 24 Mar 2009 17:18:14 GMT
From: sln@netherlands.com
Subject: Re: Read File and Output to new format
Message-Id: <185is4hud2gamu1lj59llp7r4mmt338bol@4ax.com>
On Tue, 24 Mar 2009 06:07:16 -0700 (PDT), ansher <Ansher.M@gmail.com> wrote:
>Hello
>
>What I am trying to achieve is to read a file and write the formatted
>text into a new file. But I am facing some difficulty with that
>
>Format: I am reading a file where line continuation is indicated by
>+ sign at the beginning of the new line. Remove the line
>continuation and add (join) this new line to prev. one
>
>NOTE: file do not have line number, it is only for your reference.
>
>Line13: n01contacts/friends do you
>Line14: +have in each of the services ;c=contacts(433)1
>
>Output: n01 contacts/friends do you have in each of the
>services ;c=contacts(433)1
>
>Challenges: I cannot always consider +sign as the beginning of the
>new line, those instances are
>
>1.Section of lines should not be formatted after text fld, refer
>line 16-23 should not be formatted. Lines after this section must be
>formatted.
>
>2. Section of lines should not be formatted after text val, refer
>line 29-33 should not be formatted. Lines after this section must be
>formatted.
>
>3. Refer line 9-12, line 10 ends with ; but lines 11 & 12 do not.
> After formatting line should be separated by single ;
>
> *include q10.qin;txt=UNIQUENESS; bb=Top line; tx=Mid Value;tb=Low
>Value
>
>4.Refer line 13-14,
>
>Line13: n01contacts/friends do you
>Line14: +have in each of the services ;c=contacts(433)1
>
>After formatting line should not be separated by single ; instead it
>should read as
>
>n01contacts/friends do you have in each of the services ;c=contacts
>(433)1
>
>
>Any solution to this will be of great help to me. Thanks
But what about ';' ?
Sure the sample in this form can be done. Not quite so simple
though. The rules you specify are not quite distinct.
-sln
--------------------------------------
use strict;
use warnings;
my ($buf, $skip) = ('', 0);
while ( <DATA> )
{
chomp;
if ( /^\s* (?: fld | val )/x )
{
$skip = 1;
}
elsif ( /^\s*\+/ )
{
unless ( $skip || !$buf )
{
s/;+$//; s/^\s*\++//;
if ( /^\s*\w*\s*=/ )
{
$buf =~ s/;+$//;
$buf .= ';';
} else {
$buf .= ' '
}
$buf .= $_;
$skip = 0;
next;
}
}
else {
$skip = 0;
}
print $buf,"\n" if ( $buf );
$buf = $_;
}
print $buf,"\n" if ( $buf );
__DATA__
n010-10 ;c=temp(433)'1'
n0111-25 ;c=temp(433)'2'
n0126-50 ;c=temp(433)'3'
n0151-100 ;c=temp(433)'4'
n01101-150 ;c=temp(433)'5'
net1151 CONTACTS OR MORE (NET)
n01151-200 ;c=temp(433)'6'
n01200+ ;c=temp(433)'7'
*include q10.qin;txt=UNIQUENESS
+bb=Top line;
+tx=Mid Value
+tb=Low Value
n01contacts/friends do you
+have in each of the services ;c=contacts(433)1
net1CONVENIENCE (NET)
fld c(m00),c(m96):3
+Easy to find/noticeable=044
+Quick=045
+Convenient=046
+Other convenience comments=050;%nosort
netend1
fld c(m00),c(m96):3
+NA=996;%nosort
*include lib\9pscale.qin;col(a)=697
+txt1=Value 1
+txt2=
+txt3=
+txt4=Value 4
val c(650,652);i
+1-25=1-25
+26-50=26-50
+51-75=51-75
+76-100=76-100
n01Clear testing/QA
+requirements ;c=c100'1'
------------------------------
Date: Tue, 24 Mar 2009 15:22:58 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Read File and Output to new format
Message-Id: <slrngsig92.nh2.tadmc@tadmc30.sbcglobal.net>
ansher <Ansher.M@gmail.com> wrote:
> Format: I am reading a file where line continuation is indicated by
> ?+? sign at the beginning of the new line. Remove the line
> continuation and add (join) this new line to prev. one
> Challenges: I cannot always consider ?+?sign as the beginning of the
> new line, those instances are
>
> 1.Section of lines should not be formatted after text ?fld?, refer
> line 16-23 should not be formatted. Lines after this section must be
> formatted.
>
> 2. Section of lines should not be formatted after text ?val?, refer
> line 29-33 should not be formatted. Lines after this section must be
> formatted.
I'll do that part for you.
> 3. Refer line 9-12, line 10 ends with ; but lines 11 & 12 do not.
> After formatting line should be separated by single ;
>
> *include q10.qin;txt=UNIQUENESS; bb=Top line; tx=Mid Value;tb=Low
> Value
>
> 4.Refer line 13-14,
>
> Line13: n01contacts/friends do you
> Line14: +have in each of the services ;c=contacts(433)?1?
>
> After formatting line should not be separated by single ; instead it
> should read as
>
> n01contacts/friends do you have in each of the services ;c=contacts
> (433)?1?
I'll leave that so that you have the opportunity to write some code
yourself, unless you plan to send me your paycheck. :-)
---------------------------
#!/usr/bin/perl
use warnings;
use strict;
my $buf='';
while ( <DATA> ) {
s/Line\d+: //;
if ( /^\+/ ) {
if ( $buf =~ /^(fld|val)/ ) {
$buf .= $_;
}
else {
s/^\+/ /;
$buf =~ s/\n/$_/;
}
}
else {
print $buf;
$buf = $_;
}
}
print $buf;
__DATA__
Line1: n010-10 ;c=temp(433)'1'
Line2: n0111-25 ;c=temp(433)'2'
Line3: n0126-50 ;c=temp(433)'3'
Line4: n0151-100 ;c=temp(433)'4'
Line5: n01101-150 ;c=temp(433)'5'
Line6: net1151 CONTACTS OR MORE (NET)
Line7: n01151-200 ;c=temp(433)'6'
Line8: n01200+ ;c=temp(433)'7'
Line9: *include q10.qin;txt=UNIQUENESS
Line10: +bb=Top line;
Line11: +tx=Mid Value
Line12: +tb=Low Value
Line13: n01contacts/friends do you
Line14: +have in each of the services ;c=contacts(433)?1?
Line15: net1CONVENIENCE (NET)
Line16: fld c(m00),c(m96):3
Line17: +Easy to find/noticeable=044
Line18: +Quick=045
Line19: +Convenient=046
Line20: +Other convenience comments=050;%nosort
Line21: netend1
Line22: fld c(m00),c(m96):3
Line23: +NA=996;%nosort
Line24: *include lib\9pscale.qin;col(a)=697
Line25: +txt1=Value 1
Line26: +txt2=
Line27: +txt3=
Line28: +txt4=Value 4
Line29: val c(650,652);i
Line30: +1-25=1-25
Line31: +26-50=26-50
Line32: +51-75=51-75
Line33: +76-100=76-100
Line34: n01Clear testing/QA
Line35: +requirements ;c=c100'1'
---------------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 24 Mar 2009 15:49:56 -0700 (PDT)
From: ansher <Ansher.M@gmail.com>
Subject: Re: Read File and Output to new format
Message-Id: <6f122a32-752c-46db-b66c-25973681a011@d25g2000prn.googlegroups.com>
On Mar 24, 10:18=A0pm, s...@netherlands.com wrote:
> On Tue, 24 Mar 2009 06:07:16 -0700 (PDT), ansher <Anshe...@gmail.com> wro=
te:
> >Hello
>
> >What I am trying to achieve is to read a file and write the formatted
> >text into a new file. But I am facing some difficulty with that
>
> >Format: I am reading a file where line continuation is indicated by
> >=93+=94 sign at the beginning of the new line. Remove the line
> >continuation and add (join) this new line to prev. one
>
> >NOTE: file do not have line number, it is only for your reference.
>
> >Line13: n01contacts/friends do you
> >Line14: +have in each of the services =A0;c=3Dcontacts(433)=921=92
>
> >Output: n01 contacts/friends do you have in each of the
> >services =A0;c=3Dcontacts(433)=921=92
>
> >Challenges: I cannot always consider =93+=94sign as the beginning of the
> >new line, those instances are
>
> >1.Section of lines should not be formatted after text =91fld=92, refer
> >line 16-23 should not be formatted. Lines after this section must be
> >formatted.
>
> >2. Section of lines should not be formatted after text =91val=92, refer
> >line 29-33 should not be formatted. Lines after this section must be
> >formatted.
>
> >3. Refer line 9-12, line 10 ends with ; but lines 11 & 12 do not.
> > =A0 =A0After formatting line should be separated by single ;
>
> > =A0 =A0*include q10.qin;txt=3DUNIQUENESS; bb=3DTop line; tx=3DMid Value=
;tb=3DLow
> >Value
>
> >4.Refer line 13-14,
>
> >Line13: n01contacts/friends do you
> >Line14: +have in each of the services =A0;c=3Dcontacts(433)=921=92
>
> >After formatting line should not be separated by single ; instead it
> >should read as
>
> >n01contacts/friends do you have in each of the services =A0;c=3Dcontacts
> >(433)=921=92
>
> >Any solution to this will be of great help to me. Thanks
>
> But what about ';' ?
> Sure the sample in this form can be done. Not quite so simple
> though. The rules you specify are not quite distinct.
>
> -sln
>
> --------------------------------------
> use strict;
> use warnings;
>
> my ($buf, $skip) =3D ('', 0);
>
> while ( <DATA> )
> {
> =A0 =A0 =A0 =A0 chomp;
> =A0 =A0 =A0 =A0 if ( /^\s* (?: fld | val )/x )
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $skip =3D 1;
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 elsif ( /^\s*\+/ )
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unless ( $skip || !$buf )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 s/;+$//; s/^\s*\++//;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ( /^\s*\w*\s*=3D/ )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $buf =3D~=
s/;+$//;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $buf .=3D=
';';
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$buf .=
=3D ' '
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $buf .=3D $_;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $skip =3D 0;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 next;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 else {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $skip =3D 0;
> =A0 =A0 =A0 =A0 }
>
> =A0 =A0 =A0 =A0 print $buf,"\n" if ( $buf );
> =A0 =A0 =A0 =A0 $buf =3D $_;
>
> }
>
> print $buf,"\n" if ( $buf );
>
> __DATA__
>
> n010-10 =A0 =A0 =A0 =A0;c=3Dtemp(433)'1'
> n0111-25 =A0 =A0 =A0 ;c=3Dtemp(433)'2'
> n0126-50 =A0 =A0 =A0 ;c=3Dtemp(433)'3'
> n0151-100 =A0 =A0 =A0;c=3Dtemp(433)'4'
> n01101-150 =A0 =A0 ;c=3Dtemp(433)'5'
> net1151 CONTACTS OR MORE (NET)
> n01151-200 =A0 =A0 ;c=3Dtemp(433)'6'
> n01200+ =A0 =A0 =A0 =A0;c=3Dtemp(433)'7'
> *include q10.qin;txt=3DUNIQUENESS
> +bb=3DTop line;
> +tx=3DMid Value
> +tb=3DLow Value
> n01contacts/friends do you
> +have in each of the services =A0;c=3Dcontacts(433)=921=92
> net1CONVENIENCE (NET)
> fld c(m00),c(m96):3
> +Easy to find/noticeable=3D044
> +Quick=3D045
> +Convenient=3D046
> +Other convenience comments=3D050;%nosort
> netend1
> fld c(m00),c(m96):3
> +NA=3D996;%nosort
> *include lib\9pscale.qin;col(a)=3D697
> +txt1=3DValue 1
> +txt2=3D
> +txt3=3D
> +txt4=3DValue 4
> val c(650,652);i
> +1-25=3D1-25
> +26-50=3D26-50
> +51-75=3D51-75
> +76-100=3D76-100
> n01Clear testing/QA
> +requirements =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;c=3Dc100'1'- H=
ide quoted text -
>
> - Show quoted text -
Thank you, Thank you, Thank you, wow - it works like magic. I will
check this code with similar formatted files tomorrow.
I am new to perl, didnt understand the logic behind it - too difficult
for me to understand
could you please explain it to me? Thanks again :)
------------------------------
Date: Tue, 24 Mar 2009 15:56:59 -0700 (PDT)
From: ansher <Ansher.M@gmail.com>
Subject: Re: Read File and Output to new format
Message-Id: <f7aa893f-374c-4b75-a027-5255a53f9e24@v1g2000prd.googlegroups.com>
On Mar 25, 1:22=A0am, Tad J McClellan <ta...@seesig.invalid> wrote:
> ansher <Anshe...@gmail.com> wrote:
> > Format: I am reading a file where line continuation is indicated by
> > ?+? sign at the beginning of the new line. Remove the line
> > continuation and add (join) this new line to prev. one
> > Challenges: I cannot always consider ?+?sign as the beginning of the
> > new line, those instances are
>
> > 1.Section of lines should not be formatted after text ?fld?, refer
> > line 16-23 should not be formatted. Lines after this section must be
> > formatted.
>
> > 2. Section of lines should not be formatted after text ?val?, refer
> > line 29-33 should not be formatted. Lines after this section must be
> > formatted.
>
> I'll do that part for you.
>
>
>
>
>
> > 3. Refer line 9-12, line 10 ends with ; but lines 11 & 12 do not.
> > =A0 =A0 After formatting line should be separated by single ;
>
> > =A0 =A0 *include q10.qin;txt=3DUNIQUENESS; bb=3DTop line; tx=3DMid Valu=
e;tb=3DLow
> > Value
>
> > 4.Refer line 13-14,
>
> > Line13: n01contacts/friends do you
> > Line14: +have in each of the services =A0;c=3Dcontacts(433)?1?
>
> > After formatting line should not be separated by single ; instead it
> > should read as
>
> > n01contacts/friends do you have in each of the services =A0;c=3Dcontact=
s
> > (433)?1?
>
> I'll leave that so that you have the opportunity to write some code
> yourself, unless you plan to send me your paycheck. =A0:-)
>
> ---------------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my $buf=3D'';
> while ( <DATA> ) {
> =A0 =A0 s/Line\d+: //;
> =A0 =A0 if ( /^\+/ ) {
> =A0 =A0 =A0 =A0 if ( $buf =3D~ /^(fld|val)/ ) {
> =A0 =A0 =A0 =A0 =A0 =A0 $buf .=3D $_;
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 else {
> =A0 =A0 =A0 =A0 =A0 =A0 s/^\+/ /;
> =A0 =A0 =A0 =A0 =A0 =A0 $buf =3D~ s/\n/$_/;
> =A0 =A0 =A0 =A0 }
> =A0 =A0 }
> =A0 =A0 else {
> =A0 =A0 =A0 =A0 print $buf;
> =A0 =A0 =A0 =A0 $buf =3D $_;
> =A0 =A0 }}
>
> print $buf;
>
> __DATA__
> Line1: n010-10 =A0 =A0 =A0 =A0;c=3Dtemp(433)'1'
> Line2: n0111-25 =A0 =A0 =A0 ;c=3Dtemp(433)'2'
> Line3: n0126-50 =A0 =A0 =A0 ;c=3Dtemp(433)'3'
> Line4: n0151-100 =A0 =A0 =A0;c=3Dtemp(433)'4'
> Line5: n01101-150 =A0 =A0 ;c=3Dtemp(433)'5'
> Line6: net1151 CONTACTS OR MORE (NET)
> Line7: n01151-200 =A0 =A0 ;c=3Dtemp(433)'6'
> Line8: n01200+ =A0 =A0 =A0 =A0;c=3Dtemp(433)'7'
> Line9: *include q10.qin;txt=3DUNIQUENESS
> Line10: +bb=3DTop line;
> Line11: +tx=3DMid Value
> Line12: +tb=3DLow Value
> Line13: n01contacts/friends do you
> Line14: +have in each of the services =A0;c=3Dcontacts(433)?1?
> Line15: net1CONVENIENCE (NET)
> Line16: fld c(m00),c(m96):3
> Line17: +Easy to find/noticeable=3D044
> Line18: +Quick=3D045
> Line19: +Convenient=3D046
> Line20: +Other convenience comments=3D050;%nosort
> Line21: netend1
> Line22: fld c(m00),c(m96):3
> Line23: +NA=3D996;%nosort
> Line24: *include lib\9pscale.qin;col(a)=3D697
> Line25: +txt1=3DValue 1
> Line26: +txt2=3D
> Line27: +txt3=3D
> Line28: +txt4=3DValue 4
> Line29: val c(650,652);i
> Line30: +1-25=3D1-25
> Line31: +26-50=3D26-50
> Line32: +51-75=3D51-75
> Line33: +76-100=3D76-100
> Line34: n01Clear testing/QA
> Line35: +requirements =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;c=3Dc1=
00'1'
> ---------------------------
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"- Hid=
e quoted text -
>
> - Show quoted text -
This code works but there are few formatting conditions not taken care
of, like it do not add single ; after joining lines.
Thanks for your help, I must appreciate the fact you guys (sln & Tad)
can come up with solution in a flash
------------------------------
Date: Tue, 24 Mar 2009 21:41:10 +0000 (UTC)
From: Werner Lemberg <wl@gnu.org>
Subject: Re: regex question: extended [^...] concept?
Message-Id: <gqbk1l$s66$1@news.albasani.net>
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> Hope this helps,
Thanks a lot to all the posters who presented further ideas and comments.
> P.S. Of course, with "onion rings" implemented (google for it) there
> would be no problem whatsoever...
Yeah. I've looked at
http://dev.perl.org/perl6/rfc/198.html
and this is exactly what I would like to have. In the same document there
is also
(?*{code})
which I would like to see too.
Werner
------------------------------
Date: Tue, 24 Mar 2009 11:10:39 -0700 (PDT)
From: Marek <mstep@podiuminternational.org>
Subject: rolling frame (3)
Message-Id: <2ace6711-5fd2-4394-bcb1-12e0c0f8c945@z9g2000yqi.googlegroups.com>
Hello all!
I don't want to abuse this group. I know, that you expect everybody to
give a solution first, when asking for help. I am afraid, that A.
Sinan Unur will pop up and will shout on me ... So forgive me, I try
nevertheless ...
I have a friend who is claiming to have the hundred percent working
roulette system. I said, that there is no such kind of system, but I
promised him to program it in Perl, just to learn this language with
an interesting project. So please don't laugh at me. I don't believe
in such childish ideas ...
I promised to keep his "system" secret. So don't tell it to
anybody :-) But his "system" is so silly, that I unveil it to you
nevertheless :-)
If there is a double number in a frame up to $five, play this number
$five times, just after the double number appeared. (The frame and the
number of bets are variables). If there comes this double number in
the coming five numbers:
$bet*35
if not
$stake-$bet
and see whether the double number comes the next game ...
Already the "rolling frame" was over my head. sln in this group
suggested the following code for it. I fired up the debugger, just to
study how this fantastic code is working. But I am unable to implement
the roulette system in this rolling frame. Would somebody be so kind
and help me with this? Perhaps even offlist, if I am bothering this
group?
Thank you in advance
marek
*****sln code for the rolling frame:
#!/usr/bin/perl
use warnings;
use strict;
# Variables that control buffer manipulation ...
my %Lines; # Line buffer, up to $frame lines: line => number.
my %Nums; # Number buffer, less than or equal to $frame:
number => [line,line,line]
my $Frame = 20; # Frame size, can be many times larger than Subframe
my $line = 0; # "line" counter.
# Virtual frame variable (used for rampdown and data printing)
my $vframe = $Frame;
# Variables to control number matching ...
my $rampup = 1; # 1 = process frame before it fills (no match,
for debug only), 0 = wait for full frame
my $rampdown = 0; # 1 = process last full frame until its empty
(RECOMMENDED), 0 = do not process last frame
my $subframe = 5; # Subframe size to check for number after double
(can be 1 .. # for different effects)
my $suboffset= 2; # Suboffset from 'double' where Subframe starts,
'double' is on Frame boundry (0 .. # for effects)
my $firstdouble = 1; # 1 = force first sequential double found (22)
22222
# 0 = force last double found 22222(22), offset
should be greater than 2
# Misc ...
my ($data,$nbr,$nbr_count,$aref,$off_frame_nbr);
print <<"EOINF";
===========================
Frame size $Frame
Subframe size $subframe
Suboffset $suboffset
Rampup $rampup
Rampdown $rampdown
First double $firstdouble
===========================
EOINF
while ( defined ($data = <DATA>) || ($rampdown && keys %Lines))
{
# Get digits
if (defined $data) {
$data =~ /^\s*(\d+)\s*$/;
next if (!defined $1);
$nbr = $1;
$line++;
$Lines{ $line} = $nbr;
unshift @{$Nums{ $nbr}}, $line; # prepend line to
array
} else {
--$vframe;
$vframe = $line if ($vframe > $line);
}
if ( $rampup || ($vframe != $Frame) || keys %Lines ==
$vframe )
{
## Display/check whats in the Numbs buffer
if ( keys %Lines ) { print "\nFrame ".($line <
$vframe ? 1: $line-$vframe+1)."-$line\n" }
foreach $nbr ( sort { $a <=> $b } keys %Nums )
{
$aref = $Nums{ $nbr};
$nbr_count = @$aref;
my @ln_array = reverse @$aref;
printf "%3d: %3d times at lines (%s)\n", $nbr,
$nbr_count, join(', ', @ln_array);
#
-------------------------------------------------------------------------------------
# Check if number is seen within a subframe at
suboffset past finding its 'double'.
# Detection of 'double' is on a frame boundry
only.
# --------------
my ($cur,$prev,$offset,$check_subframe) =
(0,-1,0,1);
foreach $cur (@ln_array)
{
if ( !($check_subframe &&
$firstdouble) && $cur == ($prev + 1)) {
$offset = $prev + $suboffset;
$check_subframe = 1;
# ---
# Force detection on frame
boundry (full frame or ramp down frame).
last if (($line - $vframe +
1) != ($offset - $suboffset));
}
if ($check_subframe && $cur >= $offset
&& $cur < ($offset + $subframe) ) {
print "\t\$\$ >> Found #
($nbr) !! Sequence \@ " . ($offset - $suboffset) .
", subframe = " .
$offset ."-". ($offset + $subframe - 1) .
", line = $cur\n";
last;
}
$prev = $cur;
}
}
print "---------\n";
## Handle buffers
if ( keys %Lines == $vframe || !defined $data)
{
# Deplete line going out of frame
$off_frame_nbr = $Lines{ $line - $vframe + 1};
pop @{$Nums{ $off_frame_nbr}};
delete $Nums{ $off_frame_nbr} if (!@{$Nums
{ $off_frame_nbr}});
# Maintain Line buffer size
delete $Lines{ $line - $vframe + 1};
}
}
}
__DATA__
01.01.98
31
33
14
31
7
35
31
16
7
20
20
13
1
1
7
22
7
9
30
30
17
11
27
21
14
30
11
29
25
19
6
25
34
------------------------------
Date: Tue, 24 Mar 2009 18:30:18 +0000
From: Robert Billing <unclebob@tnglwood.demon.co.uk>
Subject: Roulette, was rolling frame (seriously OT)
Message-Id: <3F9yl.60800$cy5.8594@newsfe18.ams2>
Marek wrote:
> Hello all!
> I have a friend who is claiming to have the hundred percent working
> roulette system. I said, that there is no such kind of system, but I
> promised him to program it in Perl, just to learn this language with
> an interesting project. So please don't laugh at me. I don't believe
> in such childish ideas ...
There is a perfect system. Play roulette *exactly* *once*. If you win
(as I did in 1981) you are, for the rest of your life, one of the very
few people who have made a profit out of roulette. If you lose the
damage is minimal.
Incidentally, and this might be a more interesting project, consider
what happens if you start with say $36, and play $1 on each spin until
you either are ahead, or have no money left. Computing the probability
of the two outcomes is a quite fascinating and curiously you are more
likely to quit *slightly* ahead than lose everything, but over many
trials the house still wins. However the probability of being ahead at
some point (around 61% IIRC) goes a long way to explaining the
phenomenon of "beginner's luck" and may be the cause of some compulsive
gambling.
------------------------------
Date: Tue, 24 Mar 2009 08:40:44 -0700 (PDT)
From: joe <jcharth@gmail.com>
Subject: Re: translating memcache php code to perl
Message-Id: <5dcb65e1-8144-4c2f-be6d-c95eee81225d@j38g2000yqa.googlegroups.com>
Ok looks like i got it to work. I could be cleaner special on the
redirect part but for now it is ok.
$key = md5_hex($ENV{'REMOTE_ADDR'}.time());
my $mem = Cache::Memcached->new({
servers => ['localhost:11000'],
});
$value="UserName=".$my_user."\r\n";
$value.="Groups=".$my_groups."\r\n";
$value.="RemoteIP=".$my_remoteip."\r\n";
$value.="Expiration=".$my_expiretime."\r\n";
$value.="Password=".$my_password."\r\n";
$value.="Email=".$my_mail."\r\n";
$value.="Name=".$my_nom."\r\n";
$value.="GivenName=".$my_prenom."\r\n";
$mem->set("$key", "$value");
$cookie = $query->cookie(-name=>$my_cookie_name,
-value=>$key);
# -expires=>'+4h');
print $query->header(-cookie=>$cookie);
print $query->start_html('My cookie-set.cgi program');
print "<meta http-equiv=\"REFRESH\" content=\"0;url=$my_referer\">";
print $query->h3('The cookie has been set');
#print "key $key <BR>";
print $mem->get('$key');
print $query->end_html;
------------------------------
Date: Tue, 24 Mar 2009 16:06:29 -0700 (PDT)
From: shul <meshulum@gmail.com>
Subject: what is the return value type of !1 ?
Message-Id: <8412cdc2-d3ec-4025-abe3-e904563b091e@p11g2000yqe.googlegroups.com>
Hi,
I am curious. If I take !1 and put it into an array or hash, what
lives in that position?
I know that !1 is false, which can be represented by () or 0.
Well if I do this
my @arp = 1 .. 4;
my $len= $#arp;
print "length is $len\n";
my $out1 = ! 1;
push(@arp, $out1);
print "$arp[4]\n";
my $len= $#arp;
print "length is $len\n";
well clearly the @arp array is longer is longer, but I dont get
anything printed when I try to print
print " the value is $arp[4]\n";
it just prints
"the value is "
So what is that object at position $arp[4]?
What operator will identify what lives at $arp[4]?
Note if I push a new thing on to @arp it goes to the next position $arp
[5].
shouldn't it be 0 or maybe it really its just () ?
This came up while I was reading a article which discussed different
ways of selecting unique elements of an array, which used a ! operator
together with ++ on a hash.
------------------------------
Date: Tue, 24 Mar 2009 23:19:38 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: what is the return value type of !1 ?
Message-Id: <gqbpqa$6os$1@reader1.panix.com>
In article
<8412cdc2-d3ec-4025-abe3-e904563b091e@p11g2000yqe.googlegroups.com>,
shul <meshulum@gmail.com> wrote:
>I am curious. If I take !1 and put it into an array or hash, what
>lives in that position?
The same thing as if you put it into a scalar ...
>I know that !1 is false, which can be represented by () or 0.
That can be stated more precisely. Luckily, "man perlsyn" does.
There are actually 5 things that are treated as false in a boolean
context, and !(something true) has a special value:
Truth and Falsehood
The number 0, the strings '0' and '', the empty list "()", and
"undef" are all false in a boolean context. All other values are
true. Negation of a true value by "!" or "not" returns a special
false value. When evaluated as a string it is treated as '', but
as a number, it is treated as 0.
>but I dont get anything printed when I try to print
>print " the value is $arp[4]\n";
>
>it just prints
>
>"the value is "
Well, you do get something: the null string, but that's a rather
pedantic statement. In
print " the value is $arp[4]\n";
With $arp[4] in the double-quoted string, it's evaluated as a string,
so as "man perlsyn" says, "it is treated as ''".
Answers to variants you didn't ask about:
By default, using it in print on its own is in string context too, so
$ perl -e '$x = !1; print "This false is <", $x, ">\n"'
This false is <>
But if you force a numeric context:
$ perl -we '$x = !1; print "This false is <", $x+0, ">\n"'
This false is <0>
Note the difference between that and this:
$ perl -we '$x = ""; print "This false is <", $x+0, ">\n"'
Argument "" isn't numeric in add at -e line 1.
This false is <0>
That is, !1 really is a special false, as "man perlsyn" says:
"" gives a warning message that !1 doesn't.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Tue, 24 Mar 2009 17:23:35 -0700 (PDT)
From: shul <meshulum@gmail.com>
Subject: Re: what is the return value type of !1 ?
Message-Id: <f4d772ff-9c3b-413b-b38a-2463026488fb@a12g2000yqm.googlegroups.com>
Negation of a true value by "!" or "not" returns a special
false value. When evaluated as a string it is treated as '', but
as a number, it is treated as 0.
That is what I needed! A special false value!
It is a 'special false value', that when evaluated is interpreted in
context as string or number.
Now I can analyze that algorithm to think about the context :).
Thanks!
MItchell
------------------------------
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 2294
***************************************