in reply to Re: I have a perl snippet. And I need help understanding it. Can you help answer these questions.
in thread I have a perl snippet. And I need help understanding it. Can you help answer these questions.

Thank-you so much Dave! I am really grateful to you. I sort agree this is a bad way to study Perl. But then again, this is a work that fell in my lap, and they just expect me to do it ASAP whether I know Perl or not. I had to understand this code in order to make the required hacks/modifications to meet my new specs.

I got the books you have told me to fetch from the company library :). Btw, to answer your question why is the scalar value nested in so deep, that is the way the log file is which I need to dig out the data from. It's from a Universal format for Scientific data called NetCDF unfortunately.

For Question 3. I want to write down what I understood. I know parse0FFA is a function inside the .pm file Fruits.pm and that obj is a reference to that pm file and by $obj->parse0FFA() I am able to fetch a sub from that pm file. Correct me if I am wrong thus far.

Now, you used a term 'deference' which I didn't understand in your answer. Here. Lets try again. Are you telling me sir that in

$fruitobj=$obj->parse0FFA($BananaNum);

the number of Bananapackets is given to the subroutine parse0FFA() which is in the pm file and the result (or return) of that function is now stored in the scalar variable $fruitobj. And that $obj is only a reference (what we call objects in C or C++) to the function parse0FFA ? Is that a correct understanding. I think I am getting the hang of Perl now. At-least syntax and coding style. And finally for Q7. I fully understand your answer. Thankyou. Please read your answer again. Now, I have a question. Is the $obj->{timestamp} the reference $obj from the logprocess.pl file or is this a local reference $obj from the .pm file? I think it's the latter, but just wanted to check. Thanks again!

  • Comment on Re^2: I have a perl snippet. And I need help understanding it. Can you help answer these questions.

Replies are listed 'Best First'.
Re^3: I have a perl snippet. And I need help understanding it. Can you help answer these questions.
by aaron_baugher (Curate) on Nov 09, 2011 at 06:25 UTC

    The word was "dereference," which means "to get at the thing pointed to by the reference." If you're familiar with C, references are a lot like pointers, except that you can't do arithmetic on them; they're essentially read-only. So for instance:

    my @array = qw(a b c d); # create an array print $array[2]; # prints 'c' my $arrayref = \@array; # create a reference to the array print $arrayref->[2]; # prints 'c'. The arrow is required when # getting an element of an array or hash # pointed to by a reference my @newarray = @{$arrayref}; # dereference $arrayref to get at the # array it points to, and # copy it to @newarray print $newarray[2]; # prints 'c'

    Aaron B.
    My Woefully Neglected Blog, where I occasionally mention Perl.