matching several occurences of pattern in same line in Perl?
Hey,
im doing an assignment for pel and im having a bit of trouble. What im trying to do is search a piece of text for any email addresses or URLs and then printing them out in the program.
This is my code:
#!/usr/bin/perl
use strict;
use warnings;
my@matches;
while(<>)
{
if(@matches = m/(\.\&&!\s+)(@)(\w|_|-)/g)
{
foreach my $match(@matches)
{
print"$match\n";
}
}
}
my@matches1
while(<>)
{
if(@matches1 =m/(http|https|telnet|gopher|imap|file)(://)/g)
{
foreach my$match1(@matches1)
{
print"$match\n";
}
}
}
but i am getting the following error
"my" variable @matches1 masks earlier declaration in same statement at assignmen
t_2.plx line 22.
syntax error at assignment_2.plx line 19, near ")
{"
Global symbol "@matches1" requires explicit package name at assignment_2.plx lin
e 20.
Execution of assignment_2.plx aborted due to compilation errors.
any ideas whats up?im really lost!!
its perl, not java :-)
nope its not, changed that....added the semicolon
Thanks ill try using the while loop, but the error is exactly the on i get....copied and pasted exactly
|