> 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 (
Re: Check if words are in uppercase?
am 10.06.2011 19:49:10 von jwkrahn
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 (
Re: Check if words are in uppercase?
am 10.06.2011 21:51:13 von 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 (
Re: Check if words are in uppercase?
am 13.06.2011 10:11:22 von Beware
Hi,
Sorry, i forgot to write my question clearly. But you well understand my=20
problem :)
Well, i try your answer, and it seems matching my request. Thanks you=20
very much.
Le 10/06/2011 21:51, Rob Dixon a =E9crit :
> 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 =3D 0;
>>
>> while (
Re: Check if words are in uppercase?
am 14.06.2011 09:30:59 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Check if words are in uppercase?
am 14.06.2011 16:40:14 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re : Re: Check if words are in uppercase?
am 14.06.2011 16:47:04 von Beware
Hi and thank you for your answer.
But how can i use it with a list of word.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re : Re: Check if words are in uppercase?
am 14.06.2011 17:53:18 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re : Re: Re : Re: Check if words are in uppercase?
am 15.06.2011 08:56:04 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re : Re: Re :Re: Checkif words are in uppercase?
am 15.06.2011 13:10:56 von 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 - paul@pjcj.net
http://www.pjcj.net
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re : Re: Re : Re: Check if words are in uppercase?
am 15.06.2011 13:38:02 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re : Re: Re : Re: Check if words are in uppercase?
am 15.06.2011 14:41:39 von jwkrahn
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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re : Re: Re : Re: Check if words are in uppercase?
am 15.06.2011 17:02:15 von 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
Jim@Gibson.org
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re : Re: Re : Re: Check if words are in uppercase?
am 15.06.2011 17:20:47 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re : Re: Re : Re: Check if words are in uppercase?
am 15.06.2011 18:09:01 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re : Re: Re : Re: Check if words are in uppercase?
am 15.06.2011 18:57:03 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re : Re: Re : Re: Check if words are in uppercase?
am 17.06.2011 21:57:28 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re : Re: Re : Re: Re : Re: Check if words are in up
am 21.06.2011 14:57:22 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re :Re: Re : Re: Re : Re:Check if words are in uppercase?
am 21.06.2011 15:53:53 von 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 - paul@pjcj.net
http://www.pjcj.net
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
RE: Re : Re: Re : Re: Re : Re: Check if
am 21.06.2011 16:01:17 von Bob McConnell
From: Paul Johnson
> On Tue, Jun 21, 2011 at 05:57:22AM -0700, Beware wrote:
>=20
> > Hi to all,
>>=20
>> First of all, sorry for the late of my answer.
>> Thank for all your sentence.
>>=20
>> Here's my solution (for now) :
>>=20
>> for my $w (@keywords)
>> {
>> if ( /\b$w\b/ and !/\buc($w)\b/ )
>> {
>> print "Keyword '$w' not uppercase line $.\n";
>> ajoute_erreur( 7, $. );
>> last;
>> }
>> }
>>=20
>> It's probably less fast than other ones, but it seems to work.
>=20
> I'm afraid you may need to improve your testing skills.
>=20
> 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re :Re: Re : Re: Re : Re:Check if words are in uppercase?
am 21.06.2011 16:47:51 von 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 - paul@pjcj.net
http://www.pjcj.net
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Re : Re: Re : Re: Re : Re: Check if words are in uppercase?
am 21.06.2011 19:09:54 von 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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/