[25157] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7406 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 15 14:05:54 2004

Date: Mon, 15 Nov 2004 11:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 15 Nov 2004     Volume: 10 Number: 7406

Today's topics:
        A preference in the style guide <do-not-use@invalid.net>
    Re: A preference in the style guide (Anno Siegel)
    Re: array - removing duplicates <uri@stemsystems.com>
        DBD::CSV or  DBD::DBM or something else? <meneg@nospm.org>
    Re: Easiest way to read one character at a time until t ctcgag@hotmail.com
    Re: Excluding in Substitution <rwxr-xr-x@gmx.de>
    Re: FAQ 7.27: How do I clear a package? <lawshouse.public@btconnect.com>
        FAQ 7.7: Why do Perl operators have different precedenc <comdog@panix.com>
        OPEN command (Filippo)
    Re: OPEN command <do-not-use@invalid.net>
    Re: OPEN command <bik.mido@tiscalinet.it>
    Re: OPEN command <tadmc@augustmail.com>
    Re: OPEN command <notvalid@email.com>
    Re: Password-protected login problem <jimsimpson@cox.net>
    Re: Script to pass info to GET string <flavell@ph.gla.ac.uk>
    Re: Script to pass info to GET string <tadmc@augustmail.com>
    Re: Script to pass info to GET string <lawshouse.public@btconnect.com>
        Sending email using perl <roland@diku.dk>
    Re: Sending email using perl <bik.mido@tiscalinet.it>
        SQL ERROR (Tyler)
    Re: SQL ERROR <1usa@llenroc.ude.invalid>
    Re: SQL ERROR <tadmc@augustmail.com>
    Re: Two operations with one last if? <dwall@fastmail.fm>
    Re: Two operations with one last if? <uguttman@athenahealth.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 15 Nov 2004 15:19:06 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: A preference in the style guide
Message-Id: <yzd7jonci05.fsf@invalid.net>


I've been reading the style guide (perldoc perlstyle), and I have
trouble understanding one of the short preferences listed in the
beginning:

"Space after last parenthesis matching on current line."

Can someone give simple examples where this preference is
followed, and not followed, respectively?

(I also had problems with "uncuddled elses.", but dejanews solved that
for me - "cuddled" means being surrounded by braces on the same line.)


------------------------------

Date: 15 Nov 2004 14:44:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: A preference in the style guide
Message-Id: <cnafcg$mg$1@mamenchi.zrz.TU-Berlin.DE>

Arndt Jonasson  <do-not-use@invalid.net> wrote in comp.lang.perl.misc:
> 
> I've been reading the style guide (perldoc perlstyle), and I have
> trouble understanding one of the short preferences listed in the
> beginning:
> 
> "Space after last parenthesis matching on current line."
> 
> Can someone give simple examples where this preference is
> followed, and not followed, respectively?

This follows the rule:

    foo(
        bar( baz( 3.141)) );

There's a space before the last ")" because the matching opening "("
isn't on the same line.

Anno


------------------------------

Date: Mon, 15 Nov 2004 14:24:43 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: array - removing duplicates
Message-Id: <x7vfc7rxzo.fsf@mail.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  AS> My guess is, the (undeclared) hash %dat still contains data from an
  AS> earlier run in 99 % of the cases.  Solution: use strict.

i guessed that too. strict won't help unless the declaration is in the
tightest scope and it will clear the hash before the uniquing line. if
it is declared outside a loop doing the unique it will have the same
bug.

and the OP never stated what was wrong with the results. typical poor
description of the problem. if we were given some data from a bad result
then this guess could be made more assuredly or disregarded.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Mon, 15 Nov 2004 20:55:38 +0200
From: meneg <meneg@nospm.org>
Subject: DBD::CSV or  DBD::DBM or something else?
Message-Id: <pan.2004.11.15.18.55.37.301280@nospm.org>

Hello all and thanks in advance for any help you may give.

I'm currently in the process of making a cgi website for a family business
which would carry a few online orders and a few database entries. I soon
came to realize using postgresql - which I used last year when I was
learning php - would be an overkill because we talk about no more that a
thousand entries in a couple of small tables. Also since our hosting is
remote, I don't want to deal with remote databases. If I had it on my
linux machine, I wouldn't really care if it was an overkill or not.

Anyway, to the point. I read a a couple of decent perl books in the past
couple of months and I remember - not exactly where - that DBD::CSV is a
great alternative to a full featured SQL server or a hard to maintain
plain flat file. Also I recenty read somewhere DBD::DBM to mentioned for
exactly the same motives.

I was reading the manpages of these two but I'm really not convinced what
I should use. I need any a advice you may give me. What made it worce, I
read that DBD::DBM has several dbase types to cover (although one of them
is dominant with better support).

The database would only have a couple of tables with no more that a
thousand entries each but these should be of boolean, numeric and string
scalar values that (the string scalars) could do at least some thousand
words (keeping comments and stuff).

Any suggestion on the matter would be greatly appreciated,

- meneg.


------------------------------

Date: 15 Nov 2004 17:23:29 GMT
From: ctcgag@hotmail.com
Subject: Re: Easiest way to read one character at a time until the first |
Message-Id: <20041115122329.266$46@newsreader.com>

mortgageloan2004@aol.com (Mortgageloan2004) wrote:
> I'd like to grab a line from a file (up to the newline) and then read one
> character of a lin starting at the far left, until I get to the end of
> the first data element in a flat text file, (until first pipe symbol
> reached) counting the number of characters with a counter.   Assign the
> first counter -1 characters to a variable. Then test to see if it matches
> the string being searched. If it does, then grab the third data element.
> Everything between the 2nd and 3rd pipe symbol and end the loop. If it
> doesn't match, then read in the next line from the file.

Perl doesn't require babytalk.  You don't say what to do if a match is
never found, so I just leave $third undefined in that case.

my $third;
while (<>) {
  chomp;
  my $first;
  ($first,undef,$third) = split /\|/;
  last if $first eq $wanted;
  undef $third;
};


> Is this possible? Any ideas are appreciated very much.
>
> Thanks,
>
> Scot

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: 15 Nov 2004 11:45:36 GMT
From: Lukas Mai <rwxr-xr-x@gmx.de>
Subject: Re: Excluding in Substitution
Message-Id: <cna4t0$9ml$1@wsc10.lrz-muenchen.de>

Grant Nosbush schrob:
> How would I go about removing spaces from a string in perl except
> those spaces found in brackets?  In other words, if I have the
> following string:

> $str = "Hello World (My name is Bob) What is your name?"

> I would like it to become:

> $str = "HelloWorld(My name is Bob)Whatisyourname?"

> I was thinking of using substituion in Perl, but not sure what
> parameters to use.  Anyone have any ideas?  Thanks for your help!

1 while $str =~ s/^([^(\s]*(?:\([^)]*\)[^(\s]*)*)\s+/$1/;

1 while s/
  ^    # beginning of string
  (    # capture
       # this is what we want to keep:
    [^(\s]*  # 0 or more non-whitespace non-( chars
    (?:      # a group of:
      \(       # opening (
      [^)]*    # 0 or more non-) chars
      \)       # closing )
      [^(\s]*  # 0 or more non-whitespace non-( chars
    )*       # ... repeated 0 or more times
  )    # end of capture
  \s+  # 1 or more whitespace chars
       # note: this is the first run of whitespace not surrounded by ( )
/
  $1   # replace all of the above with the first capturing group, which
       # contains only non-whitespace and (...) groups
/xe;
-- 
print+74.117.115.116,,qq.\c!..not::.her,Perl=>q$hacker,$,!($,=$")


------------------------------

Date: Mon, 15 Nov 2004 18:43:36 +0000
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: FAQ 7.27: How do I clear a package?
Message-Id: <k4uhp0hvkb9aj2d6phgopbs721d0nrprgi@4ax.com>

On Mon, 15 Nov 2004 02:55:28 -0500, Sherm Pendley
<spamtrap@dot-app.org> wrote:

>Henry Law wrote:
>
>> On Sun, 14 Nov 2004 23:03:03 +0000 (UTC), PerlFAQ Server
>> <comdog@panix.com> wrote:
>> 
>>>           my $stash = *{$pack . '::'}{HASH};
>> 
>> 
>> I appreciate these FAQs; they improve my education.  But can someone
>> help me understand the last line and work out what it does?
>
>It's a typeglob. Have a look at perldata/"Typeglobs and Filehandles", 
>and perlmod/"Symbol Tables" for details.

Of course; I remember now.  (Smites forehead).  Thanks.
-- 

Henry Law       <><     Manchester, England 


------------------------------

Date: Mon, 15 Nov 2004 17:03:05 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 7.7: Why do Perl operators have different precedence than C operators?
Message-Id: <cnang9$s4t$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

--------------------------------------------------------------------

7.7: Why do Perl operators have different precedence than C operators?

    Actually, they don't. All C operators that Perl copies have the same
    precedence in Perl as they do in C. The problem is with operators that C
    doesn't have, especially functions that give a list context to
    everything on their right, eg. print, chmod, exec, and so on. Such
    functions are called "list operators" and appear as such in the
    precedence table in perlop.

    A common mistake is to write:

        unlink $file || die "snafu";

    This gets interpreted as:

        unlink ($file || die "snafu");

    To avoid this problem, either put in extra parentheses or use the super
    low precedence "or" operator:

        (unlink $file) || die "snafu";
        unlink $file or die "snafu";

    The "English" operators ("and", "or", "xor", and "not") deliberately
    have precedence lower than that of list operators for just such
    situations as the one above.

    Another operator with surprising precedence is exponentiation. It binds
    more tightly even than unary minus, making "-2**2" product a negative
    not a positive four. It is also right-associating, meaning that
    "2**3**2" is two raised to the ninth power, not eight squared.

    Although it has the same precedence as in C, Perl's "?:" operator
    produces an lvalue. This assigns $x to either $a or $b, depending on the
    trueness of $maybe:

        ($maybe ? $a : $b) = $x;



--------------------------------------------------------------------

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


------------------------------

Date: 15 Nov 2004 05:18:03 -0800
From: soxos@libero.it (Filippo)
Subject: OPEN command
Message-Id: <8075843c.0411150518.4182d876@posting.google.com>

Hi all,
I'm a very beginner with the Perl and I have this problem: trying to
use Satellite2 (search engine for website) with PdfToHtml (so that it
can search inside pdfs) the first indexes strange and nonsense words.

If I use pdftohtml from the command line (es. "pdftohtml -stdout
hello.pdf") it works, printing the html file resulting from the pdf.

Scanning Satellite's scripts I found these lines:

      $a = open(fileIN, "etc/pdftohtml  -q -i -stdout \"$file\"
\"data/myTemp/temp\" | ");

	while(<fileIN>)
		{
		$_ =~ s/\n/ /;
		$content .= $_;
		}
	close fileIN;

I can't understand this way of using the OPEN command. 
Can anybody explain it to me?


------------------------------

Date: 15 Nov 2004 14:39:42 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: OPEN command
Message-Id: <yzdd5yfcjtt.fsf@invalid.net>


soxos@libero.it (Filippo) writes:
>       $a = open(fileIN, "etc/pdftohtml  -q -i -stdout \"$file\"
> \"data/myTemp/temp\" | ");
> 
> 	while(<fileIN>)
> 		{
> 		$_ =~ s/\n/ /;
> 		$content .= $_;
> 		}
> 	close fileIN;
> 
> I can't understand this way of using the OPEN command. 
> Can anybody explain it to me?

perldoc -f open

says, among other things:

"If the filename begins with C<'|'>, the filename is interpreted as a
command to which output is to be piped, and if the filename ends with a
C<'|'>, the filename is interpreted as a command which pipes output to
us."

It probably says somewhere that trailing spaces are not significant,
because they don't seem to be.


------------------------------

Date: Mon, 15 Nov 2004 14:59:57 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: OPEN command
Message-Id: <gjchp0hn0tqn9qj53491vchif0qiitq2t1@4ax.com>

On 15 Nov 2004 05:18:03 -0800, soxos@libero.it (Filippo) wrote:

>Scanning Satellite's scripts I found these lines:
>
>      $a = open(fileIN, "etc/pdftohtml  -q -i -stdout \"$file\"
>\"data/myTemp/temp\" | ");

BTW: as it is this line of code suggests it's a badly written script
for, just to pinpoint some issues:

(i) $a shouldn't be used as a general purpose variable (see 'perldoc
perlvar'). A more illustrative name like $pid would have been better
anyway; also, I can't say for sure, but this strongly makes one
suspect that we're not running under strict;

(ii) no error checking that open() succeeded: very bad!

(iii) clumsy use of all those quoted quotes, whereas

  qq{etc/pdftohtml -q -i -stdout "$file" "data/myTemp/temp" |}

would have been just as good;

(iv) using lexical filehandles and the three arguments form of open()
is preferrable in any case. (But this may depend on which version of
perl the script was written for.)

>	while(<fileIN>)
>		{
>		$_ =~ s/\n/ /;
>		$content .= $_;
>		}
>	close fileIN;

more badly written code, from indentation style to useless use of 

  $_ =~ ... ;

Also I *guess* that one may want to

  s/\n/ /g;
  #      ^

instead. (But I may well be wrong on this!)

>I can't understand this way of using the OPEN command. 
>Can anybody explain it to me?

Well I can't, but 'perldoc -f open' can.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Mon, 15 Nov 2004 09:32:30 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: OPEN command
Message-Id: <slrncphj0e.kg.tadmc@magna.augustmail.com>

Filippo <soxos@libero.it> wrote:

> I'm a very beginner with the Perl 


You should make an attempt to find the answer to your question
in the standard docs that come with the perl distribution *before*
asking hundreds of people to help you with it.


> I can't understand this way of using the OPEN command. 


There is no "OPEN" in Perl, only "open". Case matters.

open() is not a "command".


> Can anybody explain it to me?


The documentation for the open() function can explain the use
of the open() function:

   perldoc -f open


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 15 Nov 2004 17:19:54 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: OPEN command
Message-Id: <_y5md.21515$6q2.798@newssvr14.news.prodigy.com>

Michele Dondi wrote:

> On 15 Nov 2004 05:18:03 -0800, soxos@libero.it (Filippo) wrote:
>>	while(<fileIN>)
>>		{
>>		$_ =~ s/\n/ /;
>>		$content .= $_;
>>		}
>>	close fileIN;
> 
> 
> more badly written code, from indentation style to useless use of 
> 
>   $_ =~ ... ;
> 
> Also I *guess* that one may want to
> 
>   s/\n/ /g;
>   #      ^
> 
> instead. (But I may well be wrong on this!)

I believe you are :)
Since the OP does not show any modification to $/, I'll assume that it 
has its default value of "\n", in which case there can be at most one 
newline character in $_, and it will necessarily be at the end. Hence, 
the /g is superfluous.

FWIW, I would've done things like this:

	chomp;
	$content .= " $_";

But, TMTOWTDI.

--Ala


------------------------------

Date: Mon, 15 Nov 2004 13:51:38 -0500
From: "jim simpson" <jimsimpson@cox.net>
Subject: Re: Password-protected login problem
Message-Id: <CV6md.5$zA.1@lakeread05>

Bob, Thanks a lot for your response.

I'll try your netscape suggestion and look into "Web Scraping Proxy". I had
already checked that no Java Script is involved in this site, however it is
involved in some of the others.

Thank you very much.

Jim


"Bob Walton" <see@sig.invalid> wrote in message
news:41980a22$1_5@127.0.0.1...
> jim simpson wrote:
>
> > I am trying to automate the process of loggin in to a number of
> > password-protected financial sites and downloading my statements from
them.
> > I've succeeded with about one-half of them. In each case, I've started
with
> > the HTML for the login page, stripped it down to just the login FORM,
and
> > logged in using that abbreviated login page in IE. Once I get that
shortened
> > form working, I write a perl script using the same INPUT fields and
ACTION
> > URL as that form. In about half the cases, that works fine -- in the
other
> > half I'm unable to get logged in. I get an "i The page cannot be
displayed"
> > page returned.
> >
> > For example, the following script fails to login to the Scudder website
> > athttp://www.myscudder.com/t/index.jhtml. You can see below the
abbreviated
> > (form-only) login page, which gets me logged in just fine.
> >
> > It appears that something else is required to be submitted for those
sites
> > where this procedure fails to login.
>
> In addition to duplicating the method and field names of the form, you
> may also need to provide an agent that the web site recognizes.
> Pretending like you're Internet Explorer should do the trick.  Maybe
> something like:
>
> $browser->agent(
>    'Mozilla /4.0 (compatible; MSIE 6.0; MSN 2.5; Windows 98)'
>    );
>
> If that doesn't do it, you can try the "Web Scraping Proxy" (look it up
> on Google) to see precisely what is being transmitted back and forth
> during a successful session.
>
> You should also scour the login web page for Javascript tricks.  If
> those are used, you'll have to duplicate their result.  Those would be
> used to stop people like you from doing what you are trying to do.
> Sometimes there might even be a series of web pages that all blow by
> transparently following a successful login, each employing a Javascript
> trick, all just an attempt to make sure it is actually a real web
> browser out there, not some guy's Perl program.
> ...
> > Jim
> ...
> -- 
> Bob Walton
> Email: http://bwalton.com/cgi-bin/emailbob.pl




------------------------------

Date: Mon, 15 Nov 2004 12:56:28 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Script to pass info to GET string
Message-Id: <Pine.LNX.4.61.0411151255330.1479@ppepc56.ph.gla.ac.uk>

On Sun, 14 Nov 2004, Kendall K. Down wrote:

> 1. If the script is written in Perl, why should it not be welcome on a Perl
> newsgroup?

Most programmers need coffee, so why not discuss all programming
questions on a coffee newsgroup ?  Hence or otherwise deduce...


------------------------------

Date: Mon, 15 Nov 2004 09:08:52 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Script to pass info to GET string
Message-Id: <slrncphhk4.bi.tadmc@magna.augustmail.com>


[ Newsgroups trimmed. ]


Kendall K Down <webmaster@diggingsonline.com> wrote:
> In message <7jgf62-mh5.ln1@osiris.mauzo.dyndns.org>
>           Ben Morrow <usenet@morrow.me.uk> wrote:
> 
>> No, he meant that your question was actually about CGI, but you didn't
>> say so. Questions like that are not welcome here: we get too many of
>> them, and they're not interesting.
> 
> 1. If the script is written in Perl, 


The criteria is not what language you are using, the criteria is
what your question is about.

Your question was basically:

   How do I do a redirect?

(Which is a Perl Frequently Asked Question BTW.)

If you were using Java instead of Perl, your question would have been:

   How do I do a redirect?

ie. the question is independent of the programming language being used.

The answer is:

   Output the appropriate Location header.

without regard to which programming language you've chosen to use.



Step 1 is knowing what output you want to make.

Step 2 is knowing how to make that output with your language of choice.


> why should it not be welcome on a Perl
> newsgroup?


The answer to the "Step 2" part of your question is:

   You use the print() function to make output.


> 2. However, if it really is not welcome, where should people with Perl cgi
> scripts go?


That depends on what their question is about.

If it is about Perl, then ask here.

If it is about the CGI, then ask in a CGI newsgroup.


(there is a mailing list specificaly for using Perl in a CGI
 environment, see http://lists.perl.org.
)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 15 Nov 2004 18:41:57 +0000
From: Henry Law <lawshouse.public@btconnect.com>
Subject: Re: Script to pass info to GET string
Message-Id: <c2uhp0dinut3f1d07q6p9f9gftogiu8br1@4ax.com>

On Mon, 15 Nov 2004 09:08:52 -0600, Tad McClellan
<tadmc@augustmail.com> wrote:

>The criteria is not what language you are using, 
            on
-- 

Henry Law       <><     Manchester, England 


------------------------------

Date: Mon, 15 Nov 2004 13:24:21 +0100
From: Lars Roland <roland@diku.dk>
Subject: Sending email using perl
Message-Id: <Pine.LNX.4.58.0411151319001.30202@brok.diku.dk>

Hi all

I use the folowing script to send email directly to a server (using its ip
address), my problem is that the script nerver halts (eg. its while loop
semas to run forever), can someone in here see why this is so ? as I can
not understand this:

--------------------------------------------
#!/usr/bin/perl
use strict;
use MIME::Entity;
my $mailhost = shift(@ARGV);
my $recip = shift(@ARGV);
my $sender = shift(@ARGV);
my $subject = shift(@ARGV);
my $nrofmsg = shift(@ARGV);
if ($mailhost =~ /--help/)
{
       die "usage: mail.pl smtp-server recipient sender subject nrofmails.
The e-mail body is empty"
};
my $nrofsend = 1;
#the e-mail
my $message;
$message="Test";
while( $nrofsend <= $nrofmsg)
{
        fork;
        # MIME stuff
        my $top = MIME::Entity->build(Type    =>"multipart/mixed",
                From    => "$sender",
                To      => "$recip",
                Subject => "Messages number $nrofsend:
        $subject");
        print STDOUT "Sending message $nrofsend of $nrofmsg\n";
        # contact $mailhost
        $top->smtpsend(   Host => $mailhost,
                To   => $recip,
                From => $sender,
                Hello=> "HELO",
        Port => 25) || die;
        ++$nrofsend;
        sleep 1;
};
--------------------------------------------

example of use (if the code is put in mail.pl)

 ./mail.pl IP-OF-MAILSERVER RECIPIENT@EMAIL SENDER@EMAIL SUBJECT NUM_OF_EMAILS




Thanks in advance


------------------------------

Date: Mon, 15 Nov 2004 14:59:55 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Sending email using perl
Message-Id: <rmbhp09tp728utdvtcr7f6ob87urfof7vu@4ax.com>

On Mon, 15 Nov 2004 13:24:21 +0100, Lars Roland <roland@diku.dk>
wrote:

>#!/usr/bin/perl
>use strict;

While you're there you may

  use warnings;

too.

>use MIME::Entity;
>my $mailhost = shift(@ARGV);

C<shift;> is completely equivalent to C<shift(@ARGV);>, in this
context. With the difference that it is more terse and readable...

>my $recip = shift(@ARGV);
>my $sender = shift(@ARGV);
>my $subject = shift(@ARGV);
>my $nrofmsg = shift(@ARGV);

Apart the side effect of removing entries from @ARGV (that doesn't
have any influence on the rest of the script as far as I can see) this
would have done the same:

  my ($mailhost, $recip, ..., $nrofmsg)=@ARGV;

and would be preferable under different points of view.

>if ($mailhost =~ /--help/)

Not that this is technically wrong (but it is awkward and clumsy, as
for one thing I think you really want /^--help$/ aka C<$mailhost eq
'--help'>), but you may want to

  use GetOpt::*;

instead.

>while( $nrofsend <= $nrofmsg)
>{
>        fork;

As a general rule fork()s are followed by code that takes different
actions based on its return value (including checking that it worked
at all).

Or do you want to exponentially increase the number of processes
generated by your program?

Remark: to be fair I'm not following the logic of your script in
detail, but I don't see why a fork() is needed at all...

>        # MIME stuff
>        my $top = MIME::Entity->build(Type    =>"multipart/mixed",
>                From    => "$sender",
>                To      => "$recip",
>                Subject => "Messages number $nrofsend:
>        $subject");
>        print STDOUT "Sending message $nrofsend of $nrofmsg\n";

print()s default to STDOUT. No need to indicate so, unless you have
select()ed something else... and it doesn't seem to me that you did.


HTH,
Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: 15 Nov 2004 07:51:01 -0800
From: tyler.bowler@gmail.com (Tyler)
Subject: SQL ERROR
Message-Id: <ca5e307a.0411150751.5ff256f8@posting.google.com>

I am trying to prepare an SQL statement to read a database.  I am
using DBI v1.41  However this code works on an older server that is
running DBI v.1.14.  I am putting my values into an array and then
comparing them in the Where clause.  Should I have to dereference my
array that I am putting my values into?  I have tried to deference by
doing the following.  @@arrayname[0] , @arrayname->[0] and
$$arrayname.

Please advise, Thanks

ERROR
==================================
$SQL ERROR: Bad predicate: '^3^'!

SQL ERROR: Couldn't find predicate!

Prepared
SV = RV(0x1baa020) at 0x1c3592c
  REFCNT = 1
  FLAGS = (PADBUSY,PADMY,ROK)
  RV = 0x1e849ec
DBD::CSV::st execute failed: dbih_getcom handle
DBD::CSV::Statement=HASH(0x1e849
ec) is not a DBI handle (has no magic) at
C:/Perl/site/lib/SQL/Statement.pm line
 164.
Executed


------------------------------

Date: 15 Nov 2004 16:42:29 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: SQL ERROR
Message-Id: <Xns95A2771B6FDEEasu1cornelledu@132.236.56.8>

tyler.bowler@gmail.com (Tyler) wrote in news:ca5e307a.0411150751.5ff256f8
@posting.google.com:

> I am trying to prepare an SQL statement to read a database.  I am
> using DBI v1.41  However this code works on an older server that is
> running DBI v.1.14.  I am putting my values into an array and then
> comparing them in the Where clause.  Should I have to dereference my
> array that I am putting my values into?  I have tried to deference by
> doing the following.  @@arrayname[0] , @arrayname->[0] and
> $$arrayname.
> 
> Please advise, Thanks

Please provide a short but complete script that exhbits the problem you 
are experiencing.

Also, you seem to be using symbolic references. It is generally not a 
good idea. See

perldoc -q "variable name"

to read why.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



------------------------------

Date: Mon, 15 Nov 2004 11:54:01 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: SQL ERROR
Message-Id: <slrncphr9p.10v.tadmc@magna.augustmail.com>

Tyler <tyler.bowler@gmail.com> wrote:

> I have tried to deference by
> doing the following.  @@arrayname[0] , @arrayname->[0] and
> $$arrayname.
> 
> Please advise, Thanks


I advise against making stuff up and hoping that it works.

If you want to know how to dereference a reference, then read
the std docs about how to dereference a reference:

   perldoc perlreftut
   perldoc perlref


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 15 Nov 2004 15:13:08 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Two operations with one last if?
Message-Id: <Xns95A267F417711dkwwashere@216.168.3.30>

Uri Guttman wrote:
>>>>>> "DKW" == David K Wall <dwall@fastmail.fm> writes:
>
>DKW> Uri Guttman <uri@stemsystems.com> wrote:
>>> i now follow the rule (from peter scott) to use &&/|| in logical
>>> expressions and and/or for logical flow control (as in open or
>>> die). it makes more sense and it usually matches the precedence
>>> very well. 
>DKW> Do you have a reference for that? I generally use 'and' and
>DKW> 'or' and enforce my desired precedence with parens, but I'm
>DKW> willing to be persuaded otherwise.
>
>you do know that &&/|| are the exact same operations as and/or
>but with tighter binding? all of them short circuit too.

Yes, I knew that.


[snip]
>but when you get into expressions, you usually want the tighter
>binding. this works as expected:
>
>my $foo = $bar || $default ;

And is what I would normally write....


>but this doesn't:
>
>my $foo = $bar or $default ;
>
>adding parens fixes it but at a cost of noise:
>
>my $foo = ( $bar or $default ) ;

I'm not sure I'd even thought of writing something like this. :-)


>&&/|| work well in expressions since their binding is higher than
>assignment. and/or work well in flow control since their binding
>is lower than assignment

Ok, I see what you mean now. I was thinking along the lines of 

    if ($foo eq 'bar' or $foo eq 'baz') {
        # do something
    }

In this simple case I see little reason to prefer || to or, although 
I'm sure you could come up with an example where || is the better 
choice.


>$foo = $bar or print "[$bar] isn't true\n" ;
>
>that does what you think it would do. this doesn't:
>
>$foo = $bar || print "[$bar] isn't true\n" ;
>
>that will print but also assign 1 (the return value of print) to
>$foo when $bar is false .

Heh. I would look at that code and decide that I was trying to be too 
clever, and rewrite it. I don't spend all day every day writing Perl 
code, so what code I do write I try to make easy for me to read 
months or years later when I need to update something.

>so choose your boolean ops wisely. you may save someone's life!
>:)

Or some monkey's life. :-)


------------------------------

Date: Mon, 15 Nov 2004 13:37:42 -0500
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: Two operations with one last if?
Message-Id: <m3fz3bdkll.fsf@lap.athenahealth.com>

>>>>> "DKW" == David K Wall <dwall@fastmail.fm> writes:

  DKW> Yes, I knew that.

some of that was meant for the whole thread, not just you.

  >> my $foo = ( $bar or $default ) ;

  DKW> I'm not sure I'd even thought of writing something like this. :-)

but you said before:

  DKW> Do you have a reference for that? I generally use 'and' and
  DKW> 'or' and enforce my desired precedence with parens, but I'm
  DKW> willing to be persuaded otherwise.

so that example was doing what you said :)


  >> &&/|| work well in expressions since their binding is higher than
  >> assignment. and/or work well in flow control since their binding
  >> is lower than assignment

  DKW> Ok, I see what you mean now. I was thinking along the lines of 

  DKW>     if ($foo eq 'bar' or $foo eq 'baz') {
  DKW>         # do something
  DKW>     }

that is still an expression. ||/&& has always bound tighter than the
comparision ops since they are meant to join those into larger boolean
expressions. this is classic precedence stuff in many languages.

  DKW> In this simple case I see little reason to prefer || to or, although 
  DKW> I'm sure you could come up with an example where || is the better 
  DKW> choice.

i think you meant 'or' instead of the last '||'.

but here is a possible example. i like to assign stuff from a hash to a
scalar and test it at the same time. something like this:

	if ( my $foo = $href->{foo} and my $bar = $href->{bar} ) {

		# use $foo and $bar
	}

&& will fail miserably there and the extra parens needed will be noisy.

note that $foo and $bar are scoped to the block. i do that so i can use
the data inside the block and not have to do a hash access each time. i
don't recall doing 2 of them like that but i do the single assign/test
often. many times the value is another hash ref and it is used multiple
times so saving the higher level deref is faster and cleaner as well.

	if ( my $foo_ref = $href->{foo} ) {

		do stuff with $foo_ref
	}

uri


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7406
***************************************


home help back first fref pref prev next nref lref last post