[22836] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5057 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 29 14:06:06 2003

Date: Thu, 29 May 2003 11:05:09 -0700 (PDT)
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, 29 May 2003     Volume: 10 Number: 5057

Today's topics:
        "nice"ing a script on Unix <bernie@rev.net>
        Form script changes (Steve)
    Re: Form script changes <john.thetenant-s@moving-picture.com>
    Re: hard time with regexp to validate image <woloski@sion.com>
    Re: Help Needed Building Packet <nobull@mail.com>
        Invalid Arguement <porter96@lycos.com>
    Re: Invalid Arguement <matthew@weierophinney.net>
    Re: Piping STDOUT to sendmail via a perl script <nobull@mail.com>
        Please help with this script <leonid.lamburt@gte.com>
        regex-identifying a new line when using /s <lance-news@augustmail.com>
    Re: regular expression matches but $1 left undefined (Tad McClellan)
    Re: regular expression matches but $1 left undefined (justin)
    Re: regular expression matches but $1 left undefined <nobull@mail.com>
    Re: regular expression matches but $1 left undefined <ddunham@redwood.taos.com>
    Re: Semi-Newbie Steps Into Module Hell <kevin.vaughn@ttu.edu>
    Re: Semi-Newbie Steps Into Module Hell <nospam@raytheon.com>
    Re: uninitialized value in eval block? <spam.me.senseless@sitting.duck>
    Re: uninitialized value in eval block? <spam.me.senseless@sitting.duck>
    Re: uninitialized value in eval block? <nobull@mail.com>
    Re: uninitialized value in eval block? <spam.me.senseless@sitting.duck>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 29 May 2003 14:02:42 -0400
From: Bernard Cosell <bernie@rev.net>
Subject: "nice"ing a script on Unix
Message-Id: <7lacdvgcerrprvlmm3n09710cd76evkonn@4ax.com>

Does perl include hooks for the unix 'nice(2)' system call?  perldoc
didn't show up anything and searching CPAN for 'nice' gets me a
thousand hits.  Tnx..

  /Bernie\


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

Date: 29 May 2003 08:39:03 -0700
From: techadmin@shaw.ca (Steve)
Subject: Form script changes
Message-Id: <2e27f51a.0305290739.361202b5@posting.google.com>

I have a simple perl script running to process form input (bnbform
version 4.0?)(The forms are all html). Right now the form returns all
the values that are available on the form in the form of a list, a=,
b=, c=. If you enter into the form the value for a as ABC then you
reveive, a=abc,b=,c= etc. I would like to recode it so that the only
values returned are those input values used. so in fact b= and c=,
would not show in the e-amil as there was no input value assigned. I
hope this all makes sence.
My knowledge of perl is limited to none but follow instruction well.


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

Date: Thu, 29 May 2003 17:06:40 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Form script changes
Message-Id: <20030529170640.27025d13.john.thetenant-s@moving-picture.com>

On 29 May 2003 08:39:03 -0700
techadmin@shaw.ca (Steve) wrote:
>
> I have a simple perl script running to process form input (bnbform
> version 4.0?)(The forms are all html). Right now the form returns all
> the values that are available on the form in the form of a list, a=,
> b=, c=. If you enter into the form the value for a as ABC then you
> reveive, a=abc,b=,c= etc. I would like to recode it so that the only
> values returned are those input values used. so in fact b= and c=,
> would not show in the e-amil as there was no input value assigned. I
> hope this all makes sence.
> My knowledge of perl is limited to none but follow instruction well.

replace 
@pairs=split(/&/,$temp);

with
@pairs=grep(/=.+/,split(/&/,$temp));



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail


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

Date: Thu, 29 May 2003 12:31:08 -0300
From: "Matias Woloski" <woloski@sion.com>
Subject: Re: hard time with regexp to validate image
Message-Id: <bb5937$5mfvo$1@ID-148083.news.dfncis.de>

Jürgen
I will tell you the truth... this won't be perl... I'm working with .Net and
Javascript... I tried here because I know perl has lot of regexp gurus.

I will implement a custom solution if I don't get a pure regexp one...

thanks for your help,
Matias

"Jürgen Exner" <jurgenex@hotmail.com> escribió en el mensaje
news:0CgBa.23446$8i4.2648@nwrddc02.gnilink.net...
> Matias Woloski wrote:
> > I'm trying to write a regular expression to validate valid images.
> > This means that will have to match
> >
> > Match
> > 1) myfile1.gif
> > 2) myfile
> > 3) myfile.mine.jpg
> > 4) my file.jpeg
> > etc..
> >
> > Non-match
> > 1) file.exe
> > 2) file.vbs
> > 3) file.notknownextension
> > etc
> >
> > Those are the basic cases
> > So far I did this one
> >
> > ^[^\.]+(?:\.(?:gif|jpe?g))?$
> >
> > This will validate every case but leaves out the case 3) where there
> > are two points in the input.
> >
> > Now that's the problem... How would you change or create a new regexp
> > to deal with that?
>
> Unless you insist on doing it the hard way you wouldn't.
>
> First of all you should use File::Basename to split the full name into
path,
> name, and extension.
> And then you would simply use exist() to check if the extension exists in
a
> hash that contains all known/wanted extensions.
>
> jue
>
>




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

Date: 29 May 2003 17:59:21 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Help Needed Building Packet
Message-Id: <u9u1bdvgd2.fsf@wcl-l.bham.ac.uk>

Derek Mark Edding <dreq@earthlink.net> writes:

> Hi Folks,
> 
> My Perl has gotten a bit rusty in the last couple of years.  I'm
> looking for an example that shows how to build a packet (either UDP or
> IP) starting with an array of hexadecimal numbers.
> 
> I start out with a scalar array, @hexVals, of hexadecimal values for
> the packet.  I need to convert this to a binary stream of data to give
> to send(), called $MSG.  This is the character string form of a scalar
> variable.

join '', map { pack('H*',$_) } @hexVals;

or 

pack 'H*', join '', @hexVals;

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


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

Date: Thu, 29 May 2003 10:45:16 -0500
From: "Steve" <porter96@lycos.com>
Subject: Invalid Arguement
Message-Id: <vdcao4o6e7s78d@corp.supernews.com>

At the risk of revealing just how ignorant I am when it comes to Perl ...
could someone tell me why this gives me a "Invalid Arguement" error?


     $pass_file = 'http://www.domainname.com/cgi-bin/password.dat';

     open (PASSWORDS, "$pass_file") || die print "Can't open file
$pass_file: $!\n";
             @pass_array = <PASSWORDS>;
     close(PASSWORDS);


"Can't open file http://www.domainname.com/cgi-bin/password.dat: Invalid
argument"


Thanks,
Steve




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

Date: Thu, 29 May 2003 15:48:15 GMT
From: Matthew Weier O'Phinney <matthew@weierophinney.net>
Subject: Re: Invalid Arguement
Message-Id: <slrnbdcatv.12b.matthew@kavalier.weierophinney.net>

* Steve <porter96@lycos.com>:
> At the risk of revealing just how ignorant I am when it comes to Perl ...
> could someone tell me why this gives me a "Invalid Arguement" error?
> 
> 
>      $pass_file = 'http://www.domainname.com/cgi-bin/password.dat';
> 
>      open (PASSWORDS, "$pass_file") || die print "Can't open file
> $pass_file: $!\n";
>              @pass_array = <PASSWORDS>;
>      close(PASSWORDS);
> 
> 
> "Can't open file http://www.domainname.com/cgi-bin/password.dat: Invalid
> argument"

open is used to open files on the local filesystem. You'll need to use
LWP or a socket to grab this file.

-- 
Matthew Weier O'Phinney
matthew@weierophinney.net
http://matthew.weierophinney.net


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

Date: 29 May 2003 17:15:26 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Piping STDOUT to sendmail via a perl script
Message-Id: <u9fzmxwwyp.fsf@wcl-l.bham.ac.uk>

AcCeSsDeNiEd <dillon@SpamMinuSaccessdenied.darktech.org> writes:

> Subject: Piping STDOUT to sendmail via a perl script

Your question has nothing to do with STDOUT, sendmail, or pipes.

Enable either strictures or warnings and Perl will point your error
out to you.

Better still enable both!

> To e-mail, remove the obvious

To debug Perl problems, add the obvious.

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


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

Date: Thu, 29 May 2003 13:31:31 -0400
From: L Lamburt <leonid.lamburt@gte.com>
Subject: Please help with this script
Message-Id: <3ED643F2.8315B7A9@gte.com>

Hello,
Can any one please help me with the following problem?

The script below produces the following output:

Top
Bakeries|Shops
======
Top
Travel|Bakeries|Shops
======
Why is that ? Why is it printing Bakeries and Shops when I dump second
level
keys in the second hash while only Travel should be printed ?
(
 /tools/perl/bin/perl -V
 Summary of my perl5 (revision 5.0 version 6 subversion 1)
configuration:
 Platform: osname=solaris, osvers=2.8, archname=sun4-solaris
)

Thanks in advance for any help.
LL
---------------------------------------------------------------------------------------------

#!/tools/perl/bin/perl

eval "\$m{Top}=1";
eval "\$m{Top}{Shops}=1";
$str =  "\$m{Top}{Bakeries}{Wedding_Cake}=1";
eval $str;

$" = '|';
print keys %m, "\n";
@a = keys %{$m{Top}};

print "@a\n======\n"; #dumping keys for hash 1

%n = ();
$n{Top}=1;
$n{Top}{Travel}{Agencies}=1;
$n{Top}{Travel}{Money_Exchange}=1;

print  keys %n, "\n";
@b =  keys %{$n{Top}};
print "@b\n======\n"; #dumping keys for hash 2





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

Date: Thu, 29 May 2003 10:50:48 -0500
From: Lance Hoffmeyer <lance-news@augustmail.com>
Subject: regex-identifying a new line when using /s
Message-Id: <YsOcnVkS3I3ssUujXTWcog@august.net>

I am running a regex with the /s to ignore newlines but I want to be 
able to identify a newline.

Here is what I am using to get to the newline
Q4.*?AD AWARE.*?
but would rather have something like
Q4.*?\n AD AWARE.*?

but \n does not work (I am assuming because of the /s).  How can
I identify a newline while using the /s?

Lance



$file=~/TABLE\s+14.*?Q4.*?AD AWARE.*?(?:(\d{1,3}\.\d|\- 
)[A-T\s]+){1}/s;my $P07A086=Round($1,0)/100;

Q4 - TOP OF MIND       26      3     23     17    11    15    22
  AD AWARE             9.3    8.4    9.4    8.6  11.3  13.9  22.3DE



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

Date: Thu, 29 May 2003 08:50:53 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regular expression matches but $1 left undefined
Message-Id: <slrnbdc41t.381.tadmc@magna.augustmail.com>

Garry Short <g4rry_short@zw4llet.com> wrote:

[snip full-quote]

> print "1. $1\n" if $1;

> The print command will only happen if $x is defined,
                                              ^^^^^^^

No it won't. The print() will only happen if $x is _true_.

You must test for definedness if that is what you want to test for:

   print "1. $1\n" if defined $1;


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


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

Date: 29 May 2003 09:39:58 -0700
From: justinrobertson@btinternet.com (justin)
Subject: Re: regular expression matches but $1 left undefined
Message-Id: <48f83c27.0305290839.57598f48@posting.google.com>

These are all great answers and they all seems to be right! Thank you
very much. I had assumed that $1 got the first bracketed expression
that was matched, and not the first one whether it matched or not.

Here's another quick one for you:

Is this:

($x) = $y =~ /$re/;
if ($x) {
  print "Match";
}

equivalent to this:

if ($y =~ /$re/) {
  print "Match";
}

If not, what's the difference?

Thanks again all of you for your great help.


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

Date: 29 May 2003 17:52:40 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: regular expression matches but $1 left undefined
Message-Id: <u9y90pvgo7.fsf@wcl-l.bham.ac.uk>

justinrobertson@btinternet.com (justin) writes:

> These are all great answers and they all seems to be right! Thank you
> very much. I had assumed that $1 got the first bracketed expression
> that was matched, and not the first one whether it matched or not.
> 
> Here's another quick one for you:
> 
> Is this:
> 
> ($x) = $y =~ /$re/;
> if ($x) {
>   print "Match";
> }
> 
> equivalent to this:
> 
> if ($y =~ /$re/) {
>   print "Match";
> }

No.
 
> If not, what's the difference?

The behaviour of m// in a list v. scalar context.  Change ($x)= to $x=
and then they'd be the same.

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


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

Date: Thu, 29 May 2003 17:15:41 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: regular expression matches but $1 left undefined
Message-Id: <1frBa.17$sB5.2077853@newssvr15.news.prodigy.com>

justin <justinrobertson@btinternet.com> wrote:
> Is this:

> ($x) = $y =~ /$re/;
> if ($x) {
>   print "Match";
> }

This evaluates $x for truth.  Undefined and zero "0" will be false, with
all others true. 

What $x is depends on what $re is.  If there are no capturing
parenthesis, then $x will be 1 on a match and undefined otherwise.
If there are capturing parentheses, then $x will be the value of the
first set if a match occurs.

> equivalent to this:

> if ($y =~ /$re/) {
>   print "Match";
> }

This evaluates the match itself, which will be true if the match is
successful, and false otherwise.

> If not, what's the difference?

Try your samples with these two variables....

$y = "I walked 1000 miles";
$re = "1(.)";

Or these two.
$y = "Isn't it true?";
$re = "(is)|(Isn't)"

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: Thu, 29 May 2003 10:48:16 -0500
From: "Kevin Vaughn" <kevin.vaughn@ttu.edu>
Subject: Re: Semi-Newbie Steps Into Module Hell
Message-Id: <vdcaudbrr3qr3b@corp.supernews.com>

I've upgraded to 5.8, but there doesn't appear to be support for ADO... Do
you know of a way around this?  Is there a way to use 5.6.1 with the newest
version of Win32::OLE?




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

Date: Thu, 29 May 2003 11:58:40 -0500
From: Chris Olive <nospam@raytheon.com>
Subject: Re: Semi-Newbie Steps Into Module Hell
Message-Id: <R_qBa.3412$c6.3325@bos-service2.ext.raytheon.com>

Kevin Vaughn wrote:
> Thanks for the help guys.  I'm pretty sure my installation is botched.  Now
> I can't get it to work at all.  I get errors either way I run it (with .1403
> or .1501).  I am either going to reinstall or upgrade to 5.8.
> 
> I found no other instances of ole.pm outside of lib and site/lib.
> 
> Assuming I reinstall Perl and I don't upgrade to 5.8, what would be the
> proper way to upgrade ole.pm?  I know I should RTFM - can you refer me to
> the proper one?
> 

The "proper way" to install modules using ActiveState Perl is to use PPM 
as it appears you have been doing.  It would seem there is something 
wrong with your 5.6.1 install, esp. since you've not installed any 
modules previous.  This can happen, occasionally, with AS Perl installs; 
I've seen it happen.  It probably wouldn't hurt one bit to remove your 
Perl directory and start with a clean install of 5.8.0.  The 5.8.0 
installer is a bit more robust than the 5.6.0 and 5.6.1 installers 
were/are, though I never had any issues with a 5.6.x installer above 
Release 630.

Chris
-----
Chris Olive
Systems Consultant
Raytheon Technical Services Corporation
Indianapolis, IN

email: olivec(AT)indy(DOT)raytheon(DOT)com



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

Date: Thu, 29 May 2003 17:51:39 +0100
From: SeeMySig <spam.me.senseless@sitting.duck>
Subject: Re: uninitialized value in eval block?
Message-Id: <DK0dQJJbqj1+EwZl@nildram.co.uk>

In message <3ED61348.3000908@acm.org>, Winfried Koenig 
<w.koenig@acm.org> writes
[edited]
>>   Take this example:
>>          my $method1 = <<EOMETH1;
>>     sub {
>>         #line 1 (method1)
>>         print "hello";
>>         die;
>>     }
>>     EOMETH1
>>          $method2 = <<EOMETH2;
>>     sub {
>>         #line 1 (method2)
>>         print "hello";
>>         die;
>>     }
>>     EOMETH2
>>      *meth1 = eval $method1;
>>     *meth2 = eval $method2;
>>      meth2();
>>     __END__
>>     Died at (method2) line 2.
>>     Consider CGI.pm that has a lot of methods defined as strings that 
>>later
>> get evaluated (like the above). It is not always spontaneously obvious
>> which one failed. But if each method at least has a label, you instantly
>> know which piece of string croaked. Counting a couple of lines in such a
>> bunch of code is then left as a trivial excercise. It is certainly much
>> clearer than the usual
>>      Died at (eval 2) line 4.
>
>Hmm, for Perl Versions 5.003 up to 5.8.0 the line directive must
>start at beginning of a line. For Versions 5.003 to 5.6.0 the
>directive must not be in the first evaluated line. So the example
>should read:
>
>my $method2 = <<EOMETH2;
>sub {
># line 2 (method2)
>    print "hello\n";
>    die;
>}
>EOMETH2
>
>Winfried
>
Oh dear - now I'm hopelessly lost - v 5.003 to 5.8.0 surely includes 
5.6.0?
-- 
RA Jones
ra(dot)jones(at)dpw(dot)clara(dot)net



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

Date: Thu, 29 May 2003 17:52:43 +0100
From: SeeMySig <spam.me.senseless@sitting.duck>
Subject: Re: uninitialized value in eval block?
Message-Id: <KKkfQpJbrj1+Ew4F@nildram.co.uk>

In message <bb4rd0$l16$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval 
<tassilo.parseval@rwth-aachen.de> writes
>Also sprach SeeMySig:
>
>> In message <bb4a2v$64f$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval
>><tassilo.parseval@rwth-aachen.de> writes
>
>>>For larger pieces that are executed within an eval(), it's sometimes not
>>>a bad idea to add #line comments:
>>>
>>>    eval <<EOEVAL;
>>>    ...
>>>    #line 100 (oops)
>>>    die;
>>>    EOEVAL
>>>
>>>Results in the much more meaningful
>>>
>>>    Died at (oops) line 100.
>> Que? I can see that would work if I knew it was going to choke at line
>> 100, but then if I knew that...
>>
>> How does it help me otherwise within a large eval block?
>
>Take this example:
>
>    my $method1 = <<EOMETH1;
>    sub {
>        #line 1 (method1)
>        print "hello";
>        die;
>    }
>    EOMETH1
>
>    $method2 = <<EOMETH2;
>    sub {
>        #line 1 (method2)
>        print "hello";
>        die;
>    }
>    EOMETH2
>
>    *meth1 = eval $method1;
>    *meth2 = eval $method2;
>
>    meth2();
>    __END__
>    Died at (method2) line 2.
>
>Consider CGI.pm that has a lot of methods defined as strings that later
>get evaluated (like the above). It is not always spontaneously obvious
>which one failed. But if each method at least has a label, you instantly
>know which piece of string croaked. Counting a couple of lines in such a
>bunch of code is then left as a trivial excercise. It is certainly much
>clearer than the usual
>
>    Died at (eval 2) line 4.
It certainly is Tassilo, but I am not familiar with what you are doing 
here (the *meth1  = eval $method, etc), so I cannot follow it.

But I like the idea in principle of putting helpful die labels into the 
methods. Presumably everyone gets one, and the method causing the script 
to die gets identified by the comment in the first line?
-- 
RA Jones
ra(dot)jones(at)dpw(dot)clara(dot)net



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

Date: 29 May 2003 17:43:14 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: uninitialized value in eval block?
Message-Id: <u98yspwvod.fsf@wcl-l.bham.ac.uk>

SeeMySig <spam.me.senseless@sitting.duck> writes:

> In the process of removing all warning violations from my CGI script,
> I find the following gets passed during warningsToBrowser(1):
> 
> <!-- warning: Use of uninitialized value in concatenation (.) or
> string at (eval 18) line 32. -->

Yes this is a known problem with CGI.pm.  It uses a kind of weird
autoload mechanism that uses eval EXPR (not eval BLOCK).  The problem
is that if an error or warning occurs in code that results from an
eval EXPR the location information is cyrptic.

This could be resolved by putting a #line directive into the string that
is evaled in CGI::_compile.

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


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

Date: Thu, 29 May 2003 18:21:09 +0100
From: SeeMySig <spam.me.senseless@sitting.duck>
Subject: Re: uninitialized value in eval block?
Message-Id: <LtzvpYLFGk1+Ewqk@nildram.co.uk>

In message <u98yspwvod.fsf@wcl-l.bham.ac.uk>, Brian McCauley 
<nobull@mail.com> writes
>SeeMySig <spam.me.senseless@sitting.duck> writes:
>
>> In the process of removing all warning violations from my CGI script,
>> I find the following gets passed during warningsToBrowser(1):
>>
>> <!-- warning: Use of uninitialized value in concatenation (.) or
>> string at (eval 18) line 32. -->
>
>Yes this is a known problem with CGI.pm.  It uses a kind of weird
>autoload mechanism that uses eval EXPR (not eval BLOCK).  The problem
>is that if an error or warning occurs in code that results from an
>eval EXPR the location information is cyrptic.
You mean I have been tearing out what little hair I have left for no 
good reason :-(

>This could be resolved by putting a #line directive into the string that
>is evaled in CGI::_compile.
>
Care to spell that one out for me?
-- 
RA Jones
ra(dot)jones(at)dpw(dot)clara(dot)net



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

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


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