qiang8
asked on
3 questions from beginner.
Q1:
open(LOG, ">>/home/bin/counts ABC.txt")
Does "LOG" refer to a file name to be opened? How about ">>"?
Q2:
line 1: if (/^\*/ && / 1 S/)
line 2: {
line 3: @array = split(':');
line 4: $Idd{$rec[$#rec]}=1;
line 5: $count++;
line 6: }
How do we interpret 3rd and 4th lines?
Q3:
What does this function "chomp()" do?
chomp($Time)
Pls advise and thanks.
open(LOG, ">>/home/bin/counts ABC.txt")
Does "LOG" refer to a file name to be opened? How about ">>"?
Q2:
line 1: if (/^\*/ && / 1 S/)
line 2: {
line 3: @array = split(':');
line 4: $Idd{$rec[$#rec]}=1;
line 5: $count++;
line 6: }
How do we interpret 3rd and 4th lines?
Q3:
What does this function "chomp()" do?
chomp($Time)
Pls advise and thanks.
ASKER
Thanks. How about question 2.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>line 4: $Idd{$rec[$#rec]}=1;
assign the value 1 to the hashtable entry (of the hashtable $ldd).
the key of the entry is at the last entry of the array $rec.
assign the value 1 to the hashtable entry (of the hashtable $ldd).
the key of the entry is at the last entry of the array $rec.
do I win the 100 points? :-)
ASKER
Thank you very much. Pls lock the answer so that I can award u points and a good grade.
ASKER
Thank you very much. Pls lock the answer so that I can award u points and a good grade.
ASKER
Thank you.
Anytime.
How about line 1 of Q2?
I'm also beginner.
I'm also beginner.
(
/^ #match the beginning of the line
\* #quote the *
/x #see `perldoc perlre`
&& #short-circuit logical AND, returns the right value if the left value is true, if the left value is false, the right value is not evaluated, `see perldoc perlop`
/ 1 S/ #match a space, the digit 1, a space, the letter S
)
/^ #match the beginning of the line
\* #quote the *
/x #see `perldoc perlre`
&& #short-circuit logical AND, returns the right value if the left value is true, if the left value is false, the right value is not evaluated, `see perldoc perlop`
/ 1 S/ #match a space, the digit 1, a space, the letter S
)
/home/bin/counts/ABC.txt
>> should mean you open the file for writing and when you open it again it appends the extra data rather then overwriting it.
chomp() gets a string and checks to see if it ends with a line-feed (enter) - if it ends with that - that character is "chopped".
otherwise, nothing happens.
from the man page:
chomp removes any line ending that corresponds
to the current value of $/ (also known as
$INPUT_RECORD_SEPARATOR in the English module). It
returns the number of characters removed. It's
often used to remove the newline from the end of an
input record when you're worried that the final
record may be missing its newline. When in
paragraph mode ($/ = ""), it removes all trailing
newlines from the string. If VARIABLE is omitted,
it chomps $_. Example:
while (<>) {
chomp; # avoid \n on last field
@array = split(/:/);
...
}
You can actually chomp anything that's an lvalue,
including an assignment:
chomp($cwd = `pwd`);
chomp($answer = <STDIN>);
If you chomp a list, each element is chomped, and
the total number of characters removed is returned.