[22034] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4256 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 12 18:10:54 2002

Date: Thu, 12 Dec 2002 15:10:15 -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           Thu, 12 Dec 2002     Volume: 10 Number: 4256

Today's topics:
        Net::SMTP error (Andrew Burton)
    Re: Net::SMTP error <no@email.com>
    Re: Net::SMTP error (Andrew Burton)
    Re: Net::SMTP error (Andrew Burton)
        Perl IDE suggestion for Win32 environment <kasp@NO_SPAMepatra.com>
    Re: Perl IDE suggestion for Win32 environment <penny1482@attbi.com>
        Perl variables Which part of Memory <mark@lismark.org>
        Question about Subroutines <extendedpartition@NOSPAM.yahoo.com>
    Re: Question about Subroutines <no@email.com>
    Re: Question about Subroutines <no@email.com>
        regexp help <lance@augustmail.com>
    Re: Simplify split and s/// statement <skuo@mtwhitney.nsc.com>
    Re: Sorting large hex numbers <nobody@dev.null>
        Spawn a new process in Perl? <kasp@NO_SPAMepatra.com>
    Re: Spawn a new process in Perl? <jurgenex@hotmail.com>
    Re: Spawn a new process in Perl? <usenet@tinita.de>
        Suffering from Buffering - Help  <sunil_franklin@hotmail.com>
    Re: Suffering from Buffering - Help  <sunil_franklin@hotmail.com>
        Thanks! (James Foster)
        unix2dos newbie question <vervoom@hotmail.com>
        when uploading a file to CGI.pm, how to tell if file is (Ryan)
    Re: when uploading a file to CGI.pm, how to tell if fil (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 12 Dec 2002 20:58:17 GMT
From: tuglyraisin@aol.commune (Andrew Burton)
Subject: Net::SMTP error
Message-Id: <20021212155817.18036.00000034@mb-mv.aol.com>

Ok, error first:

[error]
Can't call method "mail" on an undefined value at ./testmail.pl line 10.
[/error]

I've searched through Google, and come up with a couple of things that could
have been the problem, yet when I modified/changed them I kept getting the same
error.  I first thought that strict might have been working against $ENV{USER}
so I took strict out.  That still didn't work, so I just replaced $ENV{USER}
with a static value (i.e., I typed in the user name).  Still it fails.  I also
read that my error could be caused because Net::SMTP wasn't installed
correctly, yet it seems that Net::SMTP is working by virtue of the fact that
"use Net::SMTP;" doesn't return any errors.  So, in summation, I am STuMPed
(pun intended).  Could some kind soul out there help me?  Thanks.

[code]

#!/usr/bin/perl -w

use Net::SMTP;
use CGI;

# variables
my $page = CGI->new();
my $smtp = Net::SMTP->new('elearning.wccs.edu', Debug => 1);

$smtp->mail('superboy');
$smtp->to('aburton@wccs.edu');

$smtp->data();
$smtp->datasend("To: andy");
$smtp->datasend("\n");
$smtp->datasend("Hello, World!");
$smtp->dataend();

$smtp->quit;

print 	$page->header(),
	$page->start_html(),
	"It worked.",
	$page->end_html;

exit;

[/code]

Andrew Burton -- tuglyraisin at aol dot com
Felecia Station on Harvestgain
"well, it's software, it can do anything :-)" - Ankh
"A racist alien robot, now that's cutting-edge children's programming, screw
the AIDS puppets." - Derik Smith



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

Date: Thu, 12 Dec 2002 21:19:49 -0000
From: "Brian Wakem" <no@email.com>
Subject: Re: Net::SMTP error
Message-Id: <atauhq$11bvek$1@ID-112158.news.dfncis.de>


"Andrew Burton" <tuglyraisin@aol.commune> wrote in message
news:20021212155817.18036.00000034@mb-mv.aol.com...
> Ok, error first:
>
> [error]
> Can't call method "mail" on an undefined value at ./testmail.pl line 10.
> [/error]

> my $smtp = Net::SMTP->new('elearning.wccs.edu', Debug => 1);

> $smtp->mail('superboy');


It could be that you don't have permission to connect to elearning.wccs.edu,
so $smtp is undefined.  You should always check this using something like:

if (defined $smtp) {
$smtp->mail('superboy');
 ..
}
else {
print "Couldn't connect to mail server\n";
# whatver
}

--
Brian Wakem







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

Date: 12 Dec 2002 21:55:17 GMT
From: tuglyraisin@aol.commune (Andrew Burton)
Subject: Re: Net::SMTP error
Message-Id: <20021212165517.18036.00000038@mb-mv.aol.com>

> It could be that you don't have 
> permission to connect to 
> learning.wccs.edu, so $smtp is 
> undefined.  You should always check 
> this using something like:

Well, I'm writing this on elearning.wccs.edu as root...  I thought that would
give me access, but I'll give that a whirl.  Thanks!





Andrew Burton -- tuglyraisin at aol dot com
Felecia Station on Harvestgain
"well, it's software, it can do anything :-)" - Ankh
"A racist alien robot, now that's cutting-edge children's programming, screw
the AIDS puppets." - Derik Smith



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

Date: 12 Dec 2002 22:11:12 GMT
From: tuglyraisin@aol.commune (Andrew Burton)
Subject: Re: Net::SMTP error
Message-Id: <20021212171112.18036.00000039@mb-mv.aol.com>

Apparently root means nothing to SMTP.  That's the problem.  Thanks!

Andrew Burton -- tuglyraisin at aol dot com
Felecia Station on Harvestgain
"well, it's software, it can do anything :-)" - Ankh
"A racist alien robot, now that's cutting-edge children's programming, screw
the AIDS puppets." - Derik Smith



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

Date: Fri, 13 Dec 2002 03:47:43 +0530
From: "Kasp" <kasp@NO_SPAMepatra.com>
Subject: Perl IDE suggestion for Win32 environment
Message-Id: <atb1uf$u3s$1@newsreader.mailgate.org>

Hi,
I would like your suggestion for a good IDE for developing and debugging
Perl for windows environment.
I heard about Komodo from ActiveState, but they have a 21 day trial version.
I am a student and can not spend $s for software. So a freeware would be
great.
Thanks.





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

Date: Thu, 12 Dec 2002 22:38:36 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Re: Perl IDE suggestion for Win32 environment
Message-Id: <Md8K9.128409$pN3.8829@sccrnsc03>

I'm not one of the gurus and I don't like to mess with changing my Win2K
system and its settings AT ALL. Here's what I did/do:
1) I run everything through my text editor, TexPad, from Helios software in
the UK.
1a) you spend MOST of your time editing/creating scripts anyway
2) when you run a script (with a drop down macro withing TexPad) the results
are returned into a "results"  file or window (as you wish) that you also
view from TexPad.
2a) if you need to, you can split the screen between results & script but I
never bother
3) use its free version, or pay the ~$25 reg fee to avoid annoying messages.
I never, ever use a DOS command window. I never, ever run Perl "1 liners."

It works GREAT as far as I am concerned.

Dick Penny
(have no stock nor investment in Helios)

"Kasp" <kasp@NO_SPAMepatra.com> wrote in message
news:atb1uf$u3s$1@newsreader.mailgate.org...
> Hi,
> I would like your suggestion for a good IDE for developing and debugging
> Perl for windows environment.
> I heard about Komodo from ActiveState, but they have a 21 day trial
version.
> I am a student and can not spend $s for software. So a freeware would be
> great.
> Thanks.
>
>
>




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

Date: Thu, 12 Dec 2002 16:25:01 +0000
From: Markmm <mark@lismark.org>
Subject: Perl variables Which part of Memory
Message-Id: <atad8q$11j1m6$1@ID-162318.news.dfncis.de>

I know that temp variables are held on the stack, but are all other 
variables held on the heap or just certain ones?. 


-- 
  4:22pm  up  5:19,  5 users,  load average: 0.20, 0.05, 0.01
 Markmm - Running Suse 8.0 on Athlon XP 1800


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

Date: Thu, 12 Dec 2002 16:03:14 -0600
From: "Extended Partition" <extendedpartition@NOSPAM.yahoo.com>
Subject: Question about Subroutines
Message-Id: <3df90839_2@nntp2.nac.net>

Hello Everyone,

I am having a bit of trouble with subroutines. Here is a sample of code that
mimics what I am doing in my real program:

$this_port = "21";
&id_port($this_port);

print "PORT 21 is $port_name\n";


sub id_port{
    $port_name = shift;
    if($port == 21){
        $port_name = "FTP";
    }
    else {
        $port_name = "Unknown";
    }
    return $port_name;
}


No my problem is that the value of $port_name is never returned. My output
ends up being "PORT 21 is " and that's it. What am I doing wrong here?  Your
help is greatly appreciated.

Thanks!
Anthony




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

Date: Thu, 12 Dec 2002 22:37:20 -0000
From: "Brian Wakem" <no@email.com>
Subject: Re: Question about Subroutines
Message-Id: <atb337$11vmh7$1@ID-112158.news.dfncis.de>


"Extended Partition" <extendedpartition@NOSPAM.yahoo.com> wrote in message
news:3df90839_2@nntp2.nac.net...
> Hello Everyone,
>
> I am having a bit of trouble with subroutines. Here is a sample of code
that
> mimics what I am doing in my real program:
>
> $this_port = "21";
> &id_port($this_port);
>
> print "PORT 21 is $port_name\n";
>
>
> sub id_port{
>     $port_name = shift;
>     if($port == 21){


$port is undefined at this point.  I think you mean to have $port_name in
there instead.

--
Brian Wakem




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

Date: Thu, 12 Dec 2002 22:42:51 -0000
From: "Brian Wakem" <no@email.com>
Subject: Re: Question about Subroutines
Message-Id: <atb3dj$12a900$1@ID-112158.news.dfncis.de>


"Brian Wakem" <no@email.com> wrote in message
news:atb337$11vmh7$1@ID-112158.news.dfncis.de...
>
> "Extended Partition" <extendedpartition@NOSPAM.yahoo.com> wrote in message
> news:3df90839_2@nntp2.nac.net...
> > Hello Everyone,
> >
> > I am having a bit of trouble with subroutines. Here is a sample of code
> that
> > mimics what I am doing in my real program:
> >
> > $this_port = "21";
> > &id_port($this_port);
> >
> > print "PORT 21 is $port_name\n";
> >
> >
> > sub id_port{
> >     $port_name = shift;
> >     if($port == 21){
>
>
> $port is undefined at this point.  I think you mean to have $port_name in
> there instead.
>
> --
> Brian Wakem
>
>

On seconds thoughts you probably wanted $this_port in there instead, but the
result would be the same.  More to the point though, why are you bothering
to return a global variable?  It'll do exactly the same without the return
statement.

Brian Wakem




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

Date: Thu, 12 Dec 2002 16:08:00 -0600
From: Lance Hoffmeyer <lance@augustmail.com>
Subject: regexp help
Message-Id: <pan.2002.12.12.22.07.59.867327.4907@augustmail.com>

Given a file that looks like:

TABLE 106
                                         
Base - Rewards    -* -* - -** 10 50 100 999 150 200 10 10

and a regexp:

$file =~ /TABLE\s$_[0].*?BASE \- [^\-].*?(?:(\d{1,4}|\-)[\*]+?\s+){$colnum}/s;

where $_[0] = 106
and $colnum = 8

I am trying to grab the number 999.  Usually there are no "-","-*","-**"
but in this particular file there are.  Also, the part that states "Base -
Rewards" could say almost anything but it always starts with "Base -".  This
file is a set of tables where there is some text followed by a group of
columns with numbers in them.


The
old syntax and table looked like:

Base - Total Per     9 100 50 50 10 50 100 999 150 200 300 10 10

$file =~ /TABLE\s$_[0].*?BASE.*?(?:(\d{1,4}|\-)\s+){$colnum}/s;


1) Line always starts with Base - 
2) There is some amount of text after the "Base -" and perhaps a space
between words
3) There is some amount of space
4) There are some columns with "\d+","\-","\-\*+?" 


How can I modify the above regexp to account for these items?


Lance


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

Date: Thu, 12 Dec 2002 09:21:58 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Simplify split and s/// statement
Message-Id: <Pine.GSO.4.21.0212120902190.21920-100000@mtwhitney.nsc.com>

On Thu, 12 Dec 2002, Garry Williams wrote:

> On Thu, 12 Dec 2002 04:23:57 GMT, Martien Verbruggen
> <mgjv@tradingpost.com.au> wrote:
> > (snipped)...
> > Just to add another possibility:
> > 
> > my ($pat_name,$pat_id,$birth_date,$accnbr,$study_date) = 
> >     map { s/\s+$// } split (/\|/, $PDS_LINE);
> > 
> > I like map for the readability of the code.
> 
> Maybe it contributes readability, but it doesn't do what you intend.
> :-)  
> 




I think grep would be appropriate (and readable):

my ($pat_name,$pat_id,$birth_date,$accnbr,$study_date) = 
   grep { s/\s*$// } 	# pattern always succeeds
   split (/\|/, $PDS_LINE);


O.T.: I often have to pause to decide between "map" and "grep".  I
blame Randal and Uri for without their marvelous sorting algorithms,
I would use "map" and "grep" far less than I do.  ;)


-- 
Regards,
Steven



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

Date: Thu, 12 Dec 2002 16:34:20 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Sorting large hex numbers
Message-Id: <3DF8BA07.1020104@dev.null>



tim wrote:

> Is there a module or method of handling large hex numbers?  I want to sort
> them into largest first order


One way to do it is to recognize that cmp correctly compares hex numbers 
  of equal lengths (assuming your digits are all uppercase), so if you 
left-pad your numbers with zeros you can just use string comparison to 
sort them. So this:

use strict;
use warnings;
my $maxlength=10000; #Adjust this as needed
$maxlength++;
my @hexarray=qw (11 1A 1 11 111 2 22 222 DEADBEEFBADDEED FEEDDEAFDADBEEF 
1234567890ABCDEF  ABCD 1234 42);
print join "\n", sort {pad($b) cmp pad($a)} @hexarray;
sub pad{
	my $number=shift;
	die "Number too long.\n" unless length($number)<$maxlength;
	return substr('0'x$maxlength.$number, -$maxlength);
};

Gives me
1234567890ABCDEF
FEEDDEAFDADBEEF
DEADBEEFBADDEED
ABCD
1234
222
111
42
22
1A
11
11
2
1

Notice that we didn't really make use of the fact  that these are hex 
numbers; in fact, the same trick works for any base less than 36.



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

Date: Thu, 12 Dec 2002 23:25:45 +0530
From: "Kasp" <kasp@NO_SPAMepatra.com>
Subject: Spawn a new process in Perl?
Message-Id: <ataijc$j6o$2@newsreader.mailgate.org>

I have another question.
In Unix, we have fork() to spawn a process & Exec().
Is there something in Perl like that? I want to run multiple instances of my
program and I must ensure that it runs on both - Unix or Windows.

Regards,
Kasp.





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

Date: Thu, 12 Dec 2002 18:40:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Spawn a new process in Perl?
Message-Id: <8K4K9.4660$ce5.3539@nwrddc03.gnilink.net>

Kasp wrote:
> In Unix, we have fork() to spawn a process & Exec().
> Is there something in Perl like that?

I recommend to reinstall Perl because apparently your current Perl
installation must be broken.
At least that's the only explanation I have because otherwise you couldn't
have probably missed "perldoc -f fork" and "perldoc -f exec".

jue




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

Date: 12 Dec 2002 18:46:27 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Spawn a new process in Perl?
Message-Id: <atali3$10oigi$1@fu-berlin.de>

Kasp <kasp@no_spamepatra.com> wrote:
> In Unix, we have fork() to spawn a process & Exec().
> Is there something in Perl like that?

oh, you don't know yet that there's a great documentation
coming with your perl distribution?
it called with "perldoc".
i think i remember that there are functions to fork and
to exec in perl. just can't remember the names... (SCNR =)

as you are on unix, try:
for keyword in "fork" "exec"; do perldoc -f $keyword; done

> I want to run multiple instances of my
> program and I must ensure that it runs on both - Unix or Windows.

you can only fork() on some windows versions.
please see:
perldoc perlport

hth, tina

-- 
http://www.tinita.de/        \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/      \     / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/   \    \ _,_\ __/\ __/_| /__/ perception


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

Date: Thu, 12 Dec 2002 23:59:35 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: Suffering from Buffering - Help 
Message-Id: <nD4K9.8$cw5.67@news.oracle.com>

---------------------------------------------------
    open(ERRLOG, ">$errorLog") or die "Can't open error log! $!";
    $OUTPUT_AUTOFLUSH = 1; # make unbuffered

    open(OUTPUT, ">>$logFile") or die "Can't open output log! $!";
    OUTPUT->autoflush(1);

    my $pid;
    eval
    {
        my $pid = open3("<&STDIN", ">&OUTPUT", ">&ERRLOG", $command) or die
"$!";
    };
    die $@ if $@;

    waitpid ($pid, 0); # wait for it to die

    close(ERRLOG) or die "Can't close filehandle! $!";
    close(OUTPUT) or die "Can't close filehandle! $!";

### This check never works ###########################
    if (-s "$errorLog")
    {  }

    if (open(RESULTS_FILE, "$logFile"))
    {
        while (<RESULTS_FILE>)
        {
            print ;
### Does not print anything :-( ########################
        }
        close(RESULTS_FILE);
    }
---------------------------------------------------

    Anything to lessen my misery?


Thanks,
Sunil.





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

Date: Fri, 13 Dec 2002 00:35:45 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: Re: Suffering from Buffering - Help 
Message-Id: <395K9.9$cw5.40@news.oracle.com>


"Sunil" <sunil_franklin@hotmail.com> wrote in message
news:nD4K9.8$cw5.67@news.oracle.com...
> ---------------------------------------------------
>     open(ERRLOG, ">$errorLog") or die "Can't open error log! $!";
>     $OUTPUT_AUTOFLUSH = 1; # make unbuffered
>
>     open(OUTPUT, ">>$logFile") or die "Can't open output log! $!";
>     OUTPUT->autoflush(1);
>
>     my $pid;
>     eval
>     {
>         my $pid = open3("<&STDIN", ">&OUTPUT", ">&ERRLOG", $command) or
die
> "$!";
>     };
>     die $@ if $@;
>
>     waitpid ($pid, 0); # wait for it to die
>
>     close(ERRLOG) or die "Can't close filehandle! $!";
>     close(OUTPUT) or die "Can't close filehandle! $!";
>
> ### This check never works ###########################
>     if (-s "$errorLog")
>     {  }
>
>     if (open(RESULTS_FILE, "$logFile"))
>     {
>         while (<RESULTS_FILE>)
>         {
>             print ;
> ### Does not print anything :-( ########################
>         }
>         close(RESULTS_FILE);
>     }
> ---------------------------------------------------
>
>     Anything to lessen my misery?
>
>

This went away after I removed the "my"  before the following stmt.

      $pid = open3("<&STDIN", ">&OUTPUT", ">&ERRLOG", $command) or die "$!";


Thanks,
Sunil.





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

Date: 12 Dec 2002 12:17:02 -0800
From: idmercury@yahoo.co.uk (James Foster)
Subject: Thanks!
Message-Id: <b4d37d82.0212121217.64c46ddb@posting.google.com>

Thanks people, already ordered a book.

Thanks again.

Merry Christmas!

James Foster.


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

Date: Thu, 12 Dec 2002 22:34:41 -0800
From: "Edward Quick" <vervoom@hotmail.com>
Subject: unix2dos newbie question
Message-Id: <atb36n$nem$1@cspc1n11.baplc.com>

The following extract of code reads a file and writes it out to a socket.
Does anyone know what changes could be made to this code in order to get it
to insert Carriage Returns if it's reading a unix file and writing out a
windows file? Presumably I need to perform a unix2dos function on $ftpbuf,
but I'm not too sure how to do this in Perl.

Thanks in advance,

JS.

while( ($len = sysread( FH, $ftpbuf, $ftpbufsize )) > 0 ){
        $left = $len ;
        while( ($len2 = &write( NS, $ftpbuf, $left )) > 0 ){
                        $left = $len - $len2 ;
                        $bytes_written+= $len2;
                        $ftpbuf = substr( $ftpbuf, $len2, $left);
                }
         if( $len2 < 0 ){
                        print "error occurred while writing to network\n";
                        return 0;
         }
}




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

Date: 12 Dec 2002 13:19:55 -0800
From: zirconx9@yahoo.com (Ryan)
Subject: when uploading a file to CGI.pm, how to tell if file is zero bytes?
Message-Id: <e7d49913.0212121319.696125f1@posting.google.com>

When I go to write the file out I use:

$filename = $cgiobj->param('filename');
while ($bytesread=read($filename,$buffer,16384)) {
  print OUTFILE $buffer;
  }

I could do a check there but BEFORE I get to that point I do
validation on all the other fields from the form, and I'd like to
check for a zero byte file at that point.

I read the CGI.pm documentation but didn't see specific examples of
this.

Thanks,
-Ryan


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

Date: Thu, 12 Dec 2002 15:35:27 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: when uploading a file to CGI.pm, how to tell if file is zero bytes?
Message-Id: <slrnavi08v.3va.tadmc@magna.augustmail.com>

Ryan <zirconx9@yahoo.com> wrote:


> I'd like to
> check for a zero byte file at that point.


   if ( -z $filename ) {
      print "'$filename' is empty\n";
   }


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


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

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


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