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.
qiang8Asked:
Who is Participating?
 
shlomoyConnect With a Mentor Commented:
line 3:

take the string at $_
cut is into several strings, cut by the ':' character.
substrings will be put in the array named @array
0
 
shlomoyCommented:
LOG refers to the file
/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.

0
 
qiang8Author Commented:
Thanks. How about question 2.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
shlomoyCommented:
>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.
0
 
shlomoyCommented:
do I win the 100 points? :-)
0
 
qiang8Author Commented:
Thank you very much. Pls lock the answer so that I can award u points and a good grade.
0
 
qiang8Author Commented:
Thank you very much. Pls lock the answer so that I can award u points and a good grade.
0
 
qiang8Author Commented:
Thank you.
0
 
shlomoyCommented:
Anytime.
0
 
intaniaCommented:
How about line 1 of Q2?
I'm also beginner.
0
 
ozoCommented:
(
/^     #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
)
0
All Courses

From novice to tech pro — start learning today.