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

Re: [PBML] Need help with mysterious code!!

Expand Messages
  • Ingenue
    They don t work in different ways -- they both delete file s contents and create an empty file (not literally, but to the end-user). He just didn t run his
    Message 1 of 6 , Apr 21, 2000
    • 0 Attachment
      They don't work in different ways -- they both delete file's contents and
      create an empty file (not literally, but to the end-user).

      He just didn't run his program correctly or is on drugs.

      [root@operations /home/nikita]# more t.txt
      1
      2
      3
      [root@operations /home/nikita]# more foo2.pl
      #!/usr/bin/perl
      open (In,">t.txt");
      close (In);
      [root@operations /home/nikita]# perl foo2.pl
      [root@operations /home/nikita]# more t.txt
      [root@operations /home/nikita]#

      other-

      [root@operations /home/nikita]# more t.txt
      1
      2
      3
      [root@operations /home/nikita]# more foo.pl
      #!/usr/bin/perl -w
      &aa();
      &bb();
      sub aa{ open (In,">t.txt"); }
      sub bb { close (In); }
      [root@operations /home/nikita]# perl foo.pl
      [root@operations /home/nikita]# more t.txt
      [root@operations /home/nikita]#


      ----- Original Message -----
      From: "Tom Barron" <tbarron@...>
      To: <perl-beginner@egroups.com>
      Sent: Friday, April 21, 2000 4:45 PM
      Subject: Re: [PBML] Need help with mysterious code!!


      > Dan Boger wrote:
      > >
      > > Ingenue wrote:
      > > > ...
      > > yes, that's all very true - I don't think you should write code like
      > > this. However, I still don't know why the two programs work in
      > > different ways..
      >
      > They don't work in different ways on my machine. With both programs,
      > t.txt winds up truncated to 0 bytes. One possibility I can think of is
      > that perhaps in program 2, Antonio had left off the final line
      > terminator and Perl was not processing the last line so that the close
      > never happened. Something like that might explain it.
      >
      > In any case, Antonio, if you're wanting to add information to t.txt
      > without losing what's already there, you need to use the append operator
      > ">>" when you open the file as Ingenue pointed out.
      >
      > rgds,
      > Tom
      >
      > ------------------------------------------------------------------------
      > Good friends, school spirit, hair-dos you'd like to forget.
      > Classmates.com has them all. And with 4.4 million alumni already
      > registered, there's a good chance you'll find your friends here:
      > http://click.egroups.com/1/2885/1/_/12898/_/956360745/
      > ------------------------------------------------------------------------
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.