[21697] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3901 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 2 14:10:07 2002

Date: Wed, 2 Oct 2002 11: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           Wed, 2 Oct 2002     Volume: 10 Number: 3901

Today's topics:
    Re: A simple form problem! <asimmons@mitre.org>
    Re: Can one use parens with a (&) prototyped sub? (Greg)
        Can't send html e-mail (Andy)
    Re: Can't send html e-mail <Graham.T.Wood@oracle.com>
    Re: Can't send html e-mail <no@email.com>
    Re: Extract email address <jurgenex@hotmail.com>
    Re: File Handling Help [\] <notspam@spamfree.dud>
    Re: Floating point question <A@B>
    Re: ignore case in Greek <alecler@sympatico.ca>
        Mac OS X and Perl 6 <heather710101@yahoo.com>
    Re: Mac OS X and Perl 6 <dave@aragorn.westbourne.net>
    Re: Mac OS X and Perl 6 (Tad McClellan)
        Messages getting truncated. <nospam@nospam.com>
    Re: Messages getting truncated. <Tassilo.Parseval@post.rwth-aachen.de>
    Re: module Vs package <uri@stemsystems.com>
        New Perl Module for QA Engineers (Rob Marchetti)
    Re: New Perl Module for QA Engineers <ubl@schaffhausen.de>
        odd regexp grouping issue (Shambo)
    Re: odd regexp grouping issue <no@email.com>
    Re: odd regexp grouping issue (Tad McClellan)
    Re: odd regexp grouping issue <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 2 Oct 2002 13:37:10 -0400
From: "Aaron Simmons" <asimmons@mitre.org>
Subject: Re: A simple form problem!
Message-Id: <anfar7$o6g$1@newslocal.mitre.org>

I agree with the first responder that you can sequentially number the
checkboxes--I've done that before, but why can't you just do this:

Example HTML:
<input type=checkbox name=clubs value=Club1> Club1<br>
<input type=checkbox name=clubs value=Club2> Club2<br>
<input type=checkbox name=clubs value=Club3> Club3<br>

Example Perl picking up the checked checkboxes:
my $clubs = join(',', $cgi->param('clubs'));

Name all of the checkboxes the same --> "clubs"

This method will work if you are storing the data in the database as one
column.  If you have one column per club i.e. a true/false implementation
per club, then the first approach is better.  If you need that approach then
you also will need to track which checkboxes aren't checked so you can
update that column to false.

-Aaron


"Simon Harvey" <ReplyToGroup@thanks.com> wrote in message
news:Shom9.11757$J47.1041932@stones...
> Hi guys,
>
> Thanks to anyone who can poijt me in the right direction with this one. I
> would so appreciate a helping hand on the following problem. I'm sure its
> really easy if you know the right function!:
>
> The problem:
>
>
> Script A generate an html page with a number of checkboxes, on the fly.
The
> number of checkboxes created depends on the number of clubs in a database
> table (Fewer than 20)
>
> Here the main bit:
>
>
> When the html form submits to script B, how do I get the information on
> which checkboxes have been ticked into the recieving script?. The point
> being I DON'T even know how many checkboxes there are. The only way I know
> how to get form data is if I know the name in advance, then I can use the
> param function in the CGI package. That's nice and easy but obviously I
cant
> right 25 param statements to make sure i get all the check boxes!
>
> How would you go about handling this sort of situation?
>
>
> I was hoping I could do something like this:
>
> While (there are more form elements){
>       Do Stuff();
> }
>
>
> Please, please say there is a nice fluffy and easy answer to this in perl.
I
> cant find anything like that, but how else would you deal with not knowing
> the exact names of the form elements?
>
> Thanks so much to anyone who can point me in the right direction
>
> Kindest Regards
>
> Simon
>
>
>




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

Date: 2 Oct 2002 09:49:13 -0700
From: gdsafford@hotmail.com (Greg)
Subject: Re: Can one use parens with a (&) prototyped sub?
Message-Id: <a8f367ed.0210020849.463b2ce@posting.google.com>

Malte Ubl <ubl@schaffhausen.de> wrote in message news:<anbm20$p63
 ...
> 
> map seems to be special. Perl's prototype handling according to Tom 
> Christiansen is considered harmful. At best it sometimes doesn't do what 
> you expect. It thus doesn't follow Perl's DWIM-concept. So, use it only 
> if you know 100% what you are doing.
> 
> bye,
> ->malte

I take your point. I have been finding Perl unexpectedly difficult to
learn well. It seems that the interpretation of strings of symbols is
dependent on context to an unusual degree, which makes it difficult to
build on what one has learned.

Oh well.


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

Date: 2 Oct 2002 09:35:22 -0700
From: jaw@diamondlappin.com (Andy)
Subject: Can't send html e-mail
Message-Id: <690815e1.0210020835.3b702002@posting.google.com>

I have a mysql database that has around 3000 e-mail adresses.  I also
have an email tracking and mailing system.  The mailing system works
by sending 1 person or choosing to send everyone an email and then you
fill out your message in a text area input field.  Click send.

This is written in php and perl.  I inherited all the scripts from
someone else and I only have a basic knowledge of perl.

Here is my problem:

I want to be able to send html in my e-mails.  It only sends text. 
So, if I were to fill out <h1> hello </h1> then I would see the actual
html code not the bolded text.
I've done some research and figured out that i need to have the right
headers in the e-mail plus I need to use sendmail with the -t option. 
I've scanned the cgi document for these headers and they are there but
I still cannot send html in my e-mails.  Here is the section of the
CGI script that writes the headers:

# fire up sendmail!
			    open(FH,"| $sendmail -t") || die "Could not open sendmail!";
				print FH "bcc:$send_to\n";
				print FH "Content-type:text/html\r\n";
			    print FH "from:info\@mydomain.com\n";
			    print FH "subject: $input_ref->{subj}\n\n";
			    print FH "$input_ref->{msg}";
			    print FH "\n.\n";
			    close(FH);

Would it be easier to post the entire cgi script? 

 I think that this problem is probably very simple but because I do
not know as much as I should then it is making it very difficult for
me.

Also, could it be that because I am writing the message through a form
that the html tags are not being recognized?  For example- in php if i
wanted to put quotes around a string then I would put a backslash in
front of the quotes:  $testVariable = "My nickname is \"clueless\"";  
Is there some form of declaration that I need to use that the script
will recognize an html tag?

Thanks for all your help and your time in reading this post


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

Date: Wed, 02 Oct 2002 18:01:31 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Can't send html e-mail
Message-Id: <3D9B266B.D03295A3@oracle.com>

Andy wrote:

> Here is my problem:
>
> I want to be able to send html in my e-mails.
> I've done some research and figured out that i need to have the right
> headers in the e-mail plus I need to use sendmail with the -t option.
>

One way of doing it is to use the module Mail::Sendmail.  Put
use Mail::Sendmail;
at the top of the script to use the module.  Then set the values you want to use into a hash
like this

%mail= (
  To => "person\@domain.com",
  From => "info\@mydomaon.com",
  Subject => "$input_ref{subj}",
  'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",
  Message => "$input_ref->{msg}",
  Content-type => 'text/html; charset="iso-8859-1"' # This should set the header correctly
);


if(sendmail(%mail)){
      # it worked so print some comforting message to the browser
}
else{
     print "Error sending mail: $Mail::Sendmail::error<br>\n";
}

I think there are e-mail routines built into the CGI module but this method would involve
less changing of your existing script.

Hope this helps

Graham Wood



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

Date: Wed, 2 Oct 2002 18:25:10 +0100
From: "Brian Wakem" <no@email.com>
Subject: Re: Can't send html e-mail
Message-Id: <anfa5q$e1e7v$1@ID-112158.news.dfncis.de>


"Andy" <jaw@diamondlappin.com> wrote in message
news:690815e1.0210020835.3b702002@posting.google.com...
> I have a mysql database that has around 3000 e-mail adresses.  I also
> have an email tracking and mailing system.  The mailing system works
> by sending 1 person or choosing to send everyone an email and then you
> fill out your message in a text area input field.  Click send.
>
> This is written in php and perl.  I inherited all the scripts from
> someone else and I only have a basic knowledge of perl.
>
> Here is my problem:
>
> I want to be able to send html in my e-mails.  It only sends text.
> So, if I were to fill out <h1> hello </h1> then I would see the actual
> html code not the bolded text.
> I've done some research and figured out that i need to have the right
> headers in the e-mail plus I need to use sendmail with the -t option.
> I've scanned the cgi document for these headers and they are there but
> I still cannot send html in my e-mails.  Here is the section of the
> CGI script that writes the headers:
>
> # fire up sendmail!
>     open(FH,"| $sendmail -t") || die "Could not open sendmail!";
> print FH "bcc:$send_to\n";
> print FH "Content-type:text/html\r\n";
>     print FH "from:info\@mydomain.com\n";
>     print FH "subject: $input_ref->{subj}\n\n";
>     print FH "$input_ref->{msg}";
>     print FH "\n.\n";
>     close(FH);


Send yourself an html email using whatever email client you use, and then
view the source.  That is how the email needs to be composed - just with
different html.

--
Brian Wakem




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

Date: Wed, 2 Oct 2002 08:58:10 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Extract email address
Message-Id: <3d9b1792$1@news.microsoft.com>

Barry Krusch wrote:
> $_ =~ s/(.+)/$1/g;

You are replacing any non-empty sequence of any character (the ".+") with,
guess what, the first matched group which happens to be the original text.
So basically you replaced the text with itself.

Did you mean to include the params in the RE?
 $_ =~ s/\((.+)\)/$1/g;

>  print $_;

BTW: if you just want the matched text then there is no need for a
substitute command, a simple 'm' will do, too.
And before using the value of $1 you should always test if the match was
successful. Otherwise you will end up with corrupted data.

jue




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

Date: Wed, 02 Oct 2002 16:39:02 GMT
From: Sean O'Dwyer <notspam@spamfree.dud>
Subject: Re: File Handling Help [\]
Message-Id: <notspam-B73157.12390402102002@typhoon4-1.nyroc.rr.com>

In article <ancnat$3lp$1@nebula.dnttm.ro>,
 "Dan Borlovan" <danb@mail.dnttm.ro> wrote:

> > My question is this: is there a way to lock the script while it's busy
> > so that it doesn't accept further commands until it's finished working.
> 
> - use some locking mechanism of your own in the script (like pid files) - is
> there any module that does this?
> 
> - use some hidden variable in the form as a "session id" to filter out
> duplicates (requires that at least that value is generated in some way, i.e.
> using php)

Thanks, Dan, for the good ideas, much appreciated.

Sean

-- 

Tanta agenda, tantula voluntas.


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

Date: Wed, 2 Oct 2002 08:46:16 -0500
From: "J" <A@B>
Subject: Re: Floating point question
Message-Id: <uplu00hgqm2t17@corp.supernews.com>


"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
news:Xns929AD3B8FDBA0sdn.comcast@216.166.71.239...
> "J" <<A@B>> wrote in news:upjooeq5n8egf0@corp.supernews.com:
>
> That's really really silly.
>
> --
> Eric
> print scalar reverse sort qw p ekca lre reh
> ts uJ p, $/.r, map $_.$", qw e p h tona e;

Ok, it may seems silly.

I work on a large system written in delphi. It complies fairly fast, but the
procedure I am running takes quite a bit of time to run since it processes
lots of data.
Occasionally, I will try out new ideas in perl along with writing
pseudocode, this
helps me think about what I am doing before I start hacking on a unit with
1,000
lines of code. If the perl script turns out to be extremely efficient I
sometimes use the
activeX scripting component to execute the script.

Also, I am not a perl guru, so seeing how certain algorithms work in perl is
a good way to learn the language.







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

Date: Wed, 02 Oct 2002 11:50:24 -0400
From: Andre <alecler@sympatico.ca>
Subject: Re: ignore case in Greek
Message-Id: <alecler-D0F6C5.11502402102002@news1.qc.sympatico.ca>

In article <anedhf$af6$1@nic.grnet.gr>, "aragorn" 
<aragorn@freemail.gr.gr> wrote:

> I am trying to create a search form and i have problems with the "i"
> switch in the regular expression statement. The problem is that it
> doesn't work with Greek, propably will not work with any other
> language.
> I use the following command
> 
> if ($op1 =~ /$searchstr/i)
> {
> # code goes here
> }
> 
> as i said it works fine with English but not with Greek. I try to find
> a perl way to do the job and not do it myself with a convert sub.

You need to "use locale". For your convenience, the code would look like 
this:

use POSIX 'locale_h';

# set up the Greek CTYPE for when "use locale" is invoked
setlocale LC_CTYPE, 'gr';  # NOTE: you need to find the right name for the
                           # Greek locale on your system. 
                           # Just guessing here.

# temporarily change the locale for this block
{ use locale;
  if ($op =~ /\Q$searchstr/i) {
     ...
  }
}

See the perllocale manpage for (fairly confusing) details. 

Please note that you would want to quotemeta() the search string, as in 
the example above, unless it is meant to be a regex pattern.

HTH,
Andre


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

Date: Wed, 2 Oct 2002 13:58:56 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: Mac OS X and Perl 6
Message-Id: <aneu30$g62$1@reader1.panix.com>


In O'Reilly's page on the Mac OS X Conference (url below), it says
that "[a]lmost all of the Perl 6 core team has switched to Mac OS X."
I was quite surprised by that statement (is it even true???).  Somehow
I thought that Perl was a lot more committed to Linux than that.  I
guess I was mistaken...  As a die-hard fan of Linux, or rather, of the
idea of a non-proprietary operating system, I'm rather bummed by these
news.

h

http://conferences.oreillynet.com/pub/w/19/invite.html




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

Date: Wed, 2 Oct 2002 14:21:18 +0000 (UTC)
From: Dave Peacock <dave@aragorn.westbourne.net>
Subject: Re: Mac OS X and Perl 6
Message-Id: <slrnapm08h.ad4.dave@aragorn.westbourne.net>

In article <aneu30$g62$1@reader1.panix.com>, Da Witch wrote:
> In O'Reilly's page on the Mac OS X Conference (url below), it says
> that "[a]lmost all of the Perl 6 core team has switched to Mac OS X."
> I was quite surprised by that statement (is it even true???).  Somehow

[snip FUD]

This is off-topic, and grossly mis-informed. 

Apart from the fact that Linux is not the be-all and end-all of 
non-proprietary OS, Mac OS X is based on BSD which has as much to 
do with Perl has any other Unix-like OS out there...

Perl has no special link with the Linux community other than the 
fact that it can run on the Linux kernel.

-- 
Dave Peacock - davejpeacock@btinternet.com - http://darkcorner.org/
A: Top posting
Q: What is the most irritating thing on Usenet?
                    - "Gordon" on apihna


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

Date: Wed, 02 Oct 2002 15:13:21 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Mac OS X and Perl 6
Message-Id: <slrnapm362.2vf.tadmc@magna.augustmail.com>

Da Witch <heather710101@yahoo.com> wrote:
> 
> In O'Reilly's page on the Mac OS X Conference (url below), it says
> that "[a]lmost all of the Perl 6 core team has switched to Mac OS X."
> I was quite surprised by that statement (is it even true???).  


I don't know about the p6p itself, but I noticed that I was
seeing a lot of upside-down apples on the podiums when I
attended O'Reilly's Open Source Convention this summer.

So then I started to take notice of _all_ laptops I saw. I'd
say 3/4ths of them were OS X.

By the time the conference was over, I had decided that I'll
probably get an OX X machine when I need my next laptop upgrade.


> Somehow
> I thought that Perl was a lot more committed to Linux than that.  I
> guess I was mistaken...  


Perl is for "getting things done", so we're a pragmatic lot.

Until now, "consumer" OSes got in the way of a programmer
"getting things done". (Where's the command line? I gotta
_buy_ something to compile my code? etc...)

I think the attachment to the "unix like" OSes is stronger
than the attachment to the "open source" OSes. Unix was 
designed by programmers for programmers, so it is not 
surprising that programmers like it.  :-)


I just want what I want[1]. Perhaps now OS X will give me what I want.



[1] I also want what I must have, even though I don't _want_ it.
    eg. I gotta be able to read Word docs that my clients send, etc...
    Oh yeah, and I want to work with audio/video/stills, and run
    Quickbooks (for my accountant), and play games, and ...

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


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

Date: Wed, 02 Oct 2002 15:50:57 GMT
From: "No Spam Please" <nospam@nospam.com>
Subject: Messages getting truncated.
Message-Id: <BBEm9.41025$w63.466026@twister.rdc-kc.rr.com>

I don't know if I'm having a sendmail problem here or a
Perl problem, so I'll post it to both groups.

We have an email support system which is implemented in
Perl and invoked by having an alias in the aliases file...

    support: "|/some/path/supportscript.pl"

The script first sucks the whole message into a string like this...

    $/ = 0777;    # Don't break at newlines
    $the_whole_bloody_thing = <STDIN>;
    $/ = "\n";
    ($headers, $body) = split("\n\n", $the_whole_bloody_thing, 2);

This works 99% of the time.  However, sometimes we get
messages which terminate before they even get through the
headers.
I've collected several of the truncated messages to see if I
can find a pattern.  In most of the cases there isn't even a subject
line.  One stops in the middle of a Received header.  A lot of them
appear to stop in the middle of the Message-ID header.  Common
things I'm seeing are...

    Message-ID: <DAC15316530ED511

Usually things are longer and have a closing ">"

I don't know if the problem is that my Perl script is not getting the whole
message or if Sendmail is not sending it to me.

I'm wondering if my problem might be setting $/ = 0777 to make the
<STDIN> give me the whole message.  Could Perl be assuming I meant
"0777" as a string instead of 0777 the octal number (which would be
0x01FF and not possible in any 8 bit stream -- that's the point)

I've had it reading the message one line at a time and combining it
back together in the past with the same results.  Is there a better way
to read a whole stdin stream at once?

System specifics...

    Sendmail 8.12.2
    Perl 5.6.0
    Linux 7.2 (I think, uname -a reports 2.4.2-2)


Note: Reply To: on this message is spam bait.  Real address
is:      dwilliss at microimages dot com

--
 -- Dave Williss
------
Meddle not in the affairs of dragons,
   for you are crunchy and taste good with catsup





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

Date: 2 Oct 2002 17:05:56 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Messages getting truncated.
Message-Id: <anf91k$r47$1@nets3.rz.RWTH-Aachen.DE>

Also sprach No Spam Please:

> I don't know if I'm having a sendmail problem here or a
> Perl problem, so I'll post it to both groups.
> 
> We have an email support system which is implemented in
> Perl and invoked by having an alias in the aliases file...
> 
>     support: "|/some/path/supportscript.pl"
> 
> The script first sucks the whole message into a string like this...
> 
>     $/ = 0777;    # Don't break at newlines
>     $the_whole_bloody_thing = <STDIN>;
>     $/ = "\n";
>     ($headers, $body) = split("\n\n", $the_whole_bloody_thing, 2);

While I don't believe that this is the problem, you should handle the
input record separator differently. Also, there is no need to set it to
an octal value here. Simply undef it:

    $the_whole_bloody_thing = do { local $/; <STDIN> };
    ($headers, $body) = split ...;

> This works 99% of the time.  However, sometimes we get
> messages which terminate before they even get through the
> headers.
> I've collected several of the truncated messages to see if I
> can find a pattern.  In most of the cases there isn't even a subject
> line.  One stops in the middle of a Received header.  A lot of them
> appear to stop in the middle of the Message-ID header.  Common
> things I'm seeing are...
> 
>     Message-ID: <DAC15316530ED511
> 
> Usually things are longer and have a closing ">"
> 
> I don't know if the problem is that my Perl script is not getting the whole
> message or if Sendmail is not sending it to me.
> 
> I'm wondering if my problem might be setting $/ = 0777 to make the
><STDIN> give me the whole message.  Could Perl be assuming I meant
> "0777" as a string instead of 0777 the octal number (which would be
> 0x01FF and not possible in any 8 bit stream -- that's the point)

I thought so, too, for a second. perlvar does not mention this setting
$/ to an octal value. I only knew it from the -0 switch but obviously it
works with $/ as well (tested it).

> I've had it reading the message one line at a time and combining it
> back together in the past with the same results.  Is there a better way
> to read a whole stdin stream at once?

That makes me assume that it's not a Perl issue. Try to change your pipe
perhaps to perhaps find out more:

    support: "|tee -a mail.log |/some/path/supportscript.pl"

This should append a copy of the data to mail.log which you could
inspect further.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Wed, 02 Oct 2002 18:02:15 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: module Vs package
Message-Id: <x71y787m8o.fsf@mail.sysarch.com>

>>>>> "S" == Sriva  <sriva@invalid_nospam.com> writes:

  S>     I am trying to figure out why we need BOTH modules and packages in
  S>     perl.  It appears as if the only new feature that a module
  S>     provides over a package is:

  S> Question_1:  If a main uses 2 different modules, and funcName exists
  S> is both modules,  then can those functions still be invoked from main?
  S> maybe using module1::funcName()  and module2::funcName()?

  S> Question_2:  If modules are more convenient, than why do we need
  S> packages at all?

first, you can have many package spaces in a single file of perl source
(module OR main script).

second, you can have many perl source files (usually modules) which
share the same package name space. this is to divide code up into
logical groups that may share api's or other resources.

so they are two completely different aspects of perl and should not be
directly compared. they are typically used in tandem but that doesn't
mean they are the same thing.

package just defines the default namespace for all the code to follow in
this file or until another package command. a module is just a file of
perl which usually has one (or more) package namespaces in it. but the
file name is NOT required to be the same as the package names. 

so module names and their package names can be different too.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 2 Oct 2002 06:22:04 -0700
From: robert.marchetti@fmr.com (Rob Marchetti)
Subject: New Perl Module for QA Engineers
Message-Id: <65fb4119.0210020522.13118b48@posting.google.com>

http://sourceforge.net/projects/samie/

S.A.M. is a simple automation module written in Perl that allows a
user to automate Internet Explorer. This free tool is designed for
quality assurance engineers that need to run automated tests for their
browser applications.


Check it out!

Robert M.

samie4qa@yahoo.com


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

Date: Wed, 02 Oct 2002 15:37:40 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: New Perl Module for QA Engineers
Message-Id: <anf06d$ej7$1@news.dtag.de>

Rob Marchetti wrote:
> http://sourceforge.net/projects/samie/
> 
> S.A.M. is a simple automation module written in Perl that allows a
> user to automate Internet Explorer. This free tool is designed for
> quality assurance engineers that need to run automated tests for their
> browser applications.

Looks cool,

Thanx!

->malte



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

Date: 2 Oct 2002 10:04:52 -0700
From: shambo_p@yahoo.com (Shambo)
Subject: odd regexp grouping issue
Message-Id: <72190192.0210020904.5e2d5460@posting.google.com>

I am sometimes supplied with a date string that is six characters:
062402

instead of the preferred 8 characters:
06242002

I wrote a line that I thought would insert the "20" in front of the
last 2 digits:

$date =~ s/(\d\d\d\d)(\d\d)/$120$2/;

It didn't work, and I'm guessing it's because Perl assumes that the
first group reference is $120, not $1. Is there any way to insert
digits in between group references like this?

My workaround so far is:

$date =~ s/(\d\d\d\d)(\d\d)/$1fg$2/;
$date =~ s/fg/20/;

I'd like to know if there's something more elegant.

Thanks,
Shambo Pfaff


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

Date: Wed, 2 Oct 2002 18:20:24 +0100
From: "Brian Wakem" <no@email.com>
Subject: Re: odd regexp grouping issue
Message-Id: <anf9ss$dlded$1@ID-112158.news.dfncis.de>


"Shambo" <shambo_p@yahoo.com> wrote in message
news:72190192.0210020904.5e2d5460@posting.google.com...
> I am sometimes supplied with a date string that is six characters:
> 062402
>
> instead of the preferred 8 characters:
> 06242002
>
> I wrote a line that I thought would insert the "20" in front of the
> last 2 digits:
>
> $date =~ s/(\d\d\d\d)(\d\d)/$120$2/;
>
> It didn't work, and I'm guessing it's because Perl assumes that the
> first group reference is $120, not $1. Is there any way to insert
> digits in between group references like this?
>
> My workaround so far is:
>
> $date =~ s/(\d\d\d\d)(\d\d)/$1fg$2/;
> $date =~ s/fg/20/;
>
> I'd like to know if there's something more elegant.


$date =~ s/(\d\d\d\d)(\d\d)/${1}20$2/;

or a tider solution perhaps:-

$date =~ s/(\d{4})(\d{2})/${1}20$2/;


--
Brian Wakem





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

Date: Wed, 02 Oct 2002 17:36:10 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: odd regexp grouping issue
Message-Id: <slrnapmbeu.3gu.tadmc@magna.augustmail.com>

Shambo <shambo_p@yahoo.com> wrote:
> I am sometimes supplied with a date string that is six characters:
> 062402
> 
> instead of the preferred 8 characters:
> 06242002


How is the year represented in the 6-char case?

Is it "the last 2 characters" or is it "year minus 2000"?

Do you have a spec for the 6-char form? How will the date
be represented in 2100?


> I wrote a line that I thought would insert the "20" in front of the
> last 2 digits:


You might be inserting a y2k problem offset by a century :-)


> $date =~ s/(\d\d\d\d)(\d\d)/$120$2/;
> 
> It didn't work, 


And even if it did work, it might stop working in 98 years.


> and I'm guessing it's because Perl assumes that the
> first group reference is $120, not $1. 


You've guessed correctly.


> Is there any way to insert
> digits in between group references like this?


There is a way to disambiguate variable names from adjacent
"word characters", yes.

You wrap the variable's name (not its sigil) in curly braces,
just as in shell programming:


   $date =~ s/(\d\d\d\d)(\d\d)/${1}20$2/;


if you want the last two digits, then you should say the last two digits:

   
   $date =~ s/(\d\d)$/20$1/;

(scanning Perl source for the '19$' string was a crude test
 for uncovering y2k problems.
)

If you just want to insert 2 chars before the last 2 chars,
then you do not need pattern matching at all:

   substr($date, -2, 0) = '20';


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


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

Date: Wed, 02 Oct 2002 17:56:48 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: odd regexp grouping issue
Message-Id: <x765wk7mhr.fsf@mail.sysarch.com>

>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:

<snip of usual tad's fine stuff>

  TM>    substr($date, -2, 0) = '20';

i always like to remind perl hackers about the 4 arg version of
substr. the optional 4th arg is just like the 4th arg of splice in that
it is the replacement string.

	substr($date, -2, 0, '20' ) ;

it still returns the extracted string so you can use it to get the first
N chars and truncate them too at one time:

	$prefix = substr( $foo, 0, $n, '' ) ;

and i think it is slightly faster than the lvalue assignment method. but
i don't feel like benching it.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

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.  

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


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