in reply to Re: how to extract multiple pattern into array
in thread how to extract multiple pattern into array

... local $/ = ""; ... will cause the entire file to be slurped ...

From  perldoc -v "$/" (see also perlvar):

HANDLE->input_record_separator( EXPR ) $INPUT_RECORD_SEPARATOR $RS $/ The input record separator ... treating empty lines as a terminator if set to the null string + ... You may set it to ... "undef" to read through the end of file. ...
The idiomatic Perl statement would be something like
    my $entire_data = do { local $/;  <$filehandle>; };
(if you don't use something like File::Slurp).


Give a man a fish:  <%-(-(-(-<

Replies are listed 'Best First'.
Re^3: how to extract multiple pattern into array
by Anonymous Monk on Feb 02, 2015 at 20:27 UTC

    Oops, thanks :-)

      I had finished my code , thank you for your help!
      #!/usr/bin/perl use 5.010; use strict; use warnings; my $reS = qr{\..*?\s*?\(\s*?([0-9a-zA-Z_]*?)\s*?\)}s; my $reM = qr{\..*?\s*?\(\s*?\{\s*?(.*?)\s*?\}\s*?\)}s; open my $fh, "analog_atop_inst.v" or die $!; my @fields=(); my @matchM=(); my @matchS=(); my @allfield=(); my $entire_dataS = ''; my $entire_dataM = ''; while (<$fh>) { chomp; $entire_dataS .= $_; $entire_dataM .= $_; } #print $entire_data; while (1) { if ($entire_dataS =~ /$reS/){ push @matchS, $1; $entire_dataS = $';} else { last;} } while (1) { if ($entire_dataM =~ /$reM/){ push @matchM, $1; $entire_dataM = $';} else { last;} } #say "@@@@@@@@@@@@ MatchS @@@@@@@@@@@@@@@@@"; foreach my $fieldS (@matchS){ push @allfield, $fieldS ; } #say "############ MatchM #################"; foreach my $fieldM (@matchM){ my @fieldsplit = split / ,\s+/, $fieldM; foreach my $fieldMs (@fieldsplit){ push @allfield, $fieldMs ; } } foreach my $fieldT (@allfield){ say $fieldT; }