[28408] in Perl-Users-Digest
Perl-Users Digest, Issue: 9772 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 26 18:05:52 2006
Date: Tue, 26 Sep 2006 15:05:07 -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 Tue, 26 Sep 2006 Volume: 10 Number: 9772
Today's topics:
Re: An interactive interpreter/shell? <thisisbradley@gmail.com>
Re: An interactive interpreter/shell? (reading news)
Re: An interactive interpreter/shell? <thisisbradley@gmail.com>
Re: both 1 and not-1? <news12@8439.e4ward.com>
Re: Ftp via Perl cron job cartercc@gmail.com
Re: list vs. array <robb@acm.org>
Re: list vs. array <christoph.lamprecht.no.spam@web.de>
Re: list vs. array <David.Squire@no.spam.from.here.au>
Re: list vs. array <dha@panix.com>
Re: perl -pe for blocks of lines instead of single line <tadmc@augustmail.com>
Re: Reading from standard input <tzz@lifelogs.com>
Re: regular expression pb. with tags <tzz@lifelogs.com>
remove last 10 lines of all files in a directory rsarpi@gmail.com
Re: Splitting and keeping key/value <tadmc@augustmail.com>
Re: Splitting and keeping key/value <mr@sandman.net>
Re: Splitting and keeping key/value <mr@sandman.net>
Spreadsheet::ParseExcel on Windows with out Win32::OLE <pamelapdh@aol.com>
Re: Spreadsheet::WriteExcel & worksheet->write <benmorrow@tiscali.co.uk>
Strange output problem <ajrodriguez@gmail.com>
Re: Strange output problem <mgarrish@gmail.com>
Re: Strange output problem usenet@DavidFilmer.com
Re: Strange output problem <ajrodriguez@gmail.com>
Re: Strange output problem <DJStunks@gmail.com>
Re: Strange output problem <hjp-usenet2@hjp.at>
Re: submatch scoping in while <benmorrow@tiscali.co.uk>
Re: Tk-perl2exe FileSelect error <benmorrow@tiscali.co.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Sep 2006 12:06:36 -0700
From: "thisisbradley@gmail.com" <thisisbradley@gmail.com>
Subject: Re: An interactive interpreter/shell?
Message-Id: <1159297596.438623.84620@k70g2000cwa.googlegroups.com>
robb@acm.org wrote:
> And, I didn't get too far using the perl interpreter. Maybe I did
> something wrong? But also - it's not clear to me that this kind of
> work is supported:
>
> DB<1> print "hello\n";
> DB<2> use lib '/home/web/lib/perl';
> DB<3> use Trillium::Info;
> DB<4> my $info = Trillium::Info->new();
> DB<5> $info;
>
> DB<6> $info->is_valid_tld('lclark.edu');
> Can't call method "is_valid_tld" on an undefined value at (eval
> 21)[/usr/local/lib/perl5/5.8.0/perl5db.pl:17] line 2.
Try it without the 'my':
M:\>perl -de42
Default die handler restored.
Loading DB routines from perl5db.pl version 1.07
Editor support available.
Enter h or `h h' for help, or `perldoc perldebug' for more help.
main::(-e:1): 42
DB<1> use CGI
DB<2> $x = CGI->new
DB<3> x $x
0 CGI=HASH(0x1af3d28)
'.charset' => 'ISO-8859-1'
'.fieldnames' => HASH(0x1ad0378)
empty hash
'.parameters' => ARRAY(0x19b90f0)
empty array
DB<4> my $y = CGI->new
DB<5> x $y
0 undef
DB<6>
Bradley
------------------------------
Date: Tue, 26 Sep 2006 20:31:51 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: An interactive interpreter/shell?
Message-Id: <X6gSg.6628$UG4.4463@newsread2.news.pas.earthlink.net>
On 09/26/2006 12:28 PM, robb@acm.org wrote:
> robb@acm.org wrote:
>
>> ...As a Python
>> developer, I'm used to being able to start the interpreter, instantiate
>> some of my new classes I've written, invoke methods, determine the
>> types of the objects.
>>
>
> And, I didn't get too far using the perl interpreter. Maybe I did
> something wrong? But also - it's not clear to me that this kind of
> work is supported:
>
> DB<1> print "hello\n";
> DB<2> use lib '/home/web/lib/perl';
> DB<3> use Trillium::Info;
> DB<4> my $info = Trillium::Info->new();
I've found "my" to be tricky in the perl debugger. The variable is
probably trapped in an invisible, inaccessible block. Don't use "my" on
variables that you define at the debugger prompt.
However, my should work on scripts in the debugger.
> DB<5> $info;
By itself, "$info;" is a useless statement; you probably meant "print
$info;"
And since the $info created on line 4 (DB<4>) is trapped in an invisible
block, this info (on line 5) is undefined.
>
> DB<6> $info->is_valid_tld('lclark.edu');
> Can't call method "is_valid_tld" on an undefined value at (eval
> 21)[/usr/local/lib/perl5/5.8.0/perl5db.pl:17] line 2.
>
> DB<7> print $info;
>
Without warnings enabled, attempts to print undefined values display
nothing.
> DB<8>
>
I hope this helps.
--
paduille.4058.mumia.w@earthlink.net
------------------------------
Date: 26 Sep 2006 14:17:10 -0700
From: "thisisbradley@gmail.com" <thisisbradley@gmail.com>
Subject: Re: An interactive interpreter/shell?
Message-Id: <1159305430.768908.236480@e3g2000cwe.googlegroups.com>
Mumia W. (reading news) wrote:
> On 09/26/2006 12:28 PM, robb@acm.org wrote:
> > DB<1> print "hello\n";
> > DB<2> use lib '/home/web/lib/perl';
> > DB<3> use Trillium::Info;
> > DB<4> my $info = Trillium::Info->new();
>
> I've found "my" to be tricky in the perl debugger. The variable is
> probably trapped in an invisible, inaccessible block.
perldebug says:
Any command not recognized by the debugger is directly executed
(eval'd) as Perl code in the current package.
So when using the debugger interactively, lexically scoped variables do
not propogate across multiple statements.
> > DB<5> $info;
>
> By itself, "$info;" is a useless statement; you probably meant "print
> $info;"
Given that $info is an instance of Trillium::Info, I'd probably use 'x
$info' to recursively pretty-print its values. 'print' only outputs
the package name and its memory address.
> > DB<7> print $info;
> Without warnings enabled, attempts to print undefined values display
> nothing.
Strangely, I only receive a warning when turning on warnings via
'-wde42':
X:\S60>perl -de42
Default die handler restored.
Loading DB routines from perl5db.pl version 1.07
Editor support available.
Enter h or `h h' for help, or `perldoc perldebug' for more help.
main::(-e:1): 42
DB<1> use warnings;
DB<2> print $e
DB<3>
Bradley
------------------------------
Date: Tue, 26 Sep 2006 14:05:43 -0400
From: Michael Goerz <news12@8439.e4ward.com>
Subject: Re: both 1 and not-1?
Message-Id: <4nt8fcFc25jhU1@uni-berlin.de>
Gary E. Ansok wrote:
> I think the problem is that if any pattern matches, you are leaving
> the loop early. So, the next time you enter the function, the
> each() will continue the earlier iteration rather than starting over.
Yes! Fixing this solved the problem. Thanks a lot -- I wouldn't have
thought about this.
Thanks,
Michael
------------------------------
Date: 26 Sep 2006 12:49:37 -0700
From: cartercc@gmail.com
Subject: Re: Ftp via Perl cron job
Message-Id: <1159300177.694733.181840@b28g2000cwb.googlegroups.com>
Bill H wrote:
> I have a Perl program that processes a file, saves the results in a new
> file and then need to ftp that file to a different server, can anyone
> point me to some documentation or a module / source on how I can
> accomplish the ftp portion via Perl?
#!/usr/bin/perl
use strict;
use Net::FTP;
# Step 1 - set variables to your specifications
my ($server, $username, $password, $directory, $holdfile);
# Step 2 -- FTP to server and download the holdfile
my $ftp = Net::FTP->new($server, Debug => 0) or die "Cannot connect,
$@";
$ftp->login($username, $password) or die "Cannot login ", $ftp->
message;
$ftp->cwd($dirctory) or die "Cannot change working directory ",
$ftp->message;
$ftp->ascii;
$ftp->get($holdfile) or die "Cannot get $holdfile ", $ftp->message;
$ftp->quit;
exit();
CC
------------------------------
Date: 26 Sep 2006 11:18:40 -0700
From: "robb@acm.org" <robb@acm.org>
Subject: Re: list vs. array
Message-Id: <1159294719.872833.281920@b28g2000cwb.googlegroups.com>
Ch Lamprecht wrote:
>
> The expression (4,5,6) does not produce a list out of its own...
>
I don't understand the meaning of your post - I understand the facts,
but what conclusion are you implying? Is Tad's post incorrect? A list
is not created and returned by the function?
------------------------------
Date: Tue, 26 Sep 2006 20:25:07 +0200
From: Ch Lamprecht <christoph.lamprecht.no.spam@web.de>
Subject: Re: list vs. array
Message-Id: <efbra2$prf$2@online.de>
robb@acm.org schrieb:
> Ch Lamprecht wrote:
>
>>The expression (4,5,6) does not produce a list out of its own...
>>
>
>
> I don't understand the meaning of your post - I understand the facts,
> but what conclusion are you implying? Is Tad's post incorrect? A list
> is not created and returned by the function?
No.
>
Sorry, if that was not clear ;)
All I meant was, that his example is not about the list vs. array issue. It's
about evaluation of array and comma-operator in scalar context.
Christoph
--
perl -e "print scalar reverse q/ed.enilno@ergn.l.hc/"
------------------------------
Date: Tue, 26 Sep 2006 19:27:09 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: list vs. array
Message-Id: <efbrdt$l1l$1@gemini.csx.cam.ac.uk>
robb@acm.org wrote:
> Ch Lamprecht wrote:
>> The expression (4,5,6) does not produce a list out of its own...
>>
> I don't understand the meaning of your post
And you don't give anyone else much chance either, as you repeatedly cut
too much context when replying. The part you snipped here was in fact
the explanation you are in search of.
> - I understand the facts,
> but what conclusion are you implying? ... A list
> is not created and returned by the function?
Yep. As I learnt myself here only last week, the parentheses in, say,
@this_array = (4, 5, 6);
only fulfill a scoping function (to prevent '=' binding to '4' alone).
It is in fact the @this_array that provides list context on the RHS.
When in scalar context, e.g.,
$this_scalar = (4, 5, 6);
no list is generated at any stage. This is also mentioned in the FAQ
entry you were directed to earlier.
DS
------------------------------
Date: Tue, 26 Sep 2006 18:59:46 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: list vs. array
Message-Id: <slrnehiu53.m83.dha@panix2.panix.com>
On 2006-09-26, David Squire <David.Squire@no.spam.from.here.au> wrote:
> robb@acm.org wrote:
>> Ch Lamprecht wrote:
>>> The expression (4,5,6) does not produce a list out of its own...
>>>
>> I don't understand the meaning of your post
>
> And you don't give anyone else much chance either, as you repeatedly cut
> too much context when replying. The part you snipped here was in fact
> the explanation you are in search of.
>
>
>> - I understand the facts,
>> but what conclusion are you implying? ... A list
>> is not created and returned by the function?
>
> Yep. As I learnt myself here only last week, the parentheses in, say,
>
> @this_array = (4, 5, 6);
>
> only fulfill a scoping function (to prevent '=' binding to '4' alone).
> It is in fact the @this_array that provides list context on the RHS.
> When in scalar context, e.g.,
>
> $this_scalar = (4, 5, 6);
>
> no list is generated at any stage. This is also mentioned in the FAQ
> entry you were directed to earlier.
And, to hopefully clarify through belaboring the point,
@this_array = 4;
doesn't make @this_array any less an array even though it only contains
one value at this point.
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
All hail El Cabeza Del Oro! <http://www.panix.com/~dha/elcabeza.html>
------------------------------
Date: Tue, 26 Sep 2006 14:28:12 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl -pe for blocks of lines instead of single lines
Message-Id: <slrnehivqc.91g.tadmc@magna.augustmail.com>
Markus Dehmann <markus.dehmann@gmail.com> wrote:
> I just found the answer to my own problem.
The perlrun.pod (how to execute the Perl interpreter) manpage
contains the answer to your problem too.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 26 Sep 2006 14:06:43 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Reading from standard input
Message-Id: <g69psdi1ozw.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 26 Sep 2006, harpreet.saluja@gmail.com wrote:
> When I execute the program, I get the correct result from the first
> one and then I type into the stream some data but I don't know how
> to end it. I used the conventional unix "dot-enter" scheme but it
> didn't work. Neither did Ctrl-D. I found some examples which read
> from <STDIN> and worked with a while loop. Can somebody explain me
> why reading from the standard input doesn't work the way I have
> written ? If I am missing the escape character to denote the end of
> stream, please mention it.
You may be on a Windows or DOS system, where Ctrl-Z is the end of file
character, not Ctrl-D as in other systems. Try that.
Ted
------------------------------
Date: Tue, 26 Sep 2006 14:17:06 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: regular expression pb. with tags
Message-Id: <g69lko61oil.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 26 Sep 2006, steeve_dun@softhome.net wrote:
> I want to make some pattern replacement. ie to delete every thing
> that's between 2 tags.
> For example for
>
> 1<tag> 2</tag>3
> x<tag> a<tag> b </tag> c</tag>z
>
> I want to get
>
> 1 3
> x z
>
> But I have a problem with embeded tags.
> I've tried :
> $text =~ s/\<tag\>(.*?)\<\/tag\>//sg;
> but it doens't work for embeded tags. It gives:
> 13
> x c</tag>z
>
> Is there a way to deal with this?
For the first example, you're getting exactly what you wanted ("13").
Look at your input data.
For the second example, your requirements are not good. You don't say
whether you want to replace the outermost tags (in which case a regex
would work) or you want to balance tags. For outermost tag
replacement, use
$text =~ s/\<tag\>(.*)\<\/tag\>//sg;
but note that this will also replace "<tag>a</tag> extra <tag>b</tag>"
with "" and not " extra " as you may expect.
My guess is that you do want to balance tags, and you can use
Text::Balanced for that (especially if your text is not valid XML or
even SGML). If you are doing SGML/HTML/XML/etc. tagged formats then
you should search CPAN for the appropriate parser, as others have
suggested. Look at "perldoc -q html" as well.
Ted
------------------------------
Date: 26 Sep 2006 12:39:58 -0700
From: rsarpi@gmail.com
Subject: remove last 10 lines of all files in a directory
Message-Id: <1159299598.602038.147120@i42g2000cwa.googlegroups.com>
using perl 5.8.8
Objective: remove last 10 lines of *all* files in a directory with no
branches.
Like...xfiles directory has the files xfile1...xfile10. No
subdirectories. I want to remove the last 10 lines of xfile1...xfile10.
How do I do that?
I've tried to put all files in an array but I can't open all files at
one to write to them. And for some reason globbing doesn't do the
trick...like glob ("*.*");
I came up with something to delete the last 10 lines of ONE file only.
(A portion of this code is mine the other is from the perl cookbook)
----------
#!/usr/bin/perl
use warnings;
use strict;
my $path = "C:/path/to/file.txt";
my $addr = "";
#create a sentinel value
my $counter = 1;
#kicks out after it reaches line 10. We just want to delete 10 lines
while ( $counter <= 10 ) {
open( FH, "+< $path" ) or die $!;
while (<FH>) {
$addr = tell(FH) unless eof(FH);
}
truncate( FH, $addr ) or die $!;
#update sentinel value
$counter++;
}
print "all done\n";
------------------------------
Date: Tue, 26 Sep 2006 14:18:19 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Splitting and keeping key/value
Message-Id: <slrnehiv7r.91g.tadmc@magna.augustmail.com>
Sandman <mr@sandman.net> wrote:
> In article <1159273292.373250.51450@b28g2000cwb.googlegroups.com>,
> "Paul Lalli" <mritty@gmail.com> wrote:
>
>> > My indata is a textfile. Sorry.
>>
>> That completely fails to answer the question. How are you storing this
>> data *within your program*.
>
> If you don't want to help, that's fine.
If you don't want to be helped, that's fine too.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 26 Sep 2006 21:40:31 +0200
From: Sandman <mr@sandman.net>
Subject: Re: Splitting and keeping key/value
Message-Id: <mr-34932B.21403126092006@individual.net>
In article <slrnehiv7r.91g.tadmc@magna.augustmail.com>,
Tad McClellan <tadmc@augustmail.com> wrote:
> Sandman <mr@sandman.net> wrote:
> > In article <1159273292.373250.51450@b28g2000cwb.googlegroups.com>,
> > "Paul Lalli" <mritty@gmail.com> wrote:
> >
> >> > My indata is a textfile. Sorry.
> >>
> >> That completely fails to answer the question. How are you storing this
> >> data *within your program*.
> >
> > If you don't want to help, that's fine.
>
>
> If you don't want to be helped, that's fine too.
Indeed.
--
Sandman[.net]
------------------------------
Date: Tue, 26 Sep 2006 21:41:50 +0200
From: Sandman <mr@sandman.net>
Subject: Re: Splitting and keeping key/value
Message-Id: <mr-EFA2EB.21415026092006@individual.net>
In article <4nt2l4Fc3du5U1@news.dfncis.de>,
anno4000@radom.zrz.tu-berlin.de wrote:
> > In programming, "modular" really hasn't got a strict definition.
>
> If that is what you think then don't use the term. It can only
> add to the confusion.
>
> > I
> > used it to mean that I could add and subtract dependencies in the
> > script at will, without having to change the code.
>
> So you expect us to divine what meaning you have assigned to the
> term for the moment? Great attempt at communication!
I keep getting reminded of what a bunch of idiots this group harbors
when I spend too much time in groups where people help each other out.
*plonk*
--
Sandman[.net]
------------------------------
Date: 26 Sep 2006 14:34:23 -0700
From: "Pam" <pamelapdh@aol.com>
Subject: Spreadsheet::ParseExcel on Windows with out Win32::OLE
Message-Id: <1159306463.361524.11200@d34g2000cwd.googlegroups.com>
Hello:
I was wondering if anyone knew if it was possible to Parse a file in
the Windows
enviroment without using the Win32::OLE? Most of the sample code I see
is either
writen for UNIX/Linux or Win32:OLE. Currently I have a Perl script
running on Unix
on a cron job that works fine and I wrote it in the Windows enviroment
but used the
Spreadsheet:WriteExcel module and other modules which also works in the
UNIX enviroment. Now I am trying to add more code that will parse the
file for a value. But I am having the hardest time I work in the
Windows enviroment and the code is put on UNIX by another group so
right now I don't have access to UNIX so my code must be written in
Windows. Since previous code was writen using Spreadsheet::WriteExcel,
OLE dosen't seem to work with existing code because one writes to a
sheet and Win32::OLE uses Workbook at least that is my conclusion from
all of my efforts in trying to get my code working. I am trying to
parse an existing spreadsheet with
$oBook = Spreadsheet::ParseExcel::Workbook->Parse($original_file)
Am I correct in my conclusions? If anyone can answer this I would
greatly appreciate it.
Pam
------------------------------
Date: Mon, 25 Sep 2006 22:01:05 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Spreadsheet::WriteExcel & worksheet->write
Message-Id: <hlslu3-ocn.ln1@osiris.mauzo.dyndns.org>
Quoth "Paul Lalli" <mritty@gmail.com>:
>
> chop() is almost entirely a holdover from Perl 4. The new standard
> idiom is chomp(). (What would happen if your text file happened to not
> end with a newline?)
More importantly, what would happen if you were on win32, or doing
socket programming, and your eol sequence was "\r\n"?
Ben
--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
benmorrow@tiscali.co.uk Groucho Marx
------------------------------
Date: 26 Sep 2006 13:34:07 -0700
From: "arod" <ajrodriguez@gmail.com>
Subject: Strange output problem
Message-Id: <1159302847.115398.95940@i3g2000cwc.googlegroups.com>
I'm trying to output some data into an html table with this code:
print "\n";
for my $array ( @sorted ) {
print "<tr>";
for my $element ( @$array ) {
print "<td>" . $element . "</td>";
}
print "</tr>";
print "\n";
}
However after successfully outputting several rows it sometimes
randomly throws in a row like this:
<tr><td>CY</td><td>2.4321</td><td>16.79</td><td!>+0.04</td></tr>
where one of the <td> tags is instead <td!> which is clearly wrong.
Any idea?
------------------------------
Date: 26 Sep 2006 13:48:29 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: Strange output problem
Message-Id: <1159303709.598936.230430@i42g2000cwa.googlegroups.com>
arod wrote:
> I'm trying to output some data into an html table with this code:
>
> print "\n";
> for my $array ( @sorted ) {
> print "<tr>";
> for my $element ( @$array ) {
> print "<td>" . $element . "</td>";
> However after successfully outputting several rows it sometimes
> randomly throws in a row like this:
>
> <tr><td>CY</td><td>2.4321</td><td>16.79</td><td!>+0.04</td></tr>
> where one of the <td> tags is instead <td!> which is clearly wrong.
>
Always start with the obvious. If that is your actual code, then are
you sure that $element isn't "16.79</td><td!>+0.04"? If you're parsing
this data out from some other html than it's entirely possible whatever
cleanup you're doing on it didn't remove the invalid tag.
Matt
------------------------------
Date: 26 Sep 2006 13:51:11 -0700
From: usenet@DavidFilmer.com
Subject: Re: Strange output problem
Message-Id: <1159303871.717925.200950@i3g2000cwc.googlegroups.com>
arod wrote:
> where one of the <td> tags is instead <td!> which is clearly wrong.
Show us what the input line looks like (from the array) that produces
that output.
--
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 26 Sep 2006 13:57:07 -0700
From: "arod" <ajrodriguez@gmail.com>
Subject: Re: Strange output problem
Message-Id: <1159304227.257992.280010@i42g2000cwa.googlegroups.com>
OK yeah it actually was the input that was messed. Thanks.
usenet@DavidFilmer.com wrote:
> arod wrote:
> > where one of the <td> tags is instead <td!> which is clearly wrong.
>
> Show us what the input line looks like (from the array) that produces
> that output.
>
> --
> David Filmer (http://DavidFilmer.com)
------------------------------
Date: 26 Sep 2006 13:58:40 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Strange output problem
Message-Id: <1159304320.256870.180400@m7g2000cwm.googlegroups.com>
arod wrote:
> I'm trying to output some data into an html table with this code:
>
> print "\n";
> for my $array ( @sorted ) {
> print "<tr>";
> for my $element ( @$array ) {
> print "<td>" . $element . "</td>";
> }
> print "</tr>";
> print "\n";
> }
>
> However after successfully outputting several rows it sometimes
> randomly throws in a row like this:
>
> <tr><td>CY</td><td>2.4321</td><td>16.79</td><td!>+0.04</td></tr>
> where one of the <td> tags is instead <td!> which is clearly wrong.
>
> Any idea?
Perl is an interesting language. Once the interpreter went self aware
(August 2006) it started just trying to mess with programmers. I've
had so many random exclamation points inserted that I think I'm going
to switch to Ruby.
-jp
------------------------------
Date: Tue, 26 Sep 2006 23:17:39 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Strange output problem
Message-Id: <slrnehj67j.h6p.hjp-usenet2@yoyo.hjp.at>
On 2006-09-26 20:34, arod <ajrodriguez@gmail.com> wrote:
>
> I'm trying to output some data into an html table with this code:
>
> print "\n";
> for my $array ( @sorted ) {
> print "<tr>";
> for my $element ( @$array ) {
> print "<td>" . $element . "</td>";
> }
> print "</tr>";
> print "\n";
> }
>
> However after successfully outputting several rows it sometimes
> randomly throws in a row like this:
>
><tr><td>CY</td><td>2.4321</td><td>16.79</td><td!>+0.04</td></tr>
> where one of the <td> tags is instead <td!> which is clearly wrong.
It is also clearly impossible unless the "<td!>" is included in the
data. For example, if
@sorted = (
[ 'CY', 2.4321, '16.79</td><td!>+0.04' ],
);
your code will print the line above.
> Any idea?
First, wenn producing HTML, always escape any data. Instead of
print "<td>" . $element . "</td>";
use
print "<td>" . html_escape($element) . "</td>";
...
sub html_escape {
my $s = @_;
$s =~ s/&/&/;
$s =~ s/</</;
$s =~ s/>/>/; # only for symmetry
$s =~ s/"/&dquot;/; # only needed in attributes
$s =~ s/'/'/; # only needed in attributes
return $s;
}
For the same data in @sorted this would produce:
<tr><td>CY</td><td>2.4321</td><td>16.79</td><td!>+0.04</td></tr>
which makes it easy to spot the error. It also makes
cross-site-scripting attacks a lot harder.
Second, I've found it helpful to insert debug output in comments, for
example, something like:
my $row = 0;
for my $array ( @sorted ) {
print "<!-- row $row -->";
print "<tr>";
my $col = 0;
for my $element ( @$array ) {
print "<!-- col $col: $element -->";
print "<td>" . $element . "</td>";
$col++;
}
print "</tr>";
print "\n";
$row++;
}
makes it easier so see where the error occurs. This helps you to collect
data for a test case.
Finally, try to make the error reproducable. If something happens
"randomly", it often only means that you haven't found the cause yet.
Trim down your code to the minimal code which still exhibits the
behaviour. Don't get your data from sources which may change from one
run of your program to the next (e.g., websites, log files, etc.). Get
it from sample files or enter it directly into your program.
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: Mon, 25 Sep 2006 22:12:50 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: submatch scoping in while
Message-Id: <ibtlu3-ocn.ln1@osiris.mauzo.dyndns.org>
Quoth anno4000@radom.zrz.tu-berlin.de:
>
> while ( $i <= $#x && ! ( ( $capt) = $x[$i] =~ /^(.)b/)) { $i++ }
or
until ( $i > $#x || ($capt) = $x[$i] =~ /^(.)b/ ) { $i++ }
or (cleaner IMHO)
use List::MoreUtils qw/firstidx/;
my $capt;
my $i = firstidx { ($capt) = /^(.)b/ } @x;
Ben
--
"Awww, I'm going to miss her."
"Don't you hate her?"
"Yes, with a fiery vengeance."
[benmorrow@tiscali.co.uk]
------------------------------
Date: Mon, 25 Sep 2006 21:57:24 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Tk-perl2exe FileSelect error
Message-Id: <keslu3-ocn.ln1@osiris.mauzo.dyndns.org>
Quoth "MoshiachNow" <lev.weissman@creo.com>:
>
> > But maybe if it did, then the problem would disappear - ie, in your script:
> >
> > use utf8;
>
> "use utf8" did not work,but "require utf8" did work.
> Thanks
>
> P.S. why does this strange module give so much trouble ?I saw it
> already 20 times or more ,using different modules...
It's part of Perl's internal utf8 implementation. There are lots of
places in perl's guts where perl implicitly does a 'require utf8;' as
part of something else; IMHO perl2exe should know this and always
include it, but there y'go... :)
Ben
--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
benmorrow@tiscali.co.uk Frank Herbert, 'Dune'
------------------------------
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 9772
***************************************