How to Display full path and line by line from array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandhya2006
    New Member
    • Dec 2006
    • 11

    How to Display full path and line by line from array

    hiiiiiiiii Can Any one Help me.....
    I just printed the filename only by using this code .But i want to print the whole path of the file and which should be printed in line by line.Pls help me

    #!usr/bin/perl
    #use Cwd 'abs_path';
    $var="d:/www.indiantempl es.com";

    opendir(str,$va r);
    @file=readdir(s tr);

    #my $abs_p=abs_path ($var);
    #print $abs_p,"\n";
    for($i=2;$i<125 ;$i++)
    {


    open(Tr,">sec.t xt");
    print Tr @file[2..125],"\n";

    close(Tr);
    }

    print str $var ."\n";
    close(str);
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Straight from the documentation for readdir:



    Code:
    #!usr/bin/perl
    
    use strict;
    
    my $dir = "d:/www.indiantemples.com";
    
    opendir(DIR, $dir) or die "can't opendir $dir: $!";
    my @files = readdir(DIR);
    closedir(DIR);
    
    foreach (@files) {
    	print "$dir/$_\n";
    }

    Comment

    • sandhya2006
      New Member
      • Dec 2006
      • 11

      #3
      Thank YOu So much Mr.Miller for giving that code ,but i printd that location as my way,but now i want to know my code only take the files in the main folder ,but i wat to take the location from the subfolders and its files also.cal u help me.

      this is my code
      #!usr/bin/perl
      #use strict;
      my $var="d:/www.indiantempl es.com/";
      opendir(str,$va r);
      @file=readdir(s tr);
      close(str);
      while ($line = <@file>)
      {
      # if ($line =~ /html/)
      # {
      foreach($line)
      {
      open(Tr,">sec.t xt");

      }
      for($a=2;$a<125 ;$a++)
      {
      print Tr $var, @file[$a],"\n";
      }

      # }



      }

      Comment

      • miller
        Recognized Expert Top Contributor
        • Oct 2006
        • 1086

        #4
        Originally posted by sandhya2006
        cal u help me.
        No, I'm sorry, but I can't help you. I can't even understand what you're asking unfortunately. And I have a feeling that even if I did, I would not be inclined to just gift you code. I believe that what you are trying to do is fairly simple, so I suggest that you simply start with reading the docs, and only ask a question when you run into a specific problem.

        Good luck.

        Comment

        • anonymous
          Banned
          New Member
          • Sep 2005
          • 99

          #5
          Maybe File::Spec->rel2abs is what you're looking for.

          Comment

          Working...