Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

how read data from file

by rammohan (Acolyte)
on Jan 18, 2014 at 08:30 UTC ( [id://1071076]=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: how read data from file
by CountZero (Bishop) on Jan 18, 2014 at 08:45 UTC
    Just open the file and read it line by line:
    use Modern::Perl; open my $FH, '<', '/home/jack/Desktop/Perl_file.txt' or die "Could not + open file: $!"; while (my $line = <$FH>) { my $char = substr($line, 0, 2); print $char; } close $FH;

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      Thank you.it works perfectly. why you use another CPAN module here.?
        use Modern::Perl is to enable additional features of recent (5.10 or later) versions of Perl and automatically include use strict and use warnings, two very useful pragmas to avoid making silly mistakes. It does some more good things: read all about it at Modern::Perl.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        My blog: Imperial Deltronics
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: how read data from file (how to parse data, use split)
by Anonymous Monk on Jan 18, 2014 at 08:37 UTC
      how to achieve this output using file handling. Means which data in that string,if suppose that data in some other file.How to read that data and how to achieve my above result
Re: how read data from file
by PetreAdi (Acolyte) on Jan 18, 2014 at 12:44 UTC

    Try this

    $filename1="file.txt"; open (DAT, "<$filename1")|| die("Cannot Open File"); @MYFILE = <DAT>; close (DAT); foreach $t (@MYFILE) { $char = substr($t, 0, 2); if (length $t>1) {print "\n $char";} }
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found