[22260] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4481 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 29 06:10:37 2003

Date: Wed, 29 Jan 2003 03:10:10 -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           Wed, 29 Jan 2003     Volume: 10 Number: 4481

Today's topics:
    Re: pipes: A script works on SCO, but not on Linux <morden@shadows.net>
    Re: Question about 64bit Integers in Perl <mgjv@tradingpost.com.au>
    Re: sending attachments with mime::lite and sendmail (Dhruv)
    Re: sending attachments with mime::lite and sendmail <anfi@Box43.pl>
    Re: Substituting words in Array with items from a hash? <bigj@kamelfreund.de>
    Re: Timestamps to thousandths of a second. (Anno Siegel)
    Re: Very Basic Question on the Use of the __DATA__ Toke <gbarbay@NOnetscapeSPAM.net>
    Re: Very Basic Question on the Use of the __DATA__ Toke <tassilo.parseval@localhost.localhost>
    Re: Why doesn't  perl -ex 'print 1' work on Windows? <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: win32 tieregistry html (Nuno Cancelo)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 28 Jan 2003 23:56:46 -0800
From: morden <morden@shadows.net>
Subject: Re: pipes: A script works on SCO, but not on Linux
Message-Id: <b181gp$1el$1@bob.news.rcn.net>

morden wrote:

> This script works just fine on SCO (perl 5.002) but sptbcgen fails to
> write to pipe BCGENW on Linux (perl 5.6.1) :

Nevermind. Downgrading to perl 5.003 on Linux fixed this. Probably it's 
some change in perl 5.004+ pipe handling that broke my script.

>
> unless (pipe(BCGENR,BCGENW)) {
>     die("can't open a pipe\n");
> }
> $opipe=fileno(BCGENW);
> $pname = "|sptbcgen ".$opipe." ".fileno(BCGENR);
> print STDERR "cmd ".$pname."\n";
> print STDERR $opipe." ".fileno(BCGENR)."\n";
> unless (open(BCGEN, $pname)) {
>     die("can't pipe to sptbcgen\n");
> }
>
>
>
>
> main(int argc, char *argv[])
> {
>     if(argc>=2) {
>         int pipeout = atoi( argv[1] );
>         if(argc>2) {
>             close(atoi( argv[2] ));
>         }
>         int sz = write(pipeout, "%test\n", 6);
>         if(sz<1) {
>             fprintf(stderr, "wrote %d bytes with errno %d",
> sz, errno);
> ^^^^^^^^^^^^^^^^^^^^^^^^ on linux for some reason an attempt to write to
> fd 5 (BCGENW) failes with EBADF :-(
>
>         }
>         if(!(fpout=fdopen(pipeout, "w"))) {
>             fprintf(stderr, "I can't open fdout %s/%d error %d\n",
>                 argv[1], pipeout, errno);
>             exit(22);
>         }
>



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

Date: Wed, 29 Jan 2003 04:36:07 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Question about 64bit Integers in Perl
Message-Id: <slrnb3emhm.se5.mgjv@verbruggen.comdyn.com.au>

[Please, in the future, put your reply _after_ the suitably trimmed
text you reply to. It is the commonly accepted quoting style on this
newsgroup, and Usenet in general. Thank you]

On 28 Jan 2003 09:06:33 -0800,
	doug <doug.portz@mts.mb.ca> wrote:
>> Yes, perl can handle integers of any size, but unless perl has been
>> compiled with 64-bit integer support, then you'll need to 'use
>> Math::BigInt;' to handle integers bigger than 53 bits.
>
> After running the script you provided, it appears that the perl
> compiled on the server does not support 64 bit, but does work with
> BigInt.

An easier way to tell whether perl is compiled with 64 bit support is
looking at the output of perl -V. It should have some values for
use64bitint, and use64bitall which are not undef.

> Now maybe I am showing my ignorance here, but if we have a
> non-compiled version of the perl code that was originally written (I
> am assuming that there is a copy around) can it not be just recompiled
> with 64bit support without any changes?

Yep.

You get yourself the source distribution of Perl and compile it again,
using the Configure script. Read the INSTALL file that comes with the
distribution (sections "64 bit support", "Long doubles" and "more
bits"). Natively 64 bit platforms don't need extra work, all others do
(see the hints directory in the distribution). Note that 64 bit
support is still experimental on many platforms.

When you choose to do this, you may also need to recompile any shared
libraries and modules that are linked from perl, depending on platform
and how the modules and their shared libraries were compiled in the
first place. 

If you're not experienced with compiling things like this yourself,
and estimating the work that goes into it, you should probably
consider not doing it :)

> If so, is there a particular version of Perl that is required to
> compile with 64 bit support?

Nope. It's part of the standard distribution. 

However, if you don't really need speed, Math::BigInt is probably more
portable and safer at the moment. It certainly is easier. It should
work with any perl, 64 bit or not, and it will allow you to use Ints
larger than 64 bits as well.

Martien
-- 
                        | 
Martien Verbruggen      | That's not a lie, it's a terminological
Trading Post Australia  | inexactitude.
                        | 


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

Date: 28 Jan 2003 20:37:34 -0800
From: dmalhotr2001@yahoo.com (Dhruv)
Subject: Re: sending attachments with mime::lite and sendmail
Message-Id: <b6d0b0b.0301282037.6015a30c@posting.google.com>

Hi,

That was really a stupid mistake.  I have added in the following code
as you suggested however I am getting a software error: $attachment:
not readable.

What is wrong with this?

I tried to print out the attachment and it prints out the path+name of
attachment on my page.

What exactly do I need to fix?

Thanks.

Dhruv



Andrzej Filip <anfi@Box43.pl> wrote in message news:<3E36837D.DAD7472E@Andrzej.Adam.Filip>...
> Dhruv wrote:
> 
> > I am having problems sending message via mime::lite module using
> > sendmail.
> >
> > I can send mail via sendmail fine if i dont send an attachment.
> >
> > I am using a form to post and sending mail via a webpage.
> >
> > Below is my code that the form gets posted to.
> >
> > -------------------------------------------------------------
> >
> > #!/usr/bin/perl -w
> > use CGI;
> > use CGI qw(:standard) ;
> > use CGI::Carp qw(fatalsToBrowser);
> > use DBI;
> > use Time::localtime;
> > use strict;
> > use MIME::Lite;
> > use Net::SMTP;
> >
> > #INCLUDE FILE ########
> > require "include.cgi";#####
> > ######################
> > print header();
> >
> > my ($emails, $from, $subject, $body, $attachment);
> >
> > $emails = cookie('emails');
> > $from = param('from');
> > #$subject = param('subject');
> > $body = param('body');
> > $attachment = param('attachment');
> >
> > #SPLIT EACH EMAIL ADDRESS FROM TEXT FILE
> > my @emails = split /\n/, $emails;
> >
> >         my $from_address = '$from';
> >         my $to_address = 'dmalhotr2001@yahoo.com';
> >         my $subject = 'MIME Net::SMTP test';
> >         my $mime_type = 'multipart/mixed';
> >         my $message = "Hello world!\n";
> >
> >         # Create the initial text of the message
> >         my $mime_msg = MIME::Lite->new(
> >            From => $from_address,
> >            To   => $to_address,
> >            Subject => $subject,
> >            Type => $mime_type,
> >            Data => $message
> >            )
> >          or die "Error creating MIME body: $!\n";
> >         my $filename = '$attachment';
> >         my $recommended_filename = '$attachment';
> >         # Attach the test file
> >
> >         $mime_msg->attach(
> >            Type => 'BINARY',
> >            Path => $filename,
> >            Filename => $recommended_filename,
> >            Disposition => 'attachment'
> >            )
> >           or die "Error attaching test file: $!\n";
> >
> >             MIME::Lite->send("sendmail", "/usr/sbin/sendmail -t -oi
> > -oem");
> > ----------------------------------------------------------
> >
> > Please let me know what i am doing wrong.  When I post i dont get any
> > error messages and also my apache logs error_log has no error message.
> >  I am not sure what I am doing wrong.
> 
> Where do you call INSTANCE send method ?
> [ $mime_msg->send ]


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

Date: Wed, 29 Jan 2003 08:07:00 +0000
From: Andrzej Filip <anfi@Box43.pl>
Subject: Re: sending attachments with mime::lite and sendmail
Message-Id: <3E3786A4.2AA0D6FF@Andrzej.Adam.Filip>

Dhruv wrote:

> That was really a stupid mistake.  I have added in the following code
> as you suggested however I am getting a software error: $attachment:
> not readable.
>
> What is wrong with this?
>
> I tried to print out the attachment and it prints out the path+name of
> attachment on my page.
>
> What exactly do I need to fix?

AFAIK perl does not expand variables inside single quotes ('').

my $filename = '$attachment';
$mime_msg->attach(
[...]
     Path => $filename,
)
or die "Error attaching test file: $!\n";



> Andrzej Filip <anfi@Box43.pl> wrote in message news:<3E36837D.DAD7472E@Andrzej.Adam.Filip>...
> > Dhruv wrote:
> >
> > > I am having problems sending message via mime::lite module using
> > > sendmail.
> > >
> > > I can send mail via sendmail fine if i dont send an attachment.
> > >
> > > I am using a form to post and sending mail via a webpage.
> > >
> > > Below is my code that the form gets posted to.
> > >
> > > -------------------------------------------------------------
> > >
> > > #!/usr/bin/perl -w
> > > use CGI;
> > > use CGI qw(:standard) ;
> > > use CGI::Carp qw(fatalsToBrowser);
> > > use DBI;
> > > use Time::localtime;
> > > use strict;
> > > use MIME::Lite;
> > > use Net::SMTP;
> > >
> > > #INCLUDE FILE ########
> > > require "include.cgi";#####
> > > ######################
> > > print header();
> > >
> > > my ($emails, $from, $subject, $body, $attachment);
> > >
> > > $emails = cookie('emails');
> > > $from = param('from');
> > > #$subject = param('subject');
> > > $body = param('body');
> > > $attachment = param('attachment');
> > >
> > > #SPLIT EACH EMAIL ADDRESS FROM TEXT FILE
> > > my @emails = split /\n/, $emails;
> > >
> > >         my $from_address = '$from';
> > >         my $to_address = 'dmalhotr2001@yahoo.com';
> > >         my $subject = 'MIME Net::SMTP test';
> > >         my $mime_type = 'multipart/mixed';
> > >         my $message = "Hello world!\n";
> > >
> > >         # Create the initial text of the message
> > >         my $mime_msg = MIME::Lite->new(
> > >            From => $from_address,
> > >            To   => $to_address,
> > >            Subject => $subject,
> > >            Type => $mime_type,
> > >            Data => $message
> > >            )
> > >          or die "Error creating MIME body: $!\n";
> > >         my $filename = '$attachment';
> > >         my $recommended_filename = '$attachment';
> > >         # Attach the test file
> > >
> > >         $mime_msg->attach(
> > >            Type => 'BINARY',
> > >            Path => $filename,
> > >            Filename => $recommended_filename,
> > >            Disposition => 'attachment'
> > >            )
> > >           or die "Error attaching test file: $!\n";
> > >
> > >             MIME::Lite->send("sendmail", "/usr/sbin/sendmail -t -oi
> > > -oem");
> > > ----------------------------------------------------------
> > >
> > > Please let me know what i am doing wrong.  When I post i dont get any
> > > error messages and also my apache logs error_log has no error message.
> > >  I am not sure what I am doing wrong.
> >
> > Where do you call INSTANCE send method ?
> > [ $mime_msg->send ]

--
Andrzej [pl>en: Andrew] Adam Filip http://www.polbox.com/a/anfi/
*Random epigram* :
If you do not think about the future, you cannot have one.
	-- John Galsworthy



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

Date: Wed, 29 Jan 2003 10:08:32 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Substituting words in Array with items from a hash?
Message-Id: <pan.2003.01.29.08.26.27.425794@kamelfreund.de>

On Tue, 28 Jan 2003 19:18:38 +0000, Eric J. Roode wrote:
> > print "Content-type: text/html\n\n"; 
>
> Why code it by hand?  You'll make typos sooner or later!  Use the 
> function that CGI provides:
>
>     print header;
> ...
>> print "<title>The Response</title><h1>The Response</h1><hr>";
>> print "Here is the form data:<ul>";
>> 
>> # Print list items of the form data in %in
>>     foreach $key (keys %in) {
>>         print "<li>$key: $in{$key}";
>>     }
> 
> Under CGI, this would become:
> 
>     foreach $key (param) {
>         print "<li>$key: ", param($key);
>     }
> 
>  
>> print "</ul>";

Here's a little mistake in both versions as there is no separation
between the header part and the body part of a html file. 
(That's not a real problem as many browser won't be confused)
However, using CGI means also not to think a lot about html tags.
Let's do it in a real CGI way:

print header,
      start_html('The Response'),
      h1('The Response'),
      hr,
      'Here is the form data:',
      ul(li [map {"$_: " . param($_)} param]);

I won't say that it is a perfect code (in fact, it's untested),
but it shows the right direction IMHO and the comfort of the CGI module.


Cheerio,
Janek



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

Date: 29 Jan 2003 08:52:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Timestamps to thousandths of a second.
Message-Id: <b184p6$9hl$2@mamenchi.zrz.TU-Berlin.DE>

Andras Malatinszky  <nobody@dev.null> wrote in comp.lang.perl.misc:
> 
> 
> Anno Siegel wrote:
> 
> > Andras Malatinszky  <nobody@dev.null> wrote in comp.lang.perl.misc:
> > 
> >>
> >>Jeremy Gooch wrote:
> >>
> >>
> >>>I need to generate a current date/timestamp in the format
> >>>yyyymmddhhmmssxxx where xxx are the thousandths of a second. 
> 
> [...]
> 
> 
> >>
> >>I think you are almost there: if you have milliseconds since the epoch 
> >>in $ms then you can just do something like
> >>
> >>if ($ms=~/(.*)(...)$/){
> >>	$epoch_seconds=$1;
> >>	$xxx=$2;
> >>} else {die "Time seems to be unhinged."};
> >>
> >>Now you can turn $epoch_seconds into the yyyymmddhhmmss part of your 
> >>time stamp like you always do, end then just tack on $xxx to get the xxx 
> >>part of the time stamp.
> >>
> > 
> > I'd prefer
> > 
> >     my ( $epoch_seconds, $xxx) = ( int $ms/1000, $ms % 1000);
> > 
> > They're numbers, after all. [...]
> 
> 
> Exactly. That's why at 1043791033055 milliseconds after the epoch your 
> $xxx will be a two-digit sequence (55) while mine will be the 
> three-digit 055 the OP wanted.

The leading 0 is only of interest if you insist in treating numbers
as strings.  "+= $xxx/1000" would be the numerical alternative.

> More germanely, are you sure int $ms/1000 is always the same as $ms with 
> the last three digits cut off, given the inherent errors of 
> floating-point arithmetic? I don't know, I can't come up with an example 
> where your method gives a result that's different from mine, but I'm not 
> sure there isn't one.

If there is a difference, the numerical method will work with the
more precise internal values.  Cutting strings works with (prematurely)
rounded values.

Anno


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

Date: Wed, 29 Jan 2003 04:35:02 GMT
From: Gordon Barbay <gbarbay@NOnetscapeSPAM.net>
Subject: Re: Very Basic Question on the Use of the __DATA__ Token
Message-Id: <v2me3vc8bnf2jjpbh7435h33b6rglrn237@4ax.com>

On Tue, 28 Jan 2003 01:05:20 -0600, tadmc@augustmail.com (Tad
McClellan) wrote:

>Gordon Barbay <gbarbay@NOnetscapeSPAM.net> wrote:
>
>The DATA thing actually has nothing to do with your problem.
You are correct!
>
>
>> while (<main::DATA>) {
>> find (\&sav_fd, @_);

>You spelled the name of the variable incorrectly, that should be $_ .
Unfortunately, thats not right either.  Program still bombs if I make
that change.

From the File::Find CPAN page:
(search.cpan.org/author/JHI/perl-5.8.0/lib/File/Find.pm)

SYNOPSIS
    use File::Find;
    find(\&wanted, @directories_to_seach);
    sub wanted { ... }

Find expects an array as a second argument.
>
>> It seems like this should be simple, but I can't get it to work.  The
>><main::DATA> should read the indicated directory as the first element
>> of the @_ array, correct?  
>
>
>What did you see that made you think that?
My (incoherent) interpretation of some code in the Cookbook. :-)
>
>   while ( <INPUT> )
>
>is a special case shortcut, the longer version is:
>
>   while ( $_ = <INPUT> )
>
>the longest version is:
>
>   while ( defined($_ = <INPUT>) )
>
>The special case applies iff the input operator is the only thing
>in the condition of a while. It automatically saves the input
>line that was read into $_ for you.
>
However, your explanation allowed me to see the light (I think -
haven't had time to test it yet).  The 'while' expects a scalar and
I'm giving it a list.  To fix things it looks like the while loop has
to stick each of the individual directories into an array.  After the
'while' finishes, *then* call the find with that newly created array.

Hopefully this makes sense...
[...]

Thanks much for the reponse!

-Gordon


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

Date: 29 Jan 2003 08:41:22 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@localhost.localhost>
Subject: Re: Very Basic Question on the Use of the __DATA__ Token
Message-Id: <slrnb3f4tc.18b.tassilo.parseval@localhost.localhost>

Also sprach Gordon Barbay:

> On Tue, 28 Jan 2003 01:05:20 -0600, tadmc@augustmail.com (Tad
> McClellan) wrote:
> 
>>Gordon Barbay <gbarbay@NOnetscapeSPAM.net> wrote:
>>
>>The DATA thing actually has nothing to do with your problem.
> You are correct!
>>
>>
>>> while (<main::DATA>) {
>>> find (\&sav_fd, @_);
> 
>>You spelled the name of the variable incorrectly, that should be $_ .
> Unfortunately, thats not right either.  Program still bombs if I make
> that change.
> 
> From the File::Find CPAN page:
> (search.cpan.org/author/JHI/perl-5.8.0/lib/File/Find.pm)
> 
> SYNOPSIS
>     use File::Find;
>     find(\&wanted, @directories_to_seach);
>     sub wanted { ... }
> 
> Find expects an array as a second argument.

No, not necessarily. Perl subroutines can't expect arrays as arguments
unless a prototype is used which isn't the case with File::Find::find().

Anything you pass to a subroutine is gathered in the special variable
@_. It is of little significance what kind of arguments you pass:

    my @dirs = qw(/usr/lib /usr/local/lib);
    find(\&wanted, @dirs);


    # or
    find (\&wanted, qw(/usr/lib /usr/local/lib));

    # or even a simple scalar
    find (\&wanted, $_);

> My (incoherent) interpretation of some code in the Cookbook. :-)
>>
>>   while ( <INPUT> )
>>
>>is a special case shortcut, the longer version is:
>>
>>   while ( $_ = <INPUT> )
>>
>>the longest version is:
>>
>>   while ( defined($_ = <INPUT>) )
>>
>>The special case applies iff the input operator is the only thing
>>in the condition of a while. It automatically saves the input
>>line that was read into $_ for you.
>>
> However, your explanation allowed me to see the light (I think -
> haven't had time to test it yet).  The 'while' expects a scalar and
> I'm giving it a list.  To fix things it looks like the while loop has
> to stick each of the individual directories into an array.  After the
> 'while' finishes, *then* call the find with that newly created array.

'while' expects a condition, nothing else. Both a list and a scalar can
be interpreted as such. A common situation where a list is used as a
condition is each():

    while ( my($key, $val) = each %hash ) {
        ...
    }
    
The condition is true as long as the list isn't empty.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Wed, 29 Jan 2003 06:52:47 +0100
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Why doesn't  perl -ex 'print 1' work on Windows?
Message-Id: <8vqe3vkj2s22m53kca77bctdo490q95rsp@4ax.com>

On Tue, 28 Jan 2003 13:21:17 -0500, Jeff 'japhy' Pinyan
<pinyaj@rpi.edu> wrote:

>[posted & mailed]
>
>On Tue, 28 Jan 2003, Bernard El-Hagin wrote:
>
>>On 28 Jan 2003 01:14:38 -0800, john_ramsden@sagitta-ps.com (John
>>Ramsden) wrote:
>>
>>>Why do all the following commands, and several other variations,
>>>print just a blank line in a Windows 2K DOS window, whereas the
>>>equivalent single-line Perl scripts print what is asked for?
>>>
>>>  perl -ex "print 1"
>>>  perl -ex 'print 1'
>>>  perl -ex "print \"\n\""
>>>  perl -ex "print time"
>>>  perl -ex "print time();"
>>
>>Are you aware of what the -x switch does? If not try:
>
>The -x option doesn't enter into it.


My mistake. Mental note: knee-jerk reactions...not good.

  
>  perl -efoobar 'print 1'
>
>is the same as
>
>  perl -e 'foobar' 'print 1'
>  
>which executes the code 'foobar', and puts 'print 1' in @ARGV.  So the    
>original code executes 'x' (which does nothing) and puts 'print 1' in 
>@ARGV.


At least the advice to remove the x still stands. ;-)


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: 29 Jan 2003 01:11:37 -0800
From: nac@advancecare.com (Nuno Cancelo)
Subject: Re: win32 tieregistry html
Message-Id: <8349fc76.0301290111.211ec805@posting.google.com>

thanks to you all,
i'll try other way,
Nuno Cancelo


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

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.  

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 4481
***************************************


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