Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computing > NZ Computing > perl guff :-)

Reply
Thread Tools

perl guff :-)

 
 
Shane
Guest
Posts: n/a
 
      08-11-2005
Im bored and Ive been writing perl scripts to help me with the mail
I have written a script that checks for mail in several directorys, and
then emails me the names of the directorys that have unread mail in them
however, its sending me mail when there is no unread mail,
Ive worked out where to test, and in which subroutine, but I cant figure
out how to 'kill' it
if I use 'die' it returns an error to stdin which isnt helpful
any ideas?




ps heres part of the code
sub searcher{
#@folder = </home/vmail/weasel.is-a-geek.net/shane/.Asterisk.*>;
@folder = </home/baldrick/test/*>;
foreach $folders(@folder){
* * * * @maildirs = <$folders/cur/*>;
* * * * foreach $mail(@maildirs){
* * * * * * * * if ($mail!~/S$/){
* * * * * * * * ($folders=~s"/home/vmail/weasel.is-a-geek.net/shane/"");
* * * * * * * * push (@group, $folders."\n");}}}
* * * * * * * * if (@group<=0){die}
* * * * * * * * return @group;}

Ta Nicely

--
Hardware, n.: The parts of a computer system that can be kicked

The best way to get the right answer on usenet is to post the wrong one.

 
Reply With Quote
 
 
 
 
Chris Hope
Guest
Posts: n/a
 
      08-11-2005
Shane wrote:

[snip]

Been a few years since I did any perl coding but...

> ps heres part of the code
> sub searcher{
> #@folder = </home/vmail/weasel.is-a-geek.net/shane/.Asterisk.*>;
> @folder = </home/baldrick/test/*>;
> foreach $folders(@folder){
> @maildirs = <$folders/cur/*>;
> foreach $mail(@maildirs){
> if ($mail!~/S$/){
> ($folders=~s"/home/vmail/weasel.is-a-geek.net/shane/"");
> push (@group, $folders."\n");}}}
> if (@group<=0){die}


can you not do a 'return' here instead of 'die'?

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.co.nz
 
Reply With Quote
 
 
 
 
Harry
Guest
Posts: n/a
 
      08-11-2005
Shane wrote:

> Im bored and Ive been writing perl scripts to help me with the mail
> I have written a script that checks for mail in several directorys, and
> then emails me the names of the directorys that have unread mail in them
> however, its sending me mail when there is no unread mail,
> Ive worked out where to test, and in which subroutine, but I cant figure
> out how to 'kill' it
> if I use 'die' it returns an error to stdin which isnt helpful
> any ideas?
>
>
>
>
> ps heres part of the code
> sub searcher{
> #@folder = </home/vmail/weasel.is-a-geek.net/shane/.Asterisk.*>;
> @folder = </home/baldrick/test/*>;
> foreach $folders(@folder){
> @maildirs = <$folders/cur/*>;
> foreach $mail(@maildirs){
> if ($mail!~/S$/){
> ($folders=~s"/home/vmail/weasel.is-a-geek.net/shane/"");
> push (@group, $folders."\n");}}}
> if (@group<=0){die}
> return @group;}
>


Well, apart from the obvious errors, shouldn't you be using stat to check
the time an existing file was last modified? Just checking for its
existence is not good enough.

I don't understand what the second-to-last line is trying to do.


 
Reply With Quote
 
Shane
Guest
Posts: n/a
 
      08-11-2005
On Thu, 11 Aug 2005 21:33:34 +1000, Harry wrote:

> Shane wrote:
>
>> Im bored and Ive been writing perl scripts to help me with the mail
>> I have written a script that checks for mail in several directorys, and
>> then emails me the names of the directorys that have unread mail in them
>> however, its sending me mail when there is no unread mail, Ive worked
>> out where to test, and in which subroutine, but I cant figure out how to
>> 'kill' it
>> if I use 'die' it returns an error to stdin which isnt helpful any
>> ideas?
>>
>>
>>
>>
>> ps heres part of the code
>> sub searcher{
>> #@folder = </home/vmail/weasel.is-a-geek.net/shane/.Asterisk.*>; @folder
>> = </home/baldrick/test/*>;
>> foreach $folders(@folder){
>> @maildirs = <$folders/cur/*>;
>> foreach $mail(@maildirs){
>> if ($mail!~/S$/){
>> ($folders=~s"/home/vmail/weasel.is-a-geek.net/shane/""); push (@group,
>> $folders."\n");}}}
>> if (@group<=0){die}
>> return @group;}
>>
>>

> Well, apart from the obvious errors, shouldn't you be using stat to check
> the time an existing file was last modified? Just checking for its
> existence is not good enough.
>
> I don't understand what the second-to-last line is trying to do.


the line 'if ($mail!~/S$/){' checks if the mail has been read (imap mail
has a capital S appended to its filename when it is marked as read)
the second to last line 'if (@group<=0){die}' is supposed to check if any
elements have been added to that array and if none at all I want the whole
process to die
I have decided to change that line to
if (@group<=0){@group=("Bonneville");}
so that I can check the return from the sub routine and if it eq
"Bonneville" then I wont enter the loop that emails me

I will be using stat in another function to check if any mail has been
sent at all
Ta


--
Hardware, n.: The parts of a computer system that can be kicked

The best way to get the right answer on usenet is to post the wrong one.

 
Reply With Quote
 
Shane
Guest
Posts: n/a
 
      08-11-2005
On Thu, 11 Aug 2005 21:27:36 +1200, Chris Hope wrote:

> Shane wrote:
>
> [snip]
>
> Been a few years since I did any perl coding but...
>
>> ps heres part of the code
>> sub searcher{
>> #@folder = </home/vmail/weasel.is-a-geek.net/shane/.Asterisk.*>; @folder
>> = </home/baldrick/test/*>;
>> foreach $folders(@folder){
>> @maildirs = <$folders/cur/*>;
>> foreach $mail(@maildirs){
>> if ($mail!~/S$/){
>> ($folders=~s"/home/vmail/weasel.is-a-geek.net/shane/""); push (@group,
>> $folders."\n");}}}
>> if (@group<=0){die}

>
> can you not do a 'return' here instead of 'die'?


in the end I decided to return a crap value if @group was empty, and in
the loop that checks the return of this value I changed to
@test=&searcher
if (@test ne "Bonneville") {then email me the results}


ta

--
Hardware, n.: The parts of a computer system that can be kicked

The best way to get the right answer on usenet is to post the wrong one.

 
Reply With Quote
 
Harry
Guest
Posts: n/a
 
      08-12-2005
Shane wrote:

> On Thu, 11 Aug 2005 21:33:34 +1000, Harry wrote:
>
>> Shane wrote:
>>
>>> Im bored and Ive been writing perl scripts to help me with the mail
>>> I have written a script that checks for mail in several directorys, and
>>> then emails me the names of the directorys that have unread mail in them
>>> however, its sending me mail when there is no unread mail, Ive worked
>>> out where to test, and in which subroutine, but I cant figure out how to
>>> 'kill' it
>>> if I use 'die' it returns an error to stdin which isnt helpful any
>>> ideas?
>>>
>>>
>>>
>>>
>>> ps heres part of the code
>>> sub searcher{
>>> #@folder = </home/vmail/weasel.is-a-geek.net/shane/.Asterisk.*>; @folder
>>> = </home/baldrick/test/*>;
>>> foreach $folders(@folder){
>>> @maildirs = <$folders/cur/*>;
>>> foreach $mail(@maildirs){
>>> if ($mail!~/S$/){
>>> ($folders=~s"/home/vmail/weasel.is-a-geek.net/shane/""); push (@group,
>>> $folders."\n");}}}
>>> if (@group<=0){die}
>>> return @group;}
>>>
>>>

>> Well, apart from the obvious errors, shouldn't you be using stat to check
>> the time an existing file was last modified? Just checking for its
>> existence is not good enough.
>>
>> I don't understand what the second-to-last line is trying to do.

>
> the line 'if ($mail!~/S$/){' checks if the mail has been read (imap mail
> has a capital S appended to its filename when it is marked as read)


Not so on most standard unix/linux.
Must be something to do with the vmail you are using.

> the second to last line 'if (@group<=0){die}' is supposed to check if any
> elements have been added to that array and if none at all I want the whole
> process to die


Why don't you try "$#group"?

> I have decided to change that line to
> if (@group<=0){@group=("Bonneville");}
> so that I can check the return from the sub routine and if it eq
> "Bonneville" then I wont enter the loop that emails me
>
> I will be using stat in another function to check if any mail has been
> sent at all


Vanilla unix/linux mailbox just modifies each Status header with something
like "RO" to indicate whether a mail item has been read.
In which case you need to read the entire /var/spool/mail/fred file
and parse each set of header.

 
Reply With Quote
 
Shane
Guest
Posts: n/a
 
      08-12-2005
this is quickly degenerating into a thread that has nothing to do with my
original question
what may or may not happen to mail elsewhere is hardly my concern when
what IS happening to my mail is the concern of my script
thanks

--
Hardware, n.: The parts of a computer system that can be kicked

The best way to get the right answer on usenet is to post the wrong one.

 
Reply With Quote
 
Enkidu
Guest
Posts: n/a
 
      08-12-2005
Harry wrote:
>
> Vanilla unix/linux mailbox just modifies each Status
> header with something like "RO" to indicate whether a
> mail item has been read. In which case you need to
> read the entire /var/spool/mail/fred file
> and parse each set of header.
>

It might be mbox, or it might be maildir. I've never had to
delve that deeply, but I vaguely recall something about
maildir.....

Cheers,

Cliff

--

Barzoomian the Martian - http://barzoomian.blogspot.com
 
Reply With Quote
 
Harry
Guest
Posts: n/a
 
      08-12-2005
Shane wrote:

> this is quickly degenerating into a thread that has nothing to do with my
> original question
> what may or may not happen to mail elsewhere is hardly my concern when
> what IS happening to my mail is the concern of my script
> thanks
>


Ok, so what do you mean by "kill it"?
BTW "die" doesn't return anything to stdin, it outputs its argument
to stderr and causes exit.


 
Reply With Quote
 
Shane
Guest
Posts: n/a
 
      08-12-2005
On Fri, 12 Aug 2005 18:50:04 +1000, Harry wrote:

> Shane wrote:
>
>> this is quickly degenerating into a thread that has nothing to do with
>> my original question
>> what may or may not happen to mail elsewhere is hardly my concern when
>> what IS happening to my mail is the concern of my script thanks
>>
>>

> Ok, so what do you mean by "kill it"? BTW "die" doesn't return anything to
> stdin, it outputs its argument to stderr and causes exit.



At the time I meant.. the loop to end, more so I want the loop that called
this subroutine to end,
IOW my poorly written script is supposed to email me a list of folders
when it detects 'unread' mail in any of those folders, however if it finds
none, I dont want it emailing me
What Ive done is, if nothing meets its criteria, it now returns a crap
value (in this case "Bonneville") and the original loop checks for this
value, and then mails me if it has been returned anything ne "Bonneville"
if (@group<=0){@group=("Bonneville")}

my @check=&searcher
if ($check[0]!~m/Bonneville){send me an email}

and yeah I said STDERR


--
Hardware, n.: The parts of a computer system that can be kicked

The best way to get the right answer on usenet is to post the wrong one.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 02-27-2011 11:00 PM
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 02-03-2011 11:00 AM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 01-23-2011 05:00 AM
more apple on intel guff. Dave - Dave.net.nz NZ Computing 0 06-14-2005 09:14 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments