mechanism of application ($0 or the line) 
Author Message
 mechanism of application ($0 or the line)

HiYa

I was just wondering ... are the rules for each "line" applied to $0  
for example if I have a rule like:

/^[ \t]*#include/ { $0 = tolower($0) }

will this mean the rule will be applied to $0 , and then since it
makes a change to $0 that all subsequent rules will be operating on
this new value?

thanks

--

See Ya
(when the bandwidth gets better ;-)
Chris Eastwood                            Please remove undies for reply
Photographer, Stunt Programmer
Motorcyclist and dingbat



Fri, 27 Sep 2002 03:00:00 GMT  
 mechanism of application ($0 or the line)


...

Quote:
> I was just wondering ... are the rules for each "line" applied to $0
> for example if I have a rule like:

> /^[ \t]*#include/ { $0 = tolower($0) }

> will this mean the rule will be applied to $0 , and then since it
> makes a change to $0 that all subsequent rules will be operating on
> this new value?

Correct. Continuing with your example,

/^[ \t]*#include/ { $0 = tolower($0) }
/[A-Z]/ { print $0 }

The second pattern will always be false, so the print statement never
executes.

Sent via Deja.com http://www.deja.com/
Before you buy.



Fri, 27 Sep 2002 03:00:00 GMT  
 mechanism of application ($0 or the line)
HiYa



Quote:
>> will this mean the rule will be applied to $0 , and then since it
>> makes a change to $0 that all subsequent rules will be operating on
>> this new value?

>Correct. Continuing with your example,

>/^[ \t]*#include/ { $0 = tolower($0) }
>/[A-Z]/ { print $0 }

Ok ... that works ... so the "line" is first parsed into $0 then all
references are made to $0 ... can I compare this to the original without
specifically saving it?

Also ... you've got me worried a little ... in your example you used a
range regex [A-Z] ... is this the same as [A..Z] ?? I have used the
latter, and I wonder if it's wrong.

--

See Ya
(when the bandwidth gets better ;-)
Chris Eastwood                            Please remove undies for reply
Photographer, Stunt Programmer
Motorcyclist and dingbat



Fri, 27 Sep 2002 03:00:00 GMT  
 mechanism of application ($0 or the line)

Quote:

> Also ... you've got me worried a little ... in your example you used a
> range regex [A-Z] ... is this the same as [A..Z] ?? I have used the
> latter, and I wonder if it's wrong.

Is it "wrong"? Not necessarily, but it's not the same as [A-Z],
and it's almost certainly not what I think you think it is.

The regular expression character class [A-Z] matches an occurrence
of any of these twenty-six characters:

    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

The character class [A..Z] is the same as [.AZ] and matches an
occurrence of any of these three characters:

    . A Z

Are you perhaps confusing regular expression character class ranges
with Perl's binary range operator?

--
Jim Monty

Tempe, Arizona USA



Fri, 27 Sep 2002 03:00:00 GMT  
 mechanism of application ($0 or the line)

   >Ok ... that works ... so the "line" is first parsed into $0 then all
   >references are made to $0 ... can I compare this to the original
   >without specifically saving it?
$0 is the input buffer.  Once you change it, it's changed.  Changing any
fields ($1, $2, etc.) will also change $0.
   >Also ... you've got me worried a little ... in your example you
   >used a range regex [A-Z] ... is this the same as [A..Z] ?? I have
   >used the latter, and I wonder if it's wrong.
If [A..Z] works for you, that is if it matches any capital letter, you have
a nonstandard awk.

Net-Tamer V 1.08X - Test Drive



Fri, 27 Sep 2002 03:00:00 GMT  
 mechanism of application ($0 or the line)
HiYa


Quote:

>Is it "wrong"? Not necessarily, but it's not the same as [A-Z],
>and it's almost certainly not what I think you think it is.

thats why I got away with it, cos it has another meaning ... interesting

Quote:
>The character class [A..Z] is the same as [.AZ] and matches an
>occurrence of any of these three characters:

yep ... I got it now

Quote:
>Are you perhaps confusing regular expression character class ranges
>with Perl's binary range operator?

that's the problem, in my job here I have to swap between VMS, UNIX,
PL/SQL, C , Awk, Perl ... ahhhhhh

thanks for the tip !!  I'll have to bring my book in, I couldn't find a
ref on the WWW (where did that gopher site go!!) for regex, so I
guessed!

--

See Ya
(when the bandwidth gets better ;-)
Chris Eastwood                            Please remove undies for reply
Photographer, Stunt Programmer
Motorcyclist and dingbat



Sat, 28 Sep 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Newbie Help required: Deleting double entries in a line ($0)

2. Appending to $0 or $_

3. variable as search-pattern: if ($0 ~ myVar)

4. executable awk scripts and shell var $(basename $0)

5. !x[$0]++

6. $0 == false ??

7. program name -> perl's $0

8. $0 == __FILE__ idiom for Unix only?

9. ruby 1.6.5, irb $0

10. __FILE__ == $0 refactored in Ruby?

11. Replacement for __FILE__ == $0

12. Maximum size of $0

 

 
Powered by phpBB® Forum Software