Need explanation of some perl syntax

Please explain each line character by character.  What is the purpose is chomp here?

while (<>) {
    chomp;
    if (/^\s*0x([0-9a-fA-F]+)\s*__AID_LOC/) {
        $aid_loc = hex($1);

# more perl statements

}
LVL 1
naseeamAsked:
Who is Participating?
 
Adam314Connect With a Mentor Commented:
The regular expression is looking for a hex number, followed optionally by whitespace (space, tab) then the literal string "__AID_LOC", saving the hex number to the special variable $1.  It is then using the hex function to convert the hex number to a number, and storing the result in $aid_loc.

So, if  your input was:     "0xabcd __AID_LOC"
Then the $aid_loc variable will contain 43981.
0
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
while (<>) {   <<< reads from standart input, line by line
    chomp;      <<< removes the End Of Line character from the line.
0
 
naseeamAuthor Commented:
Thanks.

I requested explanation of each line.

WHAT IS BEING READ FROM STANDARD INPUT?
Please explain if condition.  What's all that obscure syntax in the if condition?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
>WHAT IS BEING READ FROM STANDARD INPUT?
well, what the user puts in, resp is redirected into the standard input.


>    if (/^\s*0x([0-9a-fA-F]+)\s*__AID_LOC/) {
that checks, with the regular expression of ^\s*0x([0-9a-fA-F]+)\s*__AID_LOC (which means in short of the input is starting with 0-0 or a-f or A-F ),

> $aid_loc = hex($1);
and puts the match into the variable $aid_loc

0
 
naseeamAuthor Commented:
Could you provide a detailed example.  Enter some input data and manually execute above code to come up with match that would get put into $aid_loc.
0
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
i have to admit that I am rather a newbie on Perl, and most I know about perl is from similarities from other languages I know much better.
I would hence suggest you get through some tutorials, for example:
http://www.english.uga.edu/humcomp/perl/regex2a.html
and some more detailed explanations:
http://www.english.uga.edu/humcomp/perl/regular_expressions.HTML

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.