[24183] in Perl-Users-Digest
Perl-Users Digest, Issue: 6375 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 8 09:05:42 2004
Date: Thu, 8 Apr 2004 06:05:10 -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, 8 Apr 2004 Volume: 10 Number: 6375
Today's topics:
Re: arrays of parameters in CGI.pm <zen13097@zen.co.uk>
Re: arrays of parameters in CGI.pm (another one)
Cygwin and path question <me@nospam.net>
Re: Cygwin and path question <postmaster@castleamber.com>
Initializing an anonymous hash (repost) (Neil Shadrach)
Re: Initializing an anonymous hash (repost) <nobull@mail.com>
Re: Initializing an anonymous hash (repost) <tadmc@augustmail.com>
Localised sub? <mb@uq.net.au.invalid>
Re: Localised sub? <abigail@abigail.nl>
Re: Localised sub? (Anno Siegel)
Re: Open GUI transcript window <zentara@highstream.net>
perl -e and bash (Rob Beattie)
Re: perl -e and bash <kalinaubears@iinet.net.au>
Re: perl -e and bash <Joe.Smith@inwap.com>
Re: perl -e and bash <postmaster@castleamber.com>
Re: perl -e and bash <tadmc@augustmail.com>
Re: Perl neq Python <Joe.Smith@inwap.com>
Re: print given character range. <adam+usenet@pappnase.co.uk>
Re: problem with HangUP (Anno Siegel)
Re: Question on refs inside hash <nobull@mail.com>
Re: real, simple sample OOP intro text??!! <bart.lateur@pandora.be>
Re: real, simple sample OOP intro text??!! <bart.lateur@pandora.be>
Regular Expression - Abbreviation Matching (Ben McClaren)
Re: Regular Expression - Abbreviation Matching <postmaster@castleamber.com>
Re: subroutine only returns non zero sums <nobull@mail.com>
Telnet module doesnot return the prompt back nilendud@rediffmail.com
Re: Telnet module doesnot return the prompt back <nospam@bigpond.com>
Re: Telnet module doesnot return the prompt back <ihatespam@hotmail.com>
Re: Why does split operate over multiple lines in the a <uri.guttman@fmr.com>
Re: wrong exitstatus returned? <Joe.Smith@inwap.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 08 Apr 2004 07:06:15 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: arrays of parameters in CGI.pm
Message-Id: <slrnc79uf8.3nk.zen13097@dontmind.net>
On Wed, 07 Apr 2004 13:04:56 +0100, Steve (another one)
<y66y@56yu4b6.com> wrote:
> (@{$myparams{$_}}=$q->param($_))=~ s/[^a..z,A..Z]/_/g;
^^^^^^^^^^^^
I suspect that doesn't do what you expected.
You want to replace anything that's not 'a' '.' 'z' ',' 'A' or 'Z' with
an underscore?
You possibly meant: s/[^a-zA-Z]/_/g;
or better: tr/a-zA-Z/_/c;
Run "perldoc perlop" and "perldoc perlre" for more info.
--
Dave.
------------------------------
Date: Thu, 08 Apr 2004 10:30:05 +0100
From: "Steve (another one)" <y66y@56yu4b6.com>
Subject: Re: arrays of parameters in CGI.pm
Message-Id: <c5362u$7kv$1@news.liv.ac.uk>
Dave Weaver wrote:
> On Wed, 07 Apr 2004 13:04:56 +0100, Steve (another one)
> <y66y@56yu4b6.com> wrote:
>
>
>> (@{$myparams{$_}}=$q->param($_))=~ s/[^a..z,A..Z]/_/g;
>
>
> ^^^^^^^^^^^^
> I suspect that doesn't do what you expected.
> You want to replace anything that's not 'a' '.' 'z' ',' 'A' or 'Z' with
> an underscore?
>
> You possibly meant: s/[^a-zA-Z]/_/g;
> or better: tr/a-zA-Z/_/c;
>
> Run "perldoc perlop" and "perldoc perlre" for more info.
>
Urrm yes you are right. I wrecked this while hacking it down from a more
complex regex to illustrate what was happening to my params as they came
in. However as you point out it shouldn't let anything but those chars
through, but it does so I am obviously doing the assignment wrong. Any
thoughts ?
my @param_names = $q->param;
my %myparams;
foreach (@param_names){
(@{$myparams{$_}}=$q->param($_))=~ s/[^A-Za-z]/_/g;
# this is not doing what I expect,
# but now I can't see why it should !
}
------------------------------
Date: Thu, 08 Apr 2004 09:05:04 GMT
From: G. Randall <me@nospam.net>
Subject: Cygwin and path question
Message-Id: <MPG.1adeb57211ce5257989683@news.sf.sbcglobal.net>
I installed Cygwin after I installed an ActiveState Perl distribution.
I'm perfectly content with the ActiveState setup, and while I could
simply re-run the Cygwin setup and exclude perl, I'd like to better
understand what the interaction is. If someone could answer the
following, I'd be grateful.
1. Are there any advantages (from an administrative point of view) to
using Cygwin's perl vs. ActiveState's? My gut feeling is that Cygwin
would require more work to maintain.
2. If I were to use ActiveState's perl, will renaming Cygwin's perl.exe
suffice for the moment? It seems to do the trick, but I'm wondering
whether there's something else related I'm not aware of.
3. If I place a script foo.pl somewhere in my path, I can execute it
elsewhere using the Windows 2000 cmd interpreter by typing "foo.pl". In
Bash, I can type "cmd /C foo.pl". What I don't understand is why under
Bash "perl foo.pl" doesn't work unless I run it from where foo.pl is
actually located.
Thanks!
------------------------------
Date: Thu, 08 Apr 2004 04:24:03 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Cygwin and path question
Message-Id: <40751a34$0$24361$58c7af7e@news.kabelfoon.nl>
G. Randall wrote:
> 3. If I place a script foo.pl somewhere in my path, I can execute it
> elsewhere using the Windows 2000 cmd interpreter by typing "foo.pl". In
> Bash, I can type "cmd /C foo.pl". What I don't understand is why under
> Bash "perl foo.pl" doesn't work unless I run it from where foo.pl is
> actually located.
That's normal behaviour, the argument to perl is a file, and perl must
see the file in the current dir. Or you must specify the full path to
the file.
If foo.pl is in your path, foo.pl should work. If your current dir (.)
is not in your path, use ./foo.pl. In a *nix environment you can drop
the .pl extension, and hence create a foo command :-D.
--
John personal page: http://johnbokma.com/
Experienced Perl / Java developer available - http://castleamber.com/
------------------------------
Date: 8 Apr 2004 00:41:42 -0700
From: neil.shadrach@corryn.com (Neil Shadrach)
Subject: Initializing an anonymous hash (repost)
Message-Id: <2d184bb4.0404072341.72907301@posting.google.com>
If I have 2 arrays @k and @v I can initialize a hash %h with
@h{@k}=@v;
If my next step is
push @a,\%h;
is there a neat way to skip creating %h and initialize an anonymous
hash for use in a line like
push @a, {};
( Apologies for reposting via Google but the original doesn't seem to
have made it off the in-house server )
------------------------------
Date: 08 Apr 2004 09:11:54 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Initializing an anonymous hash (repost)
Message-Id: <u9brm2j3cl.fsf@wcl-l.bham.ac.uk>
neil.shadrach@corryn.com (Neil Shadrach) writes:
> If I have 2 arrays @k and @v I can initialize a hash %h with
> @h{@k}=@v;
> If my next step is
> push @a,\%h;
> is there a neat way to skip creating %h and initialize an anonymous
> hash for use in a line like
> push @a, {};
No. You can rearange the problem in various ways with do{} or map()
but there is nothing neat builting. If you just want neat (not fast)
you could, or course write a function:
sub anon_slice(\@\@) {
my %h;
my $keys = shift;
@h{@$keys} = @{shift()};
\%h;
}
push @a => anon_slice( @h => @v );
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 8 Apr 2004 08:07:26 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Initializing an anonymous hash (repost)
Message-Id: <slrnc7ajke.9lg.tadmc@magna.augustmail.com>
Neil Shadrach <neil.shadrach@corryn.com> wrote:
> If I have 2 arrays @k and @v I can initialize a hash %h with
> @h{@k}=@v;
> If my next step is
> push @a,\%h;
> is there a neat way to skip creating %h and initialize an anonymous
> hash for use in a line like
> push @a, {};
push @a, { map { $k[$_], $v[$_] } 0 .. $#k };
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 08 Apr 2004 15:27:41 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Localised sub?
Message-Id: <c52nsd$osh$1@bunyip.cc.uq.edu.au>
Hi all,
I was just playing around a bit (chewing time before long weekend :) ) when I
came across a bit of code that doesn't work but I can't figure out why. Running
this:
sub foo {
print "1\n";
}
{
my $oldfoo = \&foo;
print "MAIN FOO IS ", \&main::foo, "\n";
local *foo;
print "MAIN FOO NOW ", \&main::foo, "\n";
sub foo {
print "2\n";
$oldfoo->();
}
print "MAIN FOO NOW ", \&main::foo, "\n";
print "1...\n";
foo(); # Line 15
}
print "2...\n";
foo();
__END__
Results in:
MAIN FOO IS CODE(0x812583c)
MAIN FOO NOW CODE(0x81232a0)
MAIN FOO NOW CODE(0x81232a0)
1...
Undefined subroutine &main::foo called at test.pl line 15.
So now I'm wondering how to access a subroutine with a 'local' name. Is it even
possible? I was thinking this might be useful for overriding a sub call inside
another sub call without overriding the whole outer sub (yikes - I shouldn't
drink beer at lunch!) eg:
sub bar {
print "BAR 1\n";
foo();
print "BAR 2\n";
}
sub foo {
print "FOO!\n";
}
bar(); # Do everything normally
{
local *foo;
sub foo {
print "NEW FOO!\n";
}
bar(); # Override the internal call to foo
}
bar(); # Normal again
__END__
To get the output:
BAR 1
FOO!
BAR 2
BAR 1
NEW FOO!
BAR 2
BAR 1
FOO!
BAR 2
Does this make sense or am I an idiot?
MB
------------------------------
Date: 08 Apr 2004 07:27:54 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Localised sub?
Message-Id: <slrnc79vnq.egl.abigail@alexandra.abigail.nl>
Matthew Braid (mb@uq.net.au.invalid) wrote on MMMDCCCLXXIII September
MCMXCIII in <URL:news:c52nsd$osh$1@bunyip.cc.uq.edu.au>:
}} Hi all,
}}
}} I was just playing around a bit (chewing time before long weekend :) ) when I
}} came across a bit of code that doesn't work but I can't figure out why. Running
}} this:
}}
}} sub foo {
}} print "1\n";
}} }
}} {
}} my $oldfoo = \&foo;
}} print "MAIN FOO IS ", \&main::foo, "\n";
}} local *foo;
}} print "MAIN FOO NOW ", \&main::foo, "\n";
}} sub foo {
}} print "2\n";
}} $oldfoo->();
}} }
}} print "MAIN FOO NOW ", \&main::foo, "\n";
}} print "1...\n";
}} foo(); # Line 15
}} }
}} print "2...\n";
}} foo();
}} __END__
}}
}} Results in:
}}
}} MAIN FOO IS CODE(0x812583c)
}} MAIN FOO NOW CODE(0x81232a0)
}} MAIN FOO NOW CODE(0x81232a0)
}} 1...
}} Undefined subroutine &main::foo called at test.pl line 15.
Yes, that's because the subs are created at compile time, and at
runtime you localize the glob.
}} So now I'm wondering how to access a subroutine with a 'local' name. Is it even
}} possible?
Use the following in the inner block, instead of 'sub foo { ... }':
*foo = sub {
print "2\n";
$oldfoo -> ();
};
Running the code then gets you:
MAIN FOO IS CODE(0x818a2ec)
MAIN FOO NOW CODE(0x817ce20)
MAIN FOO NOW CODE(0x817cd9c)
1...
2
1
2...
1
Abigail
--
($;,$_,$|,$\)=("\@\x7Fy~*kde~box*Zoxf*Bkiaox","."x25,1,"\r");
s/./ /;{vec($_=>1+$"=>8)=ord($/^substr$;=>$"=int rand 24=>1);
print&&select$,,$,,$,,$|/($|+tr/.//c);redo if y/.//};sleep 1;
------------------------------
Date: 8 Apr 2004 07:47:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Localised sub?
Message-Id: <c5301v$drd$1@mamenchi.zrz.TU-Berlin.DE>
Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
...never mind what. Welcome back!
Anno
------------------------------
Date: Thu, 08 Apr 2004 07:36:44 -0400
From: zentara <zentara@highstream.net>
Subject: Re: Open GUI transcript window
Message-Id: <m6ea70dj0bjjmlrdoicrntn51qhrigg97g@4ax.com>
On Wed, 7 Apr 2004 17:27:42 GMT, "bxb7668" <bxb7668@somewhere.nocom>
wrote:
>Zentara,
>Thank you. This does almost everything that I need. Just one more
>thing. How do I close the new window when I'm done with it?
>Brian
Just add an exit button.
######################################################
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
open(CHILD, "./fileevent2piperb 2>&1 |") or die "Can't open: $!";
my $mw = new MainWindow;
my $t = $mw->Scrolled("Text",-width => 80, -height => 25, -wrap =>
'none');
$t->pack(-expand => 1);
$mw->fileevent(\*CHILD, 'readable', [\&fill_text_widget,$t]);
$mw->Button(-text => 'Quit', -command => sub{Tk::exit})->pack;
MainLoop;
sub fill_text_widget {
my($widget) = @_;
$_ = <CHILD>;
$widget->insert('end', $_);
$widget->yview('end');
}
####################################################
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
------------------------------
Date: Thu, 08 Apr 2004 07:27:55 GMT
From: rob@/remove/ghosh.co.uk (Rob Beattie)
Subject: perl -e and bash
Message-Id: <4074fd1d.51655548@text.news.ntlworld.com>
hi,
i'm just starting out with perl and have come across the well known
dos problem when running the following
perl -e 'print "hi \n";'
I've tried to read up on a solution for this and have seen suggestions
regarding using a bash shell. Where can I download this(cygwin.com?)
and how much space will it take up on my hard drive. I've checked at
cygwin and read that it will require 800MB of storage. This seems to
be a bit excessive to me.
So are there any windows users out there who has gone through this
route?
------------------------------
Date: Thu, 08 Apr 2004 18:14:53 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
To: Rob Beattie <rob@/remove/ghosh.co.uk>
Subject: Re: perl -e and bash
Message-Id: <407509FD.6050905@iinet.net.au>
Rob Beattie wrote:
> hi,
> i'm just starting out with perl and have come across the well known
> dos problem when running the following
> perl -e 'print "hi \n";'
>
There's also the well known solution to this problem:
perl -e "print \"hi \n\";"
(Just in case you were unaware of it :-)
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Thu, 08 Apr 2004 08:42:13 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: perl -e and bash
Message-Id: <Ff8dc.97448$K91.223857@attbi_s02>
Rob Beattie wrote:
> hi,
> i'm just starting out with perl and have come across the well known
> dos problem when running the following
> perl -e 'print "hi \n";'
>
> I've tried to read up on a solution for this and have seen suggestions
> regarding using a bash shell. Where can I download this(cygwin.com?)
Yes, http://www.cygwin.com/ is where you'll find the installer.
> and how much space will it take up on my hard drive. I've checked at
> cygwin and read that it will require 800MB of storage.
Cygwin's setup.exe does not install _everything_ by default.
I've got more than just the default and 'du -k' on my C:\cygwin shows this:
57920 bin
1821 etc
19315 home
75738 lib
22 tmp
4961 usr/doc
7467 usr/include
16517 usr/info
397 usr/local
2762 usr/man
987 usr/sbin
72015 usr/share
3392 usr/src
442 usr/ssl
256 var
264 megabytes total
It's a full-fledged Unix-like universe inside your Win32 box.
-Joe
------------------------------
Date: Thu, 08 Apr 2004 04:20:15 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: perl -e and bash
Message-Id: <4075194f$0$24353$58c7af7e@news.kabelfoon.nl>
Sisyphus wrote:
> Rob Beattie wrote:
>
>> hi,
>> i'm just starting out with perl and have come across the well known
>> dos problem when running the following
>> perl -e 'print "hi \n";'
>
>
> There's also the well known solution to this problem:
> perl -e "print \"hi \n\";"
>
> (Just in case you were unaware of it :-)
or
perl -e "print qw(hi \n);"
--
John personal page: http://johnbokma.com/
Experienced Perl / Java developer available - http://castleamber.com/
------------------------------
Date: Thu, 8 Apr 2004 08:09:47 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl -e and bash
Message-Id: <slrnc7ajor.9lg.tadmc@magna.augustmail.com>
John Bokma <postmaster@castleamber.com> wrote:
> Sisyphus wrote:
>> Rob Beattie wrote:
>>
>>> dos problem when running the following
>>> perl -e 'print "hi \n";'
>>
>>
>> There's also the well known solution to this problem:
>> perl -e "print \"hi \n\";"
>>
>> (Just in case you were unaware of it :-)
>
> or
>
> perl -e "print qw(hi \n);"
^^
^^ you meant qq() instead of qw()
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 08 Apr 2004 08:50:49 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Perl neq Python
Message-Id: <Jn8dc.97497$K91.224349@attbi_s02>
187 wrote:
> Tore Aursand wrote:
>>>Under what circumstances should I use Perl, Python or straight shell
>>>scripting?
>>
>>If you _really_ know each of these programming languages/techniques,
>>you know what to use and when to use it.
>
> Re read his question. He never claimed to be an expert.
I agree with Tore; it's sort of a Zen question.
If you have to ask, it means you won't understand the answer.
If you know enough to understand the answer, you won't need the question.
A good exercise is to find an interesting task, then implement it in
all three languages. Take notes of how long it takes to write, then
benchmark how fast each one is. Repeat a couple dozen times.
Have fun.
-Joe
------------------------------
Date: Thu, 8 Apr 2004 11:51:22 +0100
From: Adam Price <adam+usenet@pappnase.co.uk>
Subject: Re: print given character range.
Message-Id: <5ice42vhy9ib$.dlg@pappnase.co.uk>
On Mon, 5 Apr 2004 15:09:36 -0700, Jayaprakash Rudraraju wrote:
> Most of the files in bioinformatics save their sequences in fasta
> format. Fasta format files contain header lines followed by dna
> sequence. I have been using the following short-cut to get sequence
> given the range in the sequence.
>
> perl -ne 'chomp; next if />/; print' FASTA.TXT | cut -c3450-3470
>
> Is there is a better and convinient way to do it.
You could try looking at CPAN, try
http://search.cpan.org/~birney/bioperl-1.4/
as a place to start looking.
It seems to cover lots of stuff to do with FASTA files.
Adam
------------------------------
Date: 8 Apr 2004 12:09:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: problem with HangUP
Message-Id: <c53fd4$oc0$1@mamenchi.zrz.TU-Berlin.DE>
lucas <aolblowz@yahoo.com> wrote in comp.lang.perl.misc:
Don't top-post please. You're not exactly new to this group, aren't you?
> Anno Siegel wrote:
>
> > No.
> >
> > The code you show doesn't exit. If it exits for you, that happens in the
> > code you don't show. We can't correct code we don't get to see.
> >
>
> the sub routine doesn't exit either. i know this because i run it at the
> start of the program.
Where? The code you show doesn't call "the sub" (I suppose LoadFiles()).
> And i know that the $SIG(HUP) shouldn't exit, but it
> does. i put a 'print "DONE LOADING\N"; ' in the $SIG, as you can see, and
> it is printed to screen, so the LoadFiles() returns properly.
The code below is incomplete, and it doesn't run under strict and warnings.
To run it, people must make all kinds of amendments, which also means
making assumptions about the content of variables and files that you don't
show. So we still don't know what code you ran.
Show a complete, runnable piece of code, tell us what you expect it to
do and explain how what it does is different.
I have annotated your code and pointed out some mistakes. I don't know
if these have anything to do with your perceived problem.
> $SIG{HUP} = sub { print STDERR "$$: HUP Caught\n";
> LoadFiles($adfilterfile); print "DONE LOADING\n"; };
What is $adfilterfile? A global variable? It is nowhere declared, nor
does it have a value.
> sub LoadFiles {
> my $adfilterfile = shift;
This variable "$adfilterfile" is lexically scoped to the sub block. It
has nothing to do with "$adfilterfile" outside the sub. Apparently you
expect them to be the same, since you never do anything with "$adfilterfile"
in the rest of the routine. Maybe that's your error, but who knows.
If so, LoadFiles should return the array at the end, and the call should
catch it.
> #load ad filter strings into memory
> print "$$: Loading in Ad Filters from $adfilterfile..." if($debug);
What is "$debug"? It is nowhere declared, nor does it have a value.
Is it supposed to be true or false during the runs you mention?
> open(FILE,"$adfilterfile") || die "Error opening $adfilterfile: $!\n";
> @filters = <FILE>;
"@filters" is undeclared.
> close(FILE);
> for($_=0;$_<@filters;$_++) {
Why the C-style indexed loop? It is rarely needed and only encumbers
your code.
> @filters[$_] =~ s/[\r|\n]//g; #Rid of \r \n!
"@filters[ $_]" is a one-element array slice. That is better written as
"$filters[ $_]", and "warnings" would have told you so. The same applies
to two more uses of "@filters[ $_]".
"s/[\r|\n]//g" doesn't do what you think it does. It kills "|" besides
"\r" and "\n", and it kills the first appearance of any of those, not
the one at the end of the line.
What you mean is (untested) "s/[\r\n]$//" or "s/(?:\r|\n)$//", but
usually "chomp" does that job. Why do you think it doesn't in your
case?
> if (@filters[$_] eq '') { pop(@filters); $_--; next; } #skip entry if
> it's empty
Ugh. Just say "@filters = grep /./, @filters" in any convenient place
before the loop.
> print ">@filters[$_]\n" if ($debug);
> }
> print "$$: ", $_ = @filters," Strings Loaded\n" if($debug);
> }
So this is what LoadFiles should look like (untested, and minus debugging
statements):
sub LoadFiles {
open(FILE,"$adfilterfile") || die "Error opening $adfilterfile: $!\n";
chomp( my @filters = grep /./, <FILE>);
print "$_\n" for @filters;
$adfilterfile;
}
...and call it as
$adfilterfile = LoadFiles;
This is just a translation of what you have into more reasonable Perl. It
still doesn't make much sense. In particular, the array @filters is
only used to print the values, it's gone after the sub returns.
From your treatment LoadFiles it is apparent that you have no clear grasp
of the workings of sub arguments and return values. You still seem to
reach for global variables when these should be used. After three years
of Perl programming you should know better.
Anno
------------------------------
Date: 08 Apr 2004 09:05:08 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Question on refs inside hash
Message-Id: <u9fzbej3nv.fsf@wcl-l.bham.ac.uk>
rocknmetal20@yahoo.com (rocknmetal20) writes:
> Is there a way to refer other elements of the hash inside that hash
> WHILE I am defining the hash.
>
> Example: I have a hashref with 'x' mapping to an array ref. To save
> memory or for someother reason I want to use that same value for 'y'
> too.
>
> For the following,
> my $a = {
> 'x' => ['a'],
> 'y' => ['a'],
> };
You are not alaysing your problem correctly. The stuff inside the { }
anon hash constructor is just a list context expression. Until
evaluation of that expression is complete then there's no hash
involved.
So your question has nothing to do with hashes. Your question is can
I refer in an expression to an earlier part of the same expression.
The answer is that you can't without using a variable. Unfortunately
because the scope of a variable declaration starts at the next
statement the syntax gets a bit messy.
my $a = do {
my $t;
+{
x => ($t = ['a']),
y => $t,
};
};
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 08 Apr 2004 09:33:27 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: real, simple sample OOP intro text??!!
Message-Id: <5d6a70ho48v54vavkalk5jol7111672eee@4ax.com>
David H. Adler wrote:
>I seem to remember
>that someone was working on a book on Perl regexen as such, but afaik
>it's not actually available.
That must be Jeff Pinyan AKA japhy, author of the modules YAPE::*
alternative parser modules, including YAPE::Regex::Explain. His draft
for his book is available online at <http://japhy.perlmonk.org/book/> --
and yes, perlmonk.org is back online.
>Re: pricing - I don't know the reasons for it, but I have always found
>the "same price but in sterling" to hold for US vs. UK. I remember
>picking up a copy of Elvis Costello's My Aim Is True (on VINYL, so this
>is a *long* time ago :-) in London at one point and it was whatever it
>cost here, but in pounds. So this neither new nor restricted to
>computer books.
You should see what they charge for a copy of Dr. Dobb's Journal here...
its price is $4.95 in the USA, here in Belgium, loose copies cost about
10 Euro. Quite a steep price, especially if you reconsider that in the
USA, a subscription would cost you < $2 per magazine.
--
Bart.
------------------------------
Date: Thu, 08 Apr 2004 09:35:13 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: real, simple sample OOP intro text??!!
Message-Id: <c47a701u2o9iu0p9vq53nnq1ntj2761usv@4ax.com>
Geoff Cox wrote:
>wouldn't dream of suggesting you are personally responsible for this!!
>if a book costs say $30 in the US and £30 here - does it really cost
>£10 to get it into a shop the UK??
Don't forget about shipping. It's a long way from the USA to the UK...
Buy the book over the internet, if you must. If you order several at
once, you'll pay far less than you would in a local shop.
--
Bart.
------------------------------
Date: 8 Apr 2004 01:54:07 -0700
From: benmcclaren@yahoo.co.uk (Ben McClaren)
Subject: Regular Expression - Abbreviation Matching
Message-Id: <93ded50e.0404080054.176056ba@posting.google.com>
Hi,
I'm trying to write two regular expressions that will match a sequence
of characters to a string and a string to a sequence of characters,
i.e.
The first: cms will match to centimetres and centimeters
and
The second: centimetres will match to cms and cm
Is this possible and if so how do I go about doing so?
Thanks, in advance,
Ben McClaren
------------------------------
Date: Thu, 08 Apr 2004 04:17:59 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Regular Expression - Abbreviation Matching
Message-Id: <407518ca$0$24353$58c7af7e@news.kabelfoon.nl>
Ben McClaren wrote:
> Hi,
>
> I'm trying to write two regular expressions that will match a sequence
> of characters to a string and a string to a sequence of characters,
> i.e.
>
> The first: cms will match to centimetres and centimeters
>
> and
>
> The second: centimetres will match to cms and cm
>
> Is this possible and if so how do I go about doing so?
Create two look up tables using hashes. A key could be an array ref in
case there are more solutions to one look up.
my %expand = (
cms => [ qw(centimetres centimeters) ],
);
You can match the most general form of your keys, and check if there
exists a key for the thing you matched in your hash.
--
John personal page: http://johnbokma.com/
Experienced Perl / Java developer available - http://castleamber.com/
------------------------------
Date: 08 Apr 2004 08:54:12 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: subroutine only returns non zero sums
Message-Id: <u9k70qj463.fsf@wcl-l.bham.ac.uk>
Richard Morse <remorse@partners.org> writes:
> my $total += $_ foreach @_;
AFAIK the behaviour of a my() declaration with a statement qualifier
is explicitly undefined. So the above may happen do what you want
today but may not in future.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 7 Apr 2004 22:32:13 -0700
From: nilendud@rediffmail.com
Subject: Telnet module doesnot return the prompt back
Message-Id: <84b4df69.0404072132.47eeefbe@posting.google.com>
Hello,
I have a problem. I need to run some commands as superuser on a
remote machine.
I am using net::Telnet to login to the remote machine when i type
$telnet->cmd("su - root"); the prompt ( I guess) waits for me to type
the password on the remote machine and control never comes back :-(
Is there any work around? any otehr module that could help...
i thought about sudo but that too need password for the first time.
Please suggest
Nilendu
------------------------------
Date: Thu, 08 Apr 2004 16:19:59 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Telnet module doesnot return the prompt back
Message-Id: <3392628.gLNVFMR5XG@GMT-hosting-and-pickle-farming>
nilendud@rediffmail.com wrote:
> Hello,
>
> I have a problem. I need to run some commands as superuser on a
> remote machine.
> I am using net::Telnet to login to the remote machine when i type
> $telnet->cmd("su - root"); the prompt ( I guess) waits for me to type
> the password on the remote machine and control never comes back :-(
>
> Is there any work around? any otehr module that could help...
> i thought about sudo but that too need password for the first time.
>
> Please suggest
>
> Nilendu
I use expect (1) for this sort of thing. And use ssh instead of telnet.
gtoomey
------------------------------
Date: Thu, 08 Apr 2004 01:30:09 -0700
From: BigDaDDY <ihatespam@hotmail.com>
Subject: Re: Telnet module doesnot return the prompt back
Message-Id: <107a3bs63er3d48@corp.supernews.com>
nilendud@rediffmail.com wrote:
> Hello,
>
> I have a problem. I need to run some commands as superuser on a
> remote machine.
> I am using net::Telnet to login to the remote machine when i type
> $telnet->cmd("su - root"); the prompt ( I guess) waits for me to type
> the password on the remote machine and control never comes back :-(
>
> Is there any work around? any otehr module that could help...
> i thought about sudo but that too need password for the first time.
>
> Please suggest
>
> Nilendu
You may want to check the regular expression that attempts to match the
prompt. If you don't match the prompt correctly, the password won't get
through.
------------------------------
Date: 07 Apr 2004 16:08:00 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: Why does split operate over multiple lines in the absence of "ms" ? And why doesn't $_ work with split?
Message-Id: <sisck70rwnz3.fsf@tripoli.fmr.com>
>>>>> "S" == Sara <genericax@hotmail.com> writes:
S> To substitute over multiple lines, one would need something like
S> s/CAT/DOG/msg;
neither /m nor /s does anything there. /s only changes . to match \n. /m
only changes ^ and $ to work inside strings next to \n and not at the
ends. you don't have any need for /m nor /s there.
S> But to SPLIT those same lines the "ms" is apparently "implied":
S> my @all_matches = split /CAT/, $_;
S> my @all_matches = split /CAT/ms, $_;
S> will both split the entire paragraph, not just line 1. Why? Why would
S> one assume that programmers would need to substitute only line 1, but
S> wold always need to split the whole paragraph. Doesn't make sense, and
S> appears to be inconsistent. The only rationale I see roughly alluded
S> to in Camel is that split is the "opposite of" join, so since join
S> obviously works over multiple array elements, to be a true inverse
S> then split would need to work over the entire scalar?
huh???
split splits its input string whether it is one line or many. you don't
understand /m and /s at all and you are saying things like 'lines' which
have nothing to do with split or s/// or m//.
S> Also, along these same lines why isn't $_ taken as the default arg for
S> split, such that:
S> split /CAT/, $_;
S> would be identical to
S> split /CAT/; # throws an error
show the complete code and error.
split /PATTERN/,EXPR,LIMIT
split /PATTERN/,EXPR
split /PATTERN/
split Splits a string into a list of strings and returns
that list. By default, empty leading fields are
preserved, and empty trailing ones are deleted.
In scalar context, returns the number of fields
found and splits into the @_ array. Use of split in
scalar context is deprecated, however, because it
clobbers your subroutine arguments.
If EXPR is omitted, splits the $_ string. If
PATTERN is also omitted, splits on whitespace (after
skipping any leading whitespace). Anything matching
PATTERN is taken to be a delimiter separating the
fields. (Note that the delimiter may be longer than
one character.)
does that answer your question?
uri
------------------------------
Date: Thu, 08 Apr 2004 07:58:34 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: wrong exitstatus returned?
Message-Id: <KC7dc.214140$_w.2074838@attbi_s53>
Frank de Bot wrote:
> I have a perl script server which works with fork. But I got a problem
> with executing commands from a child which handles a request. The
> exitstatus $? is always -1 I've tried execute commands with system and
> `command` but nothing matters.
Linux?
Win32?
Win32 with cygwin?
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6375
***************************************