icon Top 9 categories map      RocketAware > Perl >

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

Tips: Browse or Search all pages for efficient awareness of Perl functions, operators, and FAQs.



Home

Search Perl pages


Subjects

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...

    

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

$/ 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;


Source: Perl FAQ: Regexps
Copyright: Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
Next: How do I substitute case insensitively on the LHS, but preserving case on the RHS?

Previous: How can I pull out lines between two patterns that are themselves on different lines?



(Corrections, notes, and links courtesy of RocketAware.com)


[Overview Topics]

Up to: NUL terminated String Comparison and Search




Rapid-Links: Search | About | Comments | Submit Path: RocketAware > Perl > perlfaq6/I_put_a_regular_expression_into_.htm
RocketAware.com is a service of Mib Software
Copyright 2000, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments