[31029] in Perl-Users-Digest
Perl-Users Digest, Issue: 2274 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 13 21:09:52 2009
Date: Fri, 13 Mar 2009 18:09:14 -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 Fri, 13 Mar 2009 Volume: 11 Number: 2274
Today's topics:
Re: Autovivification by foreach <uri@stemsystems.com>
FAQ posts <darkon.tdo@gmail.com>
Re: FAQ posts sln@netherlands.com
Re: Interactive App over Telnet <fake@phony.invalid>
Re: Interactive App over Telnet sln@netherlands.com
Re: Interactive App over Telnet sln@netherlands.com
Re: Most efficient way to do set-comparison <noreply@gunnar.cc>
Re: Perl and tail -f error_log <No_4@dsl.pipex.com>
Re: Perl and tail -f error_log <bill@ts1000.us>
Re: Perl and tail -f error_log <jurgenex@hotmail.com>
Re: Perl Pipes alertjean@rediffmail.com
Re: Perl Pipes <jurgenex@hotmail.com>
Re: s/// parametrized with backreferences sln@netherlands.com
Re: s/// parametrized with backreferences <tadmc@seesig.invalid>
Re: s/// parametrized with backreferences <tadmc@seesig.invalid>
Strange Hash Output <strongsilentone@gmail.com>
Re: Strange Hash Output <1usa@llenroc.ude.invalid>
Re: Strange Hash Output <syscjm@sumire.gwu.edu>
Re: Strange Hash Output <uri@stemsystems.com>
Re: Why does this not print the filenames ? (Tim McDaniel)
Wide character in subroutine entry - how to get bytes f <Alexander.Farber@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 13 Mar 2009 10:54:57 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Autovivification by foreach
Message-Id: <x7y6v9v2ni.fsf@mail.sysarch.com>
>>>>> "FS" == Frank Seitz <devnull4711@web.de> writes:
>> into each element of its list. and $_ is read/write so the elements
>> should be lvalues. so perl will autovivify the array ref since you might
>> be modifying elements. it can't tell (the executed code could be a sub
>> call, etc.) so it has to do this before the loop starts.
FS> This explanation is not plausible to me. Perl autovivifies before
FS> loop start, because the loop might be modifying array elements?
FS> How is this possible? The autovivificated array is empty.
FS> It is clear that the body of the loop is never executed.
if perl didn't autovivify the lvalue in the for loop, then it would die
if you attempted to modify an array ref element. perl assumes that since
the array ref being used (and it is undef) is an lvalue then you
may/will write to it so it autovivifies for you.
FS> In my opinion it would make more sense when Perl would
FS> throw an exception in this case too.
it doesn't because of DWIM. autovivification is a subtle thing at times
and very useful most of the time. it does have some edges like deep
access using exists will autovivify. perl6 fixed that problem. maybe it
could not autovivify the array ref unless an element is modified but i
can live with that as it is.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 13 Mar 2009 13:13:36 -0400
From: "darkon" <darkon.tdo@gmail.com>
Subject: FAQ posts
Message-Id: <xdadnfJ_d-_cCSfUnZ2dnUVZ_jWWnZ2d@supernews.com>
Out of simple curiousity, what algorithm is used to decide which FAQ is
posted when? I noticed that the FAQs are posted roughly in sequence, but
not strictly in sequence. For example, FAQs from section 5 began to be
posted before all the FAQs from section 4 had been posted.
------------------------------
Date: Fri, 13 Mar 2009 21:17:22 GMT
From: sln@netherlands.com
Subject: Re: FAQ posts
Message-Id: <07jlr4lj856taupdihtn0tfhaocdu2f4m8@4ax.com>
On Fri, 13 Mar 2009 13:13:36 -0400, "darkon" <darkon.tdo@gmail.com> wrote:
>Out of simple curiousity, what algorithm is used to decide which FAQ is
>posted when? I noticed that the FAQs are posted roughly in sequence, but
>not strictly in sequence. For example, FAQs from section 5 began to be
>posted before all the FAQs from section 4 had been posted.
The "workers" will preempt scheculed posts with pertinant FAQ's when the
fire is "hot" on a particular subject.
Haven't you noticed that?
-sln
------------------------------
Date: Fri, 13 Mar 2009 10:09:05 -0600
From: Shawn N Blank <fake@phony.invalid>
Subject: Re: Interactive App over Telnet
Message-Id: <ka0lr4520a38gbkop39pdclfnvb74oaja7@4ax.com>
On Thu, 12 Mar 2009 22:49:43 -0500, Michael Austin
<maustin@firstdbasource.com> wrote:
>you might also investigate using ssh vs. telnet - unless you don't care
>if your pwd is passed in clear text.
Meh. The local net routes everything to headquarters via VPN tunnel
(makes websites that use GEO-IP interesting). And if the bosses don't
care about user/pass lists taped to monitors, I'm certainly not going
to worring about someone in the building sniffing packets.
Tera Term:
Could be useful for constructing macros for live-interaction users,
but doesn't help with my full automation -- I'll have the same
problems, just with a less powerful and less familiar language.
--
Shawn
------------------------------
Date: Fri, 13 Mar 2009 20:16:39 GMT
From: sln@netherlands.com
Subject: Re: Interactive App over Telnet
Message-Id: <a6dlr4t1529tck93o0uf1q2qagse6h1guh@4ax.com>
On Fri, 13 Mar 2009 10:09:05 -0600, Shawn N Blank <fake@phony.invalid> wrote:
>On Thu, 12 Mar 2009 22:49:43 -0500, Michael Austin
><maustin@firstdbasource.com> wrote:
>
>>you might also investigate using ssh vs. telnet - unless you don't care
>>if your pwd is passed in clear text.
>
>Meh. The local net routes everything to headquarters via VPN tunnel
>(makes websites that use GEO-IP interesting). And if the bosses don't
>care about user/pass lists taped to monitors, I'm certainly not going
>to worring about someone in the building sniffing packets.
>
>Tera Term:
> Could be useful for constructing macros for live-interaction users,
>but doesn't help with my full automation -- I'll have the same
>problems, just with a less powerful and less familiar language.
I've only used it in 2006, Tera Term 2.3 version, circa 1998.
Now I guess the open source code was picked up by a few experts from
about 2003 up to the present. The latest release is 4.61 on Dec 12, 2008.
Apparently it does SSH 1 and 2 as well and is comparable with puTTY.
Be carefull when you say "less powerful" language. Compared to any comparable Perl
module that would attempt this, Tera Term is leaps and bounds ahead. Thats all it
does, it is a specialist compared to a general practicioner.
The macro constructs are easily understood and can be learned in a day or two.
I only used it to log onto about 20 Linux boxes, started ftp servers, then downloaded
files, logged out, etc.. Nothing really fancy. Fully automated. The macro lang supports
and understands if/else, login, logout, wait, timeouts, sendln, getln, logging, error levels,
control codes, character mapping, streams, labels, goto's, loops, etc...
The power is in what it does in handling what on the outside seems simple. But thats all it
does, it is a specialist.
For my project, I created a "tag file" macro template .TTL file that had placeholders
<tag_VARIABLE> embeded in the file. Then using Perl, I read the file in, replacing the tags
with the real values, then wrote out to a new .TTL file. Then I launched the new .TTL file
with system(). The ttl file did various logging and error processing, when system() returned,
results read through a particular log file (I had a few), checked the results, did some more
Perl logging/processing, then moved on to the next Linux box. This was using TT 2.3 version.
I'm sure the 4.61 is much more powerful. There is no other definition of automation.
Maybe your doing something different though. Its still just a cli so you can querry and act on
anything.
TT has its own support forum. Here are some links:
-sln
TT version Ver 4.61 @ 2008.12.16:
-------------------------------------------------
http://www.logmett.com/forum/viewtopic.php?t=3
http://www.logmett.com/index.php?/Download/Download.html
Wikipedia:
http://en.wikipedia.org/wiki/Tera_Term
-----------------------------------------------------------
Tera Term is an open source free software terminal emulator (communication program) for MS-Windows.
It emulates different types of terminals, from VT100 to VT382; it supports telnet, SSH 1 & 2 and
serial port connections. It also has a built in Macro scripting language and a few other useful plugins.
...
Since 2007 Tera Term has been maintained by Tera Term Project(Japanese Developer team) as open source software.
...
The latest versions of Tera Term are compatible with Windows 98 and higher.
...
Tera Term has comparable features to PuTTY and SecureCRT.[1]
------------------------------
Date: Fri, 13 Mar 2009 20:45:08 GMT
From: sln@netherlands.com
Subject: Re: Interactive App over Telnet
Message-Id: <d7hlr4ts040cc5dskpoib6ubje13avvhmb@4ax.com>
On Fri, 13 Mar 2009 20:16:39 GMT, sln@netherlands.com wrote:
>On Fri, 13 Mar 2009 10:09:05 -0600, Shawn N Blank <fake@phony.invalid> wrote:
>
>>On Thu, 12 Mar 2009 22:49:43 -0500, Michael Austin
>><maustin@firstdbasource.com> wrote:
>>
>>>you might also investigate using ssh vs. telnet - unless you don't care
>>>if your pwd is passed in clear text.
>>
>>Meh. The local net routes everything to headquarters via VPN tunnel
>>(makes websites that use GEO-IP interesting). And if the bosses don't
>>care about user/pass lists taped to monitors, I'm certainly not going
>>to worring about someone in the building sniffing packets.
>>
>>Tera Term:
>> Could be useful for constructing macros for live-interaction users,
>>but doesn't help with my full automation -- I'll have the same
>>problems, just with a less powerful and less familiar language.
>
>I've only used it in 2006, Tera Term 2.3 version, circa 1998.
>Now I guess the open source code was picked up by a few experts from
>about 2003 up to the present. The latest release is 4.61 on Dec 12, 2008.
>Apparently it does SSH 1 and 2 as well and is comparable with puTTY.
>
>Be carefull when you say "less powerful" language. Compared to any comparable Perl
>module that would attempt this, Tera Term is leaps and bounds ahead. Thats all it
>does, it is a specialist compared to a general practicioner.
>The macro constructs are easily understood and can be learned in a day or two.
>
>I only used it to log onto about 20 Linux boxes, started ftp servers, then downloaded
[snip]
Its been so long, I actually started clients on those boxes, and downloaded files to
them from a server... geez
-sln
------------------------------
Date: Fri, 13 Mar 2009 17:45:48 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Most efficient way to do set-comparison
Message-Id: <71vgu3Fn404eU1@mid.individual.net>
Tad J McClellan wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>>
>> $ perl -le '
>> %legalopts = (a=>1, b=>1, c=>1); %opts = (a=>1, c=>1);
>
> Fails with:
>
> %opts = ('a b'=>1, c=>1);
>
>> @L = sort keys %legalopts; @O = sort keys %opts;
>> print "@L" eq "@O" ? "Ok" : "Not equal"
>> '
>> Not equal
Ouch! This should fix that:
$ perl -le '
%legalopts = (a=>1, b=>1, c=>1); %opts = (a=>1, b=>1);
@L = sort keys %legalopts; @O = sort keys %opts;
print "@L" eq "@O" && @L == @O ? "Ok" : "Not equal"
'
Not equal
$
OTOH you might object again and ask what happens if:
%legalopts = ("a b"=>1, c=>1); %opts = (a=>1, "b c"=>1);
I give up. This simplified approach is not safe, unless you can preclude
those odd combinations based on the rest of the code.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 13 Mar 2009 22:30:50 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Perl and tail -f error_log
Message-Id: <HKWdnWpuSO4HQyfUnZ2dnUVZ8guWnZ2d@pipex.net>
Bill H wrote:
> I use tail -f to watch for errors in scripts but sometimes it is hard
> to see the errors because other programmers may have scripts
> generating errors.
Why would other programmers' scripts be generating errors on your screen?
> Is there anyway in perl to have something show in
> the error log without actually generating an error?
What error log? Are you, by any chance, running your script on a Web server? If so, try debugging
the script from a terminal/command line, rather than in a Web browser (i.e. debug the logic, not the
script).
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Fri, 13 Mar 2009 16:52:09 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: Perl and tail -f error_log
Message-Id: <fc62000f-4c53-4d70-8fba-469c22cfd353@13g2000yql.googlegroups.com>
On Mar 13, 6:30=A0pm, Big and Blue <N...@dsl.pipex.com> wrote:
> Bill H wrote:
> > I use tail -f to watch for errors in scripts but sometimes it is hard
> > to see the errors because other programmers may have scripts
> > generating errors.
>
> Why would other programmers' scripts be generating errors on your screen?
>
> =A0> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Is there anyway in perl to ha=
ve something show in
>
> > the error log without actually generating an error?
>
> What error log? =A0Are you, by any chance, running your script on a Web s=
erver? =A0If so, try debugging
> the script from a terminal/command line, rather than in a Web browser (i.=
e. debug the logic, not the
> script).
>
> --
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 Just because I've written it doesn't mean tha=
t
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0either you or I have to believe it=
.
HI, yeah on a web server. I have debugged it locally and in terminal
as much as possible, but now it interacts with flash and php so I have
to watch the error log to see if things did not work right.
Bill H
------------------------------
Date: Fri, 13 Mar 2009 17:39:56 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Perl and tail -f error_log
Message-Id: <h1vlr41qhvt8lji28pg9h24p26h8juhbqv@4ax.com>
Bill H <bill@ts1000.us> wrote:
>On Mar 13, 6:30 pm, Big and Blue <N...@dsl.pipex.com> wrote:
>> What error log? Are you, by any chance, running your script on a Web server? If so, try debugging
>> the script from a terminal/command line, rather than in a Web browser (i.e. debug the logic, not the
>> script).
>
>HI, yeah on a web server. I have debugged it locally and in terminal
>as much as possible, but now it interacts with flash and php so I have
>to watch the error log to see if things did not work right.
Normally you would further test and debug the script in an isolated test
environment, exactly to prevent interference from unrelated other
programs as well as to not break the production environment with not
fully tested code.
However, if you are taking shortcuts and are pushing unfinished code
into production then just prepend all your own error and status messages
with the name of your program. Then filtering the error log for your
messages becomes trivial.
jue
------------------------------
Date: Fri, 13 Mar 2009 15:36:02 -0700 (PDT)
From: alertjean@rediffmail.com
Subject: Re: Perl Pipes
Message-Id: <e45242cf-cc17-4505-9cc3-c6ac278f04d7@v39g2000yqm.googlegroups.com>
On Mar 12, 7:01=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> alertj...@rediffmail.com <alertj...@rediffmail.com> wrote:
> > Fellow script writers,
> > I have two linux executables. I want to give the stand ouput =A0of
> > executable1 to executable 2.
> > How can I do it with perl without creating intermediate files ?
>
> > something which can be achieved through command line.
>
> > $ executable1 > output_file1.txt
> > $ =A0executable2 =A0output_file1.txt =A0> output_file2.txt
>
> The simplest way is to let the shell do it for you:
>
> =A0 =A0 system 'executable1 | executable2 >output_file2.txt';
>
> Or, if you want to capture the end of the pipeline into your Perl
> program rather than into a file:
>
> =A0 =A0 open my $pipeline, 'executable1 | executable2 |' or die...
>
> Then you can read the data with:
>
> =A0 =A0 while ( <$pipeline> ) {
> =A0 =A0 =A0 =A0 ...
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
This is what I do currently
system("./CacheSimulator.exe $setsL1 $blockSize $assocL1 $pref_nL1
$pref_mL1 $TraceFile L1_Summary.txt > L1_Traffic_Out.txt");
system("./CacheSimulator.exe $setsL2 $blockSize $assocL2 $pref_nL2
$pref_mL2 L1_Traffic_Out.txt L2_Summary.txt > L2_Traffic_Out.txt");
I want to give L1_Traffic_Out.txt to the second execution
Can I achieve this by the methods you have mentioned ?
------------------------------
Date: Fri, 13 Mar 2009 17:42:09 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Perl Pipes
Message-Id: <d8vlr4lasjjv9o1a46ntbckfefnla0dgqg@4ax.com>
alertjean@rediffmail.com wrote:
>On Mar 12, 7:01 pm, Tad J McClellan <ta...@seesig.invalid> wrote:
>This is what I do currently
>
>system("./CacheSimulator.exe $setsL1 $blockSize $assocL1 $pref_nL1
>$pref_mL1 $TraceFile L1_Summary.txt > L1_Traffic_Out.txt");
>
>system("./CacheSimulator.exe $setsL2 $blockSize $assocL2 $pref_nL2
>$pref_mL2 L1_Traffic_Out.txt L2_Summary.txt > L2_Traffic_Out.txt");
>
>
>I want to give L1_Traffic_Out.txt to the second execution
>Can I achieve this by the methods you have mentioned ?
That depends solely on ./CacheSimulator.exe. Does it accept input from
STDIN or does it require the file name because it insists on reading
from a file?
jue
------------------------------
Date: Fri, 13 Mar 2009 21:06:23 GMT
From: sln@netherlands.com
Subject: Re: s/// parametrized with backreferences
Message-Id: <22ilr416blaus0s9v0m5t0606a0rdj8qkj@4ax.com>
On Wed, 11 Mar 2009 16:24:17 -0700 (PDT), msciwoj <m@epf.pl> wrote:
>Tad,
>
>Sorry, I was bit distracted
>Apologies
>
>I see the reason why single eval doesnt work with variable (without
>double quotes).
>If double eval works with double quotes then this also should work
>(just a check):
>s/$pattern/"$2\n$1"/ge;
>and it works indeed!
>
>The mystery for me is this 'second' evaluation actually, like you
>said, "interpolates the values for $2 and $1 into the replacement
>string" and it seems it's the only way that does the job.
>A bit of mystery for me but at the end it works and only this counts,
>I guess.
>
>Thanks again,
>m.
Indeed, the question is valid.
In the nut of it, evaling a variable with a value '$str'
will work, but with a value of '$str\n$str' will not.
But if you notice, the vaule of '$str\n$str' and '$str\\n$str'
are equal. In escence, there is a conflict with the parser on some
level that is not quite understood as pertaining to eval.
Whitness the below code. All works fine. Replace "replacement2" variable
with this value: '$2\n' and watch the error's.
There are other constructs that work when it shouldn't and visa versa,
so the Tad explanation is not even close to being correct. About the only
thing he got correct is /ee only works when there is double interpretation,
but then it works when the evals are broken apart in steps, as a single eval,
but then only on some constructs.
Beware of simple explanations!
-sln
=========================================================
use strict;
use warnings;
my ($str1,$str2,$e);
my $data = <<EOT;
A
B
C
EOT
print "\n0: -------------\n\n";
$str1 = 'hello';
$str2 = '$str1';
print $str2,"\n";
print eval($str2),"\n";
print "\n1: -------------\n\n";
my $replacement2 = '$2';
print $replacement2,"\n";
print "\n2: -------------\n\n";
$data =~ /(.)\n(.)/;
$e = eval ($replacement2);
print "->",$e,"\n";
print "\n3: -------------\n\n";
$data =~ s/(.)\n(.)/eval($replacement2)/eg;
print $data."\n";
------------------------------
Date: Fri, 13 Mar 2009 17:00:08 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: s/// parametrized with backreferences
Message-Id: <slrngrllr8.9lp.tadmc@tadmc30.sbcglobal.net>
msciwoj <m@epf.pl> wrote:
> I see the reason why single eval doesnt work with variable (without
> double quotes).
> If double eval works with double quotes then this also should work
> (just a check):
> s/$pattern/"$2\n$1"/ge;
> and it works indeed!
That is because the replacement part is "double quotish" (without s///e).
Once you add the s///e modifier, it is now an expression to be evaluated.
This does the same thing too:
s/$pattern/ $2 . "\n" . $1 /ge;
> The mystery for me is this 'second' evaluation actually, like you
> said, "interpolates the values for $2 and $1 into the replacement
> string" and it seems it's the only way that does the job.
Any expression that results in the string you want to use as
the replacement text will do the job.
In my original code, you could use any of the below to get the
same results as the original did:
my $replacement = '$2 . "\n" . $1';
or
my $replacement = '$2 . $/ . $1';
or even (if on *nix)
my $replacement = '$2 . chr(10) . $1';
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 13 Mar 2009 17:42:34 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: s/// parametrized with backreferences
Message-Id: <slrngrloaq.9lp.tadmc@tadmc30.sbcglobal.net>
sln@netherlands.com <sln@netherlands.com> wrote:
> On Wed, 11 Mar 2009 16:24:17 -0700 (PDT), msciwoj <m@epf.pl> wrote:
>>The mystery for me is this 'second' evaluation actually, like you
>>said, "interpolates the values for $2 and $1 into the replacement
>>string" and it seems it's the only way that does the job.
>>A bit of mystery for me but at the end it works and only this counts,
>>I guess.
> In the nut of it, evaling a variable with a value '$str'
> will work,
Because the value is a valid Perl expression.
> but with a value of '$str\n$str' will not.
Because the value is not a valid Perl expression.
> But if you notice, the vaule of '$str\n$str' and '$str\\n$str'
> are equal.
That is how single quoted strings work.
The "Scalar value constructors" section in perldata points out that
there are only 2 special characters in a single quoted string.
Single quote is special (it marks the end of the string) unless
it is preceded by a backslash.
Backslash is special if it preceeds a single quote or a backslash.
A backslash that does not preceed 1 of those 2 characters is literal.
So the 1st string above has a literal backslash and an "n" in it.
The 2nd string above has a backslashed backslash (which becomes
a backslash) and an "n" in it.
> In escence, there is a conflict with the parser on some
> level that is not quite understood
Don't let that stop you from pretending to answer questions about it.
> as pertaining to eval.
It has nothing to do with eval.
It has to do with single-quoted strings.
> Whitness the below code. All works fine. Replace "replacement2" variable
> with this value: '$2\n' and watch the error's.
That is because in the code below, the value of $replacement2
is a valid expression:
perl -e '$2'
But the value you suggest above is not a valid expression:
perl -e '$2\n'
Throws a syntax error just as this does:
#!/usr/bin/perl
use warnings;
use strict;
$2\n
> There are other constructs that work when it shouldn't and visa versa,
No there aren't.
Those are the result of you not understanding how things work.
When you discover one, post it here and learn what you are missing.
> so the Tad explanation is not even close to being correct.
My explanation is much more correct than your misguided attempt.
> About the only
> thing he got correct is /ee only works when there is double interpretation,
^^^^^^^^^^
I did not say that.
> but then it works when the evals are broken apart in steps, as a single eval,
No it doesn't.
> but then only on some constructs.
Show us one.
> Beware of simple explanations!
Beware of simpletons providing "explanations"!
>=========================================================
>
> use strict;
> use warnings;
>
> my ($str1,$str2,$e);
> my $data = <<EOT;
> A
> B
> C
> EOT
>
> print "\n0: -------------\n\n";
>
> $str1 = 'hello';
> $str2 = '$str1';
> print $str2,"\n";
> print eval($str2),"\n";
>
> print "\n1: -------------\n\n";
>
> my $replacement2 = '$2';
> print $replacement2,"\n";
>
> print "\n2: -------------\n\n";
>
> $data =~ /(.)\n(.)/;
> $e = eval ($replacement2);
> print "->",$e,"\n";
>
> print "\n3: -------------\n\n";
>
> $data =~ s/(.)\n(.)/eval($replacement2)/eg;
> print $data."\n";
>
>
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 13 Mar 2009 14:42:20 -0700 (PDT)
From: sso <strongsilentone@gmail.com>
Subject: Strange Hash Output
Message-Id: <36c3ba36-2a8c-4c22-a786-82132a8d6ac6@h5g2000yqh.googlegroups.com>
I'm sure this makes sense somehow, just not to me as I am
inexperienced.
When I print my hash via:
print %myhash;
it prints out something like 2/8 or 4/8. Always a fraction like
that. Is there a general cause of this?
------------------------------
Date: Fri, 13 Mar 2009 21:59:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Strange Hash Output
Message-Id: <Xns9BCDB718FCBBFasu1cornelledu@127.0.0.1>
sso <strongsilentone@gmail.com> wrote in news:36c3ba36-2a8c-4c22-a786-
82132a8d6ac6@h5g2000yqh.googlegroups.com:
> I'm sure this makes sense somehow, just not to me as I am
> inexperienced.
>
> When I print my hash via:
>
> print %myhash;
>
> it prints out something like 2/8 or 4/8.
Nope. That cannot happen. Printing the %hash in list context results in
the key-value pairs being printed.
> Always a fraction like that. Is there a general cause of this?
You get the m/n notation when you evaluate a hash in scalar context.
That means m buckets out of the n are used. This is all documented in
perldoc perldata:
If you evaluate a hash in scalar context, it returns false if the hash
is empty. If there are any key/value pairs, it returns true; more
precisely, the value returned is a string consisting of the number of
used buckets and the number of allocated buckets, separated by a slash.
This is pretty much useful only to find out whether Perl's internal
hashing algorithm is performing poorly on your data set.
You should, at the very least, read perldata, perlsyn, perlop, perlfunc
and, of course, perlfaq if you plan to learn Perl.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Fri, 13 Mar 2009 17:50:48 -0500
From: Chris Mattern <syscjm@sumire.gwu.edu>
Subject: Re: Strange Hash Output
Message-Id: <slrngrloq7.ki8.syscjm@sumire.gwu.edu>
On 2009-03-13, sso <strongsilentone@gmail.com> wrote:
> I'm sure this makes sense somehow, just not to me as I am
> inexperienced.
>
> When I print my hash via:
>
> print %myhash;
>
> it prints out something like 2/8 or 4/8. Always a fraction like
> that. Is there a general cause of this?
Yes. The cause is called, "that's how it's supposed to work." When you
use a hash in a scalar context, you get a string indicating how many
buckets out of the total available buckets the hash is using.
--
Christopher Mattern
NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
------------------------------
Date: Fri, 13 Mar 2009 17:55:50 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Strange Hash Output
Message-Id: <x7r611rq15.fsf@mail.sysarch.com>
>>>>> "CM" == Chris Mattern <syscjm@sumire.gwu.edu> writes:
CM> On 2009-03-13, sso <strongsilentone@gmail.com> wrote:
>> I'm sure this makes sense somehow, just not to me as I am
>> inexperienced.
>>
>> When I print my hash via:
>>
>> print %myhash;
>>
>> it prints out something like 2/8 or 4/8. Always a fraction like
>> that. Is there a general cause of this?
CM> Yes. The cause is called, "that's how it's supposed to work." When you
CM> use a hash in a scalar context, you get a string indicating how many
CM> buckets out of the total available buckets the hash is using.
but the code above puts the hash in list context (from print). this
likely means the above code isn't what the OP actually ran.
perl -le '%h = ( a => 2 ) ; print %h'
a2
so the OP needs to post his real code and not what he thinks he ran.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 13 Mar 2009 18:19:06 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Why does this not print the filenames ?
Message-Id: <gpe82q$lok$1@reader1.panix.com>
In article <71tse2Fmev9fU1@mid.individual.net>,
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>You are trying to alias $_ to both a file name and a line. In cases
>when you have an outer and an inner loop, you need to be specific in
>at least one of them.
That's true in general. It's usually a necessary practice: when I'm
in two loops, I usually needed to refer to both loop variables.
But foreach loops have a special rule. In man perlsyn,
The "foreach" loop iterates over a normal list value and sets the
variable VAR to be each element of the list in turn. If the
variable is preceded with the keyword "my", then it is lexically
scoped, and is therefore visible only within the loop. Otherwise,
the variable is implicitly local to the loop and regains its
former value upon exiting the loop. If the variable was
previously declared with "my", it uses that variable instead of
the global one, but it's still localized to the loop. This
implicit localisation occurs _only_ in a "foreach" loop.
For example, in Perl 5.010:
$ perl -E '
foreach (qw(1 2 3)) {
say "outer $_";
foreach (qw(a b c)) {
say "inner $_";
}
say "outer again $_";
}'
produces
outer 1
inner a
inner b
inner c
outer again 1
outer 2
inner a
inner b
inner c
outer again 2
outer 3
inner a
inner b
inner c
outer again 3
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Fri, 13 Mar 2009 16:28:34 -0700 (PDT)
From: "A. Farber" <Alexander.Farber@gmail.com>
Subject: Wide character in subroutine entry - how to get bytes for md5_hex?
Message-Id: <acfb82ce-8c93-4437-915a-149adb37c5f8@y13g2000yqn.googlegroups.com>
Hello,
I develop a card game in Flash+Perl and use phpBB as backend.
Besides using phpBB for user auth. I also want to log played
games as posts in one of the forums (in utf8 encoding). So I try:
use constant SPADES_HTML => pack ' U', 0x2660;
use constant DIAMONDS_HTML => pack ' U', 0x2666;
use constant CLUBS_HTML => pack ' U', 0x2663;
use constant HEARTS_HTML => pack ' U', 0x2665;
And then:
my $body = 'BODY TEST 10' . HEARTS_HTML;
$Sth_create_post->execute('HEADER TEST 7' . SPADES_HTML,
$body, md5_hex($body), '12345678') or die $Dbh->errstr;
(because phpBB wants to have md5-checksum as well)
Unfortunately md5 fails with "Wide character in subroutine entry".
It probably notices that the input is in UTF8 and not in bytes?
Is there a way to pass the actual bytes to the md5_hex call?
Thank you
Alex
------------------------------
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 V11 Issue 2274
***************************************