in reply to Re: regex patterns
in thread regex patterns

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

Replies are listed 'Best First'.
Re3: regex patterns
by Hofmator (Curate) on Feb 07, 2003 at 21:30 UTC
    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