Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] problem in reading data from file (file handling )

Expand Messages
  • Ken at Home
    hi all , i have a probelm in reading text from the file and writing into file.i i will describe my probelm briefly i am doing this in windows os i installed
    Message 1 of 5 , May 2, 2006
    • 0 Attachment
      hi all ,

      i have a probelm in reading text from the file and writing
      into file.i i will describe my probelm briefly

      i am doing this in windows os
      i installed perl in c: directory and kepy my programs in folder
      inside c: directory ( perlsrik : directory name).

      my code goes on like this
      --------------------------------------------------
      #!/usr/local/bin/perl

      open (MYFILE, 'file_me.txt');

      while (<MYFILE>)
      {
      chomp;
      print "$_\n";

      }

      close (MYFILE);
      ---------------------------------------

      so i gave my program name as my_me.pl and the text where i stored
      data is in the same folder as my program is there and its name is
      file_me.txt. .probelm is i have written some text into that while i
      am using above program to just read the data but i am unable to get it


      will be plz help me in solving this problem.

      srikanth



      If I understand you correctly, you are writing to the file with some other
      application while your Perl prog is trying to read it. At some time the
      file could be quite likely be empty as the writing application deletes as
      part of (re)writing.
      If that is truly what you are doing you need to use flock while reading or
      better use a separate semaphore file which the writing application creates
      after writing. The Perl looks for the existance of the semaphore before
      opening the file. Having seen the semaphore it then reads the .txt file and
      then deletes the smaphore.
      Personally I would be more explicit about the path to the file
      for example
      './file_me.txt'
      or
      '/perlsrik/file_me.txt'
    • KalyanRaj
      Hi , It looks that your program works fine when I executed on my system Probably you re running the program in a different way.. Try running from
      Message 2 of 5 , May 2, 2006
      • 0 Attachment
        Hi ,

        It looks that your program works fine when I executed on my system

        Probably you're running the program in a different way..

        Try running from c:\perl\eg\your_folder\your_perl_program

        Put your text file in the same location where you're running your perl
        program..

        Hope this helps,
        Kalyan

        -----Original Message-----
        From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
        On Behalf Of Ken at Home
        Sent: Wednesday, May 03, 2006 12:11 PM
        To: srikanth_99eee; perl-beginner@yahoogroups.com
        Subject: Re: [PBML] problem in reading data from file (file handling )



        hi all ,

        i have a probelm in reading text from the file and writing
        into file.i i will describe my probelm briefly

        i am doing this in windows os
        i installed perl in c: directory and kepy my programs in folder
        inside c: directory ( perlsrik : directory name).

        my code goes on like this
        --------------------------------------------------
        #!/usr/local/bin/perl

        open (MYFILE, 'file_me.txt');

        while (<MYFILE>)
        {
        chomp;
        print "$_\n";

        }

        close (MYFILE);
        ---------------------------------------

        so i gave my program name as my_me.pl and the text where i stored
        data is in the same folder as my program is there and its name is
        file_me.txt. .probelm is i have written some text into that while i
        am using above program to just read the data but i am unable to get it


        will be plz help me in solving this problem.

        srikanth



        If I understand you correctly, you are writing to the file with some other
        application while your Perl prog is trying to read it. At some time the
        file could be quite likely be empty as the writing application deletes as
        part of (re)writing.
        If that is truly what you are doing you need to use flock while reading or
        better use a separate semaphore file which the writing application creates
        after writing. The Perl looks for the existance of the semaphore before
        opening the file. Having seen the semaphore it then reads the .txt file and
        then deletes the smaphore.
        Personally I would be more explicit about the path to the file
        for example
        './file_me.txt'
        or
        '/perlsrik/file_me.txt'









        Unsubscribing info is here:
        http://help.yahoo.com/help/us/groups/groups-32.html
        Yahoo! Groups Links
      • mangesh HANKARE
        Can u use different File Handler for readig and writting the file like MYFILE and MYFILE1. KalyanRaj wrote: Hi , It looks that
        Message 3 of 5 , May 3, 2006
        • 0 Attachment
          Can u use different File Handler for readig and writting the file like MYFILE and MYFILE1.

          KalyanRaj <kalyanrajs@...> wrote: Hi ,

          It looks that your program works fine when I executed on my system

          Probably you're running the program in a different way..

          Try running from c:\perl\eg\your_folder\your_perl_program

          Put your text file in the same location where you're running your perl
          program..

          Hope this helps,
          Kalyan

          -----Original Message-----
          From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
          On Behalf Of Ken at Home
          Sent: Wednesday, May 03, 2006 12:11 PM
          To: srikanth_99eee; perl-beginner@yahoogroups.com
          Subject: Re: [PBML] problem in reading data from file (file handling )



          hi all ,

          i have a probelm in reading text from the file and writing
          into file.i i will describe my probelm briefly

          i am doing this in windows os
          i installed perl in c: directory and kepy my programs in folder
          inside c: directory ( perlsrik : directory name).

          my code goes on like this
          --------------------------------------------------
          #!/usr/local/bin/perl

          open (MYFILE, 'file_me.txt');

          while (<MYFILE>)
          {
          chomp;
          print "$_\n";

          }

          close (MYFILE);
          ---------------------------------------

          so i gave my program name as my_me.pl and the text where i stored
          data is in the same folder as my program is there and its name is
          file_me.txt. .probelm is i have written some text into that while i
          am using above program to just read the data but i am unable to get it


          will be plz help me in solving this problem.

          srikanth



          If I understand you correctly, you are writing to the file with some other
          application while your Perl prog is trying to read it. At some time the
          file could be quite likely be empty as the writing application deletes as
          part of (re)writing.
          If that is truly what you are doing you need to use flock while reading or
          better use a separate semaphore file which the writing application creates
          after writing. The Perl looks for the existance of the semaphore before
          opening the file. Having seen the semaphore it then reads the .txt file and
          then deletes the smaphore.
          Personally I would be more explicit about the path to the file
          for example
          './file_me.txt'
          or
          '/perlsrik/file_me.txt'









          Unsubscribing info is here:
          http://help.yahoo.com/help/us/groups/groups-32.html
          Yahoo! Groups Links







          Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html



          SPONSORED LINKS
          Basic programming language C programming language Computer programming languages The c programming language C++ programming language Software programming language

          ---------------------------------
          YAHOO! GROUPS LINKS


          Visit your group "perl-beginner" on the web.

          To unsubscribe from this group, send an email to:
          perl-beginner-unsubscribe@yahoogroups.com

          Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


          ---------------------------------





          bye....


          ---------------------------------
          Yahoo! India Answers: Share what you know. Learn something new. Click here

          [Non-text portions of this message have been removed]
        • KalyanRaj
          Yes, you can use different filehandlers to read and write to a file. #!/usr/local/bin/perl open (MYFILE, file_me.txt ); open (OUTFILE, out_me.txt ); while
          Message 4 of 5 , May 3, 2006
          • 0 Attachment
            Yes, you can use different filehandlers to read and write to a file.

            #!/usr/local/bin/perl

            open (MYFILE, 'file_me.txt');
            open (OUTFILE,'>>out_me.txt');
            while (<MYFILE>)
            {
            chomp;
            print OUTFILE "$_\n";

            }

            close (MYFILE);
            close (OUTFILE);

            Kalyan

            -----Original Message-----
            From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
            On Behalf Of mangesh HANKARE
            Sent: Wednesday, May 03, 2006 6:17 PM
            To: perl-beginner@yahoogroups.com
            Subject: RE: [PBML] problem in reading data from file (file handling )

            Can u use different File Handler for readig and writting the file like
            MYFILE and MYFILE1.

            KalyanRaj <kalyanrajs@...> wrote: Hi ,

            It looks that your program works fine when I executed on my system

            Probably you're running the program in a different way..

            Try running from c:\perl\eg\your_folder\your_perl_program

            Put your text file in the same location where you're running your perl
            program..

            Hope this helps,
            Kalyan

            -----Original Message-----
            From: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com]
            On Behalf Of Ken at Home
            Sent: Wednesday, May 03, 2006 12:11 PM
            To: srikanth_99eee; perl-beginner@yahoogroups.com
            Subject: Re: [PBML] problem in reading data from file (file handling )



            hi all ,

            i have a probelm in reading text from the file and writing
            into file.i i will describe my probelm briefly

            i am doing this in windows os
            i installed perl in c: directory and kepy my programs in folder
            inside c: directory ( perlsrik : directory name).

            my code goes on like this
            --------------------------------------------------
            #!/usr/local/bin/perl

            open (MYFILE, 'file_me.txt');

            while (<MYFILE>)
            {
            chomp;
            print "$_\n";

            }

            close (MYFILE);
            ---------------------------------------

            so i gave my program name as my_me.pl and the text where i stored
            data is in the same folder as my program is there and its name is
            file_me.txt. .probelm is i have written some text into that while i
            am using above program to just read the data but i am unable to get it


            will be plz help me in solving this problem.

            srikanth



            If I understand you correctly, you are writing to the file with some other
            application while your Perl prog is trying to read it. At some time the
            file could be quite likely be empty as the writing application deletes as
            part of (re)writing.
            If that is truly what you are doing you need to use flock while reading or
            better use a separate semaphore file which the writing application creates
            after writing. The Perl looks for the existance of the semaphore before
            opening the file. Having seen the semaphore it then reads the .txt file and
            then deletes the smaphore.
            Personally I would be more explicit about the path to the file
            for example
            './file_me.txt'
            or
            '/perlsrik/file_me.txt'









            Unsubscribing info is here:
            http://help.yahoo.com/help/us/groups/groups-32.html
            Yahoo! Groups Links







            Unsubscribing info is here:
            http://help.yahoo.com/help/us/groups/groups-32.html



            SPONSORED LINKS
            Basic programming language C programming language Computer
            programming languages The c programming language C++ programming
            language Software programming language

            ---------------------------------
            YAHOO! GROUPS LINKS


            Visit your group "perl-beginner" on the web.

            To unsubscribe from this group, send an email to:
            perl-beginner-unsubscribe@yahoogroups.com

            Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


            ---------------------------------





            bye....


            ---------------------------------
            Yahoo! India Answers: Share what you know. Learn something new. Click here

            [Non-text portions of this message have been removed]



            Unsubscribing info is here:
            http://help.yahoo.com/help/us/groups/groups-32.html
            Yahoo! Groups Links
          • merlyn@stonehenge.com
            ... KalyanRaj Yes, you can use different filehandlers to read and write to a file. KalyanRaj #!/usr/local/bin/perl KalyanRaj open (MYFILE, file_me.txt );
            Message 5 of 5 , May 3, 2006
            • 0 Attachment
              >>>>> "KalyanRaj" == KalyanRaj <kalyanrajs@...> writes:

              KalyanRaj> Yes, you can use different filehandlers to read and write to a file.
              KalyanRaj> #!/usr/local/bin/perl

              KalyanRaj> open (MYFILE, 'file_me.txt');
              KalyanRaj> open (OUTFILE,'>>out_me.txt');

              Always check the return value of open.

              open MYFILE, "file_me.txt" or die "Cannot open file_me.txt: $!";

              and so on.

              --
              Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
              <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
              Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
              See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
            Your message has been successfully submitted and would be delivered to recipients shortly.