[30683] in Perl-Users-Digest
Perl-Users Digest, Issue: 1928 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 16 21:09:43 2008
Date: Thu, 16 Oct 2008 18:09:12 -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, 16 Oct 2008 Volume: 11 Number: 1928
Today's topics:
"Escape" in perl <bill@ts1000.us>
Re: "Escape" in perl <tim@burlyhost.com>
Re: "Escape" in perl <bill@ts1000.us>
Re: "Escape" in perl <bill@ts1000.us>
Re: "Escape" in perl <tadmc@seesig.invalid>
Re: "Escape" in perl (fidokomik\)
Re: "Escape" in perl sln@netherlands.com
Re: "Escape" in perl <tim@burlyhost.com>
Re: "Escape" in perl sln@netherlands.com
Re: Comparing audio files <christian.ramseyer@gmail.com>
Re: crisis Perl <christian.ramseyer@gmail.com>
Re: crisis Perl <cartercc@gmail.com>
Re: crisis Perl xhoster@gmail.com
Re: crisis Perl <glex_no-spam@qwest-spam-no.invalid>
Re: crisis Perl <tadmc@seesig.invalid>
Re: crisis Perl <RedGrittyBrick@spamweary.invalid>
Re: crisis Perl <jurgenex@hotmail.com>
Re: Perl script: String comparison Ignoring spaces <fawaka@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 16 Oct 2008 15:21:21 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: "Escape" in perl
Message-Id: <027bf17d-3ed7-41fa-89d9-0f15b0ab915a@l76g2000hse.googlegroups.com>
I am using the following code to unescape html text that is coming
from flash:
sub unescape
{
my $text = shift;
$text =~ s/%(..)/pack("c",hex($1))/ge;
return($text);
}
for example it will take this text:
%3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3D
%2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
%2FFONT%3E
and it will convert it to this:
<FONT FACE="timesnewroman" COLOR="#000000" SIZE="20"><P
ALIGN="CENTER">Chapter Title</P></FONT>
What I am trying to figure out is how to go the other way in perl,
convert the html to an escaped format. Any hints, clues, pointers
would be appreciated
Bill H
------------------------------
Date: Thu, 16 Oct 2008 15:45:37 -0700
From: Tim Greer <tim@burlyhost.com>
Subject: Re: "Escape" in perl
Message-Id: <luPJk.3630$KW4.2356@newsfe02.iad>
Bill H wrote:
> I am using the following code to unescape html text that is coming
> from flash:
>
> sub unescape
> {
> my $text = shift;
> $text =~ s/%(..)/pack("c",hex($1))/ge;
> return($text);
> }
>
> for example it will take this text:
>
> %3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3D
> %2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
> %2FFONT%3E
>
> and it will convert it to this:
>
> <FONT FACE="timesnewroman" COLOR="#000000" SIZE="20"><P
> ALIGN="CENTER">Chapter Title</P></FONT>
>
> What I am trying to figure out is how to go the other way in perl,
> convert the html to an escaped format. Any hints, clues, pointers
> would be appreciated
>
> Bill H
Just don't run the input through the unescape sub routine (or have one
that does and another that doesn't (and do whatever you want with the
other))? Or am I misunderstanding your problem/question?
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Thu, 16 Oct 2008 16:05:14 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: "Escape" in perl
Message-Id: <79a5510b-073e-4844-98a6-48823deabbbb@v53g2000hsa.googlegroups.com>
On Oct 16, 6:45=A0pm, Tim Greer <t...@burlyhost.com> wrote:
> Bill H wrote:
> > I am using the following code to unescape html text that is coming
> > from flash:
>
> > sub unescape
> > {
> > =A0 =A0 my $text =3D shift;
> > =A0 =A0 $text =3D~ s/%(..)/pack("c",hex($1))/ge;
> > =A0 =A0 return($text);
> > }
>
> > for example it will take this text:
>
> > %3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3D
> > %2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
> > %2FFONT%3E
>
> > and it will convert it to this:
>
> > <FONT FACE=3D"timesnewroman" COLOR=3D"#000000" SIZE=3D"20"><P
> > ALIGN=3D"CENTER">Chapter Title</P></FONT>
>
> > What I am trying to figure out is how to go the other way in perl,
> > convert the html to an escaped format. Any hints, clues, pointers
> > would be appreciated
>
> > Bill H
>
> Just don't run the input through the unescape sub routine (or have one
> that does and another that doesn't (and do whatever you want with the
> other))? =A0Or am I misunderstanding your problem/question?
> --
> Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
> Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
> and Custom Hosting. =A024/7 support, 30 day guarantee, secure servers.
> Industry's most experienced staff! -- Web Hosting With Muscle!- Hide quot=
ed text -
>
> - Show quoted text -
Tim
Actually the problem is that I want to use perl to make a lot of
default "escaped" html for flash. Up till now I have been just using
flash to do it, but now I have about 60 templates that I need to
create and know there has to be a better way then code actionscript,
run flash, cut / paste escaped stuff into perl code, run perl to
create template, repeat.
I was thinking of using HTML::Entities, but I can't install it on the
server I am using.
Bill H
------------------------------
Date: Thu, 16 Oct 2008 16:10:43 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: "Escape" in perl
Message-Id: <ee806a98-8651-4195-b534-8aeb8a047abf@79g2000hsk.googlegroups.com>
On Oct 16, 7:05=A0pm, Bill H <b...@ts1000.us> wrote:
> On Oct 16, 6:45=A0pm, Tim Greer <t...@burlyhost.com> wrote:
>
>
>
>
>
> > Bill H wrote:
> > > I am using the following code to unescape html text that is coming
> > > from flash:
>
> > > sub unescape
> > > {
> > > =A0 =A0 my $text =3D shift;
> > > =A0 =A0 $text =3D~ s/%(..)/pack("c",hex($1))/ge;
> > > =A0 =A0 return($text);
> > > }
>
> > > for example it will take this text:
>
> > > %3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3=
D
> > > %2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
> > > %2FFONT%3E
>
> > > and it will convert it to this:
>
> > > <FONT FACE=3D"timesnewroman" COLOR=3D"#000000" SIZE=3D"20"><P
> > > ALIGN=3D"CENTER">Chapter Title</P></FONT>
>
> > > What I am trying to figure out is how to go the other way in perl,
> > > convert the html to an escaped format. Any hints, clues, pointers
> > > would be appreciated
>
> > > Bill H
>
> > Just don't run the input through the unescape sub routine (or have one
> > that does and another that doesn't (and do whatever you want with the
> > other))? =A0Or am I misunderstanding your problem/question?
> > --
> > Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
> > Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
> > and Custom Hosting. =A024/7 support, 30 day guarantee, secure servers.
> > Industry's most experienced staff! -- Web Hosting With Muscle!- Hide qu=
oted text -
>
> > - Show quoted text -
>
> Tim
>
> Actually the problem is that I want to use perl to make a lot of
> default "escaped" html for flash. Up till now I have been just using
> flash to do it, but now I have about 60 templates that I need to
> create and know there has to be a better way then code actionscript,
> run flash, cut / paste escaped stuff into perl code, run perl to
> create template, repeat.
>
> I was thinking of using HTML::Entities, but I can't install it on the
> server I am using.
>
> Bill H- Hide quoted text -
>
> - Show quoted text -
The other thought I had, the brute force approach, is to just escape
every character in the string (ie convert each character to a %??). I
suppose I could get a little creative and not touch any numbers or
letters, just everything below ascii 48, above ascii 57 and below
ascii 65. Above ascii 90 and below ascii 97, and above ascii 122.
Wonder if there is a regex that could do this for me?
Bill H
------------------------------
Date: Thu, 16 Oct 2008 18:36:42 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: "Escape" in perl
Message-Id: <slrngffk0a.pti.tadmc@tadmc30.sbcglobal.net>
Bill H <bill@ts1000.us> wrote:
> I was thinking of using HTML::Entities, but I can't install it on the
> server I am using.
Why not?
That is, what problem did you experience when you tried it?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 17 Oct 2008 01:54:23 +0200
From: "Petr Vileta \(fidokomik\)" <stoupa@practisoft.cz>
Subject: Re: "Escape" in perl
Message-Id: <gd8l0s$e76$1@aioe.org>
Bill H wrote:
> I was thinking of using HTML::Entities, but I can't install it on the
> server I am using.
>
HTML::Entities is the right way. When you have not a rights to install it on
server then you can try 2 ways.
1) Ask server admin or tech. support for installing this module
2) download HTML::Entities and HTML::Parser modules, place these modules to some
directory on server and write some like this to your code:
require "/full_path_to_module/HTML/Entities.pm";
require "/full_path_to_module/HTML/Parser.pm";
I think these modules have not other dependencies then Entities to Parser and
Parser to Entities.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail.
Send me your mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
------------------------------
Date: Fri, 17 Oct 2008 00:18:21 GMT
From: sln@netherlands.com
Subject: Re: "Escape" in perl
Message-Id: <vcmff4pb0e43vn514t5t93h00ato7rm4np@4ax.com>
On Thu, 16 Oct 2008 15:21:21 -0700 (PDT), Bill H <bill@ts1000.us> wrote:
>I am using the following code to unescape html text that is coming
>from flash:
>
>sub unescape
>{
> my $text = shift;
> $text =~ s/%(..)/pack("c",hex($1))/ge;
> return($text);
>}
>
>for example it will take this text:
>
>%3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3D
>%2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
>%2FFONT%3E
>
>and it will convert it to this:
>
><FONT FACE="timesnewroman" COLOR="#000000" SIZE="20"><P
>ALIGN="CENTER">Chapter Title</P></FONT>
>
>What I am trying to figure out is how to go the other way in perl,
>convert the html to an escaped format. Any hints, clues, pointers
>would be appreciated
>
>Bill H
This might be one way:
sub escape
{
my $text = shift;
$text =~ s/([<>= "#])/'%'.uc sprintf("%x", ord($1))/ge;
return($text);
}
------------------------------
Date: Thu, 16 Oct 2008 17:44:24 -0700
From: Tim Greer <tim@burlyhost.com>
Subject: Re: "Escape" in perl
Message-Id: <JdRJk.2$V35.0@newsfe14.iad>
Bill H wrote:
> On Oct 16, 6:45Â pm, Tim Greer <t...@burlyhost.com> wrote:
>> Bill H wrote:
>> > I am using the following code to unescape html text that is coming
>> > from flash:
>>
>> > sub unescape
>> > {
>> > my $text = shift;
>> > $text =~ s/%(..)/pack("c",hex($1))/ge;
>> > return($text);
>> > }
>>
>> > for example it will take this text:
>>
>> >
%3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3D
>> >
%2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
>> > %2FFONT%3E
>>
>> > and it will convert it to this:
>>
>> > <FONT FACE="timesnewroman" COLOR="#000000" SIZE="20"><P
>> > ALIGN="CENTER">Chapter Title</P></FONT>
>>
>> > What I am trying to figure out is how to go the other way in perl,
>> > convert the html to an escaped format. Any hints, clues, pointers
>> > would be appreciated
>>
>> > Bill H
>>
>> Just don't run the input through the unescape sub routine (or have
>> one that does and another that doesn't (and do whatever you want with
>> the other))? Â Or am I misunderstanding your problem/question?
>> --
...
>>
>> - Show quoted text -
>
> Tim
>
> Actually the problem is that I want to use perl to make a lot of
> default "escaped" html for flash. Up till now I have been just using
> flash to do it, but now I have about 60 templates that I need to
> create and know there has to be a better way then code actionscript,
> run flash, cut / paste escaped stuff into perl code, run perl to
> create template, repeat.
>
> I was thinking of using HTML::Entities, but I can't install it on the
> server I am using.
>
> Bill H
That should work. Did you try installing the module's files in your own
account's "lib" directory (create one and call the module there if you
need to)?
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Fri, 17 Oct 2008 01:08:14 GMT
From: sln@netherlands.com
Subject: Re: "Escape" in perl
Message-Id: <78pff4ln5tvgtbf9gbf7l1aroro5f9ejr4@4ax.com>
On Fri, 17 Oct 2008 00:18:21 GMT, sln@netherlands.com wrote:
>On Thu, 16 Oct 2008 15:21:21 -0700 (PDT), Bill H <bill@ts1000.us> wrote:
>
>>I am using the following code to unescape html text that is coming
>>from flash:
>>
>>sub unescape
>>{
>> my $text = shift;
>> $text =~ s/%(..)/pack("c",hex($1))/ge;
>> return($text);
>>}
>>
>>for example it will take this text:
>>
>>%3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3D
>>%2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
>>%2FFONT%3E
>>
>>and it will convert it to this:
>>
>><FONT FACE="timesnewroman" COLOR="#000000" SIZE="20"><P
>>ALIGN="CENTER">Chapter Title</P></FONT>
>>
>>What I am trying to figure out is how to go the other way in perl,
>>convert the html to an escaped format. Any hints, clues, pointers
>>would be appreciated
>>
>>Bill H
>
>This might be one way:
>
>sub escape
>{
> my $text = shift;
> $text =~ s/([<>= "#])/'%'.uc sprintf("%x", ord($1))/ge;
> return($text);
>}
>
Yeah, this seems to work. Try all except alpha-numeric and newline.
sln
####################
# Esc_some_html.pl
####################
use strict;
use warnings;
# Try all except alpha-numeric and newline
# --------------------------------------------
my $htmlchrs = '[^\w\n]'; # or '[<>= "#]'
my $str_escaped = '
%3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3D
%2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
%2FFONT%3E';
my $str_normal = unescape( $str_escaped);
print "$str_normal\n\n";
print escape( $str_normal)."\n";
sub unescape
{
my $text = shift;
$text =~ s/%(..)/pack("c",hex($1))/ge;
return($text);
}
sub escape
{
my $text = shift;
$text =~ s/($htmlchrs)/'%'.uc sprintf("%02x", ord($1))/ge;
return($text);
}
__END__
output:
<FONT FACE="timesnewroman" COLOR="#000000" SIZE=
"20"><P ALIGN="CENTER">Chapter Title</P><
/FONT>
%3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22%23000000%22%20SIZE%3D
%2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
%2FFONT%3E
------------------------------
Date: Thu, 16 Oct 2008 13:56:43 -0700 (PDT)
From: rc <christian.ramseyer@gmail.com>
Subject: Re: Comparing audio files
Message-Id: <0bd22374-34b4-45e3-80c9-d579e1e71c6c@k30g2000hse.googlegroups.com>
On Oct 8, 4:39=A0pm, kieran <kieranoc...@gmail.com> wrote:
> Hello,
> I am trying to compare two similar audio files (WAV). From what i have
> read i need to sample both audio files at certain frequencies and run
> these through a FFT and then compare the results. Can anyone advise me
> if this is the correct approach and also describe the steps i need to
> take to get to the stage where I can compare the files.
While this can certainly be done in Perl, a nice environment for
prototyping this kind of applications is GNU Octave or Matlab (given
you are rich or a student). Reading some files from wav, down/
upsampling them, applying filters and perform an fft is just a few
lines of code in both of these tools.
Once you have a working solution, you can still collect all modules
you need to do it in Perl from CPAN or just continue to use Octave via
Inline::Octave.
Now for what to do exactly, this heavily depends on what your input
and your goals are. To get help with this, maybe asking in a group
about audio processing or algorithms would be better.
Good luck
Christian
--
rc at networkz dot ch
------------------------------
Date: Thu, 16 Oct 2008 13:45:03 -0700 (PDT)
From: rc <christian.ramseyer@gmail.com>
Subject: Re: crisis Perl
Message-Id: <22a97f1b-72c9-49e1-855b-6ac165140605@m74g2000hsh.googlegroups.com>
On Oct 16, 7:14=A0pm, cartercc <carte...@gmail.com> wrote:.
>
> A story: We generate several thousand contracts five times a year,
> using a script I wrote. I got a panic call a couple of hours ago
> because the data file had the contract amounts all as zeros. So I
> started at the bottom of the stack, checking the inputs of the
> functions. Yep. All zeros. Worked my way up the stack to the very top.
> Zeros all the way up. Then, I looked at the input file and wouldn't
> you know it -- the script expects an eleven column input file but the
> actual input file contained ten columns. The reason we were getting
> zeros was that the relevant column had been shifted one to the left.
> Once we revised the input file to the correct format, all was fine.
> Yeah, this is a routine event in the World of Work, but it's kind of
> interesting that we get to deal with people issues as well as logical
> and language issues, "If you would match the input file to the
> documentation you would have seen that you were using the wrong input
> file, and saved both yourself and me a panic attack and a wasted
> morning."
>
This is a nice example to emphasize the "write good code in the first
place" point.
Your code probably looked something like this:
while(<STDIN>){
my @line =3D split("/;/");
generate_contract($line[0], $line[3], $line[9]);
}
By only investing 15 seconds more to write e.g.
while(<STDIN>){
my @line =3D split("/;/");
die("Invalid input line, columns !=3D 10") unless $#line =3D=3D 9;
generate_contract($line[0], $line[3], $line[9]);
}
you would immediately have seen what the problem is and spared
yourself from a panic attack. Then, you would have been able to spend
the morning doing something fun, e.g. replacing die() with a call to
logging framework that notifies you by email if an error happens.
Christian
--
rc at networkz dot ch
------------------------------
Date: Thu, 16 Oct 2008 14:14:19 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: crisis Perl
Message-Id: <9435fc7f-4635-40e7-9a6b-abd354432922@v15g2000hsa.googlegroups.com>
On Oct 16, 4:45=A0pm, rc <christian.ramse...@gmail.com> wrote:
> This is a nice example to emphasize the "write good code in the first
> place" point.
> Your code probably looked something like this:
>
> while(<STDIN>){
> =A0 =A0 my @line =A0=3D split("/;/");
> =A0 =A0 generate_contract($line[0], $line[3], $line[9]);
>
> }
Very close, except that multiple columns need massaging, and the logic
to calculate the contract amounts is over 500 LOC.
> By only investing 15 seconds more to write e.g.
>
> while(<STDIN>){
> =A0 =A0 my @line =A0=3D split("/;/");
> =A0 =A0 die("Invalid input line, columns !=3D 10") unless $#line =3D=3D 9=
;
> =A0 =A0 generate_contract($line[0], $line[3], $line[9]);
>
> }
Absolutely, except in this case I wrote both the Perl script and the
query code, and had the confidence that the query code was rock solid.
Which it was, but the user had inadvertently used a previous query
script. This is why I started out at the bottom -- I felt that the
database file could not be corrupted. I was wrong. :-(
> you would immediately have seen what the problem is and spared
> yourself from a panic attack. Then, you would have been able to spend
> the morning doing something fun, e.g. replacing die() with a call to
> logging framework that notifies you by email if an error happens.
Which I'm not going to do, mostly because I've used that technique a
lot in the past, and the first thing I do in the morning delete
emails. The SOP here is to generate successful emails because if
somethings happens to the Windows server (most of the automated stuff
runs on Windows) nothing will happen, and the people I work for want
to be notified of success so that if they don't get an email they will
worry.
Next time, I'll do it myself. Take five minutes, maybe, and I'll be
done with it.
CC
------------------------------
Date: 16 Oct 2008 21:17:13 GMT
From: xhoster@gmail.com
Subject: Re: crisis Perl
Message-Id: <20081016171554.567$xd@newsreader.com>
rc <christian.ramseyer@gmail.com> wrote:
> On Oct 16, 7:14=A0pm, cartercc <carte...@gmail.com> wrote:.
> >
> > A story: We generate several thousand contracts five times a year,
> > using a script I wrote. I got a panic call a couple of hours ago
> > because the data file had the contract amounts all as zeros. So I
> > started at the bottom of the stack, checking the inputs of the
> > functions. Yep. All zeros. Worked my way up the stack to the very top.
> > Zeros all the way up. Then, I looked at the input file and wouldn't
> > you know it -- the script expects an eleven column input file but the
> > actual input file contained ten columns. The reason we were getting
> > zeros was that the relevant column had been shifted one to the left.
> > Once we revised the input file to the correct format, all was fine.
> > Yeah, this is a routine event in the World of Work, but it's kind of
> > interesting that we get to deal with people issues as well as logical
> > and language issues, "If you would match the input file to the
> > documentation you would have seen that you were using the wrong input
> > file, and saved both yourself and me a panic attack and a wasted
> > morning."
> >
>
> This is a nice example to emphasize the "write good code in the first
> place" point.
> Your code probably looked something like this:
>
> while(<STDIN>){
> my @line =3D split("/;/");
> generate_contract($line[0], $line[3], $line[9]);
> }
>
> By only investing 15 seconds more to write e.g.
>
> while(<STDIN>){
> my @line =3D split("/;/");
> die("Invalid input line, columns !=3D 10") unless $#line =3D=3D 9;
> generate_contract($line[0], $line[3], $line[9]);
> }
>
> you would immediately have seen what the problem is and spared
> yourself from a panic attack.
If course you have the benefit of already knowing the unknown-at-the-time
failure mode. What if two columns were swapped rather than one being
missing?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Thu, 16 Oct 2008 16:22:30 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: crisis Perl
Message-Id: <48f7b097$0$89399$815e3792@news.qwest.net>
rc wrote:
[...]
> Your code probably looked something like this:
>
> while(<STDIN>){
> my @line = split("/;/");
[...]
Hopefully it was actually written better than that example. :-)
------------------------------
Date: Thu, 16 Oct 2008 16:13:37 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: crisis Perl
Message-Id: <slrngffbk1.p17.tadmc@tadmc30.sbcglobal.net>
rc <christian.ramseyer@gmail.com> wrote:
> die("Invalid input line, columns != 10") unless $#line == 9;
written more maintainably:
die("Invalid input line, columns != 10") unless @line == 10;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 16 Oct 2008 22:52:29 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: crisis Perl
Message-Id: <gd8d31$hms$1@registered.motzarella.org>
xhoster@gmail.com wrote:
> rc <christian.ramseyer@gmail.com> wrote:
>> On Oct 16, 7:14=A0pm, cartercc <carte...@gmail.com> wrote:.
>>> A story: We generate several thousand contracts five times a year,
>>> using a script I wrote. I got a panic call a couple of hours ago
>>> because the data file had the contract amounts all as zeros. So I
>>> started at the bottom of the stack, checking the inputs of the
>>> functions. Yep. All zeros. Worked my way up the stack to the very top.
>>> Zeros all the way up. Then, I looked at the input file and wouldn't
>>> you know it -- the script expects an eleven column input file but the
>>> actual input file contained ten columns. The reason we were getting
>>> zeros was that the relevant column had been shifted one to the left.
>>> Once we revised the input file to the correct format, all was fine.
>>> Yeah, this is a routine event in the World of Work, but it's kind of
>>> interesting that we get to deal with people issues as well as logical
>>> and language issues, "If you would match the input file to the
>>> documentation you would have seen that you were using the wrong input
>>> file, and saved both yourself and me a panic attack and a wasted
>>> morning."
>>>
>> This is a nice example to emphasize the "write good code in the first
>> place" point.
>> Your code probably looked something like this:
>>
>> while(<STDIN>){
>> my @line =3D split("/;/");
>> generate_contract($line[0], $line[3], $line[9]);
>> }
>>
>> By only investing 15 seconds more to write e.g.
>>
>> while(<STDIN>){
>> my @line =3D split("/;/");
>> die("Invalid input line, columns !=3D 10") unless $#line =3D=3D 9;
>> generate_contract($line[0], $line[3], $line[9]);
>> }
>>
>> you would immediately have seen what the problem is and spared
>> yourself from a panic attack.
>
> If course you have the benefit of already knowing the unknown-at-the-time
> failure mode. What if two columns were swapped rather than one being
> missing?
>
I suspect a regex would often catch a greater proportion of incorrect input?
if (/^(\d{2,5}) ... ([A-Z]+)$/) {
$contract_no=$1; ...
} else {
die "Invalid input line ... ";
}
Everything is easier in hindsight. I do think it valid to ponder
validating input and consider whether that is a habit you wish to
practise such that it becomes almost automatic, even under pressure.
I find the more you practice something when there is no pressure, the
easier it becomes when there *is* pressure.
I'm pretty sure the earlier you catch bad data, the less confusing the
failure mode will be.
Just my ¤0.02 worth, I'm sure I've written *lots* of code with similar
weaknesses (or worse).
--
RGB
------------------------------
Date: Thu, 16 Oct 2008 15:26:54 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: crisis Perl
Message-Id: <dkfff4h7u0sv8jh8ukc45q0eqc84htb3tp@4ax.com>
xhoster@gmail.com wrote:
>If course you have the benefit of already knowing the unknown-at-the-time
>failure mode. What if two columns were swapped rather than one being
>missing?
That's why you use column headers and explicitely check their values
before processing the input file. Now, that still doesn't help if the
user puts the street address in the column with the header "Order
Number", but _that_ mistake is on a level which even a manager can
understand.
However, all that requires some thought which requires some time which
is exactly what you don't have in the typical emergency.
jue
------------------------------
Date: 16 Oct 2008 20:59:09 GMT
From: Leon Timmermans <fawaka@gmail.com>
Subject: Re: Perl script: String comparison Ignoring spaces
Message-Id: <48f7ab1d$0$197$e4fe514c@news.xs4all.nl>
On Wed, 15 Oct 2008 10:46:39 -0500, Ted Zlatanov wrote:
> Why is split in scalar context considered confusing and deprecated? It
> seems like a decent way to count the tokens in a word:
Because it clobbers up @_.
Regards,
Leon Timmermans
------------------------------
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 1928
***************************************