[18495] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 663 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 9 21:07:32 2001

Date: Mon, 9 Apr 2001 18:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <986864713-v10-i663@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 9 Apr 2001     Volume: 10 Number: 663

Today's topics:
    Re: ? The best Perl book ? (Cameron Laird)
    Re: hashes keys case insensitive (Alan Barclay)
    Re: hashes keys case insensitive <gtoomey@usa.net>
    Re: inheritance within one file? <bart.lateur@skynet.be>
        Install of CPAN modules fails during date.t test <ng@conactive.com>
    Re: registration script (Steven Smolinski)
        RE: registration script <jamesfreeman@MailAndNews.com>
        Regular Expression as a variable? bob_waltenspiel@agilent.com
    Re: Regular Expression as a variable? <ocschwar@mit.edu>
    Re: Regular Expression as a variable? (Gwyn Judd)
        save a value of a variable between subroutines run... ( <NO_SPAM_klubbheads@home.com>
    Re: save a value of a variable between subroutines run. <uri@sysarch.com>
    Re: save a value of a variable between subroutines run. <joe+usenet@sunstarsys.com>
        Single character class including \n ??? <Robert.H.Lowe@X-no.spam-X.lawrence.edu>
    Re: Single character class including \n ??? <krahnj@acm.org>
    Re: Single character class including \n ??? <Robert.H.Lowe@X-no.spam-X.lawrence.edu>
    Re: Single character class including \n ??? <juex@deja.com>
    Re: Single character class including \n ??? <elijah@workspot.net>
    Re: So what do YOU use Perl for? <elaine@chaos.wustl.edu>
    Re: So what do YOU use Perl for? <elaine@chaos.wustl.edu>
    Re: There is a problem with this code containing tell a <uri@sysarch.com>
    Re: There is a problem with this code containing tell a (Jay Tilton)
    Re: There is a problem with this code containing tell a (Gwyn Judd)
    Re: unicode, perl and webbrowsers <pilsl_@goldfisch.at>
    Re: unicode, perl and webbrowsers <pilsl_@goldfisch.at>
        VI Code ??? <ridcully@hal.abics.net>
    Re: VI Code ??? <juex@deja.com>
    Re: VI Code ??? <elijah@workspot.net>
    Re: Want Lisp-like state machine impl. <cadet@alum.mit.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 9 Apr 2001 19:19:40 -0500
From: claird@starbase.neosoft.com (Cameron Laird)
Subject: Re: ? The best Perl book ?
Message-Id: <E13348BBC4777F36.BFB15A24E50B9671.6568A0FFF8D61A1E@lp.airnews.net>

In article <9aqh0a$l05$1@plutonium.btinternet.com>,
Jonathan Stowe  <gellyfish@gellyfish.com> wrote:
>In comp.lang.perl.misc Ciaran McCreesh <keesh@users.pleaseremovethisbit.sourceforge.net> wrote:
			.
			.
			.
>If Uri is still maintaining his book list I would suggest you refer to that.
			.
			.
			.
And if Uri's not, I would suggest showing ones appreciation
for all the help here by taking on the chore of maintaining
the book list.
-- 

Cameron Laird <claird@NeoSoft.com>
Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html


------------------------------

Date: 9 Apr 2001 21:22:38 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: hashes keys case insensitive
Message-Id: <986851361.884361@elaine.furryape.com>

In article <3AD2B225@MailAndNews.com>,
Federico Abascal  <fabascal@MailAndNews.com> wrote:
>Hello,
>
>	I think I have read this in some place but I cannot remember where. Is 
>there 
>a way of having a hash with case insensitive keys?

Yes. You want the Tie::CPHash module. If you use this, then 
$tied_hash{'ANY'} eq $tied_hash{'any'}, but if you get the
keys, you'll see whatever you set them with.
>
>	Thanks in advance,
>
>		Federico
>
>------------------------------------------------------------
> Get your FREE web-based e-mail and newsgroup access at:
>                http://MailAndNews.com
>
> Create a new mailbox, or access your existing IMAP4 or
> POP3 mailbox from anywhere with just a web browser.
>------------------------------------------------------------
>




------------------------------

Date: Tue, 10 Apr 2001 10:15:54 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: hashes keys case insensitive
Message-Id: <u4sA6.52$482.275@newsfeeds.bigpond.com>

An alternative is to use the lowercase function ro reference the hash
elements.
e.g. $hash{lc($var)}

gtoomey
----------------
"Alan Barclay" <gorilla@elaine.furryape.com> wrote in message
news:986851361.884361@elaine.furryape.com...
> In article <3AD2B225@MailAndNews.com>,
> Federico Abascal  <fabascal@MailAndNews.com> wrote:
> >Hello,
> >
> > I think I have read this in some place but I cannot remember where. Is
> >there
> >a way of having a hash with case insensitive keys?





------------------------------

Date: Mon, 09 Apr 2001 22:27:25 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: inheritance within one file?
Message-Id: <3qd4dton5nltv5jle6fq090cbso9o2jrtt@4ax.com>

Phil R Lawrence wrote:

>While hacking together a set of 2 modules and a script to test out
>some inheritance issues, I thought, "Why not stick this all into one
>file for convenience?"
>
>However, the following won't work because there is no A.pm module on
>my system.  Is it possible to inherit methods from packages within the
>same script?  I'm guessing not...

Yes.

>package B;
 ...
>use A;

Loose that line.

For a start: you don't need to "use" a module for OO only purposes.
"require" is good enough. Since you're already loading the A package,
there's no need to load it again.

   HTH,
   Bart.


------------------------------

Date: Tue, 10 Apr 2001 00:31:40 +0200
From: Kai Schaetzl <ng@conactive.com>
Subject: Install of CPAN modules fails during date.t test
Message-Id: <VA.00001e6a.024f96de@conactive.com>

All tests using base/date and base/message fail on this machine:

base/date...........time2str failed at base/date.t line 84.
base/date...........dubious                                           
       
        Test returned status 255 (wstat 65280, 0xff00)
DIED. FAILED tests 1-58
        Failed 58/58 tests, 0.00% okay
                                                      
base/message........ok 16/16FAILED test 4                             
       
        Failed 1/16 tests, 93.75% okay

If I force the install the module seems to work fine. What can I do 
about this, by what is it caused? I assume it is caused by an OS 
library and not by the Perl installation itself?

OS is Red Hat 6.1, Perl is 5.6.0 compiled on this machine.

Already posted to the German newsgroup which didn't have an answer 
and found an older posting in the Spanish group which also didn't get 
one. I now hope that this group will be able to help, thanks!

Kai

-- 

Conactive Internet Services, Berlin, Germany



------------------------------

Date: Mon, 09 Apr 2001 22:16:42 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: registration script
Message-Id: <slrn9d4ic2.1ag.sjs@ragnar.stevens.gulch>

Atayarani <amazingkgb@earthlink.net> wrote:
> I am very new to Perl, but hope that I will get some helpful responses. 

To get helpful responses, you must help people to understand the problem.

> I am trying to create a script for my page, in which a user can
> register (for benefits unknown) and all information submitted is sent
> to a specified email address.  I currently am using a script copied
> from a book, for a start.  It did not work, I got an Internal Server
> Error.  The permissions are correct, and the path is correct.  I have
> no idea where it went wrong.

Now, what information in the above paragraph do you think could help
anyone diagnose your problem?  No code, no details, no nothing.
Seriously, though--what sort of mind-reading did you expect?

There is a FAQ in the subject:

    http://www.perl.com/pub/doc/FAQs/cgi/perl-cgi-faq.html

and the unfortunately named checklist:

    http://www.perl.com/pub/doc/FAQs/cgi/idiots-guide.html

General information is all you posted, so general pointers is all you
can really expect.

Steve
-- 
Steven Smolinski => http://www.steven.cx/


------------------------------

Date: Mon, 9 Apr 2001 19:42:25 -0400
From: james freeman <jamesfreeman@MailAndNews.com>
Subject: RE: registration script
Message-Id: <3AD3F8D8@MailAndNews.com>

>===== Original Message From "Atayarani" <amazingkgb@earthlink.net> =====
>I am very new to Perl, but hope that I will get some helpful responses.  I
>am trying to create a script for my page, in which a user can register (for
>benefits unknown) and all information submitted is sent to a specified email
>address.  I currently am using a script copied from a book, for a start.  It
>did not work, I got an Internal Server Error.  The permissions are correct,
>and the path is correct.  I have no idea where it went wrong.
>
>-atayarani
>

Not much hope of anyone else either without more info.

First does the script compile and run ie at the command prompt type

perl myscript.pl

No news is good news, if you get messages then you have basic syntax errors.

James

------------------------------------------------------------
 Get your FREE web-based e-mail and newsgroup access at:
                http://MailAndNews.com

 Create a new mailbox, or access your existing IMAP4 or
 POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------



------------------------------

Date: Mon, 9 Apr 2001 20:52:00 +0000 (UTC)
From: bob_waltenspiel@agilent.com
Subject: Regular Expression as a variable?
Message-Id: <986858520.917565@cswreg.cos.agilent.com>

I'm writing a perl program that reads a data file containing both a
string of data and a regular expression.  My program will report the
match result of the two.  Here's a simplified example of what I want
to do.  This example always returns no match.

#!/usr/bin/perl -w

# Both of these values have been read from a file
$myData = "ABC";
$myExp  = "/^abc/i";

$regexp = $myExp;

print "   regexp: $regexp\n";

if ( $myData =~ $regexp ) {
  print "It's a match\n";
}
else {
  print "No match\n";
}


I can remove the leading and trailing '/' characters from $myExp and
put them in the test expression, but then I lose the modifier.  This
works correctly except there's no way to modify the regular
expression. 

#!/usr/bin/perl -w

# Both of these values have been read from a file
$myData = "ABC";
$myExp  = "^abc";

$regexp = $myExp;

print "   regexp: $regexp\n";

if ( $myData =~ /$regexp/ ) {
  print "It's a match\n";
}
else {
  print "No match\n";
}


I can select the expression and the modifier with simple
backreferencing but I can't use modifier outside the delimiters of the 
regular expression.  This example does not compile.

#!/usr/bin/perl -w

# Both of these values have been read from a file
$myData = "ABC";
$myExp  = "/^abc/i";

$_ = $myExp;
my ($regexp, $modifiers) = /^\/(.+)\/(.*)$/;

print "   regexp: $regexp\n";
print "modifiers: $modifiers\n";

if ( $myData =~ /$regexp/$modifiers ) {
  print "It's a match\n";
}
else {
  print "No match\n";
}

Any suggestions?

-Bob

-- 
 Bob Waltenspiel
 Agilent Technologies          | e-mail: bob_waltenspiel@agilent.com
 Santa Rosa, California  USA   | phone: (707) 577-3091



------------------------------

Date: 09 Apr 2001 19:36:13 -0400
From: Omri Schwarz <ocschwar@mit.edu>
Subject: Re: Regular Expression as a variable?
Message-Id: <octelv1bq8i.fsf@nerd-xing.mit.edu>

bob_waltenspiel@agilent.com writes:
> Any suggestions?

If you really need to be able to change the
regexp options on the fly, do something like this:

if ($regex_i) { 
   if ( $myData =~ /$regexp/i ) {
 ...
} else { 

   if ( $myData =~ /$regexp/i ) {
 ...
}

Perl compiles to a byte code and then runs,
and it will need to know the regex options 
at compile time.

This is good module fodder, actually,
bt I'm not the one to write it.

-- 
Omri Schwarz --- 
Timeless wisdom of biomedical engineering:
"Noise is principally due to the presence of the 
patient." -- R.F. Farr


------------------------------

Date: Tue, 10 Apr 2001 00:48:19 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Regular Expression as a variable?
Message-Id: <nLsA6.2408$ndm.79429926@news.xtra.co.nz>

I was shocked! How could bob_waltenspiel@agilent.com <bob_waltenspiel@agilent.com>
say such a terrible thing:
>I'm writing a perl program that reads a data file containing both a
>string of data and a regular expression.  My program will report the
>match result of the two.  Here's a simplified example of what I want
>to do.  This example always returns no match.

Something like this might do the trick:

#!/usr/bin/perl -w
use strict;

# usage: perl -w re.pl '/^abc/i' 'ABC'

my $re = shift;
my $data = shift;

my $qr = eval 'qr'.$re;
die "$@" if $@;

print "match\n" if $data =~ m/$qr/;

See the documentation:
perldoc -f eval
perldoc perlop

The use of 'eval' has some security implications, so if you don't trust
whoever can supply the data, then do not use this method.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The world began without man, and it will complete itself without him.
		-- Claude Levi-Strauss, "Tristes Tropiques", 1955


------------------------------

Date: Mon, 09 Apr 2001 22:54:34 GMT
From: "Roman Filippov" <NO_SPAM_klubbheads@home.com>
Subject: save a value of a variable between subroutines run... (++)
Message-Id: <K4rA6.189851$A6.42902884@news4.rdc1.on.home.com>

I am not sure if it's possible...

I need to save the value of a localized variable in the function. By
localized I mean - it is not accessable from the rest of the program. It can
be "my" or "local", i don't know... Here is an example and a decription of a
script:

### START OF CODE
# run a subroutine 100 times
for ($i=0;$i<99;$i++) {
  &some_sub( 'filename.txt' );   # in real program the filename is different
from time to time
}

# subroutine - reads a file and does some work with it.
sub some_sub {
  my $filename = $_[0];

  open(FILE,"< $filename") or die $!;
  my @file = <FILE>;
  close(FILE) or die $!;

  # then subrouting works with the file....
}
### END OF CODE

So, the problem is, that I don't want to open and close 100 times, because
it can overload a machine. I want $filename and @file value to be saved
between the runs of the subroutine. At the same time I don't want the
variables to be global, I want them to be local. In this case I could check
if the 'old' $filename matches a new one, that was send as an argument and
if it does match then DO NOT read the file again, if filenames do not match
then read the file.





------------------------------

Date: Mon, 09 Apr 2001 22:59:43 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: save a value of a variable between subroutines run... (++)
Message-Id: <x7bsq5ptls.fsf@home.sysarch.com>

>>>>> "RF" == Roman Filippov <NO_SPAM_klubbheads@home.com> writes:

  RF> I am not sure if it's possible...

it is.

  RF> I need to save the value of a localized variable in the
  RF> function. By localized I mean - it is not accessable from the rest
  RF> of the program. It can be "my" or "local", i don't know... Here is


{
	my $foo ;

	sub bar {

		return ++$foo ;
	}
}

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


------------------------------

Date: 09 Apr 2001 19:30:14 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: save a value of a variable between subroutines run... (++)
Message-Id: <m3zodp8xdl.fsf@mumonkan.sunstarsys.com>

"Roman Filippov" <NO_SPAM_klubbheads@home.com> writes:

> I am not sure if it's possible...
> 
> I need to save the value of a localized variable in the function. By
> localized I mean - it is not accessable from the rest of the program. It can
> be "my" or "local", i don't know... Here is an example and a decription of a
> script:

Sounds like you want to Memoize portions of some_sub.  
Did you know there's a package on CPAN that does that for you?  
Also see 

  http://perl.plover.com/MiniMemoize/

The basic gist is something like this:

  sub some_sub {
    my $filename = shift;
    my $file; # array_ref to avoid spurious copying
    #...
  }

becomes (untested)

  sub some_sub {
    my %cache if 0;         # static variable trick

    my $filename = shift;
    my $file = $cache{$filename} || # orcish maneuver
        do {
            local *FILE;
            open FILE, "< $filename" or die $!;
            $cache{$filename} = [<FILE>];
        };

    ...
  }


HTH
-- 
Joe Schaefer   "The worst thing you can do to a man is to tell him he can have
                                       what he wants."
                                               --Mark Twain


------------------------------

Date: Mon, 09 Apr 2001 16:57:47 -0500
From: Robert Lowe <Robert.H.Lowe@X-no.spam-X.lawrence.edu>
Subject: Single character class including \n ???
Message-Id: <3AD2305B.DFAD7BC@X-no.spam-X.lawrence.edu>

Hi!

Is there a character class that matches *any* character, including
\n ??  When pattern matching in multi-line data (e.g. in paragraph
mode), there are times when I'd like to just grab everything to the 
end.  Any quick and dirty way to do that??  I guess it would easy
if you could nest classes.

TIA,
Robert


------------------------------

Date: Mon, 09 Apr 2001 22:43:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Single character class including \n ???
Message-Id: <3AD23B21.1B3371A1@acm.org>

Robert Lowe wrote:
> 
> Hi!
> 
> Is there a character class that matches *any* character, including
> \n ??

[\x00-\xFF]

> When pattern matching in multi-line data (e.g. in paragraph
> mode), there are times when I'd like to just grab everything to the
> end.  Any quick and dirty way to do that??  I guess it would easy
> if you could nest classes.

Look for the /s modifier in perlre


John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Mon, 09 Apr 2001 17:46:18 -0500
From: Robert Lowe <Robert.H.Lowe@X-no.spam-X.lawrence.edu>
Subject: Re: Single character class including \n ???
Message-Id: <3AD23BBA.C66855F5@X-no.spam-X.lawrence.edu>

Robert Lowe wrote:
> 
> Hi!
> 
> Is there a character class that matches *any* character, including
> \n ??  When pattern matching in multi-line data (e.g. in paragraph
> mode), there are times when I'd like to just grab everything to the
> end.  Any quick and dirty way to do that??  I guess it would easy
> if you could nest classes.

Doh!  Just found the answer!  If you use the /s modifier, the .
will include \n in its capabilities, i.e. .* will grab everything
to the end!

-Robert


------------------------------

Date: Mon, 9 Apr 2001 16:02:11 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Single character class including \n ???
Message-Id: <3ad23f75@news.microsoft.com>

"John W. Krahn" <krahnj@acm.org> wrote in message
news:3AD23B21.1B3371A1@acm.org...
> Robert Lowe wrote:
> > Is there a character class that matches *any* character, including
> > \n ??
>
> [\x00-\xFF]

This will match all byte value all right, but by no means all *characters*.
Hint: Perl is used for more then just primitive ASCII (or even latin-1)
characters.

jue





------------------------------

Date: 9 Apr 2001 23:02:15 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: Single character class including \n ???
Message-Id: <eli$0104091854@qz.little-neck.ny.us>

In comp.lang.perl.misc, John W. Krahn <krahnj@acm.org> wrote:
> Robert Lowe wrote:
> > Is there a character class that matches *any* character, including
> > \n ??

Take any \x character class and include it's opposite:

	[\s\S]	[\w\W]	[\d\D]

> [\x00-\xFF]

Does that work for multibyte characters? 

> > When pattern matching in multi-line data (e.g. in paragraph
> > mode), there are times when I'd like to just grab everything to the
> > end.  Any quick and dirty way to do that??  I guess it would easy
> > if you could nest classes.
> Look for the /s modifier in perlre

And the companion (?s:...)

Elijah
------
facing lots of internationalization issues


------------------------------

Date: Mon, 09 Apr 2001 22:23:53 GMT
From: "Elaine Ashton" <elaine@chaos.wustl.edu>
Subject: Re: So what do YOU use Perl for?
Message-Id: <ZDqA6.8740$cF.187039@news1.nokia.com>

"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn9d07a5.3ud.mgjv@martien.heliotrope.home...
> Maybe you should visit www.cpan.org, and have a look around to see how
> many modules are available, and what sort of problem space they normally
> fall in. You'll notice that the CGI related area is very small. Even the
> Web related area is very small.

True but far and away the most searched for items on search.cpan.org are
DBI, CGI, LWP, MIME::*, HTML::* and XML. While this doesn't
indicate usage it does indate that 80% of the queries are related to
CGI and the web in some form or another. The web related modules
may be small by percentage to the rest of CPAN but they are the
most sought after as Perl is still very closely associated with CGI.

There are close to 2100 modules on CPAN at a size of over 800MB
and 175 mirrors all over the planet. There is something for just about
everyone these days and conveniently located at a mirror near you.

e.




------------------------------

Date: Mon, 09 Apr 2001 22:27:24 GMT
From: "Elaine Ashton" <elaine@chaos.wustl.edu>
Subject: Re: So what do YOU use Perl for?
Message-Id: <gHqA6.8741$cF.187039@news1.nokia.com>

"Jonathan Stowe" <gellyfish@gellyfish.com> wrote in message
news:9apjdh$avb$1@plutonium.btinternet.com...
>
> Ah Hah! I use it to charm the birds from the trees.

Sadly, it doesn't do a thing for my St. Bernard. If Perl came with peanut
butter it
might be more attractive perhaps. :)

e.




------------------------------

Date: Mon, 09 Apr 2001 22:41:08 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: There is a problem with this code containing tell and seek
Message-Id: <x7elv1pugr.fsf@home.sysarch.com>

>>>>> "M" == Milliwave  <milliwave@rfengineering.freeserve.co.uk> writes:

  M> The following code does "not" execute from the for loop downwards, or
  M> atleast
  M> it is not doing what it is supposed to do!
  M> During the "1st while loop" - first pass of the COUNT_FILE
  M> I record the $arraylength, which I feedthrough and count down
  M> within the "for" loop!  The $arraylength is fed through to the
  M> seek function which in turn starts off the 2nd while loop.
  M> But as pointed the code following the for loop does not
  M> execute????? or atleast the $index does not decrement??


  M> #!/apps/perl/bin/perl5.001

phheeww! do i smell old code rotting in the grave? upgrade that pronto. 

and i don't see -w and use strict.

  M> open(COUNT_FILE, "data.txt") or die "cannot find the CIF FILE:\n";

put $! in the die string

  M> open(COUNTOUT, ">testseek.txt");

and why test the first open and not the second?

  M> my @position=();

no need to initialize the array. my'ed arrays start out as ()

  M> while (<COUNT_FILE>)
  M> {
  M> chomp;
  M> $position[$i] = tell COUNT_FILE if ($_ =~ m/^DS1\s(\d*)\s(\d*)\s(\d*);/);

  M> $i++;

you can put that ++ inside the $position[$i].

  M> }
  M> $arraylength = @position;

no need for that.

  M> for ($index =$arraylength ; $index>0; $index--)

	for ($index = @position ; $index > 0 ; $index-- )

and your loop executes for me. 

  M> seek COUNT_FILE, $position[$index], 0;


  M> printf(COUNTOUT "$position[$index]\n");


don't use printf when you mean print. printf is actually rarely used in
perl. much more often you use sprintf and later print it.

  M>  while (<COUNT_FILE>)
  M>  {
  M>  chomp;
  M>   if ($_ =~ /^D1/)

no need for the $_.

  M>   {
  M>   printf(COUNTOUT "$_\n");

print

  M>   exit;
  M>   }

  M>          else
  M>          {
  M>          printf(COUNTOUT "$_\n");

print

i don't see a bug in the loop. but i don't have any input data either

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


------------------------------

Date: Mon, 09 Apr 2001 23:28:26 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: There is a problem with this code containing tell and seek
Message-Id: <3ad24110.30819611@news.erols.com>

On Mon, 9 Apr 2001 22:14:41 +0100, "Milliwave"
<milliwave@rfengineering.freeserve.co.uk> wrote:

Did you have to post this three times within three minutes, each with
a different subject?  Evidently, this is related to a prior thread.
Why not followup within that one?

>The following code does "not" execute from the for loop downwards, or
>atleast
>it is not doing what it is supposed to do!

What exactly is it supposed to do?  It's difficult to evaluate correct
and incorrect behavior in a vacuum like this.  Including some sample
lines from 'data.txt' would have been nice.

>#!/apps/perl/bin/perl5.001
>open(COUNT_FILE, "data.txt") or die "cannot find the CIF FILE:\n";
>open(COUNTOUT, ">testseek.txt");
>
>my @position=();
>while (<COUNT_FILE>)
>{
>chomp;
>$position[$i] = tell COUNT_FILE if ($_ =~ m/^DS1\s(\d*)\s(\d*)\s(\d*);/);
                                                   ^^^^^  ^^^^^  ^^^^^
Why capture things if you're not going to use them?

>$i++;

$i gets incremented for each line read from COUNT_FILE.  If there are
lines that don't match that regex, you'll end up with undefined
elements in @position.  Is that what you want?

>}
>$arraylength = @position;
>for ($index =$arraylength ; $index>0; $index--)

This for loop will not execute if there is nothing in @position.
Check to see if it's being properly populated.

>{
>seek COUNT_FILE, $position[$index], 0;
>printf(COUNTOUT "$position[$index]\n");

Why use 'printf' without a formatting string?

>while (<COUNT_FILE>)
>{
>chomp;
>  if ($_ =~ /^D1/)
>  {
>  printf(COUNTOUT "$_\n");
>  exit;
>  }
>         else
>         {
>         printf(COUNTOUT "$_\n");
>         }
>}
>}
>close COUNT_FILE;
>close COUNTOUT;

In one place you use the regex
  /^DS1 [snip] /
and in another you use
  /^D1/
Without knowing what the program is supposed to be doing, it's
impossible to say if one of those is a typo, but it's a strong
possibility.  If nothing in the data matches the first version, the
@position array will be empty, which would prevent the for loop from
executing.


------------------------------

Date: Tue, 10 Apr 2001 00:02:32 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: There is a problem with this code containing tell and seek
Message-Id: <s4sA6.2393$ndm.152174738@news.xtra.co.nz>

I was shocked! How could Milliwave <milliwave@rfengineering.freeserve.co.uk>
say such a terrible thing:

>$arraylength = @position;
>
>for ($index =$arraylength ; $index>0; $index--)

It's more likely you want to do:

for ($index = $#position; $index >= 0; $index--)

as your code has an off-by-one error.

A more Perlish way might be:

foreach $item (reverse @position)

and just to work with the things themselves, rather than the indices.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Birds are entangled by their feet and men by their tongues.


------------------------------

Date: Tue, 10 Apr 2001 02:11:21 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: unicode, perl and webbrowsers
Message-Id: <MPG.153c6e151d4b97f7989800@news.inode.at>

In article <Pine.LNX.4.30.0104092055460.6935-100000@lxplus003.cern.ch>, 
flavell@mail.cern.ch says...
> On Mon, 9 Apr 2001, peter pilsl wrote:
> 
> 
> As an overview of what you're doing, this seems a reasonable
> description.  But we need more detail of the parts, or a demonstration
> URL where we can look at what's happening, and see if it meets our
> expectations of what should happen at that point.
> 

thnx for your detailed answer which will be of great help to me. I'll 
start studying them immediately and give you a demonstration url here for 
a small discussiontree:

http://www.customers.goldfisch.at/cgi-bin/guestbook.pl?topic=unicode

this also includes examples for multilanguagetext entered with ie55 and 
netscape 4.06

I cant post the whole perl-source here (the whole module has more than 
2500 lines of code), but I do the usual stuff:

print out a form and read the parameters sent back from this form (with 
the CGI-module), saves them to a database (with the DBI,DBD-module) and 
load them from a database and print em out again. 
At the beginning I write 'charset=UTF-8', but I dont do anything special 
unicode-related elsewhere in the script.

And so the created html-code looks like: It dont has the unicode-chars 
written like &#1056 or whatever, but has all the unicode written as some 
special characters that my linuxterminal cant handle.
So I guess there is something wrong, but Netscape and IE can somehow 
handle it.
Is it necessary to convert the stuff returned by the form somehow in this 
&#xxxx-format and how is it done ?

I hope you understand what I'm trying to tell: It seems there are two ways 
to make IE or netscape display the same unicode-character:
* writing the char as &#xxxx
or
* just put this nonprintable char directely in the source which seem to be 
what my script actually does.

oh god, its so confusing ;)

peter

-- 
pilsl@
goldfisch.at


------------------------------

Date: Tue, 10 Apr 2001 02:12:31 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: unicode, perl and webbrowsers
Message-Id: <MPG.153c6e5f8b3c6a27989801@news.inode.at>

In article <0544dts56l35gfacev13iio0e8k88vofvh@4ax.com>, 
bart.lateur@skynet.be says...
> 
> >Netscape shows the entries saved with IE55 fine
> 
> Heh?
> 

take a look at
http://www.customers.goldfisch.at/cgi-bin/guestbook.pl?topic=unicode

which explains this more than 1000 words ...

peter
 

-- 
pilsl@
goldfisch.at


------------------------------

Date: Tue, 10 Apr 2001 00:14:01 +0200
From: Michael Frey <ridcully@hal.abics.net>
Subject: VI Code ???
Message-Id: <9atc0d$qg9$00$1@news.t-online.com>

Hello,

I have question about the handling of vi-code (I think it is vi-code) in 
files like "Welcome to ... - Kernel \r (\l)" (print of /etc/issue). Is 
there a way to handle this or have I to do some grep on a other system. 
file Thank you for your support. 

Michael Frey




------------------------------

Date: Mon, 9 Apr 2001 15:40:39 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: VI Code ???
Message-Id: <3ad23a69@news.microsoft.com>

"Michael Frey" <ridcully@hal.abics.net> wrote in message
news:9atc0d$qg9$00$1@news.t-online.com...
> I have question about the handling of vi-code (I think it is vi-code) in
> files like "Welcome to ... - Kernel \r (\l)" (print of /etc/issue).

What do you mean with "vi-code"? The only vi I know is a popular editor on
Unix systems. It does not have any "code".

> Is
> there a way to handle this or have I to do some grep on a other system.
> file

What do you mean by "to handle"?

jue




------------------------------

Date: 9 Apr 2001 22:51:57 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: VI Code ???
Message-Id: <eli$0104091845@qz.little-neck.ny.us>

In comp.lang.perl.misc, Jürgen Exner <juex@deja.com> wrote:
> "Michael Frey" <ridcully@hal.abics.net> wrote in message
> > I have question about the handling of vi-code (I think it is vi-code) in
> > files like "Welcome to ... - Kernel \r (\l)" (print of /etc/issue).

Somehow that looks like a source file to an /etc/issue where some
program, probably not vi, will subsitute in values. Probably a sh/sed/
or awk script run during system start-up.

> What do you mean with "vi-code"? The only vi I know is a popular editor on
> Unix systems. It does not have any "code".

Says who?

http://www.wi.leidenuniv.nl/~jvhemert/vim/

They sure look like programs to me. And the code used rivals any
obfuscated perl program (very code-like indeed).

Elijah
------
wrote Game of Life set there


------------------------------

Date: Mon, 09 Apr 2001 22:37:00 GMT
From: David Bakhash <cadet@alum.mit.edu>
Subject: Re: Want Lisp-like state machine impl.
Message-Id: <m3n19qgo6s.fsf@alum.mit.edu>

>>>>> "john" == John Joseph Trammell wrote:

 john> Should be pretty easy to implement something that meets your
 john> needs, with the possible exception of specifying types in a
 john> weakly-typed language like Perl.  Any ideas on how you plan to
 john> enforce these types?

yes.  I do believe that Perl will be able to do it, including the
types.  There are only a couple of datatypes (integer, float,
``money'', string (i.e. dont-care).  These will just correspond to
regular expressions.

I'll figure it all out, and when I do, i'll post, and people will see
what I mean.

Anyway, I thought the Lisp stuff was pretty straight-forward.  It's
syntax was:

(defstate <name> (:throws (<list-of-exception-states>)
                  :seeks (<list-of-sought-states>))
  <state-description-string>
  (<list-of-parameter-specifiations>)
  <state-implementation>)

I was defining a ``state'' as something with a fixed number of
(required) parameters, a list of possible next states (some being
exceptional, some being non-exceptional), and an implementation.
That's it.  No magic.

anyway, thanks for th help.  Sorry the post was cryptic.  The purpose
was to eliminate the Perl-iness from the definition, and making the
syntax look as custom as possible for the purposes of implementing a
state machine.

It might be as simple as:

define_state("Q1",
             parameters => ["param-1",
                            "param-2",
                            ["param-3", type => INTEGER]]
             seeks => ["P2", "P3"]
             implementation => sub { ... });

But, of course, that doesn't look as pretty as the Lisp (at least not
to me).  I was counting on a Perl guru to help me make it look nice
(e.g. getting rid of the "'s if possible, perhaps making states
generate subroutines whose names are the names of the states
themselves, etc.

thanks,
dave


------------------------------

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.  

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 663
**************************************


home help back first fref pref prev next nref lref last post