[31656] in Perl-Users-Digest
Perl-Users Digest, Issue: 2919 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 22 16:09:31 2010
Date: Thu, 22 Apr 2010 13:09:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 22 Apr 2010 Volume: 11 Number: 2919
Today's topics:
Re: Extending a class that uses 'fields' <ben@morrow.me.uk>
Re: Extending a class that uses 'fields' <fred@resel.fr>
Re: Extending a class that uses 'fields' <paduille.4061.mumia.w+nospam@earthlink.net>
Re: FAQ 7.26 How can I find out my current or calling p <ben@morrow.me.uk>
Re: Get XML content using XML::Twig <kalyanrajsista@gmail.com>
Re: Get XML content using XML::Twig <kalyanrajsista@gmail.com>
Strange file handling - please help <John.Smith@invalid.com>
Re: Strange file handling - please help <jurgenex@hotmail.com>
Re: Strange file handling - please help <John.Smith@invalid.com>
Re: Strange file handling - please help <uri@StemSystems.com>
Re: Strange file handling - please help <jimsgibson@gmail.com>
Re: Strange file handling - please help <John.Smith@invalid.com>
Re: Strange file handling - please help <uri@StemSystems.com>
Re: Strange file handling - please help <jurgenex@hotmail.com>
Re: Strange file handling - please help <jurgenex@hotmail.com>
Re: Strange file handling - please help <uri@StemSystems.com>
Re: Strange file handling - please help <stevem_clipthis_@clubtrout.com>
trying to match series of tokens to string <avilella@gmail.com>
Re: trying to match series of tokens to string <glex_no-spam@qwest-spam-no.invalid>
Re: trying to match series of tokens to string <dilbert1999@gmail.com>
Re: trying to match series of tokens to string sln@netherlands.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 22 Apr 2010 12:41:58 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Extending a class that uses 'fields'
Message-Id: <69p5a7-mp7.ln1@osiris.mauzo.dyndns.org>
Quoth =?utf-8?B?RnLDqWTDqXJpYw==?= Perrin <fred@resel.fr>:
> Ben Morrow <ben@morrow.me.uk> writes:
>
> Unfortunately, I have to run of RHEL5 with perl 5.8.8. I'm not using
> threads, but I don't want to close that door in the future.
I'm not yet convinced there's *ever* any point using ithreads on a
system with a real fork(2).
> If I
> understand correctly [1], the problem with threads is the refaddr; if
> I use an other index that I know is unique between my objects (in my
> example, it could be the hostname of the remote server), that will
> work, right?
Yes, provided you are *certain* there will never be an overlap.
You will also need a DESTROY method to remove dead entries, which I
forgot to mention before. HUF and OIO both handle this for you.
Ben
------------------------------
Date: Thu, 22 Apr 2010 14:43:57 +0200
From: =?utf-8?B?RnLDqWTDqXJpYw==?= Perrin <fred@resel.fr>
Subject: Re: Extending a class that uses 'fields'
Message-Id: <kggd3xrzmgi.fsf@pc-df-203.priv.enst-bretagne.fr>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth =?utf-8?B?RnLDqWTDqXJpYw==?= Perrin <fred@resel.fr>:
>> If I understand correctly [1], the problem with threads is the
>> refaddr; if I use an other index that I know is unique between my
>> objects (in my example, it could be the hostname of the remote
>> server), that will work, right?
>
> Yes, provided you are *certain* there will never be an overlap.
Yes I am (or rather, the mapping hostname -> my_new_field is well
defined, i.e. a given host will always have the same value for
my_new_field; plus my_new_field is always RO once the object has been
created).
> You will also need a DESTROY method to remove dead entries, which I
> forgot to mention before. HUF and OIO both handle this for you.
If I lay around an handful of extra copies of my datastructures, that
won't be a big deal, given the nature of the program. It would be more
important to remember to close the SSH sessions when I'm done with
them...
Thank you Ben, and thank you Mumia.
--
Fred
------------------------------
Date: Thu, 22 Apr 2010 09:12:19 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: Extending a class that uses 'fields'
Message-Id: <L6idnZ0UnZFN_k3WnZ2dnUVZ_jqdnZ2d@earthlink.com>
On 04/22/2010 04:04 AM, Frédéric Perrin wrote:
> "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net> writes:
>> On 04/21/2010 03:24 AM, Frédéric Perrin wrote:
>>> I want to subclass Net::SSH::Expect, by adding a couple of fields to
>>> it. Using "perldoc fields" as a guide, I did the following:
>>>
>>> ---------------- 8< ----------------
>>> #!/usr/bin/perl
>>> [...]
>> Ben Morrow gave you good advice; however, if inside-out objects are
>> not your thing, Class::Struct makes it easy to create accessor methods
>> which can be inherited into other classes, e.g.:
>
> IIUC [1], I can't use that to extend Net::SSH::Expect if I don't want
> to touch its code. Do I understand correctly ?
> [...]
That's not a problem in practice. The example I posted shows how to do
it. You first create a new base class using Class::Struct, and then
inherit into a new class that you will instantiate objects with. In my
example, NewFileBase was created by Class::Struct, and NewFile was my
intended final class. NewFile inherited from both NewFileBase and
IO::File. I used IO::File in my example because I don't have
Net::SSH::Expect installed.
> [1] <http://search.cpan.org/~jesse/perl-5.12.0/lib/Class/Struct.pm#The_struct()_function>:
>> The class created by struct must not be a subclass of another class
>> other than UNIVERSAL.
>>
>> It can, however, be used as a superclass for other classes. To
>> facilitate this, the generated constructor method uses a two-argument
>> blessing. Furthermore, if the class is hash-based, the key of each
>> element is prefixed with the class name (see Perl Cookbook, Recipe
>> 13.12).
>
See ;-)
------------------------------
Date: Thu, 22 Apr 2010 12:37:56 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 7.26 How can I find out my current or calling package?
Message-Id: <k1p5a7-mp7.ln1@osiris.mauzo.dyndns.org>
Quoth Xho Jingleheimerschmidt <xhoster@gmail.com>:
> Ben Morrow wrote:
> > Quoth PerlFAQ Server <brian@theperlreview.com>:
> >> Most of the time, you shouldn't care what package an object is blessed
> >> into, however, as long as it claims to inherit from that class:
> >>
> >> my $is_right_class = eval { $object->isa( $package ) }; #
> >> true or false
> >
> > Should this answer mention ->DOES at this point?
>
> Where is that documented? I've heard of ->can, but never of ->DOES.
UNIVERSAL.
> Is this a 5.10 thing?
Yes. The idea is that ->DOES asks 'does this object implement this
interface' rather than 'does this object inherit from this class'. I'm
still a little unclear as to why it's *wrong* for ->isa to return true
in that case, especially given that Perl has many different object
systems, not all based on @ISA.
> And shouldn't there be an entry for "can" in perldoc -f? I know it
> isn't strictly a function, but it is closer to one that "use" or "my".
What, just an entry like
can
This is a method. See UNIVERSAL.
? I would be loath to see anything which encouraged people to call
UNIVERSAL::can as a function.
Ben
------------------------------
Date: Thu, 22 Apr 2010 04:28:25 -0700 (PDT)
From: alwaysonnet <kalyanrajsista@gmail.com>
Subject: Re: Get XML content using XML::Twig
Message-Id: <0b802113-06ff-4fe0-958f-23e948ef8a52@x18g2000prk.googlegroups.com>
On Apr 22, 2:34=A0pm, RedGrittyBrick <RedGrittyBr...@spamweary.invalid>
wrote:
> On 22/04/2010 09:24, alwaysonnet wrote:
>
>
>
> > On Apr 22, 12:39 pm, Klaus<klau...@gmail.com> =A0wrote:
>
> >> [XML::Reader examples and discussion omitted]
>
> > My intention is to ~
>
> > - Get each sender and receiver
> > - Get the filetype ( could be InitTAP, FatalRAP etc )
> > - For each of filetype get the TAPSeqNo, NoofCalls etc....
>
> > Basically I want all the information in place for processing the
> > data....
>
> > Also, apart from XML::Twig, is there any module which can handle
> > larger XML files..
>
> Well there's the XML::Reader that Klaus has thoughtfully spent time
> explaining and providing examples for. You didn't say whether there is
> some reason you'd not use that.
>
>
>
> > any help or suggestions are appreciated.
>
> For very arge XML files, the obvious approach to consider is any SAX
> parser. Perl SAX modules I've used before include XML::Parser and XML::SA=
X.
>
> Have you Googled for "Perl SAX" and searched CPAN for SAX?
>
> --
> RGB
I do find XML::Reader quite helpful for me.
I'm comparing my existing code with 40MB of XML file with XML::Simple
and XML::Reader to find out what fits by bill..
------------------------------
Date: Thu, 22 Apr 2010 09:00:18 -0700 (PDT)
From: alwaysonnet <kalyanrajsista@gmail.com>
Subject: Re: Get XML content using XML::Twig
Message-Id: <e45b1999-412c-4d71-9ddd-06bb1f350e5a@g30g2000prf.googlegroups.com>
I'll post my observations in my next post regarding the comparison
times between XML::Simple and XML::Reader modules...
Anyway, it is good to use Storable module to store my datastructure on
the disk or use it directly. I know this is an irrelevant question in
this context, but I'm trying to understand the possible ways for
parsing the XML file..
>>Code i've tried so far...
use strict;
use XML::Simple;
use Storable;
use Data::Dumper;
my ($XML_FILE) = "sample.xml";
my $mldata = XMLin($XML_FILE);
store \$mldata, 'file';
my $hashref = retrieve('file');
#print Dumper($hashref);
------------------------------
Date: Thu, 22 Apr 2010 19:26:23 +0300
From: John <John.Smith@invalid.com>
Subject: Strange file handling - please help
Message-Id: <clt0t5pdv9tck9nq1a9f77sif91bpgir1h@4ax.com>
I have a text file test.txt:
<style>
a {font-size: 12px;font-family: Arial,Helvetica,sans-serif;}
</style>
I want to print the file with the following Perl program:
#!/usr/bin/perl
print "Content-Type: text/html; charset=iso-8859-1\n\n";
print '<html><head>';
print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
print '</head> <BODY>';
open MYFILE,"<test.txt";
$ii=1;
while ($myline=<MYFILE>)
{
print "The value is now $ii <br>"; # I expect to see "1" --> OK!
print "Line : ".$myline." was here<br>"; # I get "Line : was here"
print "Now it is $ii <br>"; # I get "Now it is 3
$ii=$ii+1;
}
close MYFILE;
print "</body> </HTML>";
Somehow the varaiable $ii changes value from 1 to 3 in the middle.
Is this a bug in Perl or what is going on? If I change the contents on the
test.txt to something else the problem goes away.
If the file test.txt has for example:
A quick fox
jumps over a fence
The end
..then no problem is evident..
------------------------------
Date: Thu, 22 Apr 2010 10:03:19 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Strange file handling - please help
Message-Id: <oov0t5d54ebesg1129ieb1m92r57vdoim5@4ax.com>
John <John.Smith@invalid.com> wrote:
>I have a text file test.txt:
><style>
>a {font-size: 12px;font-family: Arial,Helvetica,sans-serif;}
></style>
>
>I want to print the file with the following Perl program:
>
>#!/usr/bin/perl
You are missing
use strict; use warnings;
>print "Content-Type: text/html; charset=iso-8859-1\n\n";
>print '<html><head>';
>print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
>print '</head> <BODY>';
>open MYFILE,"<test.txt";
Nowadays the three-argument form of open using a lexical file handle is
the preferred method of opening a file.
>$ii=1;
If you want the line number then you can use the predefined variable $.
>while ($myline=<MYFILE>)
> {
> print "The value is now $ii <br>"; # I expect to see "1" --> OK!
> print "Line : ".$myline." was here<br>"; # I get "Line : was here"
Cannot reproduce your result (This is perl, v5.10.1 built for
MSWin32-x64-multi-thread). I am getting
Line : <style>
was here<br>
and subsequenlty corresponding results for the other two lines.
> print "Now it is $ii <br>"; # I get "Now it is 3
I am getting
Now it is 1 <br>
during the first iteration and
Now it is 3 <br>
during the last iteration, just as I would have expected.
> $ii=$ii+1;
> }
>close MYFILE;
>print "</body> </HTML>";
jue
------------------------------
Date: Thu, 22 Apr 2010 20:29:47 +0300
From: John <John.Smith@invalid.com>
Subject: Re: Strange file handling - please help
Message-Id: <i811t5d69rnfc0kmuff35b76iirom623uh@4ax.com>
Jürgen Exner <jurgenex@hotmail.com> wrote:
>John <John.Smith@invalid.com> wrote:
>>I have a text file test.txt:
>><style>
>>a {font-size: 12px;font-family: Arial,Helvetica,sans-serif;}
>></style>
>>
>>I want to print the file with the following Perl program:
>>
>>#!/usr/bin/perl
>
>You are missing
> use strict; use warnings;
>
>>print "Content-Type: text/html; charset=iso-8859-1\n\n";
>>print '<html><head>';
>>print '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
>>print '</head> <BODY>';
>>open MYFILE,"<test.txt";
>
>Nowadays the three-argument form of open using a lexical file handle is
>the preferred method of opening a file.
>
>>$ii=1;
>
>If you want the line number then you can use the predefined variable $.
Please explain? I am giving variable $ii the value on one (number 1).
>
>>while ($myline=<MYFILE>)
>> {
>> print "The value is now $ii <br>"; # I expect to see "1" --> OK!
>> print "Line : ".$myline." was here<br>"; # I get "Line : was here"
>
>Cannot reproduce your result (This is perl, v5.10.1 built for
>MSWin32-x64-multi-thread). I am getting
>
>Line : <style>
> was here<br>
>
>and subsequenlty corresponding results for the other two lines.
>
>> print "Now it is $ii <br>"; # I get "Now it is 3
>
>I am getting
>
>Now it is 1 <br>
>
>during the first iteration and
>
>Now it is 3 <br>
>
>during the last iteration, just as I would have expected.
>
>> $ii=$ii+1;
>> }
>>close MYFILE;
>>print "</body> </HTML>";
>
>jue
If $ii has the value of one shouldn't it be 2 after $ii=$ii+1 ?
I've also tried $ii++; and still get 3
I do get correct operaton with a a diffent text file (the quick brown fox ..
version). I checked both text files and they bothe were ANSI with carriage+line
feed endings.
------------------------------
Date: Thu, 22 Apr 2010 13:37:39 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Strange file handling - please help
Message-Id: <87zl0vcrrw.fsf@quad.sysarch.com>
>>>>> "J" == John <John.Smith@invalid.com> writes:
>> John <John.Smith@invalid.com> wrote:
>>> I have a text file test.txt:
>>> <style>
>>> a {font-size: 12px;font-family: Arial,Helvetica,sans-serif;}
>>> </style>
J> I do get correct operaton with a a diffent text file (the quick
J> brown fox .. version). I checked both text files and they bothe
J> were ANSI with carriage+line feed endings.
if that is the case, then i will guess you are looking at the results in
a browser. try running this as a script directly on your box. it should
print as you think it will. and in your browser, look at the page source
after you run it. again, it should be as you think. so this means the
html font stuff you are printing is causing the middle line or something
to not be properly displayed. ALWAYS check your output independently of
what the browser shows you. look at the page source or run it outside a
browser. this is your lesson of the day.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 22 Apr 2010 11:10:07 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Strange file handling - please help
Message-Id: <220420101110078989%jimsgibson@gmail.com>
In article <clt0t5pdv9tck9nq1a9f77sif91bpgir1h@4ax.com>, John
<John.Smith@invalid.com> wrote:
> I have a text file test.txt:
> <style>
> a {font-size: 12px;font-family: Arial,Helvetica,sans-serif;}
> </style>
>
> I want to print the file with the following Perl program:
>
> #!/usr/bin/perl
> print "Content-Type: text/html; charset=iso-8859-1\n\n";
> print '<html><head>';
> print '<meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">';
> print '</head> <BODY>';
> open MYFILE,"<test.txt";
> $ii=1;
> while ($myline=<MYFILE>)
> {
> print "The value is now $ii <br>"; # I expect to see "1" -->
> OK!
> print "Line : ".$myline." was here<br>"; # I get "Line : was here"
> print "Now it is $ii <br>"; # I get "Now it is 3
> $ii=$ii+1;
> }
> close MYFILE;
> print "</body> </HTML>";
>
>
> Somehow the varaiable $ii changes value from 1 to 3 in the middle.
>
> Is this a bug in Perl or what is going on? If I change the contents on the
> test.txt to something else the problem goes away.
>
> If the file test.txt has for example:
> A quick fox
> jumps over a fence
> The end
>
> ..then no problem is evident..
Are you running your program from the command-line or viewing the
output in a browser? If the latter, then the browser may not be showing
characters between the <style> and </style> tags. Try encoding special
characters in your strings so your browser doesn't interpret them. I
don't know the best way to do this, but the HTML::Entities module might
work. Others will be found on CPAN (<http://search.cpan.org>).
--
Jim Gibson
------------------------------
Date: Thu, 22 Apr 2010 21:11:32 +0300
From: John <John.Smith@invalid.com>
Subject: Re: Strange file handling - please help
Message-Id: <2331t59eak124gggr57h9o08q9ku175rij@4ax.com>
I got it figured. My html code was in error and browser threw away output.
------------------------------
Date: Thu, 22 Apr 2010 14:22:27 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Strange file handling - please help
Message-Id: <87hbn3cpp8.fsf@quad.sysarch.com>
>>>>> "J" == John <John.Smith@invalid.com> writes:
J> I got it figured. My html code was in error and browser threw away output.
which is just what i guessed. did you learn the lesson i sent?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 22 Apr 2010 11:36:39 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Strange file handling - please help
Message-Id: <sj51t5tfvijjd1tl04n5otmqjru2utiov2@4ax.com>
John <John.Smith@invalid.com> wrote:
>Jürgen Exner <jurgenex@hotmail.com> wrote:
>>John <John.Smith@invalid.com> wrote:
[...]
>>>$ii=1;
>>
>>If you want the line number then you can use the predefined variable $.
>
>Please explain? I am giving variable $ii the value on one (number 1).
Yes. And in each iteration you are reading one line and incrementing the
number by one. In other words: $ii is a counter for the line number.
$. does that for you automatically already.
>>>while ($myline=<MYFILE>)
[...]
>>> $ii=$ii+1;
jue
------------------------------
Date: Thu, 22 Apr 2010 11:38:05 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Strange file handling - please help
Message-Id: <mr51t558ep9nd2uck3mq4jn4k9lej9nf94@4ax.com>
John <John.Smith@invalid.com> wrote:
>I got it figured. My html code was in error and browser threw away output.
And how would that affect the output of your Perl script?
jue
------------------------------
Date: Thu, 22 Apr 2010 14:46:02 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Strange file handling - please help
Message-Id: <877hnzcolx.fsf@quad.sysarch.com>
>>>>> "JE" == Jürgen Exner <jurgenex@hotmail.com> writes:
JE> John <John.Smith@invalid.com> wrote:
>> I got it figured. My html code was in error and browser threw away output.
JE> And how would that affect the output of your Perl script?
as i said (and guessed correctly) he was only looking at the browser and
not the page source or running the script directly. somehow his wacky
html (not going there) obscured his counter.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 22 Apr 2010 12:36:02 -0700
From: Steve M <stevem_clipthis_@clubtrout.com>
Subject: Re: Strange file handling - please help
Message-Id: <LE1An.172941$9b5.132992@newsfe01.iad>
On 4/22/2010 10:29 AM, John wrote:
> Jürgen Exner<jurgenex@hotmail.com> wrote:
>
>> John<John.Smith@invalid.com> wrote:
>>> I have a text file test.txt:
>>> <style>
>>> a {font-size: 12px;font-family: Arial,Helvetica,sans-serif;}
>>> </style>
>>>
>>> I want to print the file with the following Perl program:
>>>
>>> #!/usr/bin/perl
>>
>> You are missing
>> use strict; use warnings;
>>
>>> print "Content-Type: text/html; charset=iso-8859-1\n\n";
>>> print '<html><head>';
>>> print '<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">';
>>> print '</head> <BODY>';
>>> open MYFILE,"<test.txt";
>>
>> Nowadays the three-argument form of open using a lexical file handle is
>> the preferred method of opening a file.
>>
>>> $ii=1;
>>
>> If you want the line number then you can use the predefined variable $.
>
> Please explain? I am giving variable $ii the value on one (number 1).
>
$. is the INPUT_LINE_NUMBER
>
>>
>>> while ($myline=<MYFILE>)
>>> {
>>> print "The value is now $ii<br>"; # I expect to
see "1" --> OK!
>>> print "Line : ".$myline." was here<br>"; # I get "Line :
was here"
>>
>> Cannot reproduce your result (This is perl, v5.10.1 built for
>> MSWin32-x64-multi-thread). I am getting
>>
>> Line :<style>
>> was here<br>
>>
>> and subsequenlty corresponding results for the other two lines.
>>
>>> print "Now it is $ii<br>"; # I get "Now it is 3
>>
>> I am getting
>>
>> Now it is 1<br>
>>
>> during the first iteration and
>>
>> Now it is 3<br>
>>
>> during the last iteration, just as I would have expected.
>>
>>> $ii=$ii+1;
>>> }
>>> close MYFILE;
>>> print "</body> </HTML>";
>>
>> jue
>
>
> If $ii has the value of one shouldn't it be 2 after $ii=$ii+1 ?
> I've also tried $ii++; and still get 3
>
>
> I do get correct operaton with a a diffent text file (the quick brown
fox ..
> version). I checked both text files and they bothe were ANSI with
carriage+line
> feed endings.
Given the above you are banging on a simple cgi script and viewing the
output in a browser which makes this more of a CGI issue than a Perl
issue, but:
If you view the source you should see the the text you expect to see is
in fact in the source, but given that it is wrapped in the <style> tags
your browser is not displaying it.
The final line with '3' in it shows up because it is outside the closing
</style> tag.
Firebug is (or should be) your friend if you are going to do CGI work.
Get it. Learn it. Love it. Firebug is a CGI/Javascript/AJAX developers
absolute *must have* plugin for FireFox.
Your mention of the cr/lf endings AND the shebang line used suggest you
are pretty new at cross-platform CGI work. Placing the <style> where you
did (inside the <body>) is very suggestive of your relative HTML knowledge.
I'm thinking you might need to brush up on CGI in general, the
differences between *nix files/file systems and lesser operating
systems, and some HTML basics.
Uh... more Perl knowledge is always a good thing too. :-)
I'm not putting you down, we all have to start somewhere, and you *have*
started. Keep plugging away at it, you'll get there.
Here's a little framework that you may find useful in playing with CGI
'stuff'. use #!perl as the shebang for Apache on Windows (typically)
#!/usr/bin/perl
use warnings;
use strict;
# use CGI qw( :cgi );
# use Whatever::Module;
our %V; # useful global
# browser error dump routine (with Caller_error_path, EOF)
# does NOT catch earlier errors (if any) above
# also has a tendency to mess with $@ so using eval
# to trap errors won't do what you think it should
$SIG{'__DIE__'} = $SIG{'__WARN__'} = sub {
my $error = shift;
chomp $error;
$error =~ s/[<&>]/"&#".ord($&).";"/ge; # entity escape;
$error = &Caller_error_path( $error,1,0 );
&print_mime_type;
print "$error\n";
exit 0;
};
# test code goes here
&print_mime_type;
print "Success<br>\n";
# uncomment line below to test error trapping
# print &unknown_subroutine;
###############
## utility subs
# makes it easy to pass specific mime types, stops multiple
# mime types from being printed due to programmer error
# defaults to text/html
sub print_mime_type {
my $type = shift;
$V{'MIME_DONE'} and return;
$type ||= 'text/html';
print "Content-type: $type\n\n";
$V{'MIME_DONE'}++;
}
# constructs trace back to see where you failed and how you got there
# I've had this around for years, no doubt could be cleaned up a bit
sub Caller_error_path {
my $error = shift;
my $Shift = shift;
my $Pop = shift;
$error ||= '';
my $i = 0;
my @call_list = ();
while( my($p, $f, $l, $s, $h, $w ) = caller($i++) ){
my $string = '';
$f and $string .= "$f, ";
$l and $string .= "Line: $l\n";
$s and $s !~ /main::__ANON__/ and $string .= "$s, ";
push @call_list, $string;
}
$Shift and shift @call_list;
$Pop and pop @call_list;
@call_list = reverse @call_list;
my $path = qq~
<form>
<input type="button" Value="Back to Last Page"
onclick="window.history.go(-1)">
</form>
Trace:
~;
$path .= join '', @call_list;
return qq~
<pre>$path\n<span style="color: #FF0000;">$error</span></pre>
~;
1; # not required here, but IS for required library files
If someone else sees a major problem in any of the above, you have my
full attention. :-)
hth,
\s
--
"There is no use in your walking five miles to fish when you can depend
on being just as unsuccessful near home." M. Twain
------------------------------
Date: Thu, 22 Apr 2010 08:00:46 -0700 (PDT)
From: avilella <avilella@gmail.com>
Subject: trying to match series of tokens to string
Message-Id: <7b63f814-c101-4f78-89c0-f6685c951ba7@e7g2000yqf.googlegroups.com>
Hi,
I am looking for a neat way of trying a match of a series of tokens to
another string. E.g.:
$tg1 = "abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc";
$qy1 = "abdca dadcbacb dbdcadbc cbcad dbcadbc"
Because $qy1 contains the characters in $tg1, I want the match to be
true. Whereas:
$tg1 = "abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc";
$qy2 = "abdca dadcbacb aaaaaaaa cbcad dbcadbc"
Now $qy2 has a middle token that is not compatible with $tg, so the
match should be false.
Any suggestions?
Cheers,
Albert.
------------------------------
Date: Thu, 22 Apr 2010 10:41:39 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: trying to match series of tokens to string
Message-Id: <4bd06e34$0$87076$815e3792@news.qwest.net>
avilella wrote:
> Hi,
>
> I am looking for a neat way of trying a match of a series of tokens to
> another string. E.g.:
>
> $tg1 = "abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc";
> $qy1 = "abdca dadcbacb dbdcadbc cbcad dbcadbc"
>
> Because $qy1 contains the characters in $tg1, I want the match to be
> true. Whereas:
>
>
> $tg1 = "abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc";
> $qy2 = "abdca dadcbacb aaaaaaaa cbcad dbcadbc"
>
> Now $qy2 has a middle token that is not compatible with $tg, so the
> match should be false.
>
> Any suggestions?
Use a regular expression, instead of spaces, in $qy1. You could use ".*"
or '.'.
perldoc perlre
perldoc perlop
...
m/PATTERN/msixogc
/PATTERN/msixogc
Searches a string for a pattern match, and in scalar context
...
------------------------------
Date: Thu, 22 Apr 2010 08:51:24 -0700 (PDT)
From: Dilbert <dilbert1999@gmail.com>
Subject: Re: trying to match series of tokens to string
Message-Id: <8cc9fc69-34f6-4766-af63-2c3289b4469c@g23g2000yqn.googlegroups.com>
On 22 avr, 17:00, avilella <avile...@gmail.com> wrote:
> Hi,
>
> I am looking for a neat way of trying a match of a series of tokens to
> another string. E.g.:
>
> $tg1 =3D "abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc";
> $qy1 =3D "abdca =A0 =A0 dadcbacb =A0 =A0 =A0 dbdcadbc =A0 =A0 =A0cbcad =
=A0 =A0 =A0dbcadbc"
>
> Because $qy1 contains the characters in $tg1, I want the match to be
> true. Whereas:
>
> $tg1 =3D "abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc";
> $qy2 =3D "abdca =A0 =A0 dadcbacb =A0 =A0 =A0 aaaaaaaa =A0 =A0 =A0cbcad =
=A0 =A0 =A0dbcadbc"
>
> Now $qy2 has a middle token that is not compatible with $tg, so the
> match should be false.
>
> Any suggestions?
One way to look at this problem is through "Algorithm::Diff" glasses:
use strict;
use warnings;
use Algorithm::Diff qw(sdiff);
my $tg1 =3D "abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc";
my $qy1 =3D "abdca dadcbacb dbdcadbc cbcad dbcadbc";
my $qy2 =3D "abdca dadcbacb aaaaaaaa cbcad dbcadbc";
print "case-a: first string : '$tg1'\n";
print "case-a: second string : '$qy1'\n";
print "case-a: degree of diff : ", degree_of_difference($tg1, $qy1),
"\n";
print "\n";
print "case-b: first string : '$tg1'\n";
print "case-b: second string : '$qy2'\n";
print "case-b: degree of diff : ", degree_of_difference($tg1, $qy2),
"\n";
print "\n";
sub degree_of_difference {
my ($string_x, $string_y) =3D @_;
s{\s}''xmsg for $string_x, $string_y;
# the longest string always comes first:
if (length($string_x) < length($string_y)) {
my $temp =3D $string_x;
$string_x =3D $string_y;
$string_y =3D $temp;
}
my @chain_x =3D split m{}xms, $string_x;
my @chain_y =3D split m{}xms, $string_y;
my @sd =3D sdiff(\@chain_x, \@chain_y);
my $inserts =3D () =3D grep {$_->[0] eq '+'} @sd;
my $deletes =3D () =3D grep {$_->[0] eq '-'} @sd;
my $changes =3D () =3D grep {$_->[0] eq 'c'} @sd;
my $unchanged =3D () =3D grep {$_->[0] eq 'u'} @sd;
$inserts + $changes;
}
The output is:
case-a: first string :
'abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc'
case-a: second string : 'abdca dadcbacb dbdcadbc
cbcad dbcadbc'
case-a: degree of diff : 0
case-b: first string :
'abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc'
case-b: second string : 'abdca dadcbacb aaaaaaaa
cbcad dbcadbc'
case-b: degree of diff : 5
One could argue that the "degree-of-diff" =3D 0 in case-a implies that
the match is true.
With the same argument we find that "degree-of-diff" =3D 5 in case-b
implies that the match is false.
This is only one way to look at the problem, I am sure that there are
many more different ways to look at the problem.
------------------------------
Date: Thu, 22 Apr 2010 08:52:40 -0700
From: sln@netherlands.com
Subject: Re: trying to match series of tokens to string
Message-Id: <s4s0t5pg9hddfq2p41ethol8t9r6eqt9j3@4ax.com>
On Thu, 22 Apr 2010 08:00:46 -0700 (PDT), avilella <avilella@gmail.com> wrote:
>Hi,
>
>I am looking for a neat way of trying a match of a series of tokens to
>another string. E.g.:
>
>$tg1 = "abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc";
>$qy1 = "abdca dadcbacb dbdcadbc cbcad dbcadbc"
>
>Because $qy1 contains the characters in $tg1, I want the match to be
>true. Whereas:
>
>
>$tg1 = "abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc";
>$qy2 = "abdca dadcbacb aaaaaaaa cbcad dbcadbc"
>
>Now $qy2 has a middle token that is not compatible with $tg, so the
>match should be false.
>
>Any suggestions?
>
You could use index if the tokens are constant.
use strict;
use warnings;
my $String = "abdcadbcdadcbacbacbadbdcadbcbdcdcbcadabadbcadbc";
my @Toks = qw(abdca dadcbacb dbdcadbc aaaaaaaa cbcad dbcadbc);
print "\n$String'\n\n";
for my $tok (@Toks) {
my $pos = index $String, $tok;
if ($pos >= 0) {
printf "found (%2d): %s\n", $pos, $tok;
}
else {
printf "not found : %s\n", $tok;
}
}
-sln
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2919
***************************************