Beginner of Beginner getting an error

Beginner of Beginner getting an error

Post by 4everspor » Fri, 04 Mar 2011 04:25:11


Hi Guys,

I have this script:

#!/usr/bin/perl
# track, find email addresses in emails,
# writes them to /var/opt/ITrootmail/bad/ with a date
# set up as a pipe for procmail or use with Pine
$now = `date`;

# find included email-like addresses
while ($line = <STDIN>) {
if ($line =~ /\b([\w_\-\.]+ at [\w_\-\.]+)\b/) {
# exclude email addresses not needed
(next) if ( $1 =~ /\d{8,}/ );
(next) if ( $1 =~ /postmaster/i );
(next) if ( $1 =~ /DAEMON/i );
(next) if ( $1 =~ /nobody/i );
(next) if ( $1 =~ /localhost/i );
push( at names,$1);
}
}
close (STDIN);
foreach $idx (0 .. $#names) {
$uniq{$names[$idx]}=1;
}
undef at names;
foreach $item (keys %uniq) {
push ( at names,$item);
}
foreach $address (0 .. $#names) {
open (RECORD, ">>/var/opt/ITrootmail/bad/
$names[$address]");
print (RECORD $now);
close RECORD;
}

I'm getting these two errors:

Type of arg 1 to push must be array (not subroutine entry) at /etc/opt/
ITrootmail/track line 16, near "$1)"
Type of arg 1 to push must be array (not subroutine entry) at /etc/opt/
ITrootmail/track line 25, near "$item)"

Any idea?

Thanks
 
 
 

Beginner of Beginner getting an error

Post by uri » Fri, 04 Mar 2011 08:33:10

>>>>> "T" == TaP < XXXX@XXXXX.COM > writes:

T> Hi Guys,
T> I have this script:

T> #!/usr/bin/perl
T> # track, find email addresses in emails,
T> # writes them to /var/opt/ITrootmail/bad/ with a date
T> # set up as a pipe for procmail or use with Pine
T> $now = `date`;

why are you executing a shell command when perl can do that for you with
localtime?

and why is everything indented when you don't have any subs? code should
be at the left if possible and then you indent from there.

T> # find included email-like addresses
T> while ($line = <STDIN>) {
T> if ($line =~ /\b([\w_\-\.]+ at [\w_\-\.]+)\b/) {
T> # exclude email addresses not needed
T> (next) if ( $1 =~ /\d{8,}/ );
T> (next) if ( $1 =~ /postmaster/i );
T> (next) if ( $1 =~ /DAEMON/i );
T> (next) if ( $1 =~ /nobody/i );
T> (next) if ( $1 =~ /localhost/i );

why are those next's in parens? no need for it. nor are the parens
needed around the conditionals.


T> push( at names,$1);

what is 'at'?? did you means @names? i know it should be @names so where
did this code come from with that strange spam hiding @ to at thing?

T> }
T> }
T> close (STDIN);

why close STDIN? no need.

T> foreach $idx (0 .. $#names) {
T> $uniq{$names[$idx]}=1;
T> }

gack, that is bad.

@uniq{ @names } = (1) x @names ;

T> undef at names;

again the 'at' names. someone ran this through a stupid address hider

T> foreach $item (keys %uniq) {
T> push ( at names,$item);
T> }

and again.

T> foreach $address (0 .. $#names) {
T> open (RECORD, ">>/var/opt/ITrootmail/bad/
T> $names[$address]");
T> print (RECORD $now);
T> close RECORD;
T> }

T> I'm getting these two errors:

T> Type of arg 1 to push must be array (not subroutine entry) at /etc/opt/
T> ITrootmail/track line 16, near "$1)"
T> Type of arg 1 to push must be array (not subroutine entry) at /etc/opt/
T> ITrootmail/track line 25, near "$item)"

T> Any idea?

plenty. you didn't write this code. you should learn perl and not use
code from places if you don't understand it. otherwise you will always
be asking for help and can't do the work yourself.

uri

--
Uri Guttman ------ XXXX@XXXXX.COM -------- http://www.yqcomputer.com/ --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://www.yqcomputer.com/ ---------

 
 
 

Beginner of Beginner getting an error

Post by jimsgibso » Fri, 04 Mar 2011 09:19:29

On 3/2/11 Wed Mar 2, 2011 3:33 PM, "Uri Guttman" < XXXX@XXXXX.COM >
scribbled:



The ' at ' in the above line should also be '@'.
 
 
 

Beginner of Beginner getting an error

Post by uri » Fri, 04 Mar 2011 09:43:09

>>>>> "JG" == Jim Gibson < XXXX@XXXXX.COM > writes:

JG> On 3/2/11 Wed Mar 2, 2011 3:33 PM, "Uri Guttman" < XXXX@XXXXX.COM >
JG> scribbled:

>>>>>>> "T" == TaP < XXXX@XXXXX.COM > writes:
>>
T> Hi Guys,
T> I have this script:
>>

T> if ($line =~ /\b([\w_\-\.]+ at [\w_\-\.]+)\b/) {

JG> The ' at ' in the above line should also be '@'.

my eyeballs missed that one. very odd hiding harmless @'s from
spammers. never seen perl code like that before.

uri

--
Uri Guttman ------ XXXX@XXXXX.COM -------- http://www.yqcomputer.com/ --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://www.yqcomputer.com/ ---------