Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What means ($_ =~ m/\ <.*\ >/g) ? (perl)

Status
Not open for further replies.

Ave_Y

Programmer
Jan 26, 2023
1
0
0
DE
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>
 
Hi

Ave_Y said:
but what is meant by “.*”?
Those are 2 different metacharacters :
[ul]
[li][tt].[/tt] means any character[/li]
[li][tt]*[/tt] means the previous entity 0 or more times[/li]
[/ul]
You can find them documented in the perlre manual's Metacharacters section.

Some examples :
[tt]'abc' =~ m/<.*>/  [/tt] [gray]# not matches, presence of < and > is mandatory[/gray]
[tt]'a><bc' =~ m/<.*>/[/tt] [gray]# not matches, < and > must occur in that order[/gray]
[tt]'a<>bc' =~ m/<.*>/[/tt] [gray]# matches, .* quantifier allows any number of character between < and >[/gray]
[tt]'a<b>c' =~ m/<.*>/[/tt] [gray]# same[/gray]
[tt]'a<bc>' =~ m/<.*>/[/tt] [gray]# same[/gray]
[tt]'a<<>>' =~ m/<.*>/[/tt] [gray]# matches, . accepts any character, including < and >[/gray]
[tt]'<>' =~ m/<.*>/   [/tt] [gray]# matches, no other character's presence is required[/gray]
[tt]'<>a<>' =~ m/<.*>/[/tt] [gray]# matches, multiple < ... > subsequences may occur[/gray]

Additional notes :
[ul]
[li]There is no reason to escape the < and > characters[/li]
[li]In this situation there is no point in using the [tt]g[/tt] modifier ( documented in the perlre manual's Modifiers section, Other Modifiers subsection )[/li]
[/ul]


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top