Just another Perl shrine PerlMonks

### Re^2: Delete all but the most recent backup file

by jagexCoder (Novice)
 on Jan 29, 2013 at 04:34 UTC ( #1015799=note: print w/replies, xml ) Need Help??

Hi there! So I did some reading and have some queries:

(1) Why is the Schwartzian transform read from bottom to top? Since in procedural programming it's usually top to bottom. Reading the Wikipedia article it makes sense however curious as to the behavior of this method.

(2)Could you please explain the expression used in map{}? { my \$stat = stat \$_; [ \$_, \$stat->mtime ] } I understand that a scalar variable called \$stat has been defined to the 'default variable' \$_. My understanding is that when map() is run (the map on the bottom) it evaluates the expression within {} for each element in @fileNames and stores it in the default variable? So would this mean that each time an element is passed the default variable changes?

(3) Further to (2), I understand that "\$stat->mtime" is getting the last modified time since epoch for each value of \$stat, my understanding is that each time the next element from the array is passed the mtime for that particular \$stat is obtained. So what's the meaning of  [ \$_, \$stat->mtime ]. Since there's a comma separating the two.

(4) The semicolon in { my \$stat = stat \$_; [ \$_, \$stat->mtime ] } is separating the two statements within this single expression. Is that correct?

(5) I understand that in sort { \$b->[1] <=> \$a->[1] } a descending numeric sort is being performed. However what I don't get is the [1] \$b and \$a both share. Also what's the relationship between \$b and \$a? I found an example of this type of sort on the net however it did not explain why \$b and \$a are used. Do they simply represent two different locations in a list?

(6)The  map \$_->[0] does not appear to follow the format map({expression}, list). How is this different to the standard map function?

Thanks for your help! Sorry for these questions just clarifying my doubts.

Create A New User
Node Status?
node history
Node Type: note [id://1015799]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-06-20 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (116 votes). Check out past polls.

Notices?