Search code examples
perlfilewgetseektell

download using wget in perl


New to Perl, hope someone could kindly explain the following questions related to this code:

$url ="some url";
open FH, "wget -q -O- $url|" or die;  
while(<FH>){  
  ...  
}  
  1. what does the the second - in -O- mean?
  2. what does the | in $url | mean?
  3. I tried to do a seek with the FH like this:
 $url ="some url";
 open FH, "wget -q -O- $url|" or die;  
 seek(FH, 14000, 1);  

but if I echo the position with echo tell(FH), I get 0, anyone know why couldn't I seek the FH? Thanks


Solution

  • The -O- argument tells wget to output to standard output (i.e. your console/terminal), not to a file.

    The pipe in the open call is a pipe open. The file handle will be connected to the process's output (in this case, to what wget outputs).

    A tell call on this type of filehandle doesn't really make sens. The underlying thing is a stream, not a file. tell can return different things on streams, it depends on the OS.