[25882] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8111 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 24 21:05:20 2005

Date: Tue, 24 May 2005 18:05: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           Tue, 24 May 2005     Volume: 10 Number: 8111

Today's topics:
    Re: Calculating time of employee session from the log d <noreply@gunnar.cc>
    Re: Fibonacci string <someone@example.com>
    Re: FormMail Problem (Anno Siegel)
    Re: FormMail Problem <djames@thehub.com.au>
    Re: FormMail Problem <noreply@gunnar.cc>
    Re: Question about Modules and Variable Scope <spamtrap@dot-app.org>
    Re: Strange 'for' behaviour? <tim@vegeta.ath.cx>
        substitution <alexj@freesurf.ch>
    Re: substitution <someone@example.com>
    Re: substitution <alexj@freesurf.ch>
    Re: substitution <emschwar@pobox.com>
    Re: substitution (Anno Siegel)
    Re: substitution <alexj@freesurf.ch>
    Re: substitution <alexj@freesurf.ch>
    Re: substitution <alexj@freesurf.ch>
    Re: substitution <emschwar@pobox.com>
    Re: substitution <sbryce@scottbryce.com>
    Re: substitution <alexj@freesurf.ch>
    Re: substitution <alexj@freesurf.ch>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 25 May 2005 02:08:59 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Calculating time of employee session from the log date/time stamp using perl
Message-Id: <3fhubkF7tnqpU1@individual.net>

Jayesh Kamdar wrote:
> I would appreciate if someone can point me to any perl command/module 
> that will let me calculate the session of the person was logged on to 
> corporate server. I have included a sample of log.
> 
> employee XXXXX logged in via VPN3000 at 01:37:34 on 04/18/2005 from 
> 111.111.1.111
> employee XXXX logged out of VPN3000 at 08:12:46 on 04/18/2005

     use Date::Calc 'Delta_DHMS';
     my (%in, %sessions);

     sub timeparse {
         local $_ = shift;
         my @date = m{at\s+(\d+):(\d+):(\d+)\s+on\s+(\d+)/(\d+)/(\d+)};
         [ @date[5,3,4,0,1,2] ];
     }

     while ( <> ) {
         if ( /^employee\s+(\S+)\s+logged\s+in/ ) {
             $in{$1} = timeparse($_);
         } elsif ( /^employee\s+(\S+)\s+logged\s+out/ and
           exists $in{$1} ) {
             push @{ $sessions{$1} },
               [ Delta_DHMS( @{ delete $in{$1} }, @{ timeparse($_) } ) ];
         }
     }

     for my $empl ( keys %sessions ) {
         print "$empl sessions:\n";
         for ( @{ $sessions{$empl} } ) {
             printf "  %d days %d hours %d min %d sec\n", @$_;
         }
         print "\n";
     }

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


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

Date: Tue, 24 May 2005 23:07:18 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Fibonacci string
Message-Id: <GsOke.9458$9A2.8141@edtnps89>

John W. Krahn wrote:
> David K. Wall wrote:
> 
>> Here's a fun fact I ran across in the book _The Golden Ratio_, by 
>> Mario Livio.  Take the string '1' and replace it with '10'.  
>> Thereafter, replace any occurrence of '1' with '10' and '0' with '1'.  
>> Then count the number of 0s and 1s in the string.  You get a Fibonacci 
>> sequence for each count (offset by one iteration).
>>
>> Here's Perl code to do it.  You get about the same results if you 
>> start with '0', just offset a little.
>>
>> use strict;
>> use warnings;
>>
>> my $v = '1';
>> for (1 .. 20) {
>>     my ($n0, $n1) = (0, 0);
>>     $v = join '',         map {             if ($_) {
>>                 $n1++;
>>                 '10';
>>             }
>>             else {
>>                 $n0++;
>>                 '1';
>>             }
>>         } split //, $v;
>>     printf "%10d %10d\n",  $n0, $n1;
>> }
> 
> You can make that shorter and faster:
> 
> my $v = '1';
> for ( 1 .. 20 ) {
>     printf "%10d %10d\n", $v =~ y/0//, $v =~ y/1//;
>     $v =~ s/([01])/ $1 ? '10' : '1' /eg;
> }

A bit faster.   :-)

my $v = '1';
for ( 1 .. 20 ) {
     printf "%10d %10d\n", $v =~ y/0//, $v =~ y/1//;
     $v =~ s/./ $& ? '10' : '1' /eg;
}



John
-- 
use Perl;
program
fulfillment


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

Date: 24 May 2005 22:40:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FormMail Problem
Message-Id: <d70ahd$8p4$1@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Gunnar Hjalmarsson wrote:
> >> Christopher Nehren wrote:
> >>>> Olen R. Pearson wrote:

> >>>>> I am using FormMail.CGI v. 1.92 (04/21/02) to process s form on a
> >>>>> Website.
> >>>
> >>> *stop* using FormMail now. It's
> >>> horribly, horrendously insecure and thoroughly broken.
> >>
> >> Even if I'm not sure, I have a feeling that you are referring to 
> >> previous versions. If also v. 1.92 deserves that verdict, it would be 
> >> nice if you (or somebody else) could explain *how* it's broken.
> > 
> > I don't know about security but it's still substandard Perl code.

[...]

> There were two points I tried to raise by replying to Christopher's post:
> 
> 1. Perl 4 style programs are not automatically *broken*.

Not my point.  I mention the Perl 4 style to show that the program
has not been re-written since its Perl 4 days, when it *was* broken.

> 2. When somebody claims that one of the most spread Perl scripts out 
> there is "horribly, horrendously insecure and thoroughly broken", it's 
> reasonble to demand that he provides evidence supporting the statement. 
> If he doesn't, maybe even can't, the claim tells me more about the 
> judgement of the one who makes the claim than about the code in question.

Probably the wording doesn't apply to the current code anymore.  (I wasn't
aware of the update myself.)  However it must still be considered insecure
because it wasn't designed for security (provably), and hasn't been
redesigned.  So these days it's bad Perl, derived from horribly insecure
Perl.  I'd still not recommend it :)

Anno


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

Date: Tue, 24 May 2005 23:13:25 GMT
From: Damian James <djames@thehub.com.au>
Subject: Re: FormMail Problem
Message-Id: <slrnd97d8k.cg7.djames@puli.local>

On 24 May 2005 22:40:45 GMT, Anno Siegel said:
> Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> [...]
>> There were two points I tried to raise by replying to Christopher's post:
>> 
>> 1. Perl 4 style programs are not automatically *broken*.
> 
> Not my point.  I mention the Perl 4 style to show that the program
> has not been re-written since its Perl 4 days, when it *was* broken.
> 
>> 2. When somebody claims that one of the most spread Perl scripts out 
>> there is "horribly, horrendously insecure and thoroughly broken", it's 
>> reasonble to demand that he provides evidence supporting the statement. 
>> If he doesn't, maybe even can't, the claim tells me more about the 
>> judgement of the one who makes the claim than about the code in question.
> 
> Probably the wording doesn't apply to the current code anymore.  (I wasn't
> aware of the update myself.)  However it must still be considered insecure
> because it wasn't designed for security (provably), and hasn't been
> redesigned.  So these days it's bad Perl, derived from horribly insecure
> Perl.  I'd still not recommend it :)

I am baffled slightly that there's been an ongoing discussion of one
of MW's old broken cgi scripts here without mention being made of the
NMS project. I did have the understanding that there are versions of
"FormMail.cgi" there that one ought to be able to recommend to neophytes
with moderate confidence...

Google took me to: http://nms-cgi.sourceforge.net/scripts.shtml

Hope that's of some help to the OP. I'd strongly implore that he not use 
any extant original Formmail script without at least looking at the much
better versions available.

--damian


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

Date: Wed, 25 May 2005 02:42:54 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: FormMail Problem
Message-Id: <3fi0c2F7tkccU1@individual.net>

Damian James wrote:
> I am baffled slightly that there's been an ongoing discussion of one
> of MW's old broken cgi scripts here

The discussion has been about whether it's accurate to describe version 
1.92 of Matt's FormMail script as "horribly, horrendously insecure and 
thoroughly broken" without providing any evidence. I notice that also 
you refer to it as "broken", but that does not make a more accurate 
description just because it's being repeated, does it?

> without mention being made of the NMS project.

NMS was mentioned.

> I did have the understanding that there are versions of
> "FormMail.cgi" there that one ought to be able to recommend to neophytes
> with moderate confidence...
> 
> Google took me to: http://nms-cgi.sourceforge.net/scripts.shtml

You could have viewed my first reply in this thread instead: 
http://groups-beta.google.com/group/comp.lang.perl.misc/msg/c8b264fe6eb8bec8

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


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

Date: Tue, 24 May 2005 18:08:35 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Question about Modules and Variable Scope
Message-Id: <VamdnYX90up-OA7fRVn-jA@adelphia.com>

Anno Siegel wrote:

> Dean Hannotte <dhannotte@nyc.rr.com> wrote in comp.lang.perl.misc:
> 
>>Are you implying that I should turn 'config.pl' itself into a module (i.e.
>>'config.pm') and then issue 'use config;' both in my scripts and from inside
>>'cms.pm'?
> 
> Yes.

config.pm is a bad choice of module names though. On OSs that normally 
use case-insensitive file systems (Windows, Mac OS X), it will clash 
with the standard Config.pm module.

sherm--

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


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

Date: Tue, 24 May 2005 22:38:18 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Strange 'for' behaviour?
Message-Id: <slrnd97aqt.6o4.tim@vegeta.saiyix>

A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> Tim Hammerquist <tim@vegeta.ath.cx> wrote:
> > for (my $year = 2005; $year >= 1999; $year++) {...}
>  
>  ITYM
>  
>  for (my $year = 2005; $year >= 1999; $year--) {...}

Indeed.  Thanks for the correction.

/me reverts to "lurk" mode until he can learn to post while not half
    asleep.

Tim Hammerquist
-- 
As a computer, I find your faith in technology amusing.


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

Date: Wed, 25 May 2005 00:41:51 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: substitution
Message-Id: <4293adb0$0$1157$5402220f@news.sunrise.ch>

Hi,

I would like to replace all fields values who begin by $ERROR with empty 
value:

I've try something like :
s/\$ERROR{'([\w]+)'}/ /;

but didn't work

any help ?

cheers

Alexandre Jaquet


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

Date: Tue, 24 May 2005 23:05:08 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: substitution
Message-Id: <EqOke.9456$9A2.5646@edtnps89>

Alexandre Jaquet wrote:
> 
> I would like to replace all fields values who begin by $ERROR with empty 
> value:
> 
> I've try something like :
> s/\$ERROR{'([\w]+)'}/ /;
> 
> but didn't work

Perhaps this will work better (untested):

s/\$ERROR{\s*(?:(['"]).+?\1|\w+)\s*}/ /;



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 25 May 2005 01:13:03 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: Re: substitution
Message-Id: <4293b500$0$1161$5402220f@news.sunrise.ch>

John W. Krahn a écrit :
> Alexandre Jaquet wrote:
> 
>>
>> I would like to replace all fields values who begin by $ERROR with 
>> empty value:
>>
>> I've try something like :
>> s/\$ERROR{'([\w]+)'}/ /;
>>
>> but didn't work
> 
> 
> Perhaps this will work better (untested):
> 
> s/\$ERROR{\s*(?:(['"]).+?\1|\w+)\s*}/ /;
> 
> 
> 
> John

nope still not but thanks


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

Date: Tue, 24 May 2005 17:08:58 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: substitution
Message-Id: <eto3bscmdbp.fsf@wilson.emschwar>

Alexandre Jaquet <alexj@freesurf.ch> writes:
> I would like to replace all fields values who begin by $ERROR with
> empty value:

Do you mean the literal string '$ERROR' or the contents of the
variable $ERROR?  It makes a big difference.

> I've try something like :
> s/\$ERROR{'([\w]+)'}/ /;

Why all that extra?  All you care about is if it starts with $ERROR,
right?

s/^\$ERROR.*$//;

or maybe 

s/^\Q$ERROR\E.*$//;

depending on which way you want it.

> but didn't work

Please show us a complete script, with example data, showing what your
data looks like before and after.  You can include sample data in your
script after __DATA__ and read it with the magic DATA filehandle.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: 24 May 2005 23:15:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: substitution
Message-Id: <d70ci8$8p4$2@mamenchi.zrz.TU-Berlin.DE>

Alexandre Jaquet  <alexj@freesurf.ch> wrote in comp.lang.perl.misc:
> Hi,
> 
> I would like to replace all fields values who begin by $ERROR with empty 
> value:
> 
> I've try something like :
> s/\$ERROR{'([\w]+)'}/ /;
> 
> but didn't work
> 
> any help ?

Not before you show what data you applied it to, what it did to the data
and in which way that wasn't what you want it to do.  Make a program
we can run that shows the problem.

Anno


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

Date: Wed, 25 May 2005 01:24:02 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: Re: substitution
Message-Id: <4293b793$0$1146$5402220f@news.sunrise.ch>

Eric Schwartz a écrit :
> Alexandre Jaquet <alexj@freesurf.ch> writes:
> 
>>I would like to replace all fields values who begin by $ERROR with
>>empty value:
> 
> 
> Do you mean the literal string '$ERROR' or the contents of the
> variable $ERROR?  It makes a big difference.
> 
> 
>>I've try something like :
>>s/\$ERROR{'([\w]+)'}/ /;
> 
> 
> Why all that extra?  All you care about is if it starts with $ERROR,
> right?
> 
> s/^\$ERROR.*$//;
> 
> or maybe 
> 
> s/^\Q$ERROR\E.*$//;
> 
> depending on which way you want it.
> 
> 
>>but didn't work
> 
> 
> Please show us a complete script, with example data, showing what your
> data looks like before and after.  You can include sample data in your
> script after __DATA__ and read it with the magic DATA filehandle.
> 
> -=Eric

here is a part of my cgi script :

use CGI qw(:standard);
use Switch;
use MIME::Lite;
use Digest::MD5 qw(md5_hex);
use DBI;
use vars qw(@params $LABEL $ERROR);
use File::Find;

my $dbh;
my $lang;



loadLanguage ();
loadError();
execute ();

sub execute {

     my $query = new CGI ;
     my $action = $query->param('action');
     if ($action) {
	switch ($action) {
	    case "login" { };
	    case "logout" { };
	    case "search" {};
	    case "register" {
		#registerNewUser();
		}
	    case "confirmation" {
		#confirmRegistration();
	    }
	    case "lostPassword" {
		#forgetPassword();
	    }
	}
     }
     else {loadPage ();}
}


sub loadPage {
     my $page = param('page');
     if (!$page) { $page = "main";}
     my $dir = "C:/indigoperl/apache/htdocs/recordz/";
     open (FILE, "<$dir/$page.html") or die "cannot open file 
$dir/$page.html";
     print "Content-type: text/html\n\n";
     while (<FILE>) {	
	s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
	s/\$LANG/$lang/g;
	s/^\$ERROR.*$//;
	print $_;	
     }
     close (FILE);
}

sub loadLanguage {
     $lang = param('lang');
     my $dir = "C:/indigoperl/apache/htdocs/recordz/lang";
     open (FILE, "<$dir/$lang.conf") or die "cannot open file 
$dir/$lang.conf";
     while (<FILE>) {
	(my $label, my $value) = split(/=/);
	$SERVER{$label} = $value;	
     }
     close (FILE);
}

sub loadError {
     $lang = param('lang');
     my $dir = "C:/indigoperl/apache/htdocs/recordz/lang/$lang/error.conf";
     open (FILE, "<$dir") or die "cannot open file $dir";
     while (<FILE>) {
	(my $label, my $value) = split(/=/);
	$SERVER{$label} = $value;	
     }
     close (FILE);
}


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

Date: Wed, 25 May 2005 01:29:16 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: Re: substitution
Message-Id: <4293b8cc$0$1162$5402220f@news.sunrise.ch>

Alexandre Jaquet a écrit :
> Eric Schwartz a écrit :
> 
>> Alexandre Jaquet <alexj@freesurf.ch> writes:
>>
>>> I would like to replace all fields values who begin by $ERROR with
>>> empty value:
>>
>>
>>
>> Do you mean the literal string '$ERROR' or the contents of the
>> variable $ERROR?  It makes a big difference.
>>
>>
>>> I've try something like :
>>> s/\$ERROR{'([\w]+)'}/ /;
>>
>>
>>
>> Why all that extra?  All you care about is if it starts with $ERROR,
>> right?
>>
>> s/^\$ERROR.*$//;
>>
>> or maybe
>> s/^\Q$ERROR\E.*$//;
>>
>> depending on which way you want it.
>>
>>
>>> but didn't work
>>
>>
>>
>> Please show us a complete script, with example data, showing what your
>> data looks like before and after.  You can include sample data in your
>> script after __DATA__ and read it with the magic DATA filehandle.
>>
>> -=Eric
> 
> 
> here is a part of my cgi script :
> 
> use CGI qw(:standard);
> use Switch;
> use MIME::Lite;
> use Digest::MD5 qw(md5_hex);
> use DBI;
> use vars qw(@params $LABEL $ERROR);
> use File::Find;
> 
> my $dbh;
> my $lang;
> 
> 
> 
> loadLanguage ();
> loadError();
> execute ();
> 
> sub execute {
> 
>     my $query = new CGI ;
>     my $action = $query->param('action');
>     if ($action) {
>     switch ($action) {
>         case "login" { };
>         case "logout" { };
>         case "search" {};
>         case "register" {
>         #registerNewUser();
>         }
>         case "confirmation" {
>         #confirmRegistration();
>         }
>         case "lostPassword" {
>         #forgetPassword();
>         }
>     }
>     }
>     else {loadPage ();}
> }
> 
> 
> sub loadPage {
>     my $page = param('page');
>     if (!$page) { $page = "main";}
>     my $dir = "C:/indigoperl/apache/htdocs/recordz/";
>     open (FILE, "<$dir/$page.html") or die "cannot open file 
> $dir/$page.html";
>     print "Content-type: text/html\n\n";
>     while (<FILE>) {   
>     s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
>     s/\$LANG/$lang/g;
>     s/^\$ERROR.*$//;
>     print $_;   
>     }
>     close (FILE);
> }
> 
> sub loadLanguage {
>     $lang = param('lang');
>     my $dir = "C:/indigoperl/apache/htdocs/recordz/lang";
>     open (FILE, "<$dir/$lang.conf") or die "cannot open file 
> $dir/$lang.conf";
>     while (<FILE>) {
>     (my $label, my $value) = split(/=/);
>     $SERVER{$label} = $value;   
>     }
>     close (FILE);
> }
> 
> sub loadError {
>     $lang = param('lang');
>     my $dir = "C:/indigoperl/apache/htdocs/recordz/lang/$lang/error.conf";
>     open (FILE, "<$dir") or die "cannot open file $dir";
>     while (<FILE>) {
>     (my $label, my $value) = split(/=/);
>     $SERVER{$label} = $value;   
>     }
>     close (FILE);
> }

and a sample html page that I parse to replace label :

<html>
<head>
<title>$LABEL{'label_site_title'}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
  <div align="center">
    <p><a 
href="/cgi-bin/recordz.cgi?lang=$lang">$LABEL{'label_menu_home'}</a>&nbsp;<a 
href="/cgi-bin/recordz.cgi?lang=$lang&action=myaccount">$LABEL{'label_menu_account'}</a>&nbsp;<a 
href="/cgi-bin/recordz.cgi?lang=$lang">$LABEL{'label_account'}</a>&nbsp;<a 
href="/cgi-bin/recordz.cgi?lang=$lang">$LABEL{'label_basket'}</a>&nbsp;<a 
href="/cgi-bin/recordz.cgi?lang=$lang&page=login">$LABEL{'label_login'}</a>&nbsp;<a 
href="/cgi-bin/recordz.cgi?lang=$LANG&page=register">$LABEL{'label_newuser'}</a></p>
    <p>&nbsp;</p>
    <div id="login_box">
	<form name="login_form" action="/cgi-bin/recordz.cgi" method="get">
		<fieldset>
			<label 
id="login_username_label">$LABEL{'login_username_label'}</label><input 
type="text" name="search_name" value="">
			<label 
id="login_userpassword_label">$LABEL{'login_password_label'}</label> 
<input type="password" name="user_password" value=""><input 
type="submit" value="Connect">
			<label id="login_error_label">$ERROR{'login_error_label'}</label>
		</fieldset>		
	</form>	
	<form name="forget_form" action="/cgi-bin/recordz.cgi" method="post">
		<input type="hidden" name="action" value="lostPassword">
		<input type="hidden" name="lang" value="$LANG">
		<fieldset>
			<label 
id="login_password_recover_label">$LABEL{'login_password_recover_label'}</label><label 
id="email_label">&nbsp;&nbsp;<input type="text" name="email" 
value=""><input type="submit">
			<label id="login_error_label">$ERROR{'email_error_label'}</label><br />
		</fieldset>		
	</form>	
	<p>&nbsp;</p>
    	</div>
  </div>
</body>
</html>


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

Date: Wed, 25 May 2005 01:37:36 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: Re: substitution
Message-Id: <4293bac1$0$1162$5402220f@news.sunrise.ch>

Alexandre Jaquet a écrit :
> Alexandre Jaquet a écrit :
> 
>> Eric Schwartz a écrit :
>>
>>> Alexandre Jaquet <alexj@freesurf.ch> writes:
>>>
>>>> I would like to replace all fields values who begin by $ERROR with
>>>> empty value:
>>>
>>>
>>>
>>>
>>> Do you mean the literal string '$ERROR' or the contents of the
>>> variable $ERROR?  It makes a big difference.
>>>
>>>
>>>> I've try something like :
>>>> s/\$ERROR{'([\w]+)'}/ /;
>>>
>>>
>>>
>>>
>>> Why all that extra?  All you care about is if it starts with $ERROR,
>>> right?
>>>
>>> s/^\$ERROR.*$//;
>>>
>>> or maybe
>>> s/^\Q$ERROR\E.*$//;
>>>
>>> depending on which way you want it.
>>>
>>>
>>>> but didn't work
>>>
>>>
>>>
>>>
>>> Please show us a complete script, with example data, showing what your
>>> data looks like before and after.  You can include sample data in your
>>> script after __DATA__ and read it with the magic DATA filehandle.
>>>
>>> -=Eric
>>
>>
>>
>> here is a part of my cgi script :
>>
>> use CGI qw(:standard);
>> use Switch;
>> use MIME::Lite;
>> use Digest::MD5 qw(md5_hex);
>> use DBI;
>> use vars qw(@params $LABEL $ERROR);
>> use File::Find;
>>
>> my $dbh;
>> my $lang;
>>
>>
>>
>> loadLanguage ();
>> loadError();
>> execute ();
>>
>> sub execute {
>>
>>     my $query = new CGI ;
>>     my $action = $query->param('action');
>>     if ($action) {
>>     switch ($action) {
>>         case "login" { };
>>         case "logout" { };
>>         case "search" {};
>>         case "register" {
>>         #registerNewUser();
>>         }
>>         case "confirmation" {
>>         #confirmRegistration();
>>         }
>>         case "lostPassword" {
>>         #forgetPassword();
>>         }
>>     }
>>     }
>>     else {loadPage ();}
>> }
>>
>>
>> sub loadPage {
>>     my $page = param('page');
>>     if (!$page) { $page = "main";}
>>     my $dir = "C:/indigoperl/apache/htdocs/recordz/";
>>     open (FILE, "<$dir/$page.html") or die "cannot open file 
>> $dir/$page.html";
>>     print "Content-type: text/html\n\n";
>>     while (<FILE>) {       s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
>>     s/\$LANG/$lang/g;
>>     s/^\$ERROR.*$//;
>>     print $_;       }
>>     close (FILE);
>> }
>>
>> sub loadLanguage {
>>     $lang = param('lang');
>>     my $dir = "C:/indigoperl/apache/htdocs/recordz/lang";
>>     open (FILE, "<$dir/$lang.conf") or die "cannot open file 
>> $dir/$lang.conf";
>>     while (<FILE>) {
>>     (my $label, my $value) = split(/=/);
>>     $SERVER{$label} = $value;       }
>>     close (FILE);
>> }
>>
>> sub loadError {
>>     $lang = param('lang');
>>     my $dir = 
>> "C:/indigoperl/apache/htdocs/recordz/lang/$lang/error.conf";
>>     open (FILE, "<$dir") or die "cannot open file $dir";
>>     while (<FILE>) {
>>     (my $label, my $value) = split(/=/);
>>     $SERVER{$label} = $value;       }
>>     close (FILE);
>> }
> 
> 
> and a sample html page that I parse to replace label :
> 
> <html>
> <head>
> <title>$LABEL{'label_site_title'}</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> </head>
> <body>
>  <div align="center">
>    <p><a 
> href="/cgi-bin/recordz.cgi?lang=$lang">$LABEL{'label_menu_home'}</a>&nbsp;<a 
> href="/cgi-bin/recordz.cgi?lang=$lang&action=myaccount">$LABEL{'label_menu_account'}</a>&nbsp;<a 
> href="/cgi-bin/recordz.cgi?lang=$lang">$LABEL{'label_account'}</a>&nbsp;<a 
> href="/cgi-bin/recordz.cgi?lang=$lang">$LABEL{'label_basket'}</a>&nbsp;<a 
> href="/cgi-bin/recordz.cgi?lang=$lang&page=login">$LABEL{'label_login'}</a>&nbsp;<a 
> href="/cgi-bin/recordz.cgi?lang=$LANG&page=register">$LABEL{'label_newuser'}</a></p> 
> 
>    <p>&nbsp;</p>
>    <div id="login_box">
>     <form name="login_form" action="/cgi-bin/recordz.cgi" method="get">
>         <fieldset>
>             <label 
> id="login_username_label">$LABEL{'login_username_label'}</label><input 
> type="text" name="search_name" value="">
>             <label 
> id="login_userpassword_label">$LABEL{'login_password_label'}</label> 
> <input type="password" name="user_password" value=""><input 
> type="submit" value="Connect">
>             <label 
> id="login_error_label">$ERROR{'login_error_label'}</label>
>         </fieldset>       
>     </form>   
>     <form name="forget_form" action="/cgi-bin/recordz.cgi" method="post">
>         <input type="hidden" name="action" value="lostPassword">
>         <input type="hidden" name="lang" value="$LANG">
>         <fieldset>
>             <label 
> id="login_password_recover_label">$LABEL{'login_password_recover_label'}</label><label 
> id="email_label">&nbsp;&nbsp;<input type="text" name="email" 
> value=""><input type="submit">
>             <label 
> id="login_error_label">$ERROR{'email_error_label'}</label><br />
>         </fieldset>       
>     </form>   
>     <p>&nbsp;</p>
>        </div>
>  </div>
> </body>
> </html>


my goal is in loadPage to doesn't show $ERROR message error


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

Date: Tue, 24 May 2005 17:50:37 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: substitution
Message-Id: <etooeb0kwtu.fsf@wilson.emschwar>

Alexandre Jaquet <alexj@freesurf.ch> writes:

<snip 165 or so lines of code>

That's way too much code to wade through.  If all you want is to
change a string, then please just provide a small program that
shows a string that you want to change, how you want to change it, and
what you want it to look like afterwards.

For instance, here's what such a program might look like:

#!/usr/bin/perl
use warnings;
use strict;  # ALWAYS use these two

my $ERROR   = "This is a silly error";
my @strings = (
      '$ERROR this string contains a literal $ERROR',
      "$ERROR this string contains the interpolated value of \$ERROR"
);
foreach my $string (@strings) {
   $string =~ s/^\$ERROR.*$//;
   print "After substitution, string is: [$string]\n";
}
__END__

This program prints out:
blah blah blah

I wanted it to print out:
foo bar baz

See?  No extraneous CGI, no having to look at HTML, just a very small
Perl program that demonstrates the precise problem in a way that is
easy to see, easy to reproduce, and easy to fix.  Most importantly, we
see the exact output, and exactly what you want it to be, and how
they're different.

> my goal is in loadPage to doesn't show $ERROR message error

I don't want to have to read that much code to figure out what
loadPage does, how it does or doesn't show $ERROR message error, and
most importantly, I don't want to have to figure out what "show $ERROR
message error" even MEANS.  I understand English is not your first
language; that's okay, really!  But it makes it all the more important
for you to write a very small very simple example that's easy to
understand.  Notice how you took almost 170 lines to show off your
problem, and I restated it in 14!  14 lines are always easier to
understand than 170.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Tue, 24 May 2005 17:58:41 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: substitution
Message-Id: <g-qdnekl2LQtIg7fRVn-iA@comcast.com>

Alexandre Jaquet wrote:

<code snipped>

If I understand what you are trying to do (and I may not), you are doing 
it the hard way.

http://search.cpan.org/~samtregar/HTML-Template-2.7/Template.pm



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

Date: Wed, 25 May 2005 02:09:04 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: Re: substitution
Message-Id: <4293c221$0$1158$5402220f@news.sunrise.ch>

Eric Schwartz a écrit :
> Alexandre Jaquet <alexj@freesurf.ch> writes:
> 
> <snip 165 or so lines of code>
> 
> That's way too much code to wade through.  If all you want is to
> change a string, then please just provide a small program that
> shows a string that you want to change, how you want to change it, and
> what you want it to look like afterwards.
> 
> For instance, here's what such a program might look like:
> 
> #!/usr/bin/perl
> use warnings;
> use strict;  # ALWAYS use these two
> 
> my $ERROR   = "This is a silly error";
> my @strings = (
>       '$ERROR this string contains a literal $ERROR',
>       "$ERROR this string contains the interpolated value of \$ERROR"
> );
> foreach my $string (@strings) {
>    $string =~ s/^\$ERROR.*$//;
>    print "After substitution, string is: [$string]\n";
> }
> __END__
> 
> This program prints out:
> blah blah blah
> 
> I wanted it to print out:
> foo bar baz
> 
> See?  No extraneous CGI, no having to look at HTML, just a very small
> Perl program that demonstrates the precise problem in a way that is
> easy to see, easy to reproduce, and easy to fix.  Most importantly, we
> see the exact output, and exactly what you want it to be, and how
> they're different.
> 
> 
>>my goal is in loadPage to doesn't show $ERROR message error
> 
> 
> I don't want to have to read that much code to figure out what
> loadPage does, how it does or doesn't show $ERROR message error, and
> most importantly, I don't want to have to figure out what "show $ERROR
> message error" even MEANS.  I understand English is not your first
> language; that's okay, really!  But it makes it all the more important
> for you to write a very small very simple example that's easy to
> understand.  Notice how you took almost 170 lines to show off your
> problem, and I restated it in 14!  14 lines are always easier to
> understand than 170.
> 
> -=Eric


Thanks, that's a good approche to cut a subroutine, I've doing like :

#!/usr/bin/perl -w
use strict;
use vars qw(@params $LABEL $ERROR);

my $lang;


my $dir = "C:/indigoperl/apache/htdocs/recordz/";
open (FILE, "<$dir/login.html") or die "cannot open file $dir/login.html";
while (<FILE>) {	
     s/\$ERROR{'([\w]+)'}//g;
     print $_;	
}
close (FILE);


and found the solution thanks for all :)




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

Date: Wed, 25 May 2005 02:15:16 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: Re: substitution
Message-Id: <4293c395$0$1158$5402220f@news.sunrise.ch>

Scott Bryce a écrit :
> Alexandre Jaquet wrote:
> 
> <code snipped>
> 
> If I understand what you are trying to do (and I may not), you are doing 
> it the hard way.
> 
> http://search.cpan.org/~samtregar/HTML-Template-2.7/Template.pm
> 

Not exactly the same but I'm unemployed I've time to spend to play with 
code lol :)


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

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


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