PerlPhi has asked for the wisdom of the Perl Monks concerning the following question:
hi,,,thanks guys for the wisdom about my earlier post. also, i learnt from my mistake... pardon me for that. but anyway... im getting into trouble with the special underscore filehandle.
my delimma was all about the special underscore filehandle "_".
codes from the book "Llama book" as follows:
#!/perl/bin/perl use strict; my @original_files = qw/ fred barney betty wilma pebbles dino bamm-bam +m /; my @big_old_files; # The ones we want to put on back +up tapes foreach (@original_files) { push @big_old_files, $_ if (-s) > 100_000 and -A _ > 90; # More efficient than before }
the program logic seems to be very clear, right? an excerpt explanation from the book goes this way:
"We used the default of $_ for the first test; this is as more efficient (except perhaps for the programmer), and it gets the data from the operating system. The second test uses the magic _ filehandle. For this test, the data left around after getting the file's size are used, which are what we want."
the explanation entry point was from the lines of file test "if (-s) > 100_000 and -A _ > 90;". actually it runs very well, what i don't understand is from that "_" after "-A". it says that the value of the special filehandle was the data left around after getting the file's size are used "(-s) > 100_000".
QUESTION NO. 1: what are these data that was left after getting the file size? is it the filename? or what?
on my wild understanding of this (but im not that sure) is when we use the file test "-s", maybe the function under "-s" uses the stat function as a sub function. because we all knew that the stat function returns the number of links, file size, accessed time, modified time, time created, etc. of a certain file. so when "-A _" was executed the accessed time "-A" gets the data from the special filehandle "_" in which the special filehandle has those data assigned from "-s" except for the file size because that data was pulled when "-s" was executed.
QUESTION NO. 2: was my wild undersderstanding correct? if not, then what would be the right thing?
QUESTION NO. 3: i never tried using the special filehandle righteously on my own yet, does the special filehandle be used only on one line or could it be used down the other codes of my program?
because when i tried to print on the screen the values that accompanied the special filehandle, i get nothing... the codes were as follows:
#!/perl/bin/perl use strict; my @original_files = qw/ fred /; my @big_old_files; foreach (@original_files) { if ((-s) > 0 and -A _ > 0) { push @big_old_files, $_; print _; } }
maybe i was wrong of printing with it because in the first place it is only a FILEHANDLE... but then where are the data left be found? maybe that special filehandle is only an identifier for a struct (like in C)... oh! i just don't get it exactly. TO BROAD TO GUESS, TO NARROW TO FIND THE CLUE...
that's all folks... i hope you could get me out into trouble. thanks again in advance... i hope my format fits well... keep deep and dark!
From: PerlPhi
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: About Special Underscore Filehandle
by merlyn (Sage) on May 04, 2007 at 17:51 UTC | |
by PerlPhi (Sexton) on May 04, 2007 at 18:39 UTC | |
Re: About Special Underscore Filehandle
by liverpole (Monsignor) on May 04, 2007 at 17:50 UTC | |
by merlyn (Sage) on May 04, 2007 at 17:52 UTC | |
Re: About Special Underscore Filehandle
by Fletch (Bishop) on May 04, 2007 at 18:10 UTC |