[25904] in Perl-Users-Digest
Perl-Users Digest, Issue: 8132 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 30 14:10:15 2005
Date: Mon, 30 May 2005 11:10:10 -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 Mon, 30 May 2005 Volume: 10 Number: 8132
Today's topics:
numbers and strings and regex? <geoff.cox@notquitecorrectfreeuk.com>
Re: numbers and strings and regex? (Anno Siegel)
Re: numbers and strings and regex? <geoff.cox@notquitecorrectfreeuk.com>
Re: numbers and strings and regex? <nobull@mail.com>
Re: numbers and strings and regex? <geoff.cox@notquitecorrectfreeuk.com>
Re: regexp replace problem <tadmc@augustmail.com>
Setting cookie values - repeat necessary? <rbutcher.nospam@hotmail.com>
Re: Setting cookie values - repeat necessary? <nobull@mail.com>
Re: Setting cookie values - repeat necessary? <pilkowsk@informatik.uni-marburg.de>
Re: Setting cookie values - repeat necessary? <rbutcher.nospam@hotmail.com>
Re: Setting cookie values - repeat necessary? <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 30 May 2005 16:31:56 GMT
From: Geoff Cox <geoff.cox@notquitecorrectfreeuk.com>
Subject: numbers and strings and regex?
Message-Id: <ojfm919a2hvgle3mbl1u734ra98qe8n8kc@4ax.com>
Hello
I have a series of files such as
blue-green-01-01.doc to
blue-green-01-09
blue-green-01-11 up to
blue-green-01-32
and am trying to evaluate the second set of 2 digits using File::Find
and this bit of code
if ($name =~ /.*?(\d{2})-((\d{1})(\d{1}))\.jmx/i) {
my $both = $2;
my $first = $3;
my $second = $4;
if ($4 <= 9)
{ $exnum = $4;
}
else {my $exnum = $both;
}
obviously something wrong here - where am I wrong?
Cheers
Geoff
------------------------------
Date: 30 May 2005 16:43:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: numbers and strings and regex?
Message-Id: <d7ffrd$k16$1@mamenchi.zrz.TU-Berlin.DE>
Geoff Cox <geoff.cox@notquitecorrectfreeuk.com> wrote in comp.lang.perl.misc:
> Hello
>
> I have a series of files such as
>
> blue-green-01-01.doc to
> blue-green-01-09
> blue-green-01-11 up to
> blue-green-01-32
>
> and am trying to evaluate the second set of 2 digits using File::Find
> and this bit of code
>
> if ($name =~ /.*?(\d{2})-((\d{1})(\d{1}))\.jmx/i) {
Your pattern requests files that have an extension ".jmx". Your examples
have an extension ".doc" or none. Also, \d{1} is the same as \d.
[snip]
Anno
------------------------------
Date: Mon, 30 May 2005 16:56:19 GMT
From: Geoff Cox <geoff.cox@notquitecorrectfreeuk.com>
Subject: Re: numbers and strings and regex?
Message-Id: <augm91pdf2ig3qo1vib73c52pneu525a4v@4ax.com>
On 30 May 2005 16:43:25 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:
>Geoff Cox <geoff.cox@notquitecorrectfreeuk.com> wrote in comp.lang.perl.misc:
>Your pattern requests files that have an extension ".jmx". Your examples
>have an extension ".doc" or none. Also, \d{1} is the same as \d.
my mistake they should be the same, ie .jmx
I have changed to \d instead of \d{1} but still something wrong with
the code
if ($name =~ /.*?(\d{2})-((\d)(\d))\.jmx/i) {
my $both = $2;
my $first = $3;
my $second = $4;
if ($4 <= 9)
{ $exnum = $4;
}
else {my $exnum = $both;
}
the $exnum value for when the second pair of digits in 01-11 is
greater than 09 ...?
Geoff
>[snip]
>
>Anno
------------------------------
Date: Mon, 30 May 2005 18:30:42 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: numbers and strings and regex?
Message-Id: <d7fik5$4n8$1@slavica.ukpost.com>
Geoff Cox wrote:
> I have a series of files such as
>
> blue-green-01-01.doc to
> blue-green-01-09
> blue-green-01-11 up to
> blue-green-01-32
>
> and am trying to evaluate the second set of 2 digits using File::Find
> and this bit of code
>
> if ($name =~ /.*?(\d{2})-((\d{1})(\d{1}))\.jmx/i) {
>
> my $both = $2;
> my $first = $3;
> my $second = $4;
>
> if ($4 <= 9)
> { $exnum = $4;
> }
> else {my $exnum = $both;
> }
>
> obviously something wrong here - where am I wrong?
Rather hard to know where to start at a guess the central problem is
that $4 is a single digit so ( $4 <= 9 ) is always true. You are also
capturing subexpressions you don't need.
You you appear to be delaring $esnum in the wrong place.
I also suspect you be anchoring your regex to the end of the string
raher than using .* to find the last match.
Perhaps you should try something simple like...
if ($name =~ /\d{2}-(\d{2})\.jmx$/i) {
my $exnum = 0+$1;
}
------------------------------
Date: Mon, 30 May 2005 17:41:32 GMT
From: Geoff Cox <geoff.cox@notquitecorrectfreeuk.com>
Subject: Re: numbers and strings and regex?
Message-Id: <kvjm91p3s767u4k7sn3o38a65aacg3lcrc@4ax.com>
On Mon, 30 May 2005 18:30:42 +0100, Brian McCauley <nobull@mail.com>
wrote:
>You you appear to be delaring $esnum in the wrong place.
>
>I also suspect you be anchoring your regex to the end of the string
>raher than using .* to find the last match.
>
>Perhaps you should try something simple like...
>
> if ($name =~ /\d{2}-(\d{2})\.jmx$/i) {
> my $exnum = 0+$1;
> }
Thanks Brian - will try that and get back.
Cheers
Geoff
------------------------------
Date: Mon, 30 May 2005 09:49:40 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regexp replace problem
Message-Id: <slrnd9ma04.j1c.tadmc@magna.augustmail.com>
Kasper <kcecek@gmail.com> wrote:
> Thanks for reply
What reply?
Please quote some context in followups like everybody else does.
> but I think that my post wasn't enough precise.
Your post was precise enough to be solved in other followups.
> I was thinking about only replace command.
Perl does not have "commands", and nothing named "replace"...
> s/,/,aaa/
... that is Perl's "substitution operator", not a "replace command".
> I was thinking about gathering somehow the first element maybe like
> this (?=^[^,]+) and use it in replace for ",".
Why not think about using one of the solutions already provided?
If there is some reason why those will not work for you,
then *tell us* that reason so that we can help you overcome it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 30 May 2005 14:22:08 GMT
From: "Randy" <rbutcher.nospam@hotmail.com>
Subject: Setting cookie values - repeat necessary?
Message-Id: <kkFme.1517800$Xk.1241095@pd7tw3no>
Hey everyone,
I have built a small script that I will be using in a CGI environment. The
script does work fine, but as I have learned from all you nice people
recently, that some of my ways are "newbie"ish and can sometimes be
inefficient. I always use strict now, that at least may please some of you
:). Anyways, here is the script:
#!/usr/bin/perl
use lib '/cgi-bin/lib/';
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use CGI::Cookie;
use My::Crypt;
use strict;
#use warnings; // blocked out, un-useful in CGI environment
my $crypt = My::Crypt->new( debug => 0 );
my $accountID = "username";
my $passwordID = "password";
my $startpage = "vcm_main.pl";
$accountID = $crypt->encrypt($accountID, 'MM);
$passwordID = $crypt->encrypt($passwordID, 'MM');
my $cookie1 = new CGI::Cookie(-name=>'accountID',
-value=>$accountID,
-expires=>'+1h',
-path=>'/cgi-bin/program',
-secure=>0);
my $cookie2 = new CGI::Cookie(-name=>'passwordID',
-value=>$passwordID,
-expires=>'+1h',
-path=>'/cgi-bin/program,
-secure=>0);
print redirect (-cookie => [$cookie1,$cookie2], -uri => $startpage);
exit;
So the script first encrypts a username and a password. Then in $cookie 1&2
the values are set, then sent to the browser header and redirected to
another module called vmc_main.pl where the cookie values are fetched and
used. My question is ... In the first cookie definition, I set the path,
expiry and secure mode. I then do the same for the second cookie. When all
is set and done, both cookie values are ultimately stored within a single
cookie (file) on my computer. So do I need to repeat the path, expiry and
secure mode in the second cookie definition? Or will it inherit the values
from the first. I would also appriciate and reccomendations on where my
script is using outdated code or is inefficient. TIA
Robert
------------------------------
Date: Mon, 30 May 2005 16:14:13 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Setting cookie values - repeat necessary?
Message-Id: <d7fakd$sa6$1@slavica.ukpost.com>
Randy wrote:
> Hey everyone,
>
> I have built a small script that I will be using in a CGI environment. The
> script does work fine, but as I have learned from all you nice people
> recently, that some of my ways are "newbie"ish and can sometimes be
> inefficient. I always use strict now, that at least may please some of you
> :). Anyways, here is the script:
>
> #!/usr/bin/perl
>
> use lib '/cgi-bin/lib/';
>
> use CGI qw(:standard);
> use CGI::Carp qw(fatalsToBrowser);
> use CGI::Cookie;
> use My::Crypt;
>
> use strict;
You may want to consider moving this up for maximum gain. Where it is
now it won't help spot mistakes in the preceeding use() statements.
> #use warnings; // blocked out, un-useful in CGI environment
Warnings are useful in a CGI environment. You should (anyhow)
periodically scan your webserver's error log. When you do so you'll see
the warnings.
If you prefer you can do:
use warnings FATAL => 'all';
This promotes all warnings to errors.
> my $crypt = My::Crypt->new( debug => 0 );
>
> my $accountID = "username";
> my $passwordID = "password";
>
> my $startpage = "vcm_main.pl";
>
> $accountID = $crypt->encrypt($accountID, 'MM);
I would recommend not encrypting the accountID cookie - it only serves
to irritate your users.
> print redirect (-cookie => [$cookie1,$cookie2], -uri => $startpage);
ISTR that setting cookies in a redirect doesn't work on some browsers.
> So the script first encrypts a username and a password. Then in $cookie 1&2
> the values are set, then sent to the browser header and redirected to
> another module called vmc_main.pl where the cookie values are fetched and
> used. My question is ... In the first cookie definition, I set the path,
> expiry and secure mode. I then do the same for the second cookie. When all
> is set and done, both cookie values are ultimately stored within a single
> cookie (file) on my computer. So do I need to repeat the path, expiry and
> secure mode in the second cookie definition?
Yes, these things can legitimately be set per-cookie. You can, of
course, put this stuff in a variable then use that variable in the two
cookie contructors.
------------------------------
Date: Mon, 30 May 2005 17:15:19 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Setting cookie values - repeat necessary?
Message-Id: <3g0ov6F9qedmU1@individual.net>
* Randy schrieb:
>
> I have built a small script that I will be using in a CGI environment. The
> script does work fine, but as I have learned from all you nice people
> recently, that some of my ways are "newbie"ish and can sometimes be
> inefficient. I always use strict now, that at least may please some of you
> :). Anyways, here is the script:
> my $crypt = My::Crypt->new( debug => 0 );
>
> my $accountID = "username";
> my $passwordID = "password";
>
> $accountID = $crypt->encrypt($accountID, 'MM);
^^
Please use copy&paste to avoid errors like this.
> $passwordID = $crypt->encrypt($passwordID, 'MM');
>
> my $cookie1 = new CGI::Cookie(-name=>'accountID',
> -value=>$accountID,
> -expires=>'+1h',
> -path=>'/cgi-bin/program',
> -secure=>0);
>
> my $cookie2 = new CGI::Cookie(-name=>'passwordID',
> -value=>$passwordID,
> -expires=>'+1h',
> -path=>'/cgi-bin/program,
^^
Hm, it seems that your clipboard is munging some quotes. It must be
hungry. You don't feed it regularly, do you?
> -secure=>0);
>
> print redirect (-cookie => [$cookie1,$cookie2], -uri => $startpage);
>
> exit;
>
> So the script first encrypts a username and a password. Then in $cookie 1&2
> the values are set, then sent to the browser header and redirected to
> another module called vmc_main.pl where the cookie values are fetched and
> used. My question is ... In the first cookie definition, I set the path,
> expiry and secure mode. I then do the same for the second cookie. When all
> is set and done, both cookie values are ultimately stored within a single
> cookie (file) on my computer.
Sure, my browser (Mozilla Firefox) saves *all* cookies in one file,
regardless from what website they come from. You can set all these
values independently of each other, e.g. expiring the password value
after 10 minutes in order that the user has to confirm his passwort each
10 minutes, instead of confirming name and pass once an hour. (Sure, you
have to stick some code around it for doing such tasks.)
> So do I need to repeat the path, expiry and
> secure mode in the second cookie definition?
Yes, each cookie has absolutely nothing to do with other cookies,
regardless where they are created or stored.
> Or will it inherit the values
> from the first.
No. But you could alternatively use one multi-valued cookie. This means
to put an array as value:
my $crypt = My::Crypt->new( debug => 0 );
my $accountID = "username";
my $passwordID = "password";
my $cookie = new CGI::Cookie(
-name => 'account',
-value => [
$crypt->encrypt( $accountID, 'MM' ),
$crypt->encrypt( $passwordID, 'MM' )
],
-expires => '+1h',
-path => '/cgi-bin/program',
-secure => 0
);
print redirect( -cookie => $cookie, -uri => $startpage );
This way you haven't to specify all this attributes twice. Of course,
you have to adjust the code for fetching the cookie then. Please read
about this in the docs (hint: "value() is context sensitive").
regards,
fabian
------------------------------
Date: Mon, 30 May 2005 15:50:10 GMT
From: "Randy" <rbutcher.nospam@hotmail.com>
Subject: Re: Setting cookie values - repeat necessary?
Message-Id: <SCGme.1521011$6l.146994@pd7tw2no>
"Brian McCauley" <nobull@mail.com> wrote in message
news:d7fakd$sa6$1@slavica.ukpost.com...
>
> ISTR that setting cookies in a redirect doesn't work on some browsers.
Oh I didn't know that. Might you have any suggestions on how I can safely
set a cookie and still get the page to redirect to the next module so the
cookies can be read?
Robert
------------------------------
Date: Mon, 30 May 2005 11:20:52 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Setting cookie values - repeat necessary?
Message-Id: <slrnd9mfb4.jap.tadmc@magna.augustmail.com>
Randy <rbutcher.nospam@hotmail.com> wrote:
> #use warnings; // blocked out, un-useful in CGI environment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What is it that led you to that conclusion?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 8132
***************************************