uppercase

2002-10-23 Thread Javeed SAR
Hi All,

I have a script which accepts input from keyboard,here it is $label_tag, i
want to convert it to upper case, if the input  from keyboard is given in
lowercase, in my script?
How to do that?


print "\n\nENTER THE LABEL NAME:\n";
my $label_tag=<>;
chomp$label_tag;




RE: uppercase

2002-10-23 Thread Timothy Johnson

perldoc -f uc

-Original Message-
From: Javeed SAR [mailto:SAR.Javeed@;sisl.co.in]
Sent: Wednesday, October 23, 2002 1:17 AM
To: [EMAIL PROTECTED]
Subject: uppercase


Hi All,

I have a script which accepts input from keyboard,here it is $label_tag, i
want to convert it to upper case, if the input  from keyboard is given in
lowercase, in my script?
How to do that?


print "\n\nENTER THE LABEL NAME:\n";
my $label_tag=<>;
chomp$label_tag;


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




uppercase strings

2003-10-08 Thread Sara Gribble
I would appreciate some help with this. I am learning
Perl. I have a string inputed by the user. This string
is then split, every first letter of each word in the
string is uppercased, then joined back together and
printed.

Here is my code, can anyone help? Thanks, Sara G.

!/usr/bin/perl
# Demonstrating split and join when prompting the user
for input and then changing the first letter of each
word in a sentence to uppercase.

use strict;

print "Please enter a sentence of your choice\n";
my $firstline = ;
chomp ( $firstline );

my @words = split( / /, $firstline );
print "$_\n" foreach ( @words );


$firstline = join( ' ', @words ); # joins the string
back together and prints it.
print "$firstline\n";


__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



Re: uppercase strings

2003-10-08 Thread Jeff 'japhy' Pinyan
On Oct 8, Sara Gribble said:

>I would appreciate some help with this. I am learning
>Perl. I have a string inputed by the user. This string
>is then split, every first letter of each word in the
>string is uppercased, then joined back together and
>printed.

>my @words = split( / /, $firstline );
>print "$_\n" foreach ( @words );

What you need to do goes here.

There are many ways to make the first character of a string in an array of
strings uppercase.  Here is one way:

  foreach (@words) { $_ = ucfirst }

>$firstline = join( ' ', @words ); # joins the string
>print "$firstline\n";

Read 'perldoc -f ucfirst' for more details.

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


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



Re: uppercase strings

2003-10-08 Thread simran
Looks like you are almost there... 

% perldoc -f ucfirst


On Thu, 2003-10-09 at 13:41, Sara Gribble wrote:
> I would appreciate some help with this. I am learning
> Perl. I have a string inputed by the user. This string
> is then split, every first letter of each word in the
> string is uppercased, then joined back together and
> printed.
> 
> Here is my code, can anyone help? Thanks, Sara G.
> 
> !/usr/bin/perl
> # Demonstrating split and join when prompting the user
> for input and then changing the first letter of each
> word in a sentence to uppercase.
> 
> use strict;
> 
> print "Please enter a sentence of your choice\n";
> my $firstline = ;
> chomp ( $firstline );
> 
> my @words = split( / /, $firstline );
> print "$_\n" foreach ( @words );
> 
> 
> $firstline = join( ' ', @words ); # joins the string
> back together and prints it.
> print "$firstline\n";
> 
> 
> __
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search
> http://shopping.yahoo.com


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



Automatically write in uppercase

2004-02-28 Thread John
How can activate the caps lock while the user write in a perl programt (Perl/Tk)

UPPERCASE and DOING MULTIPLE THINGS

2002-07-22 Thread Bob H

I have a script that is *supposed* to search a file and make certain 
words that I have in an array uppercase. My brain is not grokking it.

Q1: What is wrong with my script (below)?
Q2: Can I update a file in place?
Q3: How do I run multiple things against one file in one script?

=== SCRIPT ===
#!/usr/bin/perl
use strict;
use warnings;

# variables
my $word = undef;

# setup the words to uppercase
my @words = qw/ Mary John Joe /;

open FILE, ">> NEW1 "  or die "can't open FILE:  $!";

while (<>) {
 foreach $word (@words) {
 $word = ~ tr /a-z/A-Z/;
 print FILE;
 }
}

# close the file
close (FILE);



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




Re: Automatically write in uppercase

2004-02-28 Thread R. Joseph Newton
John wrote:

> How can activate the caps lock while the user write in a perl programt (Perl/Tk)

Why would you want to do that?!?

Joseph


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




Re: Automatically write in uppercase

2004-02-29 Thread zsdc
R. Joseph Newton wrote:

John wrote:

How can activate the caps lock while the user write in a perl programt (Perl/Tk)
Why would you want to do that?!?
John, if you want to do that because you need to have your input all in 
caps, then use uc:

  $text = uc $text;

You will need to add:

  use locale;

at the beginning of your program if your character set is not US-ASCII. 
You can update the text field with uppercase letters after user finishes 
typing, if you want it to be visible.

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



Re: Automatically write in uppercase

2004-02-29 Thread John
That's a nice method but i would prefer to activate the CAPS-LOCK and user
write in capitals in my text entry widget


- Original Message - 
From: "zsdc" <[EMAIL PROTECTED]>
To: "John" <[EMAIL PROTECTED]>
Cc: "Perl Beginners" <[EMAIL PROTECTED]>
Sent: Sunday, February 29, 2004 1:21 PM
Subject: Re: Automatically write in uppercase


> R. Joseph Newton wrote:
>
> > John wrote:
> >
> >>How can activate the caps lock while the user write in a perl programt
(Perl/Tk)
> >
> > Why would you want to do that?!?
>
> John, if you want to do that because you need to have your input all in
> caps, then use uc:
>
>$text = uc $text;
>
> You will need to add:
>
>use locale;
>
> at the beginning of your program if your character set is not US-ASCII.
> You can update the text field with uppercase letters after user finishes
> typing, if you want it to be visible.
>
> -- 
> ZSDC
>
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>



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




Re: Automatically write in uppercase

2004-02-29 Thread WilliamGunther
In a message dated 2/29/2004 7:31:49 AM Eastern Standard Time, 
[EMAIL PROTECTED] writes:
>That's a nice method but i would prefer to activate the CAPS-LOCK and user
>write in capitals in my text entry widget

 
I can't think of how (or why) you'd want to do that. If you want them to type 
in caps, just turn the data to upper case when you need it. 

If you really really want to do that then you probably have to do a binding 
on any keypress in the text widget to change everything to upper case. That's 
the only way I can think to do it, but I'm not super up on my Tk. My method is 
slow, especially for a lot of stuff, and unnecessary since you can change it 
all to upper case after they say they're done.


-Will
---
Handy Yet Cryptic Code. 
Just to Look Cool to Look at and try to decipher without running it.

Windows
perl -e "printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e"

Unix
perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'


Re: Automatically write in uppercase

2004-02-29 Thread James Edward Gray II
On Feb 29, 2004, at 6:30 AM, John wrote:

That's a nice method but i would prefer to activate the CAPS-LOCK and 
user
write in capitals in my text entry widget
I would prefer you didn't.  ;)

The keyboard takes commands from me, not the computer.  If a program 
started monkeying with my control of such a device, it would find my 
trash can, mighty quick.

James

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



Re: Automatically write in uppercase

2004-02-29 Thread zsdc
James Edward Gray II wrote:
On Feb 29, 2004, at 6:30 AM, John wrote:

That's a nice method but i would prefer to activate the CAPS-LOCK and 
user
write in capitals in my text entry widget
I would prefer you didn't.  ;)

The keyboard takes commands from me, not the computer.  If a program 
started monkeying with my control of such a device, it would find my 
trash can, mighty quick.
I second that. John, for your program it doesn't matter how the string 
looks like when the user writes it, but only how it looks in your 
variable, and that's exactly why the uc and lc operators are for. For 
the user it doesn't matter how the string in your variable looks like 
but it matters how it looks like on the screen.

To be honest, if I saw that I am suddenly writing all in caps, I would 
turn the caps-lock off thinking that I accidentally pressed it.

If you somehow manage how to turn the caps-lock on (if it is possible) 
then you have this problems to solve:

1. What if the user manually turns it off?
2. What if the user copies and pastes a lowercase text?
3. What if the user use shift with caps-lock on and write in lowercase?
4. How do you remember the previous state of caps-lock and restore it as 
soon as you stop messing with it? (which still would confuse users of 
course)

The short answer to how to turn caps-lock on is: don't. Use uc.

--
ZSDC


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



Re: Automatically write in uppercase

2004-03-02 Thread Paul Johnson

James Edward Gray II said:

> On Feb 29, 2004, at 6:30 AM, John wrote:
>
>> That's a nice method but i would prefer to activate the CAPS-LOCK and
>> user
>> write in capitals in my text entry widget
>
> I would prefer you didn't.  ;)
>
> The keyboard takes commands from me, not the computer.  If a program
> started monkeying with my control of such a device, it would find my
> trash can, mighty quick.

Come on people.  Maybe John has a good reason for wanting Caps Lock to be on.

I have also written a Perk/Tk program in which I would like to control
Caps Lock.  The program is used as part of a programme to help people with
dyslexia improve their reading skills.  In part this involves displaying
text on the screen and having the student type it in.  In the very early
stages of the program the letters on the screen need to match those on the
keyboard - that is they need to be uppercase - otherwise the student may
have problems locating the correct key to press.  Obviously, at this sort
of level it is not desirable to have the student also hold down the Shift
key.

I have solved this by accepting lowercase input as uppercase, and in my
case this works well as I am not using a text entry widget, but a Caps
Lock solution might also be nice.  Unfortunately, I don't think a cross
platform solution exists, but if anyone knows of one, or if John tells us
which platform he is concerned about and anyone knows of a solution for
that platform, please speak up.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net


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




Re: Automatically write in uppercase

2004-03-02 Thread zsdc
Paul Johnson wrote:

James Edward Gray II said:

On Feb 29, 2004, at 6:30 AM, John wrote:

That's a nice method but i would prefer to activate the CAPS-LOCK and
user
write in capitals in my text entry widget
I would prefer you didn't.  ;)

The keyboard takes commands from me, not the computer.  If a program
started monkeying with my control of such a device, it would find my
trash can, mighty quick.
Come on people.  Maybe John has a good reason for wanting Caps Lock to be on.
I don't think anyone said the caps lock should never be on. We were only 
saying that it should be controlled by the user, who can turn it on or 
off whenever she wants.

I have solved this by accepting lowercase input as uppercase, and in my
case this works well as I am not using a text entry widget, but a Caps
Lock solution might also be nice.  Unfortunately, I don't think a cross
platform solution exists, but if anyone knows of one, or if John tells us
which platform he is concerned about and anyone knows of a solution for
that platform, please speak up.
You might always ask the user to turn it on if it was off, if that is 
really necessary. That is the only cross-platform solution I can think 
about.
--
ZSDC

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



RE: Automatically write in uppercase

2004-03-03 Thread Taylor James
James Edward Gray II wrote:
> On Feb 29, 2004, at 6:30 AM, John wrote:
> 
> > That's a nice method but i would prefer to activate the CAPS-LOCK
> > and user write in capitals in my text entry widget
> 
> I would prefer you didn't.  ;)
> 
> The keyboard takes commands from me, not the computer.  If a program
> started monkeying with my control of such a device, it would find my
> trash can, mighty quick.
> 

Incidentally MS Word does this. If you try to type a sentence, say:

pLEASE DON'T TURN OFF MY CAPS LOCK KEY, i WANT IT LIKE THIS.

with the caps lock key on, it automatically turns off the caps lock key and
converts it to:

Please don't...etc.

It's really annoying on occasions, occasionally useful but in general I
think it's a bad idea to 'monkey' with stuff like this.

-- 
james





The information contained in this e-mail is intended for the recipient or
entity to whom it is addressed. It may contain confidential information that
is exempt from disclosure by law and if you are not the intended recipient,
you must not copy, distribute or take any act in reliance on it. If you have
received this e-mail in error, please notify the sender immediately and
delete from your system. 

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




Re: Automatically write in uppercase

2004-03-03 Thread R. Joseph Newton
Taylor James wrote:

>
> Incidentally MS Word does this. If you try to type a sentence, say:
>
> pLEASE DON'T TURN OFF MY CAPS LOCK KEY, i WANT IT LIKE THIS.
>
> with the caps lock key on, it automatically turns off the caps lock key and
> converts it to:
>
> Please don't...etc.
>
> It's really annoying on occasions, occasionally useful but in general I
> think it's a bad idea to 'monkey' with stuff like this.
>
> --
> james

OT:  You can turn this obnoxious behavior off through the Tools|AutoCorrect
dialog.  Check all tabs, though.  M$ stores its nastiest second-guessing on two
different tabs at least.

Joseph


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




Re: UPPERCASE and DOING MULTIPLE THINGS

2002-07-22 Thread Jeff 'japhy' Pinyan

On Jul 22, Bob H said:

>I have a script that is *supposed* to search a file and make certain
>words that I have in an array uppercase. My brain is not grokking it.

You should not use tr/// to make strings uppercase.  Perl provides the
uc() function for that.

>Q1: What is wrong with my script (below)?

I'll point it out.

>Q2: Can I update a file in place?

Yes, using the $^I and @ARGV varaibles.

>Q3: How do I run multiple things against one file in one script?

Send multiple files as command-line args, and loop over the @ARGV array.

>#!/usr/bin/perl
>use strict;
>use warnings;

BRAVO! :)

># variables
>my $word = undef;

The '= undef' part is redundant.

># setup the words to uppercase
>my @words = qw/ Mary John Joe /;
>
>open FILE, ">> NEW1 "  or die "can't open FILE:  $!";
>
>while (<>) {
> foreach $word (@words) {
> $word = ~ tr /a-z/A-Z/;
> print FILE;
> }

A bunch of problems here.

1. you're print the same line to FILE X times, where X is the size of the
@words array
2. you're trying to modify the elements of @words, instead of $_
3. you've got a space in the middle of the =~ operator

This is quite funny, actually.  Because of that space, your code appears
to capitalize the entire string and print it three (in your example)
times.  Why?  Because

  $word = ~ tr/a-z/A-Z/;

is like

  $word = ~($_ =~ tr/a-z/A-Z/);

>}
>
># close the file
>close (FILE);

Here is a multi-file in-place working solution:

  #!/usr/bin/perl

  use strict;
  use warnings;

  $^I = ".bak";  # keep a backup of the files as xxx.bak
  my @words = qw( make these caps );
  my $rx = join "|", map quotemeta, @words;

  # $rx is 'make|these|caps'

  # perl is magic
  while (<>) {
s/\b($rx)\b/\U$1/ig;  # "\U$1" is like uc($1)
print;
  }

The regex finds the words (and they must be alone, not part of another
word) in any case and uppercases them.  If there was a line in the file

  these students are going on a capstone experience

it would become

  THESE students are going on a capstone experience

Try it out -- it should work fine.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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




RE: UPPERCASE and DOING MULTIPLE THINGS

2002-07-22 Thread Nikola Janceski

See inline comments

> -Original Message-
> From: Bob H [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 22, 2002 11:12 AM
> To: [EMAIL PROTECTED]
> Subject: UPPERCASE and DOING MULTIPLE THINGS
> 
> 
> I have a script that is *supposed* to search a file and make certain 
> words that I have in an array uppercase. My brain is not grokking it.
> 
> Q1: What is wrong with my script (below)?
> Q2: Can I update a file in place?
> Q3: How do I run multiple things against one file in one script?
> 
> === SCRIPT ===
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> # variables
> my $word = undef;
> 
> # setup the words to uppercase
> my @words = qw/ Mary John Joe /;
#you want to use pattern matching like this:
my @words = map qr/$_/i, qw/ Mary John Joe /;

> 
> open FILE, ">> NEW1 "  or die "can't open FILE:  $!";
> 
> while (<>) {
>  foreach $word (@words) {
>  $word = ~ tr /a-z/A-Z/;
>  print FILE;
>  }
# this whole foreach just changes the words in the array not the file.
# note that you are also reading in from stdin.
# to fix do this
foreach $word (@words){
s/ ## substitute in current line, 
    ($word) # match $word (Mary) case-insenstive, 
/ # and replace 
uc($1) # with uppercase of same word.
/gex;  # g = globally (throughout line as many times), e =
eval right side (uc($1)), x = ignore whitespace and comments
}
print FILE; # print to file after all @words are changed in line
> }
> 
> # close the file
> close (FILE);
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


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




Re: UPPERCASE and DOING MULTIPLE THINGS

2002-07-22 Thread drieux


On Monday, July 22, 2002, at 08:11 , Bob H wrote:

> I have a script that is *supposed* to search a file and make certain 
> words that I have in an array uppercase. My brain is not grokking it.
>
> Q1: What is wrong with my script (below)?

what sorts of error messages did you get?

> === SCRIPT ===
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> # variables
> my $word = undef;
>
> # setup the words to uppercase
> my @words = qw/ Mary John Joe /;
>
> open FILE, ">> NEW1 "  or die "can't open FILE:  $!";

so far so good...

> while (<>) {

why this outer loop? what if nothing is passed
at the command line - hence

<> evaluates to nothing

and the script closes.

> foreach $word (@words) {
> $word = ~ tr /a-z/A-Z/;
> print FILE;

It might help to sort out what you really
wanted to do here

I am a fan of localizing scope so I

so I would have gone with say:

 foreach my $word (@words) {
 $word =~ tr /a-z/A-Z/;
 print " $word \n";

}

since I really only want to use 'my $word' here
for each of the tokens in the @words list.

then there is the bit about

"=~" vice "= ~"

the former is an operator that binds the variable on the
left of the "=" to the 'pattern play' on the right.

then, rather than hope that you did something with $_
it some times helps to just expressly Print the thing you
want - in my case - I just sent it to stdout, in your case
you want to write to the file FILE...

since you would have wanted a loop like:

 foreach (@words) {
 tr/a-z/A-Z/;
print ;
}

to use the implicit play with $_ - but I think your
original idea of naming it was the better idea, you
just needed to get that $word to the print command

[..]

> Q2: Can I update a file in place?

yes, cf

perldoc IPC::Open2

> Q3: How do I run multiple things against one file in one script?

make sure they are all done between the open() and the close


ciao
drieux

---


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




Check if words are in uppercase?

2011-06-10 Thread Beware
Hi all,

i've a question on my perl script.

In my script i read a file line per line, and check if keywords are in
uppercase. To do that, i've an array filled with all used keywords.

On each line, i check all keywords with a foreach loop.

Well, this is my code :


my $lines = 0;

while (  )
{
   # cut '\n'
   chomp($_);

   #List of keywords
   my @keywords = ("all", "wait", "for");

   #Check all keyword
   foreach $item (@keywords)
   {
  # keywords detected
  if ( /$item\b/i and !/\s*--/)
  {
 # remove keywords already in uppercase
 my $temp = $_;
 my $item_maj = uc($item);
 $temp =~ s/$item_maj//g;

 # check if  any keywords
 if ( $temp =~ /$item\b/i )
 {
print "keywords is lowercase line : ".$lines."\n";
last;
 }
  }
   }
   $lines++;
}
close ( SOURCE );

Well, thanks for your answer


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




convert string from lowercase to uppercase

2005-12-12 Thread Jenny Chen
Hi All,

Does anyone know how to convert a string in lower case
to upper case in Perl?  Thanks.

Jenny

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




Need regex to match all UPPERCASE letters?

2001-07-23 Thread KEVIN ZEMBOWER

I need help writing a regular expression that will match lines that have only upper 
case letters, and sometimes slashes and spaces, but won't match lines with mixed case.

Lines that must be matched are like:
FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY
FAMILY PLANNING / REPRODUCTIVE HEALTH PROJECTS
PUBLIC HEALTH
HIV/AIDS

Lines that must NOT be matched include:
Renewed Hope for the World's Children
http://www.earthtimes.org/jul/childrenrenewedhopejul12_01.htm 
AIDS, TB, and Malnutrition Are Triple Threat in Haiti

Any suggestions are welcomed. Thank you for helping me with my problem.

-Kevin Zembower

-
E. Kevin Zembower
Unix Administrator
Johns Hopkins University/Center for Communications Programs
111 Market Place, Suite 310
Baltimore, MD  21202
410-659-6139


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




Re: Check if words are in uppercase?

2011-06-10 Thread Rob Coops
On Thu, Jun 9, 2011 at 9:59 AM, Beware  wrote:

> Hi all,
>
> i've a question on my perl script.
>
> In my script i read a file line per line, and check if keywords are in
> uppercase. To do that, i've an array filled with all used keywords.
>
> On each line, i check all keywords with a foreach loop.
>
> Well, this is my code :
>
>
> my $lines = 0;
>
> while (  )
> {
>   # cut '\n'
>   chomp($_);
>
>   #List of keywords
>   my @keywords = ("all", "wait", "for");
>
>   #Check all keyword
>   foreach $item (@keywords)
>   {
>  # keywords detected
>  if ( /$item\b/i and !/\s*--/)
>  {
> # remove keywords already in uppercase
> my $temp = $_;
> my $item_maj = uc($item);
> $temp =~ s/$item_maj//g;
>
> # check if  any keywords
> if ( $temp =~ /$item\b/i )
> {
>print "keywords is lowercase line : ".$lines."\n";
>last;
> }
>  }
>   }
>   $lines++;
> }
> close ( SOURCE );
>
> Well, thanks for your answer
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>
Why make you life so hard?

Lets assume you will want some debug logging to know what where and how
often you replaced things...

while ( $line =~ /\b(?'keyword'keyword1|keyword2|keyword3|etc...)\b/i ) {
 print debug information ($+{keyword} contains the matched keyword);
 $line =~ /$+{keyword}/\U$+{keyword}\E/;
}

This will do the same as your for loop but it will use a single regular
expression that gets used only once if only a single keyword is present in
the line and never more often then the number of keywords in the line being
processed.

If you want to use an external array with keywords simply use that by doing
the following:

my $keywords = join '|', @keywords;
while ( $line =~ /\b(?'keyword'$keywords)\b/i ) { ... }

Regards,

Rob


Re: Check if words are in uppercase?

2011-06-10 Thread John W. Krahn

Beware wrote:

Hi all,


Hello,


i've a question on my perl script.

In my script i read a file line per line, and check if keywords are in
uppercase. To do that, i've an array filled with all used keywords.

On each line, i check all keywords with a foreach loop.

Well, this is my code :


my $lines = 0;


You don't really need this variable, just use the built-in $. variable.



while (  )
{
# cut '\n'
chomp($_);

#List of keywords
my @keywords = ("all", "wait", "for");


You don't really need this variable inside the while loop.



#Check all keyword
foreach $item (@keywords)
{
   # keywords detected
   if ( /$item\b/i and !/\s*--/)


You should probably have anchors at the beginning as well as the end:

   if ( /\b$item\b/i && !/\s*--/ )



   {
  # remove keywords already in uppercase
  my $temp = $_;
  my $item_maj = uc($item);
  $temp =~ s/$item_maj//g;


No need for the $item_maj variable and you should use the anchors here 
as well:


  $temp =~ s/\b\U$item\E\b//g;



  # check if  any keywords
  if ( $temp =~ /$item\b/i )
  {
 print "keywords is lowercase line : ".$lines."\n";
 last;
  }
   }
}
$lines++;
}
close ( SOURCE );




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Check if words are in uppercase?

2011-06-10 Thread Rob Dixon

On 09/06/2011 08:59, Beware wrote:

Hi all,

i've a question on my perl script.

In my script i read a file line per line, and check if keywords are in
uppercase. To do that, i've an array filled with all used keywords.

On each line, i check all keywords with a foreach loop.

Well, this is my code :


my $lines = 0;

while (  )
{
# cut '\n'
chomp($_);

#List of keywords
my @keywords = ("all", "wait", "for");

#Check all keyword
foreach $item (@keywords)
{
   # keywords detected
   if ( /$item\b/i and !/\s*--/)
   {
  # remove keywords already in uppercase
  my $temp = $_;
  my $item_maj = uc($item);
  $temp =~ s/$item_maj//g;

  # check if  any keywords
  if ( $temp =~ /$item\b/i )
  {
 print "keywords is lowercase line : ".$lines."\n";
 last;
  }
   }
}
$lines++;
}
close ( SOURCE );

Well, thanks for your answer


Erm, what is your question?! I am not clear what the purpose of your
program is, but you seem to printing the numbers of data lines that
contain any of a list of keywords in lower case. To do that there is no
need to remove upper case occurrences at all - simply look only for
lower case strings. The program below does just that, by first
building a regex from the keywords array.

Do consider how you want to handle keywords of mixed case, like 'For' or
'All'.

HTH,

Rob


use strict;
use warnings;

my @keywords = qw(all wait for);
my $key_re = join '|', @keywords;
$key_re = qr/\b(?:$key_re)\b/o;

while (my $line = ) {
  if ($line =~ $key_re) {
print "keywords is lowercase line : $.\n";
  }
}

__DATA__
all
wine WAITER
wait
FOR
for

**OUTPUT**

keywords is lowercase line : 2
keywords is lowercase line : 4
keywords is lowercase line : 6

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Check if words are in uppercase?

2011-06-13 Thread Mathieu Hedard

Hi,

Sorry, i forgot to write my question clearly. But you well understand my 
problem :)
Well, i try your answer, and it seems matching my request. Thanks you 
very much.


Le 10/06/2011 21:51, Rob Dixon a écrit :

On 09/06/2011 08:59, Beware wrote:

Hi all,

i've a question on my perl script.

In my script i read a file line per line, and check if keywords are in
uppercase. To do that, i've an array filled with all used keywords.

On each line, i check all keywords with a foreach loop.

Well, this is my code :


my $lines = 0;

while (  )
{
# cut '\n'
chomp($_);

#List of keywords
my @keywords = ("all", "wait", "for");

#Check all keyword
foreach $item (@keywords)
{
   # keywords detected
   if ( /$item\b/i and !/\s*--/)
   {
  # remove keywords already in uppercase
  my $temp = $_;
  my $item_maj = uc($item);
  $temp =~ s/$item_maj//g;

  # check if  any keywords
  if ( $temp =~ /$item\b/i )
  {
 print "keywords is lowercase line : ".$lines."\n";
 last;
  }
   }
}
$lines++;
}
close ( SOURCE );

Well, thanks for your answer


Erm, what is your question?! I am not clear what the purpose of your
program is, but you seem to printing the numbers of data lines that
contain any of a list of keywords in lower case. To do that there is no
need to remove upper case occurrences at all - simply look only for
lower case strings. The program below does just that, by first
building a regex from the keywords array.

Do consider how you want to handle keywords of mixed case, like 'For' or
'All'.

HTH,

Rob


use strict;
use warnings;

my @keywords = qw(all wait for);
my $key_re = join '|', @keywords;
$key_re = qr/\b(?:$key_re)\b/o;

while (my $line = ) {
  if ($line =~ $key_re) {
print "keywords is lowercase line : $.\n";
  }
}

__DATA__
all
wine WAITER
wait
FOR
for

**OUTPUT**

keywords is lowercase line : 2
keywords is lowercase line : 4
keywords is lowercase line : 6



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Check if words are in uppercase?

2011-06-14 Thread Beware
@John : Thank you for your advices.

@Rob Dixon : Your script works fine, but i want to add a little more
thing. In fact, i want to detect if a word is in line (of course) and
if it's not in uppercase.
I mean, for example, i want to detect :
aLL
aLl
All
etc..
but not ALL (which is correct for me).

Thanks.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Check if words are in uppercase?

2011-06-14 Thread Jim Gibson

At 12:30 AM -0700 6/14/11, Beware wrote:

@John : Thank you for your advices.

@Rob Dixon : Your script works fine, but i want to add a little more
thing. In fact, i want to detect if a word is in line (of course) and
if it's not in uppercase.
I mean, for example, i want to detect :
aLL
aLl
All
etc..
but not ALL (which is correct for me).


if( $word =~ /^all$/i && $word ne 'ALL' )


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: convert string from lowercase to uppercase

2005-12-12 Thread John Doe
Jenny Chen am Montag, 12. Dezember 2005 21.49:
> Hi All,

Hi

> Does anyone know how to convert a string in lower case
> to upper case in Perl?  Thanks.

yes,

perldoc -f uc 

does.

hth, joe

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




Re: convert string from lowercase to uppercase

2005-12-12 Thread Chris Devers
On Mon, 12 Dec 2005, Jenny Chen wrote:

> Does anyone know how to convert a string in lower case
> to upper case in Perl?  Thanks.
 
Undoubtedly.

How did you try to do it ?

Did you try the s/// substitution feature ?
perldoc -f s 

Did you try the tr/// transliteration operator ? 
perldoc -f tr

Did you try the uc() uppercase command ? 
perldoc -f uc

uc() is probably the one you want, but the others offer more flexibility 
and can be preferable in certain contexts. 




-- 
Chris Devers

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




RE: convert string from lowercase to uppercase

2005-12-12 Thread Buehler, Bob
Also:

$name =~ tr/a-z/A-Z/;

(the string is in $name variable)

-Original Message-
From: John Doe [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 12, 2005 3:02 PM
To: beginners@perl.org
Subject: Re: convert string from lowercase to uppercase


Jenny Chen am Montag, 12. Dezember 2005 21.49:
> Hi All,

Hi

> Does anyone know how to convert a string in lower case
> to upper case in Perl?  Thanks.

yes,

perldoc -f uc 

does.

hth, joe

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



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




Re: convert string from lowercase to uppercase

2005-12-12 Thread John Doe
Buehler, Bob am Montag, 12. Dezember 2005 22.18:
> Also:
>
> $name =~ tr/a-z/A-Z/;
>
> (the string is in $name variable)

Ok, but this won't match words in my language (and others) or words containing 
unicode.

:-)


> -Original Message-
> From: John Doe [mailto:[EMAIL PROTECTED]
[...]
> Jenny Chen am Montag, 12. Dezember 2005 21.49:
> > Hi All,
[...]
> > Does anyone know how to convert a string in lower case
> > to upper case in Perl?  Thanks.
>
> yes,
>
> perldoc -f uc
>
> does.
>
> hth, joe

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




converting the elements of a hash to uppercase

2004-11-12 Thread Octavian Rasnita
Hi all,

Please tell me how to convert the elements of a hash to uppercase, if I can
access that hash only by reference.

For example, I have something like:

my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };

And I want to make 'a' to be 'A', 'b' to be 'B' and so on, but the values of
the hash need to remain the same.

I have tried using map() but without success.

Thank you for your help.

Teddy


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




RE: Need regex to match all UPPERCASE letters?

2001-07-23 Thread John Edwards

Try something like this

@data = ("FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY", "PUBLIC HEALTH",
"Renewed Hope for the World's Children");

foreach $value(@data) {
print "$value\n" unless $value =~ /[a-z]+/;
}

Note. This will match anything it finds, unless there is a lowercase letter
in the data. You could make it more complex and search for only caps, spaces
and forward slashes, but as long as you are confident of your data source
then this should do.

HTH

John

-Original Message-
From: KEVIN ZEMBOWER [mailto:[EMAIL PROTECTED]]
Sent: 23 July 2001 14:49
To: <
Subject: Need regex to match all UPPERCASE letters?


I need help writing a regular expression that will match lines that have
only upper case letters, and sometimes slashes and spaces, but won't match
lines with mixed case.

Lines that must be matched are like:
FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY
FAMILY PLANNING / REPRODUCTIVE HEALTH PROJECTS
PUBLIC HEALTH
HIV/AIDS

Lines that must NOT be matched include:
Renewed Hope for the World's Children
http://www.earthtimes.org/jul/childrenrenewedhopejul12_01.htm 
AIDS, TB, and Malnutrition Are Triple Threat in Haiti

Any suggestions are welcomed. Thank you for helping me with my problem.

-Kevin Zembower

-
E. Kevin Zembower
Unix Administrator
Johns Hopkins University/Center for Communications Programs
111 Market Place, Suite 310
Baltimore, MD  21202
410-659-6139


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


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



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




RE: Need regex to match all UPPERCASE letters?

2001-07-23 Thread Chris Mulcahy

$_ !~ /[a-z]/

Easy enough!

hth
Chris

> -Original Message-
> From: KEVIN ZEMBOWER [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 23, 2001 8:49 AM
> To: <
> Subject: Need regex to match all UPPERCASE letters?
>
>
> I need help writing a regular expression that will match
> lines that have only upper case letters, and sometimes
> slashes and spaces, but won't match lines with mixed case.
>
> Lines that must be matched are like:
> FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY
> FAMILY PLANNING / REPRODUCTIVE HEALTH PROJECTS
> PUBLIC HEALTH
> HIV/AIDS
>
> Lines that must NOT be matched include:
> Renewed Hope for the World's Children
> http://www.earthtimes.org/jul/childrenrenewedhopejul12_01.htm
> AIDS, TB, and Malnutrition Are Triple Threat in Haiti
>
> Any suggestions are welcomed. Thank you for helping me with
> my problem.
>
> -Kevin Zembower
>



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




Re: Need regex to match all UPPERCASE letters?

2001-07-23 Thread Jeff 'japhy/Marillion' Pinyan

On Jul 23, KEVIN ZEMBOWER said:

>I need help writing a regular expression that will match lines that have
>only upper case letters, and sometimes slashes and spaces, but won't
>match lines with mixed case.
>
>Lines that must be matched are like:
>FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY
>FAMILY PLANNING / REPRODUCTIVE HEALTH PROJECTS
>PUBLIC HEALTH
>HIV/AIDS

You should probably just use a regex like:

  if ($line !~ /[a-z]/) {
# it's ok
  }

That regex says "if $line does NOT contain a lower-case letter, let it
pass."

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **


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




Re: Need regex to match all UPPERCASE letters?

2001-07-23 Thread KEVIN ZEMBOWER

Jeff and John, thanks for your help. I'm invoking my script with a command line loop:
perl -n pop2html.pl 2001-07-16.txt

The file pop2html.pl, incorporating your suggestion, is:
if (! /[a-z]/) {chomp; print "$_\n"; next;}
if (/^\s*$/) { print "\n"; next;}

The tail of the file 2001-07-16.txt is:
WOMEN'S HEALTH

Endometriosis: A Clinical Review
http://www.bmj.com/cgi/content/full/323/7304/93 


YOUTH

Renewed Hope for the World's Children
http://www.earthtimes.org/jul/childrenrenewedhopejul12_01.htm 


The output of the program is:
WOMEN'S HEALTH



YOUTH




As you can see, the first line in pop2html.pl is matching everything, and the second 
line is never executing. I think that this is because the first line matches on any 
character that is not a lower-case, including spaces and the occasional capital in an 
abbreviation or first word of a sentence.

Thanks, again, for your help. Any other suggestions?

-Kevin


>>> [EMAIL PROTECTED] 07/23/01 10:00AM >>>
On Jul 23, KEVIN ZEMBOWER said:

>I need help writing a regular expression that will match lines that have
>only upper case letters, and sometimes slashes and spaces, but won't
>match lines with mixed case.
>
>Lines that must be matched are like:
>FAMILY PLANNING / REPRODUCTIVE HEALTH POLICY
>FAMILY PLANNING / REPRODUCTIVE HEALTH PROJECTS
>PUBLIC HEALTH
>HIV/AIDS

You should probably just use a regex like:

  if ($line !~ /[a-z]/) {
# it's ok
  }

That regex says "if $line does NOT contain a lower-case letter, let it
pass."

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/ 
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/ 
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/ 
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **



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




Re: Need regex to match all UPPERCASE letters?

2001-07-23 Thread Jeff 'japhy/Marillion' Pinyan

On Jul 23, KEVIN ZEMBOWER said:

>Jeff and John, thanks for your help. I'm invoking my script with a
>command line loop: perl -n pop2html.pl 2001-07-16.txt
>
>The file pop2html.pl, incorporating your suggestion, is:
>if (! /[a-z]/) {chomp; print "$_\n"; next;}
>if (/^\s*$/) { print "\n"; next;}
>
>The output of the program is:
>WOMEN'S HEALTH
>

Well, you should re-arrange your order of tests!  If the string is made up
of ONLY whitespace (like your second test, /^\s*$/, checks), then it
ALREADY matches the !/[a-z]/ test.  Re-arrange them.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
**  Manning Publications, Co, is publishing my Perl Regex book  **


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




Re: converting hash keys to uppercase with regex

2002-06-18 Thread zentara

On Mon, 17 Jun 2002 16:55:08 -0700, [EMAIL PROTECTED] (Drieux) wrote:
>
>given that your code would generate
>$vc{'TZ'} = 'ok';$vc{'UA'} = 'ok';$vc{'UG'} = 'ok';$vc{'UK'} = 
>'ok';$vc{'UM'} = 'ok';
>$vc{'US'} = 'ok';$vc{'UY'} = 'ok';$vc{'UZ'} = 'ok';$vc{'VA'} = 
>'ok';$vc{'VC'} = 'ok';
>$vc{'VE'} = 'ok';$vc{'VG'} = 'ok';$vc{'VI'} = 'ok';$vc{'VN'} = 
>'ok';$vc{'VU'} = 'ok';
>$vc{'WF'} = 'ok';$vc{'WS'} = 'ok';$vc{'YE'} = 'ok';$vc{'YT'} = 
>'ok';$vc{'YU'} = 'ok';
>$vc{'ZA'} = 'ok';$vc{'ZM'} = 'ok';$vc{'ZR'} = 'ok';$vc{'ZW'} = 'ok';
>
>I'm not too sure that I see what the Improvement here is...
>
>Have you thought about doing say something with map and qw
>that might make it simpler in the long run to maintain such as
>
>   my @keysLower = qw/
>   tz ua ug uk um
>   us uy uz va vc
>   ve vg vi vn vu
>   wf ws ye yt yu
>   za zm zr zw
>   /;
>   my @keysUpper = map { uc } @keysLower;
>
>   my %vc = map { $_ => 'ok'} @keysUpper;
>

Thanks everyone for the replies. It dawned on me that putting the
keys in an array and regenerating the hash is the best solution, as
you guys pointed out.

It really was a matter of curiosity, on how to do the regex, for the
the sake of trying to expand my limited regex abilities.



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




Re : Re: Check if words are in uppercase?

2011-06-14 Thread Beware
Hi and thank you for your answer.

But how can i use it with a list of word.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: converting the elements of a hash to uppercase

2004-11-12 Thread David Kroeber
* Octavian Rasnita:
> Please tell me how to convert the elements of a hash to uppercase, if I can
> access that hash only by reference.

$hash = { map { uc, $hash->{$_} } keys %{$hash} };

In a hash like ('key' => 'value', 'KEY' => 'VALUE') you'll lose some
data... for {}, %{}, etc. see perldoc perlref and perldoc perlreftut

bye
//Dave

-- 
Ja, der typische "Ich tippe alles ein was mir ein paar Trottel aus dem
IRC sagen"-Newbie wird aber kein Solaris nutzen... ;)
-- Christoph Gebhardt in bjt

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




Re: converting the elements of a hash to uppercase

2004-11-12 Thread Randy W. Sims
Octavian Rasnita wrote:
Hi all,
Please tell me how to convert the elements of a hash to uppercase, if I can
access that hash only by reference.
For example, I have something like:
my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };
And I want to make 'a' to be 'A', 'b' to be 'B' and so on, but the values of
the hash need to remain the same.
I have tried using map() but without success.
You can't modify the key; you can only create a new one and remove the 
old one:

#!/usr/bin/perl;
use strict;
use warnings;
my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };
while ( my($k,$v) = each %$ref ) {
$ref->{uc($k)} = delete( $ref->{$k} );
}
use Data::Dumper;
print Dumper( $ref );
__END__
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: converting the elements of a hash to uppercase

2004-11-12 Thread Eric Walker
Can't you do the upper case thing when you first create it?


On Friday 12 November 2004 03:07 pm, Randy W. Sims wrote:
> Octavian Rasnita wrote:
> > Hi all,
> >
> > Please tell me how to convert the elements of a hash to uppercase, if I
> > can access that hash only by reference.
> >
> > For example, I have something like:
> >
> > my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };
> >
> > And I want to make 'a' to be 'A', 'b' to be 'B' and so on, but the values
> > of the hash need to remain the same.
> >
> > I have tried using map() but without success.
>
> You can't modify the key; you can only create a new one and remove the
> old one:
>
> #!/usr/bin/perl;
>
> use strict;
> use warnings;
>
> my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };
>
> while ( my($k,$v) = each %$ref ) {
>  $ref->{uc($k)} = delete( $ref->{$k} );
> }
>
> use Data::Dumper;
> print Dumper( $ref );
>
> __END__

-- 
Eric Walker -- 
CAD Engineer 
X82573 

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




Re: converting the elements of a hash to uppercase

2004-11-13 Thread John W. Krahn
Octavian Rasnita wrote:
Hi all,
Hello,
Please tell me how to convert the elements of a hash to uppercase, if I can
access that hash only by reference.
For example, I have something like:
my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };
And I want to make 'a' to be 'A', 'b' to be 'B' and so on, but the values of
the hash need to remain the same.
I have tried using map() but without success.
Did you try it like this:
%$ref = map { uc, $ref->{ $_ } } keys %$ref;
:-)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: converting the elements of a hash to uppercase

2004-11-13 Thread Randy W. Sims
John W. Krahn wrote:
Octavian Rasnita wrote:
Hi all,

Hello,
Please tell me how to convert the elements of a hash to uppercase, if 
I can
access that hash only by reference.

For example, I have something like:
my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };
And I want to make 'a' to be 'A', 'b' to be 'B' and so on, but the 
values of
the hash need to remain the same.

I have tried using map() but without success.

Did you try it like this:
%$ref = map { uc, $ref->{ $_ } } keys %$ref;
Be carefull of constructs like these; they often turn out to be 
inefficient and slow. It's actually equivelant to something like:

  my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };
  my %tmp;
  while ( my( $k, $v ) = each %$ref ) {
  $tmp{uc($k)} = $v;
  }
  $ref = \%tmp;
Here is a comparison:
#!/usr/bin/perl
use strict;
use warnings;
sub a_map {
my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };
%$ref = map { uc, $ref->{ $_ } } keys %$ref;
}
sub b_expanded {
my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };
my %tmp;
while ( my( $k, $v ) = each %$ref ) {
$tmp{uc($k)} = $v;
}
$ref = \%tmp;
}
sub c_inplace {
my $ref = { 'a' => 'aaa', 'b' => 'bbb', 'c' => 'ccc' };
foreach my $k ( keys %$ref ) {
$ref->{uc($k)} = delete( $ref->{$k} );
}
}
use Benchmark qw(cmpthese);
cmpthese( 0, {
'map'  => \&a_map,
'expanded map' => \&b_expanded,
'inplace'  => \&c_inplace
} );
__END__
Benchmark: running expanded map, inplace, map, each for at least 3 CPU 
seconds..
.
expanded map:  5 wallclock secs
  ( 3.53 usr +  0.00 sys =  3.53 CPU) @ 10844.87/s (n=38239)
inplace:  5 wallclock secs
  ( 3.13 usr +  0.00 sys =  3.13 CPU) @ 11818.12/s (n=37038)
map:  3 wallclock secs
  ( 3.06 usr +  0.00 sys =  3.06 CPU) @ 9780.03/s (n=29966)
Rate  map expanded map  inplace
map   9780/s   -- -10% -17%
expanded map 10845/s  11%   --  -8%
inplace  11818/s  21%   9%   --

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



Re: Re : Re: Check if words are in uppercase?

2011-06-14 Thread Jim Gibson
On 6/14/11 Tue  Jun 14, 2011  7:47 AM, "Beware" 
scribbled:

> Hi and thank you for your answer.
> 
> But how can i use it with a list of word.
> 

Use what? You need to put a little context in your messages so people can
help you without seeing previous messages.


If you have a list of words in an array (@words) and you want to see if some
string ($string) matches those words except for case and is not all
upper-case, there are several possibilities.

1. You can test if a string consists of only upper-case letters:

  if( $string =~ /^[A-Z]+$/ )

2. You can test if $string matches any of the words in @words in
case-insensitive fashion:

 
  for my $word ( @words ) {
if( $string =~ /^$word$/i ) {
  # string matches
  last;  # no need for further tests
}
  }

3. You can do both:

  for my $word ( @words ) {
if( $string =~ /^$word$/i && $string ne uc $word ) {
  # string matches
  last;  # no need for further tests
}
  }

(You can also set all members of @word to upper-case to begin with.)

What exactly are you trying to do? Can you provide a Perl program that
illustrates this?



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re : Re: Re : Re: Check if words are in uppercase?

2011-06-14 Thread Beware
Hi

Sorry, i've been tired these past days.

So, this is what i want to do :

I've source code files in VHDL. I want to check that all specific keywords of 
this language are in uppercase.

In fact, in my current script i read this file line per line and check others 
rules.

Am i clear, now?


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Is there any function for converting uppercase characters to lowercase chars ?

2001-08-10 Thread Rahul Garg

Hello,

Is there any function for converting uppercase characters to lowercase chars ?

Thanks

Rahul




Re: Is there any function for converting uppercase characters tolowercase chars ?

2001-08-10 Thread Jeff 'japhy/Marillion' Pinyan

On Aug 10, Rahul Garg said:

>Is there any function for converting uppercase characters to lowercase
>chars ?

The lc() function.  It returns a lowercased version of the string you pass
it.  Please read 'perldoc -f lc'.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


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




Re: Is there any function for converting uppercase characters tolowercase chars ?

2001-08-10 Thread Brett W. McCoy

> Is there any function for converting uppercase characters to lowercase
> chars ?

Of course!

perldoc -f uc
perldoc -f lc
perldoc -q capital

-- Brett
   http://www.chapelperilous.net/btfwk/

Recent investments will yield a slight profit.


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




Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-15 Thread Paul Johnson
On Tue, Jun 14, 2011 at 11:56:04PM -0700, Beware wrote:
> Hi
> 
> Sorry, i've been tired these past days.
> 
> So, this is what i want to do :
> 
> I've source code files in VHDL. I want to check that all specific keywords of 
> this language are in uppercase.
> 
> In fact, in my current script i read this file line per line and check others 
> rules.
> 
> Am i clear, now?

Here is some code that does this.  I suggest you make sure you understand what
it does and check that it is correct.  Call it by passing the names of your
VHDL files.

Note that this code isn't very clever.  In particular you will get false
positives.  To do the job properly you would need a VHDL parser.  For that
reason I would suggest against modifying the code to alter the input file as
part of a checkin hook, for example.

(I prefer my keywords to be in lowercase.)


#!/usr/bin/perl

use strict;
use warnings;

my @keywords = qw
(
abs access after alias all and architecture array assert attribute begin
block body buffer bus case component configuration constant disconnect
downto else elsif end entity exit file for function generate generic group
guarded if impure in inertial inout is label library linkage literal loop
map mod nand new next nor not null of on open or others out package port
postponed procedure process pure range record register reject return rol
ror select severity signal shared sla sli sra srl subtype then to
transport type unaffected units until use variable wait when while with
xnor xor
);

my $kw = join "|", @keywords;

while (<>)
{
for my $w (/(\b$kw\b)/ig)
{
warn "Keyword '$w' not uppercase at $ARGV:$.\n" unless $w eq uc $w;
}
}

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-15 Thread Rob Dixon

On 15/06/2011 12:10, Paul Johnson wrote:

On Tue, Jun 14, 2011 at 11:56:04PM -0700, Beware wrote:

Hi

Sorry, i've been tired these past days.

So, this is what i want to do :

I've source code files in VHDL. I want to check that all specific keywords of 
this language are in uppercase.

In fact, in my current script i read this file line per line and check others 
rules.

Am i clear, now?


Here is some code that does this.  I suggest you make sure you understand what
it does and check that it is correct.  Call it by passing the names of your
VHDL files.

Note that this code isn't very clever.  In particular you will get false
positives.  To do the job properly you would need a VHDL parser.  For that
reason I would suggest against modifying the code to alter the input file as
part of a checkin hook, for example.

(I prefer my keywords to be in lowercase.)


#!/usr/bin/perl

use strict;
use warnings;

my @keywords = qw
(
 abs access after alias all and architecture array assert attribute begin
 block body buffer bus case component configuration constant disconnect
 downto else elsif end entity exit file for function generate generic group
 guarded if impure in inertial inout is label library linkage literal loop
 map mod nand new next nor not null of on open or others out package port
 postponed procedure process pure range record register reject return rol
 ror select severity signal shared sla sli sra srl subtype then to
 transport type unaffected units until use variable wait when while with
 xnor xor
);

my $kw = join "|", @keywords;


You would need

  my $kw = join "|", map uc, @keywords;

:)

Rob


while (<>)
{
 for my $w (/(\b$kw\b)/ig)
 {
 warn "Keyword '$w' not uppercase at $ARGV:$.\n" unless $w eq uc $w;
 }
}




--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-15 Thread John W. Krahn

Rob Dixon wrote:

On 15/06/2011 12:10, Paul Johnson wrote:


#!/usr/bin/perl

use strict;
use warnings;

my @keywords = qw
(
abs access after alias all and architecture array assert attribute begin
block body buffer bus case component configuration constant disconnect
downto else elsif end entity exit file for function generate generic
group
guarded if impure in inertial inout is label library linkage literal loop
map mod nand new next nor not null of on open or others out package port
postponed procedure process pure range record register reject return rol
ror select severity signal shared sla sli sra srl subtype then to
transport type unaffected units until use variable wait when while with
xnor xor
);

my $kw = join "|", @keywords;


You would need

my $kw = join "|", map uc, @keywords;


Or:

my $kw = uc join '|', @keywords;

Why call uc() multiple times when you only need to call it once?



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-15 Thread Jim Gibson

At 12:38 PM +0100 6/15/11, Rob Dixon wrote:

On 15/06/2011 12:10, Paul Johnson wrote:

On Tue, Jun 14, 2011 at 11:56:04PM -0700, Beware wrote:

Hi

Sorry, i've been tired these past days.

So, this is what i want to do :

I've source code files in VHDL. I want to check that all specific 
keywords of this language are in uppercase.


In fact, in my current script i read this file line per line and 
check others rules.


Am i clear, now?


Here is some code that does this.  I suggest you make sure you 
understand what

it does and check that it is correct.  Call it by passing the names of your
VHDL files.

Note that this code isn't very clever.  In particular you will get false
positives.  To do the job properly you would need a VHDL parser.  For that
reason I would suggest against modifying the code to alter the input file as
part of a checkin hook, for example.

(I prefer my keywords to be in lowercase.)


#!/usr/bin/perl

use strict;
use warnings;

my @keywords = qw
(
 abs access after alias all and architecture array assert attribute begin
 block body buffer bus case component configuration constant disconnect
 downto else elsif end entity exit file for function generate 
generic group
 guarded if impure in inertial inout is label library linkage 
literal loop

 map mod nand new next nor not null of on open or others out package port
 postponed procedure process pure range record register reject return rol
 ror select severity signal shared sla sli sra srl subtype then to
 transport type unaffected units until use variable wait when while with
 xnor xor
);

my $kw = join "|", @keywords;


You would need

  my $kw = join "|", map uc, @keywords;



Why? He is using the 'i' modifier in the regular expression to find 
all keywords regardless of case (lower, upper, mixed). Then checking 
to see if the extracted keyword is equal to the upper-case version 
and printing a warning message if it is not.





while (<>)
{
 for my $w (/(\b$kw\b)/ig)
 {
 warn "Keyword '$w' not uppercase at $ARGV:$.\n" unless $w eq uc $w;
 }
}




--
Jim Gibson
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-15 Thread Rob Dixon

On 15/06/2011 16:02, Jim Gibson wrote:

At 12:38 PM +0100 6/15/11, Rob Dixon wrote:

On 15/06/2011 12:10, Paul Johnson wrote:

On Tue, Jun 14, 2011 at 11:56:04PM -0700, Beware wrote:

Hi

Sorry, i've been tired these past days.

So, this is what i want to do :

I've source code files in VHDL. I want to check that all specific
keywords of this language are in uppercase.

In fact, in my current script i read this file line per line and
check others rules.

Am i clear, now?


Here is some code that does this. I suggest you make sure you
understand what
it does and check that it is correct. Call it by passing the names of
your
VHDL files.

Note that this code isn't very clever. In particular you will get false
positives. To do the job properly you would need a VHDL parser. For that
reason I would suggest against modifying the code to alter the input
file as
part of a checkin hook, for example.

(I prefer my keywords to be in lowercase.)


#!/usr/bin/perl

use strict;
use warnings;

my @keywords = qw
(
abs access after alias all and architecture array assert attribute begin
block body buffer bus case component configuration constant disconnect
downto else elsif end entity exit file for function generate generic
group
guarded if impure in inertial inout is label library linkage literal
loop
map mod nand new next nor not null of on open or others out package port
postponed procedure process pure range record register reject return rol
ror select severity signal shared sla sli sra srl subtype then to
transport type unaffected units until use variable wait when while with
xnor xor
);

my $kw = join "|", @keywords;


You would need

my $kw = join "|", map uc, @keywords;



Why? He is using the 'i' modifier in the regular expression to find all
keywords regardless of case (lower, upper, mixed). Then checking to see
if the extracted keyword is equal to the upper-case version and printing
a warning message if it is not.


Very true: I missed the uc within the loop and the code is fine as it
stands. But it would be better to write, as John said

  my $kw = uc join "|", @keywords;

and drop the call inside the loop.

  warn "Keyword '$w' not uppercase at $ARGV:$.\n" unless $w eq $w;




while (<>)  {
  for my $w (/(\b$kw\b)/ig) {
warn "Keyword '$w' not uppercase at $ARGV:$.\n" unless $w eq uc $w;
  }
}



Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-15 Thread Jim Gibson
On 6/15/11 Wed  Jun 15, 2011  8:20 AM, "Rob Dixon" 
scribbled:

> On 15/06/2011 16:02, Jim Gibson wrote:
>> At 12:38 PM +0100 6/15/11, Rob Dixon wrote:
>>> On 15/06/2011 12:10, Paul Johnson wrote:
>>>> On Tue, Jun 14, 2011 at 11:56:04PM -0700, Beware wrote:
>>>>> Hi
>>>>> 
>>>>> Sorry, i've been tired these past days.
>>>>> 
>>>>> So, this is what i want to do :
>>>>> 
>>>>> I've source code files in VHDL. I want to check that all specific
>>>>> keywords of this language are in uppercase.
>>>>> 
>>>>> In fact, in my current script i read this file line per line and
>>>>> check others rules.
>>>>> 
>>>>> Am i clear, now?
>>>> 
>>>> Here is some code that does this. I suggest you make sure you
>>>> understand what
>>>> it does and check that it is correct. Call it by passing the names of
>>>> your
>>>> VHDL files.
>>>> 
>>>> Note that this code isn't very clever. In particular you will get false
>>>> positives. To do the job properly you would need a VHDL parser. For that
>>>> reason I would suggest against modifying the code to alter the input
>>>> file as
>>>> part of a checkin hook, for example.
>>>> 
>>>> (I prefer my keywords to be in lowercase.)
>>>> 
>>>> 
>>>> #!/usr/bin/perl
>>>> 
>>>> use strict;
>>>> use warnings;
>>>> 
>>>> my @keywords = qw
>>>> (
>>>> abs access after alias all and architecture array assert attribute begin
>>>> block body buffer bus case component configuration constant disconnect
>>>> downto else elsif end entity exit file for function generate generic
>>>> group
>>>> guarded if impure in inertial inout is label library linkage literal
>>>> loop
>>>> map mod nand new next nor not null of on open or others out package port
>>>> postponed procedure process pure range record register reject return rol
>>>> ror select severity signal shared sla sli sra srl subtype then to
>>>> transport type unaffected units until use variable wait when while with
>>>> xnor xor
>>>> );
>>>> 
>>>> my $kw = join "|", @keywords;
>>> 
>>> You would need
>>> 
>>> my $kw = join "|", map uc, @keywords;
>> 
>> 
>> Why? He is using the 'i' modifier in the regular expression to find all
>> keywords regardless of case (lower, upper, mixed). Then checking to see
>> if the extracted keyword is equal to the upper-case version and printing
>> a warning message if it is not.
> 
> Very true: I missed the uc within the loop and the code is fine as it
> stands. But it would be better to write, as John said
> 
>my $kw = uc join "|", @keywords;
> 
> and drop the call inside the loop.
> 
>warn "Keyword '$w' not uppercase at $ARGV:$.\n" unless $w eq $w;
> 

I am afraid that will not work. $w is extracted from the input line and may
contain lower-case letters. You must compare $w to uc $w to see if it
contains any lower-case letters. '$w eq $w' is always true.


>>> 
>>>> while (<>)  {
>>>>   for my $w (/(\b$kw\b)/ig) {
>>>> warn "Keyword '$w' not uppercase at $ARGV:$.\n" unless $w eq uc $w;
>>>>   }
>>>> }



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-15 Thread Rob Dixon

On 15/06/2011 17:09, Jim Gibson wrote:

On 6/15/11 Wed  Jun 15, 2011  8:20 AM, "Rob Dixon"  
scribbled:

I am afraid that will not work. $w is extracted from the input line and may
contain lower-case letters. You must compare $w to uc $w to see if it
contains any lower-case letters. '$w eq $w' is always true.


Yes, for some reason I'm talking nonsense today.

Thanks Jim

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-17 Thread Brandon McCaig
On Wed, Jun 15, 2011 at 12:09 PM, Jim Gibson  wrote:
> '$w eq $w' is always true.

It certainly is more sane when that holds true, but to have a little
fun there is overload. ;D

use strict;
use warnings;

use overload '==' => sub { return 0; };

my $foo = bless {};

print $foo == $foo;

__END__


-- 
Brandon McCaig  
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software  

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Is there any function for converting uppercase characters to lowercase chars ?

2001-08-10 Thread Chris Rogers

Try:
print "\L$variable";
This will print the entire string in lowercase.
print "\U$variable";
This will print the entire string in uppercase.


-Original Message-
From: Rahul Garg [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 10, 2001 10:20 AM
To: [EMAIL PROTECTED]
Subject: Is there any function for converting uppercase characters to
lowercase chars ?


Hello,

Is there any function for converting uppercase characters to lowercase chars
?

Thanks

Rahul


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




Re : Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-21 Thread Beware
Hi to all,

First of all, sorry for the late of my answer.
Thank for all your sentence.

Here's my solution (for now) :

for my $w (@keywords)
  {
 if ( /\b$w\b/ and !/\buc($w)\b/ )
 {
print "Keyword '$w' not uppercase line $.\n";
ajoute_erreur( 7, $. );
last;
 }
  }

It's probably less fast than other ones, but it seems to work.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Re : Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-21 Thread Paul Johnson
On Tue, Jun 21, 2011 at 05:57:22AM -0700, Beware wrote:

> Hi to all,
> 
> First of all, sorry for the late of my answer.
> Thank for all your sentence.
> 
> Here's my solution (for now) :
> 
> for my $w (@keywords)
>   {
>  if ( /\b$w\b/ and !/\buc($w)\b/ )
>  {
> print "Keyword '$w' not uppercase line $.\n";
> ajoute_erreur( 7, $. );
> last;
>  }
>   }
> 
> It's probably less fast than other ones, but it seems to work.

I'm afraid you may need to improve your testing skills.

I assume your keywords are in lower case.  What happens with mixed case?  You
would need /i on your first //

uc($w) isn't doing what you think it is - you were wanting \U$w\E

But the trouble with your method is that you will miss things like
"a and b AND c" because it *will* find the uppercase version on the line.

Also, you probably don't want the "last" there or you'll only ever find one
error per line.

I refer the right honourable Gentleman to my previous answer.

Good luck,

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Re : Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-21 Thread Bob McConnell
From: Paul Johnson

> On Tue, Jun 21, 2011 at 05:57:22AM -0700, Beware wrote:
> 
> > Hi to all,
>> 
>> First of all, sorry for the late of my answer.
>> Thank for all your sentence.
>> 
>> Here's my solution (for now) :
>> 
>> for my $w (@keywords)
>>   {
>>  if ( /\b$w\b/ and !/\buc($w)\b/ )
>>  {
>> print "Keyword '$w' not uppercase line $.\n";
>> ajoute_erreur( 7, $. );
>> last;
>>  }
>>   }
>> 
>> It's probably less fast than other ones, but it seems to work.
> 
> I'm afraid you may need to improve your testing skills.
> 
> I assume your keywords are in lower case.  What happens with mixed case?  You
> would need /i on your first //

You need to be a little more careful about those assumptions. He is looking for 
all keywords that are not in UPPERCASE.

Bob McConnell

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Re : Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-21 Thread Paul Johnson
On Tue, Jun 21, 2011 at 10:01:17AM -0400, Bob McConnell wrote:
> From: Paul Johnson
> 
> > On Tue, Jun 21, 2011 at 05:57:22AM -0700, Beware wrote:
> > 
> > > Hi to all,
> >> 
> >> First of all, sorry for the late of my answer.
> >> Thank for all your sentence.
> >> 
> >> Here's my solution (for now) :
> >> 
> >> for my $w (@keywords)
> >>   {
> >>  if ( /\b$w\b/ and !/\buc($w)\b/ )
> >>  {
> >> print "Keyword '$w' not uppercase line $.\n";
> >> ajoute_erreur( 7, $. );
> >> last;
> >>  }
> >>   }
> >> 
> >> It's probably less fast than other ones, but it seems to work.
> > 
> > I'm afraid you may need to improve your testing skills.
> > 
> > I assume your keywords are in lower case.  What happens with mixed case?  
> > You
> > would need /i on your first //
> 
> You need to be a little more careful about those assumptions. He is looking 
> for all keywords that are not in UPPERCASE.

Sorry, I wasn't clear.  What I should have said was something like: I assume
that the elements of the array @keywords are all in lower case.

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Re : Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-21 Thread Rob Dixon

On 21/06/2011 15:01, Bob McConnell wrote:

From: Paul Johnson

On Tue, Jun 21, 2011 at 05:57:22AM -0700, Beware wrote:


Hi to all,

First of all, sorry for the late of my answer.
Thank for all your sentence.

Here's my solution (for now) :

for my $w (@keywords)
   {
  if ( /\b$w\b/ and !/\buc($w)\b/ )
  {
 print "Keyword '$w' not uppercase line $.\n";
 ajoute_erreur( 7, $. );
 last;
  }
   }

It's probably less fast than other ones, but it seems to work.


I'm afraid you may need to improve your testing skills.

I assume your keywords are in lower case.  What happens with mixed case?  You
would need /i on your first //


You need to be a little more careful about those assumptions.
He is looking for all keywords that are not in UPPERCASE.


In fact not, the OP corrected his requirement later on

On 15/06/2011 07:56, Beware wrote:


So, this is what i want to do :

I've source code files in VHDL. I want to check that all specific
keywords of this language are in uppercase.

In fact, in my current script i read this file line per line and
check  others rules.

Am i clear, now?


The working solution that I prefer is Paul's

On 15/06/2011 12:10, Paul Johnson wrote:


my $kw = join "|", @keywords;

while (<>)  {
  for my $w (/(\b${kw}\b)/ig) {
warn "Keyword '$w' not uppercase at $ARGV:$.\n" unless $w eq uc $w;
  }
}


Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/