Re: string change problem

2004-03-30 Thread Wiggins d Anconia
Please bottom post.

> Hello All,
> 
> I am really very happy to receive the detailful response
from you all.It is great.
> Thanks for all helping me to start my knowledge on PERL programming.
> 

'perl' or 'Perl', never 'PERL'.

perldoc -q '"Perl"'

http://danconia.org

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




Re: string change problem

2004-03-30 Thread Muthukumar
Hello All,

I am really very happy to receive the detailful response from you all.It 
is great.
Thanks for all helping me to start my knowledge on PERL programming.

Thanks,
Muthukumar.

- Original Message -
From: "Charles K. Clarkson" <[EMAIL PROTECTED]>
To: "'MuthuKumar'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, March 29, 2004 6:09 PM
Subject: RE: string change problem


> news <[EMAIL PROTECTED]> wrote:
> :
> : I want to make a script which converts like
> : (pErl1234test = perl).I
> : wrote like
> :
> : #!/usr/bin/perl
>
> Always use the following two statements at the
> beginning of your scripts. They will help catch errors.
>
> use strict;
> use warnings;
>
>
> : print "Enter ur name"
> : $name = 
> : $org_name = $name
>
> Almost every statement in perl should end with a
> semicolon. The 'my' is added the first time you use a
> variable or sometimes just before.
>
> print 'Enter your name';
> my $name = ;
> my $org_name = $name;
>
>
> : $name =~ s/\W.*//;  #change 1
>
> \W will match any character that is /not/
> alphanumeric. You can use a POSIX character class
> ([:alpha:]) for alphabetic only characters. It must be
> place in a perl character class which is a set of square
> brackets ([]). Read 'perlre'.
>
>
> Substitution is probably not the best way to handle
> this. We'll come back in a bit.
>
>
> : $name =~ tr/A-Z/a-z/;  #change  2
>
> Perl has a lowercase function (lc) built-in. Read
> 'perlfunc'
>
>
> : print "Old = $org_name\n";
> : print "New = $name\n";
>
>
> Your solution was not built to handle '12345' or
> '' or other inputs which might fail the conversion
> process. Here's the solution I came up with:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> print 'Enter your name';
>
> # we use my the first time we use a variable.
> my $name = ;
>
> # We declare $new_name outside the if block
> #so we can use again later'
> # We set it to '' in case the regex below fails
> my $new_name = '';
>
> # [:apha:] matches alphabetical characters only.
> # /x at the end allows us to insert whitespace in
> # the regex.
> if ( $name =~ / ( [[:alpha:]]+ ) /x ) {
>
> # lc is the lower case function for perl
> # $1 is anything found in the parenthesis
> # in the regex above
> $new_name = lc $1;
>
> }
>
> print "Old = $name\n";
> print "New = $new_name\n";
>
> __END__
>
>
> HTH,
>
> Charles K. Clarkson
> --
> Mobile Homes Specialist
> 254 968-8328



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: string change problem

2004-03-29 Thread WC -Sx- Jones
Charles K. Clarkson wrote:
WC -Sx- Jones <[EMAIL PROTECTED]> wrote:
: 
: MuthuKumar wrote:
: print "Enter ur name";

Sorry, Sx. That produces this:

   Org = perltest 
As Entered = pErl1234test

   The OP wanted:

   Org = perl 
As Entered = pErl1234test


Sure, but "Enter ur name" could mean anything.

There were so many errors in the orginal post I was left with artistic 
freedom.

-Sx-

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



RE: string change problem

2004-03-29 Thread Charles K. Clarkson
WC -Sx- Jones <[EMAIL PROTECTED]> wrote:
: 
: MuthuKumar wrote:
: > 
: > I want to make a script which converts
: > like (pErl1234test = perl). I wrote like
: 
: #! /usr/bin/perl -w
: 
: print "Enter ur name";
: my $name = ;
: my $org_name = $name;
: $org_name =~ s/[^a-z]/ /gi;
: $org_name =~ tr/A-Z/a-z/;
: print "   Org = $org_name\n";
: print "As Entered = $name\n";


Sorry, Sx. That produces this:

   Org = perltest 
As Entered = pErl1234test


   The OP wanted:

   Org = perl 
As Entered = pErl1234test


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




Re: string change problem

2004-03-29 Thread James Edward Gray II
On Mar 29, 2004, at 11:02 AM, Smoot Carl-Mitchell wrote:

On Mon, 29 Mar 2004 15:05:34 +0530
"MuthuKumar" <[EMAIL PROTECTED]> wrote:
$name =~ s/\W.*//;  #change 1
This RE deletes zero or more non-alphanumeric characters followed by
anything.
So it deletes the entire string, since there was no match on a
non-alphanumeric character.
Half-right.  ;)  It deletes nothing, since there was no match...

James

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



Re: string change problem

2004-03-29 Thread Jeff 'japhy' Pinyan
On Mar 29, MuthuKumar said:

>I want to make a script which converts like (pErl1234test = perl).I

>#!/usr/bin/perl
>print "Enter ur name"
>$name = 
>$org_name = $name

Those three lines are all missing semicolons.

>$name =~ s/\W.*//;  #change 1
>$name =~ tr/A-Z/a-z/;  #change  2

Those should work, but I'd use lc() instead of tr/A-Z/a-z/.

>print "Old = $org_name\n";
>print "New = $name\n";

  #!/usr/bin/perl -w

  use strict;  # look into this -- it enforces safer coding practices

  print "Enter your name: ";
  chomp(my $name = );  # chomp removes the ending newline
  my $old_name = $name;

  $name =~ s/\W.*//;
  $name = lc $name;

  print "Old = $old_name\n";
  print "New = $name\n";

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN[Need a programmer?  If you like my work, let me know.]
 what does y/// stand for?   why, yansliterate of course.


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




RE: string change problem

2004-03-29 Thread Charles K. Clarkson
news <[EMAIL PROTECTED]> wrote:
: 
: I want to make a script which converts like 
: (pErl1234test = perl).I
: wrote like
: 
: #!/usr/bin/perl

Always use the following two statements at the
beginning of your scripts. They will help catch errors.

use strict;
use warnings;


: print "Enter ur name"
: $name = 
: $org_name = $name

Almost every statement in perl should end with a
semicolon. The 'my' is added the first time you use a
variable or sometimes just before.

print 'Enter your name';
my $name = ;
my $org_name = $name;


: $name =~ s/\W.*//;  #change 1

\W will match any character that is /not/
alphanumeric. You can use a POSIX character class
([:alpha:]) for alphabetic only characters. It must be
place in a perl character class which is a set of square
brackets ([]). Read 'perlre'.


Substitution is probably not the best way to handle
this. We'll come back in a bit.


: $name =~ tr/A-Z/a-z/;  #change  2

Perl has a lowercase function (lc) built-in. Read
'perlfunc'


: print "Old = $org_name\n";
: print "New = $name\n";


Your solution was not built to handle '12345' or
'' or other inputs which might fail the conversion
process. Here's the solution I came up with:

#!/usr/bin/perl

use strict;
use warnings;

print 'Enter your name';

# we use my the first time we use a variable.
my $name = ;

# We declare $new_name outside the if block
#so we can use again later'
# We set it to '' in case the regex below fails
my $new_name = '';

# [:apha:] matches alphabetical characters only.
# /x at the end allows us to insert whitespace in
# the regex.
if ( $name =~ / ( [[:alpha:]]+ ) /x ) {

# lc is the lower case function for perl
# $1 is anything found in the parenthesis
# in the regex above
$new_name = lc $1;

}

print "Old = $name\n";
print "New = $new_name\n";

__END__


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




Re: string change problem

2004-03-29 Thread Smoot Carl-Mitchell
On Mon, 29 Mar 2004 12:14:49 -0600
James Edward Gray II <[EMAIL PROTECTED]> wrote:

> On Mar 29, 2004, at 11:02 AM, Smoot Carl-Mitchell wrote:
> 
> > On Mon, 29 Mar 2004 15:05:34 +0530
> > "MuthuKumar" <[EMAIL PROTECTED]> wrote:
> >
> >> $name =~ s/\W.*//;  #change 1
> >
> > This RE deletes zero or more non-alphanumeric characters followed by
> > anything.
> >
> > So it deletes the entire string, since there was no match on a
> > non-alphanumeric character.
> 
> Half-right.  ;)  It deletes nothing, since there was no match...


Oops.  You are correct.  '\W' matches exactly once. I was thinking
'\W*'.

-- 
Smoot Carl-Mitchell
Systems/Network Architect
email: [EMAIL PROTECTED]
cell: +1 602 421 9005
home: +1 480 922 7313

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




Re: string change problem

2004-03-29 Thread John W. Krahn
Muthukumar wrote:
> 
> Hai all.

Hello,

> I want to make a script which converts like (pErl1234test = perl).I
> wrote like
> 
> #!/usr/bin/perl
> print "Enter ur name"
> $name = 
> $org_name = $name
> $name =~ s/\W.*//;  #change 1

The \W character class includes every character that is NOT a-z and A-Z
and 0-9 and _.  If you just want to keep only the letters at the
beginning of the string:

$name =~ s/[^a-zA-Z].*//;

Or:

$name =~ s/[^[:alpha:}].*//;

Or:

$name = $1 if $org_name =~ /^([a-zA-Z]+)/;

etc.


> $name =~ tr/A-Z/a-z/;  #change  2

You can also use the lc() function for that.

$name = lc $name;


> print "Old = $org_name\n";
> print "New = $name\n";
> 
> But i can not get a change on the change 1 and 2 lines.



John
-- 
use Perl;
program
fulfillment

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




Re: string change problem

2004-03-29 Thread Randy W. Sims
MuthuKumar wrote:
Hai all.

I want to make a script which converts like (pErl1234test = perl).I
wrote like
#!/usr/bin/perl
print "Enter ur name"
$name = 
$org_name = $name
$name =~ s/\W.*//;  #change 1
$name =~ tr/A-Z/a-z/;  #change  2
print "Old = $org_name\n";
print "New = $name\n";
But i can not get a change on the change 1 and 2 lines.
The problem with 'change 1' is that word characters (\w) _include_ 
digits where you seem to expect that they don't, so I use a character 
class to produce the results that you /seem/ to want.

#!/usr/bin/perl

use strict;
use warnings;
print 'Enter your name: ';
my $new_name = ;
chomp($new_name);
my $old_name = $new_name;
$new_name =~ s/[\W\d].*$//; #change 1
$new_name =~ tr/A-Z/a-z/;   #change 2
print "Old = $old_name\n";
print "New = $new_name\n";
__END__

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



Re: string change problem

2004-03-29 Thread WC -Sx- Jones
MuthuKumar wrote:
Hai all.

I want to make a script which converts like (pErl1234test = perl).I
wrote like
#!/usr/bin/perl
print "Enter ur name"
$name = 
$org_name = $name
$name =~ s/\W.*//;  #change 1
$name =~ tr/A-Z/a-z/;  #change  2
print "Old = $org_name\n";
print "New = $name\n";
#! /usr/bin/perl -w

print "Enter ur name";
my $name = ;
my $org_name = $name;
$org_name =~ s/[^a-z]/ /gi;
$org_name =~ tr/A-Z/a-z/;
print "   Org = $org_name\n";
print "As Entered = $name\n";
HTH/Sx

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



Re: string change problem

2004-03-29 Thread Flemming Greve Skovengaard
MuthuKumar wrote:
Hai all.

I want to make a script which converts like (pErl1234test = perl).I
wrote like
#!/usr/bin/perl
print "Enter ur name"
$name = 
$org_name = $name
$name =~ s/\W.*//;  #change 1
$name =~ tr/A-Z/a-z/;  #change  2
print "Old = $org_name\n";
print "New = $name\n";
But i can not get a change on the change 1 and 2 lines.

Regards,
Muthukumar.



This should work:

__BEGIN__

#!/usr/bin/perl

my ($name, $org_name);

print "Enter your name: ";
chomp($name = );
$org_name = $name;

$name =~ s/[^A-Za-z]\w*//g;  #change 1
$name =~ tr/A-Z/a-z/;  #change  2
print "Old = $org_name\n";
print "New = $name\n";
__END__

--
Flemming Greve SkovengaardAnd when you kill a man, you're a murderer
a.k.a Greven, TuxPowerKill many, and you're a conqueror
<[EMAIL PROTECTED]>   Kill them all ... Ooh ... Oh you're a god!
4168.08 BogoMIPS  - MegaDeth, Countdown to Extinction
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: string change problem

2004-03-29 Thread James Edward Gray II
On Mar 29, 2004, at 3:35 AM, MuthuKumar wrote:

Hai all.
Howdy.

I want to make a script which converts like (pErl1234test = 
perl).I
wrote like

#!/usr/bin/perl
print "Enter ur name"
$name = 
$org_name = $name
You are missing semi-colons on all three lines above.

$name =~ s/\W.*//;  #change 1
In English, that says, "Find a non-word character followed by zero or 
more anything characters and delete them."  Perl's idea of non-word 
characters is anything not in the set [A-Za-z0-9_].  You don't have any 
non-word characters in your sample string, so it does not match.

I believe you wanted:

$name =~ s/[^A-Za-z].*//;

$name =~ tr/A-Z/a-z/;  #change  2
The above line looks like it should be lowercasing everything to me, 
though I would probably write it as:

$name = lc $name;

Hope that helps.

James

print "Old = $org_name\n";
print "New = $name\n";
But i can not get a change on the change 1 and 2 lines.

Regards,
Muthukumar.


--
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: string change problem

2004-03-29 Thread Smoot Carl-Mitchell
On Mon, 29 Mar 2004 15:05:34 +0530
"MuthuKumar" <[EMAIL PROTECTED]> wrote:

> Hai all.
> 
> I want to make a script which converts like (pErl1234test =
> perl).I
> wrote like
> 
> #!/usr/bin/perl
> print "Enter ur name"
> $name = 
> $org_name = $name
> $name =~ s/\W.*//;  #change 1

This RE deletes zero or more non-alphanumeric characters followed by
anything.

So it deletes the entire string, since there was no match on a
non-alphanumeric character.

You probably meant something like:

$name =~ s/\d+.*//;

which matches one or more digit characters followed by anything.

See the perlre man page for details on Perl regular expressions.

-- 
Smoot Carl-Mitchell
Systems/Network Architect
email: [EMAIL PROTECTED]
cell: +1 602 421 9005
home: +1 480 922 7313

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




string change problem

2004-03-29 Thread MuthuKumar
Hai all.

I want to make a script which converts like (pErl1234test = perl).I
wrote like

#!/usr/bin/perl
print "Enter ur name"
$name = 
$org_name = $name
$name =~ s/\W.*//;  #change 1
$name =~ tr/A-Z/a-z/;  #change  2
print "Old = $org_name\n";
print "New = $name\n";

But i can not get a change on the change 1 and 2 lines.

Regards,
Muthukumar.




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