Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

How to read directories from the text file using perl?

by finddata (Sexton)
on Mar 23, 2017 at 04:50 UTC ( #1185541=perlquestion: print w/replies, xml ) Need Help??

finddata has asked for the wisdom of the Perl Monks concerning the following question:

I have the text file named as data.txt.

Now i like to read the line from data.txt in which the line starts with ZERO contains the directory path?

How can i do it?

i know to read the directory which as follows:-

I couldnt make the correct code for the above requirements

code which i have tried

use Cwd qw(realpath); print "'$0' is '", realpath($0), "'\n";

data.txt

a { ZERO:../p/ts/DEMO/ect }

Replies are listed 'Best First'.
Re: How to read directories from the text file using perl?
by poj (Abbot) on Mar 23, 2017 at 07:09 UTC
    I couldnt make the correct code for the above requirements
    #!/usr/bin/perl; use strict; # I have the text file named as data.txt. my $infile = 'data.txt'; # Now i like to read the line from data.txt open IN,'<',$infile or die "$!"; print "Reading from '$infile'\n"; my $dir; while (<IN>){ chomp; # in which the line # starts with ZERO # contains the directory path? if (/^ZERO:(.*)/){ $dir = $1; } } close IN; print "Directory is '$dir'\n";

    What's the problem, which part couldn't you do ?

    poj
Re: How to read directories from the text file using perl?
by davido (Cardinal) on Mar 23, 2017 at 06:04 UTC

    FindBin is probably a more appropriate choice than Cwd for this purpose.


    Dave

      But the FindBin will read the folders directly from the location.How it will read from one text file?
        Why not copy/paste from your previous programs or perlintro?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1185541]
Approved by beech
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2019-12-09 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?