What means ($_ =~ m/\ <.*\ >/g) ? (perl)
What means ($_ =~ m/\ <.*\ >/g) ? (perl)
(OP)
I’m an English major and for some reason my professor makes us learn about perl.
It’s just really hard to grasp for me and help would be greatly appreciated.
I already know that this m/ < means that “does this line contain “<“ same goes with “>” but what is meant by “.*”??
use strict;
use warnings;
my $k = "";
print "running ...\n";
open (IN,"auste-north-1522.txt");
open (OUT,">outfile4.txt");
while (<IN>) {
$_ =~ s/(\<i\>)|(\<\/i\>)//g;
print OUT $_ unless ($_ =~ m/\<.*\>/g);
}
close (IN);
close (OUT);
print "Press the return/enter key to finish.";
$k = <STDIN>
It’s just really hard to grasp for me and help would be greatly appreciated.
I already know that this m/ < means that “does this line contain “<“ same goes with “>” but what is meant by “.*”??
use strict;
use warnings;
my $k = "";
print "running ...\n";
open (IN,"auste-north-1522.txt");
open (OUT,">outfile4.txt");
while (<IN>) {
$_ =~ s/(\<i\>)|(\<\/i\>)//g;
print OUT $_ unless ($_ =~ m/\<.*\>/g);
}
close (IN);
close (OUT);
print "Press the return/enter key to finish.";
$k = <STDIN>
RE: What means ($_ =~ m/\ <.*\ >/g) ? (perl)
Those are 2 different metacharacters :
- . means any character
- * means the previous entity 0 or more times
You can find them documented in the perlre manual's Metacharacters section.Some examples :
'abc' =~ m/<.*>/ # not matches, presence of < and > is mandatory
'a><bc' =~ m/<.*>/ # not matches, < and > must occur in that order
'a<>bc' =~ m/<.*>/ # matches, .* quantifier allows any number of character between < and >
'a<b>c' =~ m/<.*>/ # same
'a<bc>' =~ m/<.*>/ # same
'a<<>>' =~ m/<.*>/ # matches, . accepts any character, including < and >
'<>' =~ m/<.*>/ # matches, no other character's presence is required
'<>a<>' =~ m/<.*>/ # matches, multiple < ... > subsequences may occur
Additional notes :
Feherke.
feherke.github.io