in reply to regex patterns

Unless $/ is undefined somewhere before in your code (some part you didn't show us), $text=<MAT> only reads in one line of the file - which is probably not what you want.

To read in the whole file, use something like: my $text = do { local $/; <MAT> };

-- Hofmator

Replies are listed 'Best First'.
Re: Re: regex patterns
by dogbert (Scribe) on Feb 07, 2003 at 21:14 UTC
    I can seem to get the  my $text = do { local $/; <MAT> }; to work. maybe you could advise me further. Here is my complete code.
    #! perl #! usr/bin/local/perl $file = shift; $pattern = shift; open(MAT, "<$file") or die "bad file name"; my $text = do ( local $/: <MAT> ); while($text =~ /\Q$pattern\E/g) { $x += 1; } print "found $x matches\n"; close(MAT);
    that crashes on me so here is my code that works but doesn't read the whole file.
    #! perl #! usr/bin/local/perl $file = shift; $pattern = shift; open(MAT, "<$file") or die "bad file name"; $text = <MAT>; while($text =~ /\Q$pattern\E/g) { $x += 1; } print "found $x matches\n"; close(MAT);
    thanks

    Height : varies depending on my speed relative to the observer Weight : is a sensation caused by the gravitational wrapping of time-space Age : time is only a persistent illusion

      well, in your complete code you have  do ( local $/: <MAT> ) while I wrote  do { local $/; <MAT> } can you spot the two subtle differences ;-)

      There are curly braces not parentheses and there is a semicolon not a colon between the two expressions.

      You say that your code crashes on you. It would be good if you supplied the error message you are getting. Crashing sounds so much like a core dump - which is never supposed to happen.

      Hth

      -- Hofmator

        all i have to say for my self is duh! lol thanks

        Height : varies depending on my speed relative to the observer Weight : is a sensation caused by the gravitational wrapping of time-space Age : time is only a persistent illusion