FileHandles to string

Discussion in 'Perl' started by Andrew, Jul 10, 2004.

  1. Andrew

    Andrew Guest

    Hi all,
    I am having trouble opening a file and displaying its contents. I have
    built into the code test strings and tried to display them, and all
    have no output (i am assuming that is because they are all
    null-pointers), and the code is part of a cgi.
    Any help would be appreciated, the code is below, and the lines
    commented out are the ones crashing!

    open(File, "> /someWhere/My.txt") || die $errorString="can't
    open";
    @ThreadPairs = <File>;
    foreach $items(@ThreadPairs){
    ($ThreadPosition,$ThreadName)=split(/=/,$items,2);
    $fields{$ThreadPosition}=$ThreadName;
    }
    if($fields{Thread} == 2){ $tempTest="yes"}
    $finalCount = "1" + $fields{Thread};
    for($PosCount = 1; $PosCount < $finalCount; $PosCount++){
    $tempThreadPos = "Thread"."$PosCount";
    $tempThreadName = $fields{$tempThreadPos};
    }
    close(File);
    }

    thanks All
    Andrew
     
    Andrew, Jul 10, 2004
    #1
    1. Advertising

  2. Andrew wrote:
    > Hi all,
    > I am having trouble opening a file and displaying its contents. I have
    > built into the code test strings and tried to display them, and all
    > have no output (i am assuming that is because they are all
    > null-pointers), and the code is part of a cgi.
    > Any help would be appreciated, the code is below, and the lines
    > commented out are the ones crashing!
    >
    > open(File, "> /someWhere/My.txt") || die $errorString="can't
    > open";


    You are opening the file for writing.
    The more standard form would be
    open(File, "> /someWhere/My.txt") or die "can't open file
    /someWhere/My.txt for writing because $!\n";

    > @ThreadPairs = <File>;


    And here you are trying to read from the file. Doesn't seem like a good idea
    to me.

    > foreach $items(@ThreadPairs){


    No "my"?
    Then I guess you aren't using strictures and warnings, either? You should!

    jue
     
    Jürgen Exner, Jul 10, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Phillips

    newbie - Output to multiple Filehandles

    Jeremy Phillips, May 24, 2004, in forum: Perl
    Replies:
    1
    Views:
    2,155
    Jürgen Exner
    May 25, 2004
  2. Andrew

    FileHandles to string

    Andrew, Jul 10, 2004, in forum: Perl
    Replies:
    0
    Views:
    623
    Andrew
    Jul 10, 2004
  3. Andrew

    FileHandles to string

    Andrew, Jul 10, 2004, in forum: Perl
    Replies:
    0
    Views:
    661
    Andrew
    Jul 10, 2004
  4. Sako
    Replies:
    3
    Views:
    5,629
  5. Michael Schmitt

    Reportlab Image object opens filehandles

    Michael Schmitt, Sep 10, 2003, in forum: Python
    Replies:
    4
    Views:
    1,769
    Robin Becker
    Sep 12, 2003
Loading...

Share This Page