[19883] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2078 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 6 14:05:50 2001

Date: Tue, 6 Nov 2001 11:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005073509-v10-i2078@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 6 Nov 2001     Volume: 10 Number: 2078

Today's topics:
    Re: $query not working when submitting data. nobull@mail.com
        0 response from a DHCP client (jack)
    Re: Best language for low IQ programmers? (Doug)
    Re: Best language for low IQ programmers? <glabowitz@home.com>
    Re: Best language for low IQ programmers? <tim@vegeta.ath.cx>
    Re: Best language for low IQ programmers? <tim@vegeta.ath.cx>
    Re: Best language for low IQ programmers? <lmoran@wtsg.com>
    Re: Best language for low IQ programmers? <lmoran@wtsg.com>
    Re: Can perl open a new browser window without embeddin <jurgenex@hotmail.com>
    Re: can't make use of do <ronh@iainc.com>
    Re: CGI.pm and File Upload Problem <cpryce@pryce.net>
        Everything but the if... (martinblack)
    Re: Help: simple perl question on Windows <peb@bms.umist.ac.uk>
    Re: Help: simple perl question on Windows <bart.lateur@skynet.be>
        install packages to ActivePerl <wstsoi@hongkong.com>
    Re: install packages to ActivePerl <camerond@mail.uca.edu>
        memory profiling <news@aspersion.org>
    Re: Naive Q: Why Java speed >> Perl speed? <tim@vegeta.ath.cx>
    Re: Problem with prototype function <lmaddox@us.ibm.com>
    Re: Profiling Perl <mjcarman@home.com>
    Re: Profiling Perl <bart.lateur@skynet.be>
    Re: Profiling Perl (Tad McClellan)
    Re: simple perl question on Windows <clay@panix.com>
    Re: simple perl question on Windows <tsee@gmx.net>
        Small '-w' Question with Net::POP3 <newsgroup_mike@ultrafusion.co.uk>
    Re: Small '-w' Question with Net::POP3 (Tad McClellan)
        strange behavior from cgi inside protected directory <kirsthul@casema.net>
    Re: too late for -T? <camerond@mail.uca.edu>
        using a variable in a subroutine name <kclair@soya.serve.com>
    Re: using a variable in a subroutine name <jeff@vpservices.com>
    Re: using a variable in a subroutine name <ronh@iainc.com>
    Re: using a variable in a subroutine name <uri@stemsystems.com>
    Re: using a variable in a subroutine name <jeff@vpservices.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 06 Nov 2001 18:13:31 +0000
From: nobull@mail.com
Subject: Re: $query not working when submitting data.
Message-Id: <u9g07r22es.fsf@wcl-l.bham.ac.uk>

"Mike Mackay [Ultrafusion]" <newsgroup_mike@ultrafusion.co.uk> writes:

> Also you should call the CGI.pm into your script at the top of the page with
> this :
> use CGI qw(:standard);
> $query = new CGI;

Bzzzt!

   use CGI qw(:standard);

 ...OR...

   use CGI;
   my $query = new CGI;

Mixing the OO and non OO APIs for CGI is going to get you in a mess
sooner or later.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 6 Nov 2001 08:55:01 -0800
From: jack@brainminers.net (jack)
Subject: 0 response from a DHCP client
Message-Id: <90de0398.0111060855.5c90a762@posting.google.com>

Your insight is highly appreciate.

I am a newbie for perl and I am trying to write a DHCP client to send
out a broadcasting message and receive feedback from DHCP servers on a
network.  I understand the mechanism but having trouble using socket,
etc. in perl.

I attached the "poor" perl code below.

Thanks!!













#!/usr/bin/perl -w
      # dhcp_client  -- To detect DHCP server on the network by
sending a
      broadcasting 
      #                 UDP message 

      use strict;
      use IO::Socket;
      use IO::Select;
      use Socket;

      socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname("udp")) or
die
      "socket: $!";

      my $addr = '255.255.255.255';
      my $dest = sockaddr_in(67, inet_aton($addr));

      send(SOCKET, "try..", 0, $dest) or die "can't send the
message.";

      print "Awaiting UDP messages on port\n";

      my $data;
      my $addr = recv(SOCKET, $data, 1024,0) or die "recv(): $!";
      my($port, $peer) = sockaddr_in($addr);
      my $host = gethostbyaddr($peer, AF_INET);
      print "received", length($data), "bytes from $host:$port\n";


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

Date: 6 Nov 2001 08:18:44 -0800
From: dougs@halcyon.com (Doug)
Subject: Re: Best language for low IQ programmers?
Message-Id: <9s92h4$2c5$1@halcyon.com>

In article <1004990076967295@aol.com>, Brian Metc <BrianMetc@aol.com> wrote:
>I would like to get into the programing field. ...

Troll



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

Date: Tue, 06 Nov 2001 17:25:04 GMT
From: "Gary Labowitz" <glabowitz@home.com>
Subject: Re: Best language for low IQ programmers?
Message-Id: <Q1VF7.184089$5A3.69337498@news1.rdc2.pa.home.com>

"Doug" <dougs@halcyon.com> wrote in message news:9s92h4$2c5$1@halcyon.com...
> In article <1004990076967295@aol.com>, Brian Metc <BrianMetc@aol.com>
wrote:
> >I would like to get into the programing field. ...
>
> Troll
>
Yes. And only best language is English.
Use it to write specs. Then hire someone to program them.
Gary




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

Date: Tue, 06 Nov 2001 18:32:45 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Best language for low IQ programmers?
Message-Id: <slrn9ugbj8.3s3.tim@vegeta.ath.cx>

Paul Lutus <nospam@nosite.zzz> graced us by uttering:
> 
> "Tim Hammerquist" <tim@vegeta.ath.cx> wrote in message
> news:slrn9ueho3.o7a.tim@vegeta.ath.cx...
>> Brian Metc <BrianMetc@aol.com> graced us by uttering:
>> > Would any one sugest the best language for me.
>>
>> If you want to learn a language that solves any problem that today's
>> world can throw at you, look at COBOL.  There's not a language out there
>> that is as widely used as COBOL.  Not only does it offer "classic"
>> programming experience to the user, but it offers more methods of
>> reinventing the wheel than any other programming language!
> 
> You know, the relatively inexperienced OP may not get the satirical intent.
> No little smiley to give anything away. :)

(The difficulty in finding information would quickly betray my "widely
used" statement.  And for whom is "reinventing the wheel" a positive
corporate experience?)

Besides, our "relatively inexperienced OP" is a "slightly more
experienced troll" and we need not be concerned with what subjects
he Googles for.

Tim Hammerquist
-- 
A holding company is a thing where you hand an accomplice
the goods while the policeman searches you.


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

Date: Tue, 06 Nov 2001 18:34:48 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Best language for low IQ programmers?
Message-Id: <slrn9ugbn6.3s3.tim@vegeta.ath.cx>

Kenny Chaffin <kenny@kacweb.com> graced us by uttering:
> IQ is inherent, like personality. It has nothing to do with 
> learning/deprivation/TV.

If the OP only knew what the people in this thread would _actually_
spend their time arguing about...

Tim Hammerquist
-- 
Never sleep with a woman whose troubles are worse than your own.
    -- Nelson Algren


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

Date: Tue, 06 Nov 2001 14:01:48 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: Best language for low IQ programmers?
Message-Id: <plcgutonok9r5hhdn2n69rkqe1g6p6icmc@4ax.com>

On Mon, 5 Nov 2001 15:50:54 -0500, "Marin David Condic"
<dont.bother.mcondic.auntie.spam@[acm.org> wrote wonderful things
about sparkplugs:

SNIP
>
>If not, I'd suggest the question should be rephrased to be less inciteful.
SNIP
>
This line is priceless.  It has 100 diff't ways to go.  I applaude you
and your masterful use and wildly entertaining misspelling of
insightful.  You are a lingusitic genius.  You can't see me but I am
Golf Clapping right ... now.

:)

Disclaimer -- Any sarcasm real or imagined is not the intent of this
post.


--
TMTOWTDI: My way tends to be wrong...
lmoran@wtsg.com


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

Date: Tue, 06 Nov 2001 14:03:03 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: Best language for low IQ programmers?
Message-Id: <5tcgut0qp4b08fe4na4mrt2s0d020p42tr@4ax.com>

On Mon, 05 Nov 2001 20:42:23 GMT, "Marshall Spight" <mspight@dnai.com>
wrote wonderful things about sparkplugs:

>"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message news:9s6t6v$80u$2@oravannahka.helsinki.fi...
>> But if you want to go to real PHB level, start talking about HTML as a
>> programming language. I've heard rumours of that happening in real life.
>
>I hear that *all* the *time.* Sigh.
>
Right no iteration... where do you put HTML in a resume though?  You
wouldn't want to put it under Programming Languages, or
Applications... so where does it go?

--
TMTOWTDI: My way tends to be wrong...
lmoran@wtsg.com


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

Date: Tue, 6 Nov 2001 10:29:29 -0800
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Can perl open a new browser window without embedding Javascript?
Message-Id: <3be82c18@news.microsoft.com>

"Qunfeng Dong" <qfdong@iastate.edu> wrote in message
news:9s3uqe$ec0$1@news.iastate.edu...
> Is there a way in perl itself to open a new browser window similar to
> javascript's window.open()? Thanks!

Sure. On a Windows OS just do a
    system ("explorer.exe");
and a new IE window will open (if explorer.exe is in your path). Same on a
Unix or Mac, just call the proper command to launch the browser.

Or is this a stealth CGI question and you want to open a new browser
instance on the client? In that case you don't have a Perl question but a
CGI question and you may want to ask in a CGI and/or webauthoring NG.

jue




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

Date: Tue, 06 Nov 2001 16:13:56 GMT
From: "Ron Hartikka" <ronh@iainc.com>
Subject: Re: can't make use of do
Message-Id: <8%TF7.2349$PM1.34368@typhoon.mw.mediaone.net>

Try something like....

unless ($return = do $file) {
    warn "couldn't parse $file: $@" if $@;
    warn "couldn't do $file: $!" unless defined $return;
    warn "couldn't run $file" unless $return;
}


See perlfunc  on do for explanations of each case.


"Ryan" <hkyeung9@ie.cuhk.edu.hk> wrote in message
news:9s9037$79f$1@eng-ser1.erg.cuhk.edu.hk...
> Hello,
>
> I have a question of make use of do.
> I have a program called find.pl which is a cgi program and it includes the
> following syntax:
>
> find.pl:
> ...
> use CGI;
> ...
> do "get.pl";
> ...
>
> and
> get.pl:
> ...
> $page=get("http://www.abc.com/index.html");
> ....
> when i type perl get.pl in linux,i can get the file index.html. However,
> when i try the find.pl in browser in my apache, it can run all the script
> except
> do "get.pl" this sentence(i can't get any file!!!). Why? Is it we can't
just
> treat cgi program as normal perl program and need to do something so that
we
> can make use those some function in perl like "do"?
>
> Thank you~
>
>
>




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

Date: Tue, 06 Nov 2001 10:15:26 -0600
From: cpryce <cpryce@pryce.net>
Subject: Re: CGI.pm and File Upload Problem
Message-Id: <B80D68BE.242C%cpryce@pryce.net>

in article 3BE2F4EE.C3E58E89@appstate.edu, Robert Pottschmidt at
pottschmidtr@appstate.edu wrote on 11/2/01 1:33 PM:

>   I am having problems upload files using a html push, the script
> works find on one of my servers running an older version of perl and
> CGI.pm. I get the file name fine, but I do not get the file's data.

Ummm.. I guess I'm confused. If you're not getting the file's data, how is
that 'Working properly?'

> 
> The server that has the problem is running perl 5.6.1 and CGI.pm 2.77
> 
> Here is my code:
> 
[ snip HTML code ]
> 
> PERL SCRIPT
> #!/usr/bin/perl
# Consider using warnings and strictures. They help
##!/usr/bin/perl -w
#use strict;

> use diagnostics;
> use CGI;
> use Mysql;

Not sure why this is here, you're not accessing a database. And if you were,
it's probably better to:

use DBI; 
> my $query = new CGI;
> print $query->header("text/html");

# If you're building an HTML response page, you probably want to
# print $query->header(), $query->start_html(-title=>'Test Results');

> $test = $query->param("test");
> print $test;

# If you're trying to display the file in your browser, this is
# not going to work, unless the file was HTML to start with,
# as you called the type text/html in the header function. If it is a
# text/html file, what you wanted to say was:

while ( <$test> ) {
    print;
}
> while(my $bytesread = read($test, my $buffer, 1024)){
>                               print $buffer;
>                       }
> 
> exit;

If you are looking to save a binary file to disk, you need to make a file
handle: 

 open OUTFILE, '>/path/where/you/want/the/file' or
    die "Can't open file for writing: $!"
 binmode OUTFILE; #needed for Win32. Doesn't hurt *NIX.
 $test = $query->param("test");
 my $buffer;
 while (my $bytesread = read($test, $buffer, 1024)){
                              print VAULT $buffer;
  }
 
 close OUTFILE or die " Can't close filehandle: $!";

From the Web site: http://stein.cshl.org/WWW/software/CGI/#upload

--
cp






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

Date: 6 Nov 2001 11:02:23 -0800
From: martinblack26@yahoo.com (martinblack)
Subject: Everything but the if...
Message-Id: <c025943b.0111061102.18f8156@posting.google.com>

Hi folks, another week, another mystery. Below is a snippet of code
that worked fine until I added the: if ($query eq 'set'){ do...} else
{ blah... }. The println works fine in either case, printing the SQL
commands, but if $query eq 'set' all I get is the one print line
stating the SQL command. Why won't the if statement work? Any help
would be greatly appreciated. Below is the snippet.
Ps. I've tried wrapping the prepare and executes in eval, but $@ is
always empty.

 ...

if ($query eq 'set') {
	$sql="SELECT company_id, product_id, title, 
	  description, spex, price, category_id 
	FROM product where title like \"$query\"";   

$sth = $dbh->prepare($sql);
$sth->execute || 
      die "Could not execute the SQL";

print "this is the sql: $sql \n"; 

} else {

	$sql="SELECT company_id, product_id, title, 
	  description, spex, price, category_id 
	FROM product where title like \"%$query%\"";   

$sth = $dbh->prepare($sql);
$sth->execute || 
      die "Could not execute the SQL";

print "this is the sql: $sql \n";
} 

	# database output............................

while ($x = $sth->fetchrow_hashref) {
     $com = $x->{'company_id'};
     $pro = $x->{'product_id'};
     $tit  = $x->{'title'};
     $des  = $x->{'description'};
     $spe  = $x->{'spex'};
     $pri  = $x->{'price'};
     $morf  = $x->{'sex'};
   
	$io = "$com\|$pro\|$tit\|$des\|$spe\|$pri\|$morf\|$type\n\n";
	print "<p>we have $io<br>";
}

$sth->finish() || die "finish problem: ", $DBI::errstr;
$dbh->disconnect || die "disconnection problem: ", $DBI::errstr;


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

Date: Tue, 06 Nov 2001 16:23:58 +0000
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Help: simple perl question on Windows
Message-Id: <3BE80E9E.D331C012@bms.umist.ac.uk>

Araxes Tharsis wrote:
> 
> Hi,
> I want to run the following script on Windows 2000, receiving input
> from the file employees.txt. In UNIX it is:
>        MyScript.pl < employees.txt
> But it is not working in Windows.
> Any help appreciated.


How about telling us what the error message is?
Paul


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

Date: Tue, 06 Nov 2001 16:52:03 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Help: simple perl question on Windows
Message-Id: <i85guto8j8gc8pk9eb0r65vv6r5h8de6bn@4ax.com>

Araxes Tharsis wrote:

>I want to run the following script on Windows 2000, receiving input
>from the file employees.txt. In UNIX it is:
>       MyScript.pl < employees.txt
>But it is not working in Windows.
>Any help appreciated.
>Thanks,
>Araxes
>
>
>$i = 0;
>while(<STDIN>)
>{

You likely have a DOS shell problem.

This should work:

       perl MyScript.pl <employees.txt

-- 
	Bart.


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

Date: Wed, 7 Nov 2001 02:30:44 +0800
From: "Lucas" <wstsoi@hongkong.com>
Subject: install packages to ActivePerl
Message-Id: <9s99c0$2klt$1@news.net-yan.com>

Hi all,

If I can't run ppm on my computer, how could I install a package into my
ActivPerl?

Thanks.




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

Date: Tue, 06 Nov 2001 12:32:41 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: install packages to ActivePerl
Message-Id: <3BE82CC9.6E8F84EA@mail.uca.edu>

Lucas wrote:
> 
> Hi all,
> 
> If I can't run ppm on my computer, how could I install a package into my
> ActivPerl?

You can install packages another way, but why don't you think you can
run ppm on your computer? If you can run Perl, you can run ppm, since it
is just a perl program. See the HTML docs on your hard drive on PPM,
scroll down and you will find what you need to do (exercise left to the
reader).

Cameron
-- 
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu


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

Date: Tue, 06 Nov 2001 18:20:09 GMT
From: Sonny <news@aspersion.org>
Subject: memory profiling
Message-Id: <3BE81B93.4070508@aspersion.org>

What is a good method for profiling memory usage of a perl program.  I 
am running apache/mod_perl with a fairly large application which 
potentially uses a lot of modules (lots of dynamic loading and all 
that.)  I've profiled and optimized performance pretty well with 
apache::dprof but memory usage is strikingly high.

Is there a way to see which modules are using how much memory?  I'd like 
to be able to see when a particular piece of memory gets allocated and 
then when it gets released by the program.  Anybody know of anything 
that will produce such information?

Thanks
Sonny



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

Date: Tue, 06 Nov 2001 18:41:01 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Naive Q: Why Java speed >> Perl speed?
Message-Id: <slrn9ugc2o.3s3.tim@vegeta.ath.cx>


Hash: SHA1

kj0 <kj0@mailcity.com> graced us by uttering:
> Why is it that, typically, the Java VM runs programs so much faster
> than the Perl interpreter?  Is it because of Java's strong typing?  Or
> is it some other difference between the languages that accounts for
> this disparity?
> Thanks,
> kj

Your statement is inconsistent with my experience, therefore I cannot
comment on why your statement may be true.

Your question is off-topic for this newsgroup, therefore I should not
comment.

Try asking comp.lang.java why their language kicks ass.  The responses
won't be any more biased than what you find here.

Tim Hammerquist
- -- 
"The Devil made me do it."
I have never made one of them do anything. They live their own tiny lives.
I do not live their lives for them.
    -- Lucifer, The Sandman


Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE76DBc8vyBPhAeHacRAjO4AJ9Pd0Jd3XmHEKJd6MfOnjjztKoK7QCgptI/
bj7LVVPjis4iJKxvpH++QUI=
=uACu
-----END PGP SIGNATURE-----


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

Date: 06 Nov 2001 10:15:14 -0600
From: Ren Maddox <lmaddox@us.ibm.com>
Subject: Re: Problem with prototype function
Message-Id: <m3d72vnael.fsf@dhcp9-161.support.tivoli.com>

On Tue, 6 Nov 2001, ochampag@nortelnetworks.com wrote:

> sub Connect() {

Here you declare Connect to take no arguments.

> $catasid=Connect("CATA",$addrcata,20,$login,$password);

And here you call Connect with some arguments.

> Too many arguments for Autotest::Connect at ./Init.pl line 38, near
> "$addrubi)"
> Execution of ./Init.pl aborted due to compilation errors.

So you get this error.

> Why ???

Because you declared Connect with a prototype (that's what the "()"
do) and that prototype was not matched by the call to Connect.  You
probably just want to remove the "()" from the declaration.

See the "Prototypes" section of perlsub(1) for more information.

-- 
Ren Maddox
lmaddox@us.ibm.com


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

Date: Tue, 06 Nov 2001 10:18:08 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Profiling Perl
Message-Id: <3BE80D40.923B7FF9@home.com>

Dimitri wrote:
> 
> Is there a way to automatically profile Perl code? I.e. to find
> out for how long the code runs inside any given subroutine etc.?

Check out the Devel::DProf module.

-mjc


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

Date: Tue, 06 Nov 2001 17:01:31 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Profiling Perl
Message-Id: <4c5gut89aha7itml2b26f3mi0ahpl89ttk@4ax.com>

Dimitri wrote:

>Is there a way to automatically profile Perl code? I.e. to find 
>out for how long the code runs inside any given subroutine etc.? 

The FAQ (perldoc -q profile) says:

  Found in D:\programs\indigoperl\lib\pod\perlfaq3.pod
    How do I profile my Perl programs?

            You should get the Devel::DProf module from the standard
            distribution (or separately on CPAN)
	...

See the discussion on <http://use.perl.org>: 


<http://use.perl.org/article.pl?sid=01/10/25/1511218&mode=thread>

-- 
	Bart.


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

Date: Tue, 06 Nov 2001 17:11:23 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Profiling Perl
Message-Id: <slrn9ug36e.b85.tadmc@tadmc26.august.net>

Dimitri <mauroid@csi.forth.gr> wrote:

>Is there a way to automatically profile Perl code? 


   perldoc -q profile

      "How do I profile my Perl programs?"


You should have tried that *before* posting you know.


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


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

Date: 6 Nov 2001 16:08:35 GMT
From: Clay Irving <clay@panix.com>
Subject: Re: simple perl question on Windows
Message-Id: <slrn9ug2o3.bis.clay@panix3.panix.com>

In article <9s915f$n7v$1@magnum.mmm.com>, <jstanley@mmm.com> wrote:

> Do you just want to read from the file?  If so here is the code.
> 
> 
> open (FILEHANDLE, "employees.txt");
> @arrayname=<FILEHANDLE>;
> 
> then go through the array.

If the file is large, perhaps you don't want to load the entire file into an
array. An alternative is to process one line at a time:

  open FILEHANDLE, "employees.txt" or die "$!\n";
  while (<FILEHANDLE>) {
      # process each line
  }

-- 
Clay Irving <clay@panix.com>
Eloquence is logic on fire. 



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

Date: Tue, 6 Nov 2001 17:15:15 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: simple perl question on Windows
Message-Id: <9s9292$3uh$01$1@news.t-online.com>

"Araxes Tharsis" <pnrmaia@hotmail.com> schrieb im Newsbeitrag
news:fb38b9b7.0111060700.75c29acf@posting.google.com...
| Hi,
| I want to run the following script on Windows 2000, receiving input
| from the file employees.txt. In UNIX it is:
|        MyScript.pl < employees.txt
| But it is not working in Windows.

[snip]

#!perl
use strict; # always!
use warnings; # always!

| $i = 0;
| while(<STDIN>)
| {
|   m#\w+\s+(\w+)#;
|   print("$1\n");
|   ++$i
| }
| print("$i records found.");

You could supply the filename and open it.

{ # To make $fh as well as *STDIN local, so $fh closes when it goes out of
scope.
   my $fh = open_file($ARGV[0]);
   local *STDIN = *$fh;
   my $i = 0; # use my!
   while(<STDIN>) {
      m#\w+\s+(\w+)#;
      print "$1\n";
      $i++;
   }
   print "$i records found.";
}

sub open_file {
   my $file = shift;
   die "No paramete passed" if !defined($file);
   my $fh;
   open $fh, "<$file" or die "Could not open file '$file': $!";
   return $fh;
}

Or you could open the file directly as STDIN - without the fancy scoping
thing.

Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m





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

Date: Tue, 06 Nov 2001 16:19:28 GMT
From: "Mike Mackay [Ultrafusion]" <newsgroup_mike@ultrafusion.co.uk>
Subject: Small '-w' Question with Net::POP3
Message-Id: <k4UF7.858$3N6.254873@news1.cableinet.net>

Hi,
      I've written a small perl script that logs into my pop3 account on my
webserver and checks whether I have any mail waiting or not using Net::POP3.
When I run it and enter the correct username/password it works fine, except
when the password is incorrect it comes back to the browser and tells me.
However, when I use the -w switch it errors out on an invalid password
because further on down the script I'm using a variable that gets
uninitialized due to the bad login. Can someone help me with this so that
when the password is wrong it doesn't throw up an error when the -w is on
because I want to keep that switch on for good programming
practice.....anyway here is the current script below :

 = = = = = = = = = = = = = = = = = = = = = = = = =

#!/usr/bin/perl

use Net::POP3;
use strict;

my $mailserver = www.somedomain.com;
my $username = "someusername";
my $password = "somepassword";
print "Content-type: text/html\n\n";

my $pop = new Net::POP3($mailserver);

unless (defined $pop) {
 print "Error Connecting To Mailserver : $mailserver";
 exit();
}

my $num_messages = $pop->login($username, $password);
unless (defined $num_messages) {
 print "Error Authenticating User : $username";
 exit();
}

$pop->quit();
print "<font face=Verdana size=2>Waiting : $num_messages</font>";

exit();

 = = = = = = = = = = = = = = = = = = = = = = = = = =




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

Date: Tue, 06 Nov 2001 17:11:24 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Small '-w' Question with Net::POP3
Message-Id: <slrn9ug3q5.b85.tadmc@tadmc26.august.net>

Mike Mackay [Ultrafusion] <newsgroup_mike@ultrafusion.co.uk> wrote:

>When I run it and enter the correct username/password it works fine, except
>when the password is incorrect it comes back to the browser and tells me.
>However, when I use the -w switch it errors out on an invalid password
                         ^^^^^^^^^^^^^^^^^^^^^^^


This cannot be happening.

Warnings do not change the execution of your program, all they
do is (maybe) make more output on STDERR.

Warnings are not fatal.


>#!/usr/bin/perl
>
>use Net::POP3;
>use strict;
>
>my $mailserver = www.somedomain.com;


How come you are not asking about the *fatal* error at this point?

(or maybe this _is_ what you are asking about. If so, it has nothing
 to do with warnings being enabled or not.
)

Is this your real code?

Isn't strict complaining about those three bare words?

   my $mailserver = 'www.somedomain.com';  # strings must be quoted


>unless (defined $pop) {
> print "Error Connecting To Mailserver : $mailserver";
> exit();


It is conventional to use a *non*-zero exit value for errors.

   exit(1);   


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


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

Date: Tue, 06 Nov 2001 18:28:01 GMT
From: "textnews.casema.net" <kirsthul@casema.net>
Subject: strange behavior from cgi inside protected directory
Message-Id: <RYVF7.306$xK2.957@pollux.casema.net>

Hello,
I'm using the 'ennyform' cgi scripts from www.dtp-aus.com. They work
fine when used in POST-ing a 'normal' html form: on using the 'back
button' (or backspace key) on a cgi-output page it returns the
original values of the filled-in form fields.
However, if the same html page is behind a password protected
directory, the back-button returns an *empty* (reset??) form.

This behaviour applies to IE5, NS and Mozilla but *not* to Konqueror.
The webserver is a WN 2.2.9, using authwn as authorisation module.

Has anyone a clou and/or a work-around??
Thanks.





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

Date: Tue, 06 Nov 2001 10:45:29 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: too late for -T?
Message-Id: <3BE813A9.E07876B@mail.uca.edu>

"Nicholas R. Markham" wrote:
> 
> I have a Perl CGI (several, in fact) that I want to make more secure using
> taint mode.  The shebang line looks like
> 
> #! /usr/bin/perl -T
> 
> But when I try to run it, perl says 'Too late for "-T" option at script.cgi
> line 1.'
> How can the first line of the script be too late?

Sounds like you're working on Window$, yes? (at least your message came
from a Window$ machine) You have to call Perl with the -T option enabled
in your file association. As you know, Perl is called from your file
association, instead of the script (except when you're using Apache, I
don't know) in Window$, so you have already started perl.exe when you
start reading the script. Thus it's too late.

Cameron

-- 
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu


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

Date: Tue, 06 Nov 2001 12:36:09 -0500
From: "Kristina Clair" <kclair@soya.serve.com>
Subject: using a variable in a subroutine name
Message-Id: <9s9747$r4j@netaxs.com>

Hello,

I'm trying to use a variable in the name of a subroutine, like so:

    foreach my $x ("email_zip", "email_txt", "cp_zip", "cp_txt") {
        if ($res = _send_$x($domain, $file, $date, $location)) {
            push (@results, $res);
        }
 
    sub _send_email_zip {
    }

    sub _send_email_txt{
    }

    etc...


However, I'm getting the following error message:
"Can't locate object method "_send_" via package "email_zip" (perhaps you forgot to load
"email_zip"?)"

So, then I thought I could use the whole subroutine name in the foreach
loop: ("_send_email_zip", "_send_email_txt", etc), but I cannot figure
out if there is a way to get this to work.

Does anyone know of a way to use a variable in the name of a subroutine?

Thanks,
Kristina Clair


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

Date: Tue, 06 Nov 2001 10:30:00 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: using a variable in a subroutine name
Message-Id: <3BE82C28.C7D6DAE1@vpservices.com>

Kristina Clair wrote:
> 
> Hello,
> 
> I'm trying to use a variable in the name of a subroutine, like so:
> 
>     foreach my $x ("email_zip", "email_txt", "cp_zip", "cp_txt") {
>         if ($res = _send_$x($domain, $file, $date, $location)) {

Replace that last line with these two:

   my $com = "_send_$x";
   if ($res = &$com($domain, $file, $date, $location)) {

-- 
Jeff



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

Date: Tue, 06 Nov 2001 18:36:59 GMT
From: "Ron Hartikka" <ronh@iainc.com>
Subject: Re: using a variable in a subroutine name
Message-Id: <f5WF7.2369$PM1.38655@typhoon.mw.mediaone.net>

You could put a whole sub name in a var (symbolic ref), but not part of a
name (interpolation).
But don't do that. Instead, get (hard) refs to the subs and process a list
of refs:

$email_zip = \&_send_email_zip; # take hte refs
$email_txt = \&_send_email_txt;

($domain, $file, $date, $location) = qw(domain file date location); # just
so there's someoutput

foreach my $x ($email_zip, $email_txt) {

 if ($res = &$x($domain, $file, $date, $location)) {
     push (@results, $res);
 }

}

print join " ", "results", @results, "\n";

sub _send_email_zip {
 print join " ", "zip", @_, "\n";

}

sub _send_email_txt {
 print join " ", "txt", @_, "\n";

}

 ... prints...

zip domain file date location
txt domain file date location
results 1 1

"Kristina Clair" <kclair@soya.serve.com> wrote in message
news:9s9747$r4j@netaxs.com...
> Hello,
>
> I'm trying to use a variable in the name of a subroutine, like so:
>
>     foreach my $x ("email_zip", "email_txt", "cp_zip", "cp_txt") {
>         if ($res = _send_$x($domain, $file, $date, $location)) {
>             push (@results, $res);
>         }
>
>     sub _send_email_zip {
>     }
>
>     sub _send_email_txt{
>     }
>
>     etc...
>
>
> However, I'm getting the following error message:
> "Can't locate object method "_send_" via package "email_zip" (perhaps you
forgot to load
> "email_zip"?)"
>
> So, then I thought I could use the whole subroutine name in the foreach
> loop: ("_send_email_zip", "_send_email_txt", etc), but I cannot figure
> out if there is a way to get this to work.
>
> Does anyone know of a way to use a variable in the name of a subroutine?
>
> Thanks,
> Kristina Clair






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

Date: Tue, 06 Nov 2001 18:36:58 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: using a variable in a subroutine name
Message-Id: <x78zdjvj7m.fsf@home.sysarch.com>

>>>>> "JZ" == Jeff Zucker <jeff@vpservices.com> writes:

  >> I'm trying to use a variable in the name of a subroutine, like so:
  >> 
  >> foreach my $x ("email_zip", "email_txt", "cp_zip", "cp_txt") {
  >> if ($res = _send_$x($domain, $file, $date, $location)) {

  JZ> Replace that last line with these two:

  JZ>    my $com = "_send_$x";
  JZ>    if ($res = &$com($domain, $file, $date, $location)) {

i was hoping no one would give a symbolic ref answer. too bad but you
just did. a dispatch table (hash of names to sub refs) is the best way
to do this.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Tue, 06 Nov 2001 10:41:00 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: using a variable in a subroutine name
Message-Id: <3BE82EBC.5252E25D@vpservices.com>

Uri Guttman wrote:
> 
> >>>>> "JZ" == Jeff Zucker <jeff@vpservices.com> writes:
> 
>   >> I'm trying to use a variable in the name of a subroutine, like so:
>   >>
>   >> foreach my $x ("email_zip", "email_txt", "cp_zip", "cp_txt") {
>   >> if ($res = _send_$x($domain, $file, $date, $location)) {
> 
>   JZ> Replace that last line with these two:
> 
>   JZ>    my $com = "_send_$x";
>   JZ>    if ($res = &$com($domain, $file, $date, $location)) {
> 
> i was hoping no one would give a symbolic ref answer. too bad but you
> just did. a dispatch table (hash of names to sub refs) is the best way
> to do this.

Yes, duh.  I was looking at the small picture of why  _send_$x()
wouldn't work because there was no concatenation.  You are of course
correct about it being a bad answer in the bigger picture.

-- 
Jeff



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

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


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