Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

I put a regular expression into $/ but it didn't work. What's wrong?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:25 UTC ( [id://659]=perlfaq nodetype: print w/replies, xml ) Need Help??

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:

$/ must be a string, not a regular expression. Awk has to be better for something. :-)

Actually, you could do this if you don't mind reading the whole file into memory:

    undef $/;
    @records = split /your_pattern/, <FH>;

The Net::Telnet module (available from CPAN) has the capability to wait for a pattern in the input stream, or timeout if it doesn't appear within a certain time.

    ## Create a file with three lines.
    open FH, ">file";
    print FH "The first line\nThe second line\nThe third line\n";
    close FH;

    ## Get a read/write filehandle to it.
    $fh = new FileHandle "+<file";

    ## Attach it to a "stream" object.
    use Net::Telnet;
    $file = new Net::Telnet (-fhopen => $fh);

    ## Search for the second line and print out the third.
    $file->waitfor('/second line\n/');
    print $file->getline;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2025-03-27 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (70 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.