Not in answer to your question, (which has been answered) but where you have the block of print statements:
print TOHOST "To: $your_email \nFrom: $your_email\n"; print TOHOST "Subject: Name Change\n"; print TOHOST "$email_send\n";
You can easily combine those all into one:
print TOHOST "To: $your_email \nFrom: $your_email\n", "Subject: Name Change\n", "$email_send\n";
or if you want to see more clearly what it is sending:
print TOHOST <<EOT; To: $your_email From: $your_email Subject: Name Change $email_send EOT
(as this is an email you're going to need to make sure you have a blank line before the body to seperate it from the header too - but perhaps you already have this in @email before the loop)

Also... you don't seem to be using

use strict; use warnings;
In the top of your script... you will do yourself big favours by using them as a matter of habit, because there are a number of errors in your example which they will pick up for you.

You'll also massively aid your debuggging by putting in context relevent info in your error messages including filenames (quoted so you can see if they're empty or have spaces at the end or anything silly) and a short, specific description of what you were trying to do when it died.

Presuming that you have:

$sock, $name, $match, @email, $sendmail, $your_email
all defined before your example here you might end up with something like:
#!/usr/bin/perl use strict; use warnings; # (the code before your example here...) my $n = 50; while (1) { my $time = time(); print $sock "$name\r\n"; my @output; my $output = join( '', @output ); $| = 1; while (<$sock>) { if ( $output = /$match/ ) { my $searchlog = "searchlog.txt"; open( FILELOG, ">>$searchlog" ) || die "Can't write to '$searchlog': $!\n"; print FILELOG "$time $name\n"; close FILELOG; my $tmpl = "email.txt.asc"; my @tmpl; open( TMPL, $tmpl ) || print "Can't read '$tmpl': $!\n"; @tmpl = <TMPL>; close(TMPL); my ( @email_send, $email_send ); foreach my $line (@tmpl) { $line =~ s/XnameX/$name/g; push @email, $line; $email_send = join( '', @email ); } open( TOHOST, "|$sendmail $your_email" ) || print "Can't run '$sendmail': $!\n"; print TOHOST "To: $your_email \nFrom: $your_email\n", "Subject: Name Change\n", "$email_send\n"; close(TOHOST); } else { my $log_txt = "log.txt"; open( FILELOG, ">>$log_txt" ) || die "Can't write to '$log_txt': $!\n"; print FILELOG "$time $name\n"; close FILELOG; } sleep( int( 43200 / $n ) - ( time() - $time ) ); } }

In reply to Re: nested loops by serf
in thread nested loops by webshark

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.