[29684] in Perl-Users-Digest
Perl-Users Digest, Issue: 928 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 11 21:09:52 2007
Date: Thu, 11 Oct 2007 18:09:13 -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, 11 Oct 2007 Volume: 11 Number: 928
Today's topics:
changing format comment char (Time Waster)
Re: changing format comment char <mritty@gmail.com>
Re: changing format comment char (Time Waster)
Re: changing format comment char <ben@morrow.me.uk>
Re: changing format comment char <jgibson@mail.arc.nasa.gov>
Re: changing format comment char <No_4@dsl.pipex.com>
Re: Does Perl micro-optimize? <bik.mido@tiscalinet.it>
Re: file uploader script <barn104_1999@yahoo.com>
Guitars Masters arturklis2@gmail.com
newbie question andrew_nuss@yahoo.com
Re: Perl 5.8 and MD5 <jruffino@gailborden.info>
Re: Perl 5.8 and MD5 <jgibson@mail.arc.nasa.gov>
quotes difference in Perl5.6 vs 5.8 <stoupa@practisoft.cz>
Re: Regex problem. sln@netherlands.co
Simple Array question <davechunny@gmail.com>
Re: Simple Array question <usenet@larseighner.com>
Re: Simple Array question usenet@DavidFilmer.com
Re: Simple Array question <mritty@gmail.com>
Re: Simple Array question <mritty@gmail.com>
Re: Simple Array question <1usa@llenroc.ude.invalid>
Re: Simple Array question sln@netherlands.co
Re: Simple Array question sln@netherlands.co
Re: The Modernization of Emacs: terminology buffer and <jwkenne@attglobal.net>
Re: Use of "caller" is ambiguous <bik.mido@tiscalinet.it>
Re: Use of "caller" is ambiguous <ben@morrow.me.uk>
Re: Using system() like an http "get" <glennj@ncf.ca>
Re: UTF8 strings and filesystem access <hjp-usenet2@hjp.at>
Re: UTF8 strings and filesystem access (Gary E. Ansok)
wana watch latest hindi hot videos? diprat7@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 11 Oct 2007 21:21:01 GMT
From: bfc@fenway.UUCP (Time Waster)
Subject: changing format comment char
Message-Id: <1twPi.7914$j14.6210@trnddc06>
I wanted to use the format statement to create a script for a
different language:
if (open(FP,">$SOMEFNAME")) {
format FP =
#!/usr/bin/expect
spawn some-commnd
expect -re "some string"
more here of course
.
write FP;
close FP;
}
..but that doesn't work because the '#' means comment, and I can't
seem to escape it. I will continue reading about this feature,
but anyone know offhand if there's a way around this?
TIA
------------------------------
Date: Thu, 11 Oct 2007 14:38:35 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: changing format comment char
Message-Id: <1192138715.781963.5970@19g2000hsx.googlegroups.com>
On Oct 11, 5:21 pm, b...@fenway.UUCP (Time Waster) wrote:
> I wanted to use the format statement to create a script for a
> different language:
>
> if (open(FP,">$SOMEFNAME")) {
> format FP =
> #!/usr/bin/expect
> spawn some-commnd
> expect -re "some string"
> more here of course
> .
> write FP;
> close FP;
> }
>
> ..but that doesn't work because the '#' means comment, and I can't
> seem to escape it. I will continue reading about this feature,
> but anyone know offhand if there's a way around this?
>
> TIA
Natively, I would try a backslash.
But why on earth are you using formats for this, as opposed to just a
normal string? Or even heredocs?
if (open my $FP, '>', $SOMEFILENAME) {
print $FP << EO_SCRIPT;
#!/usr/bin/expect
spawn some-commnd
expect -re "some string"
more here of course
EO_SCRIPT
close $FP;
}
Paul Lalli
------------------------------
Date: Thu, 11 Oct 2007 21:57:08 GMT
From: bfc@fenway.UUCP (Time Waster)
Subject: Re: changing format comment char
Message-Id: <U_wPi.17599$Cd7.8082@trnddc03>
In article <1192138715.781963.5970@19g2000hsx.googlegroups.com>,
Paul Lalli <mritty@gmail.com> wrote:
>But why on earth are you using formats for this, as opposed to just a
>normal string? Or even heredocs?
>
>if (open my $FP, '>', $SOMEFILENAME) {
> print $FP << EO_SCRIPT;
>#!/usr/bin/expect
>spawn some-commnd
>expect -re "some string"
>more here of course
>EO_SCRIPT
> close $FP;
>}
>
>Paul Lalli
>
That was my first choice, a quick try didn't make it work. Using
something closer to yours:
#!/usr/bin/perl
if (open my $FP, '>', "/tmp/tmp.out") {
print $FP << EO_SCRIPT;
#!/bin/sometest
something more
EO_SCRIPT
close $FP;
}
Output:
syntax error at /tmp/tmp2.pl line 7, near "EO_SCRIPT
close"
Execution of /tmp/tmp2.pl aborted due to compilation errors.
------------------------------
Date: Fri, 12 Oct 2007 00:41:25 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: changing format comment char
Message-Id: <5uo2u4-kjt2.ln1@osiris.mauzo.dyndns.org>
Quoth noone@nowhere.com:
> In article <1192138715.781963.5970@19g2000hsx.googlegroups.com>,
> Paul Lalli <mritty@gmail.com> wrote:
> >But why on earth are you using formats for this, as opposed to just a
> >normal string? Or even heredocs?
> >
> >if (open my $FP, '>', $SOMEFILENAME) {
> > print $FP << EO_SCRIPT;
> >#!/usr/bin/expect
> >spawn some-commnd
> >expect -re "some string"
> >more here of course
> >EO_SCRIPT
> > close $FP;
> >}
>
> That was my first choice, a quick try didn't make it work. Using
> something closer to yours:
>
> #!/usr/bin/perl
> if (open my $FP, '>', "/tmp/tmp.out") {
> print $FP << EO_SCRIPT;
Heredocs must be written as <<FOO, not << FOO. What you have there
parses as an attempt to left-shift $FP by the numeric value of
'EO_SCRIPT': if you had used strict it would have forbidden the bareword
EO_SCRIPT, and if you had used warnings it would have warned about the
numeric conversion. This is why you should *always* use both.
Ben
------------------------------
Date: Thu, 11 Oct 2007 16:57:55 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: changing format comment char
Message-Id: <111020071657557709%jgibson@mail.arc.nasa.gov>
In article <U_wPi.17599$Cd7.8082@trnddc03>, Time Waster
<bfc@fenway.UUCP> wrote:
[suggested program using here document snipped]
> That was my first choice, a quick try didn't make it work. Using
> something closer to yours:
>
> #!/usr/bin/perl
use strict;
use warnings;
> if (open my $FP, '>', "/tmp/tmp.out") {
> print $FP << EO_SCRIPT;
> #!/bin/sometest
> something more
> EO_SCRIPT
> close $FP;
> }
>
> Output:
> syntax error at /tmp/tmp2.pl line 7, near "EO_SCRIPT
> close"
> Execution of /tmp/tmp2.pl aborted due to compilation errors.
>
Adding those two lines will tell you what the problem is.
See also 'perldoc -q documents' "Why don't my <<HERE documents work?"
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Fri, 12 Oct 2007 01:51:08 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: changing format comment char
Message-Id: <xrudne1W5MibWJPanZ2dnUVZ8qSnnZ2d@pipex.net>
Time Waster wrote:
> I wanted to use the format statement to create a script for a
> different language:
>
> if (open(FP,">$SOMEFNAME")) {
> format FP =
> #!/usr/bin/expect
> spawn some-commnd
>.......
>
> ..but that doesn't work because the '#' means comment, and I can't
> seem to escape it. I will continue reading about this feature,
> but anyone know offhand if there's a way around this?
As has been pointed out, you don't want to do that anyway, but if you ever
come across a case where you do then all you need to do is put the difficult
line into a string and print the string:
==========
<start of code>...
my $str="#!/usr/bin/expect";
format =
@*
$str
spawn some-commnd
expect -re "some string"
more here of course
.
....<rest of code>
==========
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Thu, 11 Oct 2007 23:37:39 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Does Perl micro-optimize?
Message-Id: <455tg3pu72npqdog61nhbnuh5hb3dsomdf@4ax.com>
On Thu, 11 Oct 2007 06:46:27 -0700, rihad <rihad@mail.ru> wrote:
>> There is some support for this in 5.9.x, but I don't
>> think it's ready to be used yet (?).
>>
>
>Noo, you've got to be kidding... At least subroutine arguments are
>always passed by reference in Perl (which is good for speed, but bad
>if you unintentionally modify them).
Nooo, arguments passing is known to be terribly inefficient in Perl.
Ask Ilya!!
>On a side note, and I won't be the first one to say this: Perl is
>difficult. Too many special cases. Or maybe I have this impression
Yes it is, and yes there are. But you're not required to know them all
from scratch.
However, if you're patient enough, Perl 6 will be an even more complex
language whose complexity will be built by the complex interaction
between simpler pieces, in a consistent and orthogonal manner, with no
special cases.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 11 Oct 2007 14:35:12 -0700
From: ll <barn104_1999@yahoo.com>
Subject: Re: file uploader script
Message-Id: <1192138512.919141.214000@o80g2000hse.googlegroups.com>
On Oct 10, 7:41 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> ll wrote:
> > On Oct 10, 10:07 am, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> >> If that script doesn't work as expected, please consult the
> >> documentation or the script author.
>
> >> If you want to write your own script, and are encountering difficulties
> >> when doing so, this group may be a good place to ask for help. Btw, you
> >> may want to make use of the CPAN module CGI::UploadEasy.
>
> > Thanks for your reply. I've now got the files to upload (to "cgi-bin/
> > upload/" - for some reason I cannot get them to upload to "root/
> > upload/".
>
> I had a look at the script's config variables. Try this setting:
>
> $parent_dir = "$ENV{DOCUMENT_ROOT}/";
>
> > I am able to open the files from the ftp client, although
> > when I try opening them via the link created (which turns out to be
> > the empty "root/upload/" directory) on the page, I get the following
> > error:
> > "Not Found
> > The requested URL /upload/comm_khicks.gif was not found on this
> > server.
> > Additionally, a 404 Not Found error was encountered while trying to
> > use an ErrorDocument to handle the request. "
>
> > I would like a way to view/open the files within the "root/upload/"
> > directory.
>
> As long as the files are not saved in that directory, you can't
> reasonably be expecting to view/open the files there, can you?
>
> > Thanks for the tip re CGI::UploadEasy.
>
> You're welcome. Note, again, that this group is for discussing Perl
> programming, not for assistance with ready-to-use scripts.
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar,
Many thanks - that was what it needed - the correct diretory is
receiving and displaying the files. Also, thanks for the word on the
group - will look for a group more suitably tailored to this.
regards,
Louis
------------------------------
Date: Thu, 11 Oct 2007 19:54:44 -0000
From: arturklis2@gmail.com
Subject: Guitars Masters
Message-Id: <1192132484.261013.4810@o3g2000hsb.googlegroups.com>
Guitars reviews, lessons, pictures, and more!!!!!!!
http://guitars-masters.blogspot.com/
------------------------------
Date: Thu, 11 Oct 2007 17:48:25 -0700
From: andrew_nuss@yahoo.com
Subject: newbie question
Message-Id: <1192150105.564077.163370@y27g2000pre.googlegroups.com>
Hi,
How do you apply a regexp directly to a stream rather than a string?
Andy
------------------------------
Date: Thu, 11 Oct 2007 14:48:20 -0700
From: Joe <jruffino@gailborden.info>
Subject: Re: Perl 5.8 and MD5
Message-Id: <1192139300.936964.261360@22g2000hsm.googlegroups.com>
This the the smallest, I have:
01. #!/usr/bin/perl
02.
03. #Libarry file that will read the form data and store in
formdata{'value'} form
04. require '../lib/forminput.lib';
05.
06. &FormInput;
07.
08. print "HTTP/1.0 200 OK\n" if ($ENV{PERLXS} eq "PerlIS");
09. print "Content-Type: text/html\n\n";
10.
11. use Digest::MD5 qw(md5_hex);
12.
13. print qq(<html><head><title>MD5 Encryption</title></head><body>);
14.
15. if ($formdata{'flag'} eq "1") {
16. print qq(
17. Encryption
18. <br />
19. <br />
20. $formdata{'toEncrypt'} = );
21.
22. print md5_hex($formdata{'toEncrypt'})
23.
24. }
25. else {
26.
27. print qq(
28. <form action="md5.cgi?flag=1" method="post">
29. Text to Encrypt: <input type="text" name="toEncrypt">
30. <br />
31. <br />
32. <input type="submit" value="Encrypt">
33. </form>
34. );
35. }
36. print qq(</body></html>);
It runs fine on a Server (Win 2000) with Perl 5.6 installed. It will
not run with a server (Win 2003) and Perl 5.8 installed.
The error message I get is:
Content-type: text/html
'C:\Inetpub\wwwroot\cgi-bin\md5\md5.cgi' script produced no output.
It uses the MD5 module to encrypt a string, (password) in hex. Also,
I read the docs I was able to find on eval, and it says it runs what
is has, like a small program. So,, if it does not work, then
something is wrong with the Module?
------------------------------
Date: Thu, 11 Oct 2007 16:49:40 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Perl 5.8 and MD5
Message-Id: <111020071649408002%jgibson@mail.arc.nasa.gov>
In article <1192139300.936964.261360@22g2000hsm.googlegroups.com>, Joe
<jruffino@gailborden.info> wrote:
> This the the smallest, I have:
>
> 01. #!/usr/bin/perl
Please do not post code with line numbers. It makes it harder to
cut-and-paste from your posting.
You should have 'use strict;' here.
You also may want 'use CGI::Carp qw(fatalsToBrowser);'.
> 02.
> 03. #Libarry file that will read the form data and store in
> formdata{'value'} form
> 04. require '../lib/forminput.lib';
What is forminput.lib? Is it a Perl package for processing CGI
requests? You have still not indicated how your script is being
executed. It is apparently being run as a CGI program by a web server,
but it helps to say so explicitly.
> 05.
> 06. &FormInput;
> 07.
> 08. print "HTTP/1.0 200 OK\n" if ($ENV{PERLXS} eq "PerlIS");
What is PERLXS on your new server?
> 09. print "Content-Type: text/html\n\n";
> 10.
> 11. use Digest::MD5 qw(md5_hex);
It is better to have all of you use statements near the beginning of
the program (they all get executed at the beginning, anyway, regardless
of where they are located in the program).
> 12.
> 13. print qq(<html><head><title>MD5 Encryption</title></head><body>);
> 14.
> 15. if ($formdata{'flag'} eq "1") {
> 16. print qq(
> 17. Encryption
> 18. <br />
> 19. <br />
> 20. $formdata{'toEncrypt'} = );
> 21.
> 22. print md5_hex($formdata{'toEncrypt'})
> 23.
> 24. }
> 25. else {
> 26.
> 27. print qq(
> 28. <form action="md5.cgi?flag=1" method="post">
> 29. Text to Encrypt: <input type="text" name="toEncrypt">
> 30. <br />
> 31. <br />
> 32. <input type="submit" value="Encrypt">
> 33. </form>
> 34. );
> 35. }
> 36. print qq(</body></html>);
>
> It runs fine on a Server (Win 2000) with Perl 5.6 installed. It will
> not run with a server (Win 2003) and Perl 5.8 installed.
Does it execute from the command line?
>
> The error message I get is:
> Content-type: text/html
>
> 'C:\Inetpub\wwwroot\cgi-bin\md5\md5.cgi' script produced no output.
>
> It uses the MD5 module to encrypt a string, (password) in hex. Also,
> I read the docs I was able to find on eval, and it says it runs what
> is has, like a small program. So,, if it does not work, then
> something is wrong with the Module?
If this is really a CGI program, see the troubleshooting tips at
<http://www.perlmonks.org/?node_id=380424>
I would refer you also to 'perldoc -q 500', but the first link on that
page seems not to be working. Try the second one.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Fri, 12 Oct 2007 02:48:29 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: quotes difference in Perl5.6 vs 5.8
Message-Id: <femg9b$10oj$1@ns.felk.cvut.cz>
I have script written in Perl 5.6.1 and it wotk fine. But when I run the
same script on hosting server then this fail on trivial operation. On server
Perl 5.8.0 is installed.
The example to ilustrate error is this
#!/usr/bin/perl
use strict;
use warnings;
my $var = "abcd'efg";
open OUT, "> log.txt";
print OUT "$var\n"; # here script fail on server with SIG-PIPE signal
close OUT;
Is something wrong in my script or is some bug in Perl 5.8.0 ?
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Thu, 11 Oct 2007 17:21:33 -0700
From: sln@netherlands.co
Subject: Re: Regex problem.
Message-Id: <4eftg3loh7d5fprv69315h9ojbtk7p4pca@4ax.com>
On Wed, 10 Oct 2007 21:59:20 +0200, Michele Dondi <bik.mido@tiscalinet.it> wrote:
>On Wed, 10 Oct 2007 14:55:22 -0000, it_says_BALLS_on_your forehead
><simon.chao@fmr.com> wrote:
>
>>> >A B B c A c B d A A
>>>
>>> >I have a string as represented above. They are separated by spaces of
>>> >unknown length. I need to match As and Bs and store them in array in
>>> >the order they occur, or as they occur. The array filled from above
>>> >string should contain: ABBABAA.
>>>
>>> my @AandBs = /[AB]/g;
>>
>>That won't quite work since 'A' and 'B' are representative of more
>>complex strings, and so can't fit into a character class.
>
>Then he should have said so. In fact I admit I was in a hurry and
>didn't read the rest of his post: somwhat my fault. But then one thing
>is to say that the problem is about
>
> A B B c A c B d A A
>
>and later specify that A is not A and B is not B and another thing is
>to say so to begin with. However if the problem is not more clearly
>defined, one can suppose that
>
> my @AandBs = /one|two or three/g;
>
>will be enough. If the OP wants to exclude a bone and two or
>threesome, then he may want to do
>
> my @AandBs = /\b(?:one|two or three)\b/g;
>
>If he wants something more complicated, then he should say so.
I don't want one two or three, I want everything else | nothing
------------------------------
Date: Thu, 11 Oct 2007 22:45:26 -0000
From: elroyerni <davechunny@gmail.com>
Subject: Simple Array question
Message-Id: <1192142726.763354.235610@e34g2000pro.googlegroups.com>
Hi -
I'm trying to assign to a variable the number of elements in a array
for example. I have array with data:
my @array_data;
I want to assign the number of elements in the array to a variable, i
tried this and looked it up and can't find a solution :(
Say array_data contains {0,1,2,3,4,5} i want to assign the number of
elements to a variable, in this case "6" to a variable.
i tried this and failed...
my $total = `0 + @{$results}`;
Any help?
Thanks!
------------------------------
Date: 11 Oct 2007 22:51:48 GMT
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: Simple Array question
Message-Id: <slrnfgta68.3mc.usenet@debranded.larseighner.com>
In our last episode,
<1192142726.763354.235610@e34g2000pro.googlegroups.com>,
the lovely and talented elroyerni
broadcast on comp.lang.perl.misc:
> Hi -
> I'm trying to assign to a variable the number of elements in a array
> for example. I have array with data:
> my @array_data;
> I want to assign the number of elements in the array to a variable, i
> tried this and looked it up and can't find a solution :(
> Say array_data contains {0,1,2,3,4,5} i want to assign the number of
> elements to a variable, in this case "6" to a variable.
> i tried this and failed...
> my $total = `0 + @{$results}`;
> Any help?
Wow, it's a little late to be doing your first week's homework.
Why doesn't $#array_data + 1 work for you?
--
Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
Countdown: 466 days to go.
What do you do when you're debranded?
------------------------------
Date: Thu, 11 Oct 2007 23:40:56 -0000
From: usenet@DavidFilmer.com
Subject: Re: Simple Array question
Message-Id: <1192146056.600987.152640@e9g2000prf.googlegroups.com>
On Oct 11, 3:51 pm, Lars Eighner <use...@larseighner.com> wrote:
> Why doesn't $#array_data + 1 work for you?
Many programmers would just use @array_data in a scalar context, or
force it with scalar(@array_data). When an array is evaluated in
scalar context it returns the number of elements it contains.
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Thu, 11 Oct 2007 17:24:52 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Simple Array question
Message-Id: <1192148692.692151.131080@q5g2000prf.googlegroups.com>
On Oct 11, 6:51 pm, Lars Eighner <use...@larseighner.com> wrote:
> In our last episode,
> <1192142726.763354.235...@e34g2000pro.googlegroups.com>,
> the lovely and talented elroyerni
> broadcast on comp.lang.perl.misc:
>
> > Hi -
> > I'm trying to assign to a variable the number of elements in a array
> > for example. I have array with data:
> > my @array_data;
> > I want to assign the number of elements in the array to a variable, i
> > tried this and looked it up and can't find a solution :(
> > Say array_data contains {0,1,2,3,4,5} i want to assign the number of
> > elements to a variable, in this case "6" to a variable.
> > i tried this and failed...
> > my $total = `0 + @{$results}`;
> > Any help?
>
> Wow, it's a little late to be doing your first week's homework.
>
> Why doesn't $#array_data + 1 work for you?
A little late for you to have to be told you shouldn't use that.
Somewhere, someway, some schmuck will edit your code and change the $
[ variable, and all of a sudden, $#foo will no longer be "one less
than the size". Because $#foo is not intended to be "one less than
the size". It actually is "the last index of".
Use the array in scalar context. That is defined to be the size.
Paul Lalli
------------------------------
Date: Thu, 11 Oct 2007 17:29:10 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Simple Array question
Message-Id: <1192148950.663458.168390@q5g2000prf.googlegroups.com>
On Oct 11, 6:45 pm, elroyerni <davechu...@gmail.com> wrote:
> I'm trying to assign to a variable the number of elements in a
> array for example. I have array with data:
>
> my @array_data;
>
> I want to assign the number of elements in the array to a
> variable
my $size = @array_data;
> i tried this and looked it up and can't find a solution :(
perldoc perldata:
If you evaluate an array in scalar context, it returns the
length of the array. (Note that this is not true of lists,
which return the last value, like the C comma operator, nor
of built-in functions, which return whatever they feel like
returning.)
> Say array_data contains {0,1,2,3,4,5} i want to assign the number
> of elements to a variable, in this case "6" to a variable.
>
> i tried this and failed...
>
> my $total = `0 + @{$results}`;
There are a number of things wrong with that expression. For one,
what the heck is $results? You've only mentioned the array
@array_data. You're using $results there as though it's an array
reference. Is it? How is it being created.
For two, you're taking the result of that 0 + @{$results} expression,
and executing it as an external program. Then you're taking the
output of that program and assigning it to $total. That's what the
`...` quotes do.
Paul Lalli
------------------------------
Date: Fri, 12 Oct 2007 00:31:25 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Simple Array question
Message-Id: <Xns99C6D0C658364asu1cornelledu@127.0.0.1>
elroyerni <davechunny@gmail.com> wrote in news:1192142726.763354.235610
@e34g2000pro.googlegroups.com:
> I'm trying to assign to a variable the number of elements in a array
> for example. I have array with data:
>
> my @array_data;
>
> I want to assign the number of elements in the array to a variable, i
> tried this and looked it up and can't find a solution :(
>
> Say array_data contains {0,1,2,3,4,5} i want to assign the number of
> elements to a variable, in this case "6" to a variable.
my @array_data = (0 .. 5);
my $total = @array_data;
print "Total = $total\n";
>
> i tried this and failed...
>
>
> my $total = `0 + @{$results}`;
Read perldoc -f system to find out what backticks actually do (or
consult perldoc perlop for the qx operator).
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
Date: Thu, 11 Oct 2007 17:45:30 -0700
From: sln@netherlands.co
Subject: Re: Simple Array question
Message-Id: <oogtg3h8hlhn3cue9bs6k0ai1mvvf3vht8@4ax.com>
On Thu, 11 Oct 2007 22:45:26 -0000, elroyerni <davechunny@gmail.com> wrote:
>Hi -
>
>I'm trying to assign to a variable the number of elements in a array
>for example. I have array with data:
>
>my @array_data;
>
>I want to assign the number of elements in the array to a variable, i
>tried this and looked it up and can't find a solution :(
>
>Say array_data contains {0,1,2,3,4,5} i want to assign the number of
>elements to a variable, in this case "6" to a variable.
>
>i tried this and failed...
>
>
>my $total = `0 + @{$results}`;
>
>Any help?
>
>Thanks!
use strict;
use warnings;
my @array = (0,1,2,3,4);
my $tt = @array;
print "@array $tt\n";
print @array.$tt;
---output:
0 1 2 3 4 5
55
------------------------------
Date: Thu, 11 Oct 2007 18:07:10 -0700
From: sln@netherlands.co
Subject: Re: Simple Array question
Message-Id: <euhtg391g62qj345uh86h7gpj1f3t0u0iq@4ax.com>
On Thu, 11 Oct 2007 17:45:30 -0700, sln@netherlands.co wrote:
>On Thu, 11 Oct 2007 22:45:26 -0000, elroyerni <davechunny@gmail.com> wrote:
>
>>Hi -
>>
>>I'm trying to assign to a variable the number of elements in a array
>>for example. I have array with data:
>>
>>my @array_data;
>>
>>I want to assign the number of elements in the array to a variable, i
>>tried this and looked it up and can't find a solution :(
>>
>>Say array_data contains {0,1,2,3,4,5} i want to assign the number of
>>elements to a variable, in this case "6" to a variable.
>>
>>i tried this and failed...
>>
>>
>>my $total = `0 + @{$results}`;
>>
>>Any help?
>>
>>Thanks!
>
>use strict;
>use warnings;
>
>my @array = (0,1,2,3,4);
>my $tt = @array;
>
>print "@array $tt\n";
>print @array.$tt;
>
>---output:
>0 1 2 3 4 5
>55
and,
print @array*$tt;
25
------------------------------
Date: Thu, 11 Oct 2007 17:40:48 -0400
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: The Modernization of Emacs: terminology buffer and keybinding
Message-Id: <CLwPi.2348$Yb2.747@newsfe12.lga>
nebulous99@gmail.com wrote:
> Do not bluntly contradict me in public.
You are in grave need of professional psychiatric help.
Seek it now, if you do not wish your life to be ended three or four
years down the line by a police sniper.
--
John W. Kennedy
Read the remains of Shakespeare's lost play, now annotated!
http://pws.prserv.net/jwkennedy/Double%20Falshood/index.html
------------------------------
Date: Thu, 11 Oct 2007 23:57:28 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Use of "caller" is ambiguous
Message-Id: <jv6tg3tc80o24vn7ucus4qsa88b4qhnsk7@4ax.com>
On Thu, 11 Oct 2007 19:04:25 +0200, "Ferry Bolhar"
<ferry.bolhar@chello.at> wrote:
>*{caller . '::vtx_get_page'} = sub {....};
>
>Perl complains with
>
>Use of "caller" without parentheses is ambiguous
>
>Why is this expression ambiguous?
I don't know, but I often get the same behaviour with another
construct, which is also surprising. I've never dared to ask and just
added parens without doing so.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Fri, 12 Oct 2007 00:00:19 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Use of "caller" is ambiguous
Message-Id: <3hm2u4-pss2.ln1@osiris.mauzo.dyndns.org>
Quoth "Ferry Bolhar" <ferry.bolhar@chello.at>:
>
> when writing
>
> *{caller . '::vtx_get_page'} = sub {....};
>
> Perl complains with
>
> Use of "caller" without parentheses is ambiguous
>
> Why is this expression ambiguous?
It's not. However, the analogous expression
caller + 5
*is* ambiguous ( caller(+5) rather than caller() + 5 ) and the warning
code either isn't smart enough to tell the difference, or is assuming
you aren't.
That's my story, anyway, and I'm sticking to it. If I do too much poking
around in toke.c my brain will dribble out of my ears... :)
For example, with 5.8.8:
~% perl -wle'print rand-10'
Warning: Use of "rand-10" without parentheses is ambiguous at -e
line 1.
-5.64649815977649
Ben
------------------------------
Date: 11 Oct 2007 19:00:41 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Using system() like an http "get"
Message-Id: <slrnfgssmq.440.glennj@smeagol.ncf.ca>
At 2007-10-11 01:02PM, "Bill H" wrote:
> I have a number of pages on a website that run perl scripts to create
> different content. They are all basically accessed with an HREF such
> as:
>
> scriptname.pl?param1=1¶m2=2 etc
>
> The question I have is, an I use the same syntax in a system call from
> another perl program, ie:
>
> system("scriptname.pl?param1=1¶m2=2");
If your scripts use CGI, you might be able to get away with this:
system("scriptname.pl param1=1 param2=2");
See http://perldoc.perl.org/CGI.html#DEBUGGING
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Thu, 11 Oct 2007 22:28:16 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: UTF8 strings and filesystem access
Message-Id: <slrnfgt1r0.o12.hjp-usenet2@zeno.hjp.at>
On 2007-10-11 00:31, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth ansok@alumni.caltech.edu (Gary E. Ansok):
>> One way to access the files in a directory is
>>
>> opendir DH, $dir or die "opendir: $!";
>> while (my $file = readdir DH) {
>> next unless -f "$dir/$file";
>> # do whatever needs to be done with "$dir/$file";
>> }
>>
>> However, this fails given the combination of two facts:
>> 1) $dir is encoded internally in UTF8 (even if $dir doesn't
>> contain any non-ASCII characters)
Then why is it a wide string?
>> 2) $file contains non-ASCII characters
>>
>> The string "$dir/$file" becomes UTF8-encoded, and while it
>> prints correctly, and compares equal to the same string not
>> UTF8-encoded, apparently the internal encoding is used
>> in a stat() (or open()) call, which then fails with $! being
>> "No such file".
>>
>> Is there a way to work around this without needing to
>> transcode all strings that might be UTF8-encoded?
>
> No, not with current versions of perl. All interactions with the system
> use raw byte-strings[1], so you will need to encode them correctly in
> your local character set for open, and decode them from readdir.
or alternatively, treat file names as opaque byte strings.
> [1] The -C switch used to switch to the Unicode API on Win32, but noone
> used it and the switch was removed in 5.8.1.
The switch is still there but it does something different now: It
controls whether I/O streams and command line parameters are in UTF-8.
I use
#!/usr/bin/perl -CSAL
quite often.
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Thu, 11 Oct 2007 22:22:22 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: UTF8 strings and filesystem access
Message-Id: <fem7mu$4o5$1@naig.caltech.edu>
In article <slrnfgt1r0.o12.hjp-usenet2@zeno.hjp.at>,
Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
>> Quoth ansok@alumni.caltech.edu (Gary E. Ansok):
>>>
>>> 1) $dir is encoded internally in UTF8 (even if $dir doesn't
>>> contain any non-ASCII characters)
>
>Then why is it a wide string?
It's read in using XML::Simple from a config file that does not
contain any non-ASCII characters, or any encoding specification in
the XML prolog (though adding "encoding='ISO-8859-1'" didn't help).
Now that I've dug a little deeper, I think upgrading some of our
module versions may help avoid this problem -- a recent change to
XML::LibXML mentioned "strip-off UTF8 flag for consistent behavior
independent of document encoding".
The module versions we're using:
XML::Simple 2.16, XML::SAX 0.12, XML::LibXML 1.52, libxml2.so.2.6.26
Gary
------------------------------
Date: Thu, 11 Oct 2007 11:16:02 -0700
From: diprat7@gmail.com
Subject: wana watch latest hindi hot videos?
Message-Id: <1192126562.053872.36910@19g2000hsx.googlegroups.com>
wana watch latest hindi hot videos?
than www.yedil.com is the site you are looking for
have a nice time with www.yedil.com .Log on now
------------------------------
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 928
**************************************