[22838] in Perl-Users-Digest
Perl-Users Digest, Issue: 5059 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 29 18:10:34 2003
Date: Thu, 29 May 2003 15:10:11 -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: 5059
Today's topics:
Re: Please help with this script (Tad McClellan)
Re: Please help with this script <s_grazzini@hotmail.com>
Re: Please help with this script <leonid.lamburt@gte.com>
Re: Please help with this script <uri@stemsystems.com>
Re: Please help with this script <mbudash@sonic.net>
Re: Please help with this script (Jay Tilton)
Re: Please help with this script <leonid.lamburt@gte.com>
Re: regex-identifying a new line when using /s <s_grazzini@hotmail.com>
Re: scope of variable (Al MacHonahey)
Re: scope of variable <emschwar@pobox.com>
sends email from the Windows machine <levalt@rogers.com>
Using Getopt::Long with multiple options in quotes <bvenkata+nospam@sm.intel.com>
Re: Using Getopt::Long with multiple options in quotes <TruthXayer@yahoo.com>
variable for current line number (of script) <ericw@nospam.ku.edu>
Re: variable for current line number (of script) <uri@stemsystems.com>
WCTP and perl <roach@kronic.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 29 May 2003 14:00:01 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Please help with this script
Message-Id: <slrnbdcm5h.1pe.tadmc@magna.augustmail.com>
L Lamburt <leonid.lamburt@gte.com> wrote:
> eval "\$m{Top}=1";
What is wrong with $m{Top}=1; ??
> eval "\$m{Top}{Shops}=1";
What is wrong with $m{Top}{Shops}=1; ??
> $str = "\$m{Top}{Bakeries}{Wedding_Cake}=1";
> eval $str;
What is wrong with $m{Top}{Bakeries}{Wedding_Cake}=1; ??
What's with all those (unnecessary) eval()s?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 29 May 2003 19:52:05 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Please help with this script
Message-Id: <FxtBa.32626$4_1.9237457@twister.nyc.rr.com>
L Lamburt <leonid.lamburt@gte.com> writes:
>
> Why is it printing Bakeries and Shops when I dump second level
> keys in the second hash while only Travel should be printed?
>
Great! You don't even need all the eval() business:
#!/usr/bin/perl -l
$_++ for $x{foo}, $y{foo};
$x{foo}{bar} = "whoops";
print $y{foo}{bar};
Remarkably buglike, but I could only check it with 5.6.1...
--
Steve
------------------------------
Date: Thu, 29 May 2003 15:59:33 -0400
From: L Lamburt <leonid.lamburt@gte.com>
Subject: Re: Please help with this script
Message-Id: <3ED666A4.9224FDAC@gte.com>
So, is it a bug or some obscure feature?
Leonid
Steve Grazzini wrote:
> L Lamburt <leonid.lamburt@gte.com> writes:
> >
> > Why is it printing Bakeries and Shops when I dump second level
> > keys in the second hash while only Travel should be printed?
> >
>
> Great! You don't even need all the eval() business:
>
> #!/usr/bin/perl -l
>
> $_++ for $x{foo}, $y{foo};
>
> $x{foo}{bar} = "whoops";
> print $y{foo}{bar};
>
> Remarkably buglike, but I could only check it with 5.6.1...
>
> --
> Steve
------------------------------
Date: Thu, 29 May 2003 20:05:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Please help with this script
Message-Id: <x7znl5cydt.fsf@mail.sysarch.com>
>>>>> "LL" == L Lamburt <leonid.lamburt@gte.com> writes:
LL> #!/tools/perl/bin/perl
put in use strict. then see what happens.
LL> eval "\$m{Top}=1";
LL> eval "\$m{Top}{Shops}=1";
why the eval? absolutely no reason for it. where did you even get the
idea that eval is needed for simple hash assignments?
also think about what is in $m{Top} after the second assignment. it is
not what you think it should be. read perlreftut, perlref, perldsc and
perllol to learn about perl data structures. you are breaking a major
rule there (which strict catches).
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 29 May 2003 20:03:17 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Please help with this script
Message-Id: <mbudash-D7BFBF.13031529052003@typhoon.sonic.net>
In article <3ED643F2.8315B7A9@gte.com>,
L Lamburt <leonid.lamburt@gte.com> wrote:
> 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
>
>
>
aside from the other answers you've gotten (drop the eval's, etc.), drop
these and it works fine (i'll let some of the better perloids explain
why):
$m{Top}=1;
$n{Top}=1;
hth-
--
Michael Budash
------------------------------
Date: Thu, 29 May 2003 20:25:49 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Please help with this script
Message-Id: <3ed66815.48683151@news.erols.com>
L Lamburt <leonid.lamburt@gte.com> wrote:
: Hello,
: Can any one please help me with the following problem?
Perl could have.
use strict 'refs';
But you didn't ask it to, did you?
: #!/tools/perl/bin/perl
:
: eval "\$m{Top}=1";
: eval "\$m{Top}{Shops}=1";
$m{Top} has a value of 1, but you're treating it like it's a hash
reference. You're asking Perl to dereference "1" into a hash, so it
does.
What happens is the same as saying
$1{Shops} = 1;
Congratulations on accidentally discovering evil symbolic references.
: $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;
Same thing. You're asking Perl to dereference "1" into a hash, and it
does. The data structures in %m and %n are now lashed to each other
by symbolic references to %main::1
: $n{Top}{Travel}{Money_Exchange}=1;
:
: print keys %n, "\n";
: @b = keys %{$n{Top}};
: print "@b\n======\n"; #dumping keys for hash 2
Now dig what happens if you say
use Data::Dumper;
print Dumper( \%main::1 );
The cure is to let autovificiation take care of creating the necessary
hash keys in the data structure, instead of explicitly creating them
yourself and assigning the wrong data type to the values.
And "use strict;". Always.
------------------------------
Date: Thu, 29 May 2003 16:30:33 -0400
From: L Lamburt <leonid.lamburt@gte.com>
Subject: Re: Please help with this script
Message-Id: <3ED66DE8.D6F8F94@gte.com>
Thanks a lot.
LL
Jay Tilton wrote:
> L Lamburt <leonid.lamburt@gte.com> wrote:
>
> : Hello,
> : Can any one please help me with the following problem?
>
> Perl could have.
>
> use strict 'refs';
>
> But you didn't ask it to, did you?
>
> : #!/tools/perl/bin/perl
> :
> : eval "\$m{Top}=1";
> : eval "\$m{Top}{Shops}=1";
>
> $m{Top} has a value of 1, but you're treating it like it's a hash
> reference. You're asking Perl to dereference "1" into a hash, so it
> does.
>
> What happens is the same as saying
>
> $1{Shops} = 1;
>
> Congratulations on accidentally discovering evil symbolic references.
>
> : $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;
>
> Same thing. You're asking Perl to dereference "1" into a hash, and it
> does. The data structures in %m and %n are now lashed to each other
> by symbolic references to %main::1
>
> : $n{Top}{Travel}{Money_Exchange}=1;
> :
> : print keys %n, "\n";
> : @b = keys %{$n{Top}};
> : print "@b\n======\n"; #dumping keys for hash 2
>
> Now dig what happens if you say
>
> use Data::Dumper;
> print Dumper( \%main::1 );
>
>
> The cure is to let autovificiation take care of creating the necessary
> hash keys in the data structure, instead of explicitly creating them
> yourself and assigning the wrong data type to the values.
>
> And "use strict;". Always.
------------------------------
Date: Thu, 29 May 2003 18:11:32 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: regex-identifying a new line when using /s
Message-Id: <o3sBa.77757$h42.27023@twister.nyc.rr.com>
Lance Hoffmeyer <lance-news@augustmail.com> writes:
>
> 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?
The /s modifier doesn't change the meaning of "\n" -- which
always matches a newline. It changes the meaning of dot.
$ perldoc perlre
> $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
Looks like you have a newline followed by two spaces in the
sample data, and a newline followed by one space in the regex.
--
Steve
------------------------------
Date: 29 May 2003 14:06:27 -0700
From: supermanisadork71@yahoo.com (Al MacHonahey)
Subject: Re: scope of variable
Message-Id: <f48b8b09.0305291306.36a4c698@posting.google.com>
Abigail <abigail@abigail.nl> wrote in message news:<slrnbd6le9.co.abigail@alexandra.abigail.nl>...
> fatted (fatted@yahoo.com) wrote on MMMDLVI September MCMXCIII in
> <URL:news:4eb7646d.0305270116.665b04ab@posting.google.com>:
> // Consider code:
> //
> // use warnings;
> // use strict;
> //
> // open(OUT,'>>','program.log');
> //
> // while(1)
> // {
> // sleep(3);
> // print OUT "Hello\n";
> // }
> //
> // With the strict pragma, the filehandle OUT is not available in the
> // while block,
>
> Please show us the compile time error you are getting you moron,
> because it seems you have stumbled upon the reality that you should
> not be working in Perl.
>
>
> Abigail
???
------------------------------
Date: 29 May 2003 15:17:41 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: scope of variable
Message-Id: <eto3cixzc3u.fsf@wormtongue.emschwar>
supermanisadork71@yahoo.com (Al MacHonahey) writes:
> Abigail <abigail@abigail.nl> wrote in message news:<slrnbd6le9.co.abigail@alexandra.abigail.nl>...
> > Please show us the compile time error you are getting you moron,
> > because it seems you have stumbled upon the reality that you should
> > not be working in Perl.
No she didn't. It's unconscionable to edit someone's words to make it
appear they said something they didn't, doubly so when you do so to
make it appear they said the opposite of what they did. Abigail
actually said:
> > Please show us the compile time error you are getting, because it
> > seems you have stumbled upon a bug in Perl.
*plonk*
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Thu, 29 May 2003 21:56:33 GMT
From: "Lev Altshuler" <levalt@rogers.com>
Subject: sends email from the Windows machine
Message-Id: <lmvBa.303860$w7k.65766@news04.bloor.is.net.cable.rogers.com>
Hi,
I am trying to write a program that sends email from the Windows machine.
I am using Mail::Mailer module when specifying 'smtp' as an argument:
#!perl -w
use Mail::Mailer;
use Net::SMTP;
my $type = 'smtp';
my $server = 'smtp';
my $mailer = new Mail::Mailer 'smtp', Server => $server;
$mailer->open ( { From => 'levalt@rogers.com',
To => 'altlev@hotmail.com',
Subject => 'Hello' });
print $mailer "Hello world";
$mailer->close;
I get an error: "Can't locate Mail/Mailer.pm in @INC (@INC contains...)"
whereas it is available there.
Could anyone give me a clue why it happens on Windows, please.
Yet, please review this peace of code if everything is OK.
Thanks,
Lev
------------------------------
Date: Thu, 29 May 2003 12:13:51 -0700
From: Balaji Venkataraman <bvenkata+nospam@sm.intel.com>
Subject: Using Getopt::Long with multiple options in quotes
Message-Id: <8afzmxva4w.fsf@sm.intel.com>
When using Getopt::Long I have something like this:
--my_script--
GetOptions (\%hash, "libs=s@");
--my_script--
Now if the user invokes 'my_script' thus:
Shell-Prompt$ my_script -l "/usr/lib /usr/local/lib"
This puts both '/usr/lib' and '/usr/local/lib' into ${$hash{libs}}[0] as a
single string. I can see that this is expected, but can I avoid this somehow
- meaning I'd like them to be elements [0] and [1]? I can work around this
by parsing each element of @{$hash{libs}}, but would like to know if there's
something better.
Thanks!
--
Remember 2 + 2 = 5, for large values of 2
------------------------------
Date: Thu, 29 May 2003 13:24:42 -0700
From: TruthXayer <TruthXayer@yahoo.com>
Subject: Re: Using Getopt::Long with multiple options in quotes
Message-Id: <3ED66C8A.8D8F0756@yahoo.com>
Balaji Venkataraman wrote:
>
> When using Getopt::Long I have something like this:
>
> --my_script--
> GetOptions (\%hash, "libs=s@");
> --my_script--
>
> Now if the user invokes 'my_script' thus:
> Shell-Prompt$ my_script -l "/usr/lib /usr/local/lib"
Hmm, user could also have specified the same thing as:
one\ two
"one two"
'one two'
You should not expect Getopt::Long module to handle this...
Maybe check the user argument list with something like
(join("|",@ARGV),"\n"); before continuing on...
> This puts both '/usr/lib' and '/usr/local/lib' into ${$hash{libs}}[0] as a
> single string. I can see that this is expected, but can I avoid this somehow
> - meaning I'd like them to be elements [0] and [1]? I can work around this
> by parsing each element of @{$hash{libs}}, but would like to know if there's
> something better.
>
> Thanks!
> --
> Remember 2 + 2 = 5, for large values of 2
------------------------------
Date: Thu, 29 May 2003 21:37:11 GMT
From: Eric Wilhelm <ericw@nospam.ku.edu>
Subject: variable for current line number (of script)
Message-Id: <pan.2003.05.29.16.34.08.356856.8222@nospam.ku.edu>
If a script is making an assumption to which the data does not conform, I
would like to be able to print the line-number (or nearly so) of said
assumption in a warning message.
If the assumption caused something like "divide by zero", the interpreter
would die with an error and print the line number and filename at which
the error occured. I would like to be able to do this without dying
(e.g. warn and skip).
I've only been able to find the $. special variable, which counts the
lines of input, but not anything which would count the lines of the
script.
--Eric
------------------------------
Date: Thu, 29 May 2003 21:50:49 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: variable for current line number (of script)
Message-Id: <x7he7dcthj.fsf@mail.sysarch.com>
>>>>> "EW" == Eric Wilhelm <ericw@nospam.ku.edu> writes:
EW> If a script is making an assumption to which the data does not conform, I
EW> would like to be able to print the line-number (or nearly so) of said
EW> assumption in a warning message.
perldoc -f warn
and read it carefully.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 29 May 2003 21:49:44 GMT
From: "roach_01" <roach@kronic.net>
Subject: WCTP and perl
Message-Id: <YfvBa.8493$Gg7.387317@twister.tampabay.rr.com>
Does anyone know anyway to go about writing a web app in PERL that utilizes
WCTP (wire communication protocol) for paging.
I've written a pager using NET:SNPP module and it works well, but
unfortantly I cant justify opening up port 444 on the intranet.
Any help with perl and wctp would be great, i've looked all over and have
found one thing on sourceforge but it is in developement.
Someone point me i the right direction =)
thanks
-r
------------------------------
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 5059
***************************************