View Single Post
  #4  
Old 12-13-2003, 04:18 PM
SaguratuS
Sarnak
 
Join Date: Dec 2003
Location: Rocky Mountains, CO
Posts: 64
Default

sorry, had to post it from the comp which had it on it.
Code:
    ### use 5.005;
    use IO::Scalar;
    $data = "My message:\n";

    ### Open a handle on a string, and append to it:
    $SH = new IO::Scalar \$data;
    $SH->print("Hello");       
    $SH->print(", world!\nBye now!\n");  
    print "The string is now: ", $data, "\n";

    ### Open a handle on a string, read it line-by-line, then close it:
    $SH = new IO::Scalar \$data;
    while (defined($_ = $SH->getline)) { 
	print "Got line: $_";
    }
    $SH->close;

    ### Open a handle on a string, and slurp in all the lines:
    $SH = new IO::Scalar \$data;
    print "All lines:\n", $SH->getlines; 

    ### Get the current position (either of two ways):
    $pos = $SH->getpos;         
    $offset = $SH->tell;  

    ### Set the current position (either of two ways):
    $SH->setpos($pos);        
    $SH->seek($offset, 0);

    ### Open an anonymous temporary scalar:
    $SH = new IO::Scalar;
    $SH->print("Hi there!");
    print "I printed: ", ${$SH->sref}, "\n";      ### get at value
Reply With Quote