removing white space

2002-02-14 Thread David Gilden


Is this correct, I want to remove leading and trailing white space,
Thanks

Dave
--

foreach $item (param()) {
my $value = param($item);
$value =~ s/^\s+//;
$value =~ s/\s+$//;
}

better??
foreach $item (param()) {
my $value = param($item);
$value =~ s/^\s+(.*)\s+$/$1/;
}



-

#!/usr/bin/perl 

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use POSIX 'strftime';

$mailprog = '/usr/lib/sendmail';


# Retrieve Date
$date = strftime('%A, %B %1d, %Y %I:%M %p',localtime) ,"\n";


# my %in = {};

# remove any extra spaces at the front or back 

foreach $item (param()) {
my $value = param($item);
$value =~ s/^\s+//;
$value =~ s/\s+$//;
}


$email = param('email');
$realname = param('name');

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: removing white space

2002-02-14 Thread Hanson, Robert

The first is more efficient, the second is less typing.

And actually the second one is incorrect, it should be this:


Rob

-Original Message-
From: David Gilden [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 14, 2002 12:29 PM
To: [EMAIL PROTECTED]
Subject: removing white space

Is this correct, I want to remove leading and trailing white space,
Thanks

Dave
--

foreach $item (param()) {
my $value = param($item);
$value =~ s/^\s+//;
$value =~ s/\s+$//;
}

better??
foreach $item (param()) {
my $value = param($item);
$value =~ s/^\s+(.*)\s+$/$1/;
}



-

#!/usr/bin/perl 

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use POSIX 'strftime';

$mailprog = '/usr/lib/sendmail';


# Retrieve Date
$date = strftime('%A, %B %1d, %Y %I:%M %p',localtime) ,"\n";


# my %in = {};

# remove any extra spaces at the front or back 

foreach $item (param()) {
my $value = param($item);
$value =~ s/^\s+//;
$value =~ s/\s+$//;
}


$email = param('email');
$realname = param('name');

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: removing white space

2002-02-14 Thread Hanson, Robert

Oops, I sent that before I was done (sliped with the fingers).

The first is more efficient, the second is less typing.

And actually the second one is incorrect, it should be this:

$value =~ s/^\s*(.*)\s*$/$1/;

You need to use \s* because one of them might match a space and the other
might not.  The way you had it would only with if there was both a leading
and trailing whitespace char(s).

But yes, either will work... although most will recommend the first option
due to performance (although it is minimal unless the string is very large).

Rob

-Original Message-
From: Hanson, Robert 
Sent: Thursday, February 14, 2002 12:36 PM
To: 'David Gilden'; [EMAIL PROTECTED]
Subject: RE: removing white space


The first is more efficient, the second is less typing.

And actually the second one is incorrect, it should be this:


Rob

-Original Message-
From: David Gilden [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 14, 2002 12:29 PM
To: [EMAIL PROTECTED]
Subject: removing white space

Is this correct, I want to remove leading and trailing white space,
Thanks

Dave
--

foreach $item (param()) {
my $value = param($item);
$value =~ s/^\s+//;
$value =~ s/\s+$//;
}

better??
foreach $item (param()) {
my $value = param($item);
$value =~ s/^\s+(.*)\s+$/$1/;
}



-

#!/usr/bin/perl 

use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use POSIX 'strftime';

$mailprog = '/usr/lib/sendmail';


# Retrieve Date
$date = strftime('%A, %B %1d, %Y %I:%M %p',localtime) ,"\n";


# my %in = {};

# remove any extra spaces at the front or back 

foreach $item (param()) {
my $value = param($item);
$value =~ s/^\s+//;
$value =~ s/\s+$//;
}


$email = param('email');
$realname = param('name');

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




removing white space revisited

2002-02-18 Thread David Gilden

Hi,

My goal is to  clean up the fields submitted from a form and then be able to use them 
in other places.

Does the following modify the value of param('name') -- if I have a form element named 
'name' --
permanently (like when you have an array)


foreach my $key (param()){

$val = param($key),
$value =~ s/^\s+//;
$value =~ s/\s+$//;
$key =~ s/\d$//;


print "$key: $val\n\n";

}


later in the script 

print param('email')  # will this have been cleaned regrex in the up the loop above?


Do I have to assign my 'cleaned' data to a hash?

Thanks!

Dave

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: removing white space revisited

2002-02-18 Thread David Gilden

That is kool, but I am using CGI.pm like we all should be :)

On Monday, February 18, 2002 at 2:01 PM, [EMAIL PROTECTED] (John M) wrote:

> David,
> 
> foreach $key (keys(%in))
>{ $in{$key} =~ s/^\s+//;  $in{$key} =~ s/\s+$//; }
> 
> That's all you have to do.
> 
> -jdm
> 
> (%in is generated under cgi-lib.pl)

So back to my question do need to assign param() to hash?

Thx,

Dave


>From an earlier post:
This is great for 'Upper-casing' just the first letter of a string!

#!/usr/bin/perl -w

my $key ="today's Departure date";
$key =~ s/([\w'-]+)/\u$1/g;

print  $key;





> 
> >From: David Gilden <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED]
> >Subject: removing white space revisited
> >Date: Mon, 18 Feb 2002 13:48:46 -0500
> >
> >Hi,
> >
> >My goal is to  clean up the fields submitted from a form and then be able 
> >to use them in other places.
> >
> >Does the following modify the value of param('name') -- if I have a form 
> >element named 'name' --
> >permanently (like when you have an array)
> >
> >
> >foreach my $key (param()){
> >
> >$val = param($key),
> >$value =~ s/^\s+//;
> >$value =~ s/\s+$//;
> >$key =~ s/\d$//;
> >
> >
> >print "$key: $val\n\n";
> >
> > }
> >
> >
> >later in the script
> >
> >print param('email')  # will this have been cleaned regrex in the up the 
> >loop above?
> >
> >
> >Do I have to assign my 'cleaned' data to a hash?
> >
> >Thanks!
> >
> >Dave
> >
> >**
> >*   Cora Connection Your West African Music Source   *
> >*   http://www.coraconnection.com/   *
> >*   Resources, Recordings, Instruments & More!   *
> >**
> >
> >--
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> 
> 
> _
> MSN Photos is the easiest way to share and print your photos: 
> http://photos.msn.com/support/worldwide.aspx

**
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/   *  
*   Resources, Recordings, Instruments & More!   *
**

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: removing white space revisited

2002-02-18 Thread Briac Pilpré

On Mon, 18 Feb 2002 at 18:48 GMT, David Gilden wrote:
> Hi,
> 
> My goal is to clean up the fields submitted from a form and then be
> able to use them in other places.
> 
> Do I have to assign my 'cleaned' data to a hash?

 You can try it by yourself:

#!/usr/bin/perl -w
use strict;
use CGI qw(:cgi);

foreach my $key ( param() ) {
my $value = param($key);# Fetch the parameter value
$value =~ s/^\s*|\d*\s*$//g;# Strip whitespaces and trailing digits
param( $key, $value );  # Reassigning the value in the parameter
}

# We verify the parameters to see if the values were changed
foreach ( param() ) {
print "$_ => '", param($_), "'\n";
}

__END__


-- 
briac
 << dynamic .sig on strike, we apologize for the inconvenience >>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: removing white space revisited

2002-02-18 Thread John M

David,

cgi-lib.pl and CGI.pm do the same things, for all intents and purposes.  
I've not bothered to use CGI.pm, in part because of its overly cumbersome 
style and kludges.
But that's my preference.  There are very few 'shoulds' in perl and far 
fewer 'musts.'  CGI.pm over cgi-lib.pl is neither of those.  :o>

So, for giggles, here's the problem solved in CGI.pm

#!/usr/bin/perl

use CGI;
$q = new CGI;
$q->header;
%params = $q->Vars;
foreach $key (keys(%params))
{ $params{$key} = s/^\s+//; $params{$key} =~ s/\s+$//; }

#
# whatever else
#

  And, equally for giggles, here's the same thing in cgi-lib.pl:

#!/usr/bin/perl

require 'cgi-lib.pl';
&ReadParse;
print &PrintHeader;
foreach $key (keys(%in))
{ $in{$key} = s/^\s+//; $in{$key} =~ s/\s+$//; }

#
# whatever else
#


   One involves less typing.  It's also clearer in the eye of the beholder.

-jdm

>From: David Gilden <[EMAIL PROTECTED]>
>To: John M <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
>Subject: Re: removing white space revisited
>Date: Mon, 18 Feb 2002 14:13:34 -0500
>
>That is kool, but I am using CGI.pm like we all should be :)
>
>On Monday, February 18, 2002 at 2:01 PM, [EMAIL PROTECTED] (John 
>M) wrote:
>
> > David,
> >
> > foreach $key (keys(%in))
> >{ $in{$key} =~ s/^\s+//;  $in{$key} =~ s/\s+$//; }
> >
> > That's all you have to do.
> >
> > -jdm
> >
> > (%in is generated under cgi-lib.pl)
>
>So back to my question do need to assign param() to hash?
>
>Thx,
>
>Dave
>
>
> >From an earlier post:
>This is great for 'Upper-casing' just the first letter of a string!
>
>#!/usr/bin/perl -w
>
>my $key ="today's Departure date";
>$key =~ s/([\w'-]+)/\u$1/g;
>
>print  $key;
>
>
>
>
>
> >
> > >From: David Gilden <[EMAIL PROTECTED]>
> > >To: [EMAIL PROTECTED]
> > >Subject: removing white space revisited
> > >Date: Mon, 18 Feb 2002 13:48:46 -0500
> > >
> > >Hi,
> > >
> > >My goal is to  clean up the fields submitted from a form and then be 
>able
> > >to use them in other places.
> > >
> > >Does the following modify the value of param('name') -- if I have a 
>form
> > >element named 'name' --
> > >permanently (like when you have an array)
> > >
> > >
> > >foreach my $key (param()){
> > >
> > >$val = param($key),
> > >$value =~ s/^\s+//;
> > >$value =~ s/\s+$//;
> > >$key =~ s/\d$//;
> > >
> > >
> > >print "$key: $val\n\n";
> > >
> > > }
> > >
> > >
> > >later in the script
> > >
> > >print param('email')  # will this have been cleaned regrex in the up 
>the
> > >loop above?
> > >
> > >
> > >Do I have to assign my 'cleaned' data to a hash?
> > >
> > >Thanks!
> > >
> > >Dave
> > >
> > >**
> > >*   Cora Connection Your West African Music Source   *
> > >*   http://www.coraconnection.com/   *
> > >*   Resources, Recordings, Instruments & More!   *
> > >**
> > >
> > >--
> > >To unsubscribe, e-mail: [EMAIL PROTECTED]
> > >For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> >
> >
> > _
> > MSN Photos is the easiest way to share and print your photos:
> > http://photos.msn.com/support/worldwide.aspx
>
>**
>*   Cora Connection Your West African Music Source   *
>*   http://www.coraconnection.com/   *
>*   Resources, Recordings, Instruments & More!   *
>**


_
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]