[23133] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5354 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 13 21:05:39 2003

Date: Wed, 13 Aug 2003 18:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 13 Aug 2003     Volume: 10 Number: 5354

Today's topics:
    Re: 'make' implemented in Perl (was: Windows user) (Randal L. Schwartz)
    Re: 'make' implemented in Perl <emschwar@pobox.com>
    Re: FrontPage and perl <l0g0m0tion@earthlink.net>
    Re: FrontPage and perl <matthew.garrish@sympatico.ca>
    Re: Help w/ BNB Survey Script <-- (Gunnar Hjalmarsson)
        Perl and recursive copying? <kylewitherspoon@hotmail.com>
    Re: please critique...random link generator <bharn_S_ish@te_P_chnologi_A_st._M_com>
    Re: please critique...random link generator (Randal L. Schwartz)
    Re: populating anonymous arrays inside for loop? (Matt DeFoor)
        Problem using Benchmark (Chris Charley)
    Re: Problem with join and unicode <abuseonly@sgrail.org>
        Simple tr/// script <mikeflan@earthlink.net>
    Re: Simple tr/// script <bwalton@rochester.rr.com>
    Re: Simple tr/// script <l0g0m0tion@earthlink.net>
        Suggestions for further perl reading (Chad)
    Re: Suggestions for further perl reading <uri@stemsystems.com>
    Re: To count a number of lines in C++ or Java or ASCII  <krahnj@acm.org>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 14 Aug 2003 00:08:45 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: 'make' implemented in Perl (was: Windows user)
Message-Id: <d4b789081f41688e851585ce3844903b@free.teranews.com>

>>>>> "Ted" == Ted Zlatanov <tzz@lifelogs.com> writes:

Ted> Actually there's quite a few Perl users, myself included, who think a
Ted> Perl-based make would be much better than relying on the standard
Ted> one that may or may not be installed, available, or functioning.  For
Ted> modules that require C compilation, maybe.  But for pure Perl
Ted> installs?  That's silly, given Perl's power.

Ted> This comes up periodically in Perl discussion lists, and usually the
Ted> answer is "just wait for XYZ, it will do this and more."  I'm not sure
Ted> what the current XYZ is/are, especially regarding why XYZ hasn't yet
Ted> replaced 'make' in CPAN installs and standard Perl usage.  I'm very
Ted> interested in any information, as I have needed tighter integration
Ted> between Perl and 'make' many times.

There already *is* one.

<http://search.cpan.org/author/NI-S/Make-1.00/>

11 April 1999 for the release date.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 13 Aug 2003 16:22:12 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: 'make' implemented in Perl
Message-Id: <eton0edkxkb.fsf@wormtongue.emschwar>

Ted Zlatanov <tzz@lifelogs.com> writes:
> I don't claim that they replace make, I'm just looking for
> information on what's available and why it hasn't replaced make.

I think I explained why make hasn't been replaced.  Hope someone gives
you more alternatives.

>> Make is *hard*,
>
> I don't think it's that hard, as evidenced by the billion make
> reimplementations.

Many of which are broken in some way or other.

> Right, but the question remains, why use it?

Because it's nigh-universal (it's even easy to get on Windows, with
cygwin and other emulation environments), everybody knows it, and the
old adage, "Standard is better than better".

> make may be portable, but that doesn't mean it's available,

Um, where isn't it available?  If you can download a perl module, you
can download a copy of make.

> functional, or accessible.  Furthermore, it's a tool external to Perl
> and my point was that Perl can do the same job.

Except that make already does it, and works fine.

> I'm saying that it
> matters if make is broken or unavailable, for instance on Windows.

Windows has perfectly functional make implementations, at least one of
which is even free.

> Perl can do the job by itself.

Sure, but why reinvent the wheel when there's a perfectly good one
available?

>>> I'm very interested in any information, as I have needed tighter
>>> integration between Perl and 'make' many times.
>> 
>> Such as?  Offhand, I can't think of any time I've needed to
>> integrate Perl and make, other than having the one call the other
>> (or vice versa).
>
> - installing Perl software (the step Makefile.PL -> Makefile could be
>   skipped)

Doesn't require integration.  It's a nice WIBNI, but irrelevant.

> - general dependency-driven actions that use Perl syntax inside the
>   Makefile

What's the advantage over using make syntax?

> - class-based file hierarchies that drive actions when modified

Either I don't understand what this is, or it's trivially implemented
with a make rule that drives those same actions when a .pm is
modified.

> - see the make.pl and Cons pages for more examples

I'll take a look when I get a chance.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Wed, 13 Aug 2003 23:59:48 GMT
From: Christopher Shatto <l0g0m0tion@earthlink.net>
Subject: Re: FrontPage and perl
Message-Id: <UhA_a.11627$M6.992647@newsread1.prod.itd.earthlink.net>

John M. Gamble wrote:

> Are there any known "gotchas" when developing with FrontPage
> and perl?  The ISP provides perl for the server side, and my
> friend's husband is very insistent about using FrontPage for
> designing the website.
> 
> It's not my first choice, but i'm willing to go along.  So...
> 
> Anything i should look out for (excluding the usual MS-bashing)?
> This will be my first foray into FrontPage.
> 
I too am forced to use FrontPage, but I'm desperately trying to replace 
the Extensions "functionality" with Perl.  The only thing I've ever had 
trouble with was using HTML::Template templates.  FrontPage will 
gleefully eliminate your TMPL_ tags without warning if you try to edit 
the files in design view.  Caveat coder.

Actually, with all the problems FP has caused me over the two years I've 
been forced to use it, I've been extremely happy that I had Perl around 
to fix things.

-- Christopher Shatto (Ctb)



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

Date: Wed, 13 Aug 2003 19:50:58 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: FrontPage and perl
Message-Id: <Q9A_a.4589$kp4.760062@news20.bellglobal.com>


"John M. Gamble" <jgamble@ripco.com> wrote in message
news:bhe1rh$k0p$1@e250.ripco.com...
> Are there any known "gotchas" when developing with FrontPage
> and perl?  The ISP provides perl for the server side, and my
> friend's husband is very insistent about using FrontPage for
> designing the website.
>

You've essentially answered your question in that paragraph. Perl is a
server-side scripting language and FrontPage is a wysiwyg html editor. Never
the twain shall meet...

Matt




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

Date: 13 Aug 2003 16:04:26 -0700
From: noreply@gunnar.cc (Gunnar Hjalmarsson)
Subject: Re: Help w/ BNB Survey Script <--
Message-Id: <3fcbff18.0308131504.4b27dded@posting.google.com>

"-|Turbosyde|-" wrote:
> I have the 3.2.2 version of the big nose bird survey script and have a
> problem with cookies. When i allow the survey users to view the
> results, the cookies work and prevent multiple votes. But when i send
> the users to a thank you page (via $JUMP_URL variable), the results
> are logged, but a cookie isn't dropped and the user can vote multiple
> times. Any suggestions, hints?

Browsers can be configured to only accept cookies for the originating
web site. Could it possibly be that you redirect them to some other
site, and that the cookie isn't set for that reason?

That was just a thought. Whatever the explanation is, there is not
much of Perl language in your question, so this group is probably not
the right place to ask, and I doubt that there is any other Usenet
group that provides free support for any CGI script.

Consult the docs. Ask the author. If there is a user forum for the
script you are using, that may be a way to get help.

Good luck.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 14 Aug 2003 00:20:21 GMT
From: Kyle Witherspoon <kylewitherspoon@hotmail.com>
Subject: Perl and recursive copying?
Message-Id: <9BA_a.12846$mB5.905077@twister.southeast.rr.com>

I'm trying to write a web based perl script that writes a self 
replicating website.
For now, I'm trying to have it copy the contents of
/usr/apache/joe
to /usr/apache/bill.

So I need it to programmatically create bill and copy the entire 
contents of joe...I'm using Perl 5.6.0 and none of the File::Copy 
commands are working, or I am doing it wrong..anyone have a bone to 
throw? thanks



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

Date: Wed, 13 Aug 2003 22:36:55 GMT
From: Brian Harnish <bharn_S_ish@te_P_chnologi_A_st._M_com>
Subject: Re: please critique...random link generator
Message-Id: <pan.2003.08.13.22.37.09.305340@te_P_chnologi_A_st._M_com>

On Wed, 13 Aug 2003 17:01:07 -0700, Hudson wrote:

> Hi everyone,
> 
> Here's a subroutine I made using the fisher yates shuffle from the
> perl faq's to print a random number of links to a web page. But I was
> wondering if there is a simplier way to do this. The idea was to have
> non-repeating links, so that's why I choose this method. Thanks in
> advance and all criticism is welcome ;-)

First, try passing variables to your subroutines, it makes debugging
easier. Next, the code did make sense, and after a minute or two of
thought, I came up with a scaled down version. Instead of shuffling the
whole array, I just randomly take out a piece. 

sub print_random_links {
  my ($min, $max, @links) = @_;
  foreach (1..int(rand($max-$min)+$min)) {
    my $link = splice(@links, rand @links, 1);
    my $link_us = $link;
    # ... etc ...
    # print $link;
  }
}

 - Brian


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

Date: Thu, 14 Aug 2003 00:08:45 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: scripts@hudsonscripting.com
Subject: Re: please critique...random link generator
Message-Id: <4d071b569fcdab62cc2abe237d8b7a4f@free.teranews.com>

>>>>> "Hudson" == Hudson  <scripts_you-know-the-drill_@hudsonscripting.com> writes:

Hudson> Hi everyone,
Hudson> Here's a subroutine I made using the fisher yates shuffle from the
Hudson> perl faq's to print a random number of links to a web page. But I was
Hudson> wondering if there is a simplier way to do this. The idea was to have
Hudson> non-repeating links, so that's why I choose this method. Thanks in
Hudson> advance and all criticism is welcome ;-)

Hudson> # --------------------------------------- random links

Hudson> sub print_random_links {
Hudson>     my @links = @keywords;
Hudson>     my $range = $kv{max_links} - $kv{min_links} + 1;

Where does %kv come from?  A global?  And no "# comment" to say that?

Hudson>     my $links_number = int( rand($range)) + $kv{min_links};

Hudson>     fisher_yates_shuffle( \@links );

Hudson>     my $i = 0;
Hudson>     while ($links_number > $i) {
Hudson>         my $link = shift(@links);
Hudson>         my $link_us = $link;
Hudson>         $link_us =~ s/ /_/g;
Hudson>         print " <a href=\"$link_us.html\"><b>$link</b></a> ";
Hudson>         $i++;
Hudson>     }
Hudson> }

Hudson> # --------------------------------------- fisher_yates_shuffle

Hudson> sub fisher_yates_shuffle {
Hudson>     my $deck = shift;  # $deck is a reference to an array
Hudson>     my $i = @$deck;
Hudson>     while ($i--) {
Hudson>         my $j = int rand ($i+1);
Hudson>         @$deck[$i,$j] = @$deck[$j,$i];
Hudson>     }
Hudson> }

I'd factor this more like so:

    print random_links($min, $max, \@links);

    sub random_links {
      my $min = shift;
      my $max = shift;
      my @links = @{+shift}; # must be a copy, because we nibble

      join " ", map {
        my $link = splice @links, rand @links, 1;
        (my $ulink = $link) =~ tr/ /_/;
        "<a href=\"$ulink.html\"><b>$link</b></a>";
      } 1..($min+rand($max-$min));
    }

Untested, except in my head. :)

print "Just another Perl hacker,"
  
-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 13 Aug 2003 17:49:09 -0700
From: mattd@myrealbox.com (Matt DeFoor)
Subject: Re: populating anonymous arrays inside for loop?
Message-Id: <45c889e4.0308131649.608ba1a5@posting.google.com>

> Maybe you don't even need to divide larger array but you're the one who
> decide about your algorithm. ;)

Thanks to all that responded. The solutions (as usual) are excellent.

Unfortunately, based on the speed of database queries that I'm dealing
with, I have to split the larger array into smaller pieces and
spawn/fork several processes to complete the task in a reasonable of
time. It is taking ~27hrs to query and process ~8000 entries from the
DB. Once I get the data, I'm fine. It's the long waits for the DB
queries to return that are killing me. According to the DBA, several
concurrent jobs won't impact performance, so I'm hoping that spawning
several processes to do the work will reduce the amount of time it
takes for all entries to be processed. We'll see.

Thanks again.


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

Date: 13 Aug 2003 17:30:21 -0700
From: charley@pulsenet.com (Chris Charley)
Subject: Problem using Benchmark
Message-Id: <4f7ed6d.0308131630.37814d3e@posting.google.com>

Hi

	I hope someone might point out the obvious error in my benchmark tests.
One test concatenates strings to a string and the other pushes them
onto an array. I tried the debugger (not Benchmark debug, which is
probably the right one, but I don't know how to use), and tried to find the
problem but perl debug won't let me step through the code. It will when
the code is enclosed in sub blocks (and not as strings to be eval'd?).
	The test for forming arrays gave results (below) that were in the
millions (joins 1752848/s) but the test using concatenation gave results in
the thousands (joins    2116/s ). Below are the 2 tests and the resulting
runs for various input parameters. Note that for the 2 different tests, one
was run with Benchmark count 4,000 and the other for count of 4,000,000.
	Thanks in advance for any suggestions or help offered. The order of
command line arguments is: 
	my ($count, $size_list, $string_size, $loops) = @ARGV;

	
Chris

##########################################################################
##########################################################################
#!/usr/bin/perl
# concat5_ar.pl
# Benchmark concat vs. join vs. interpolate when returning arrays
use strict;
use warnings;
use Benchmark qw( timethese cmpthese ) ;

# Enter count, size_list string_size and # loops from the command line
my ($count, $size_list, $string_size, $loops) = @ARGV;
my $string = "." x $string_size;
my @strings = ($string) x $size_list;
    
print "COUNT=$count, LIST_SIZE=$size_list, STRING_SIZE: $string_size, ";
print "LOOPS=$loops\n";

    my $r = cmpthese( $count, {
        joins  => q {
	        my @join;
            push @join, join(' ', @strings) for 1..$loops;
        },
        concat => q {
	        my $concat;
	        my @concat;
	        for (1..$loops) {
	            $concat .= "$_ " for @strings;
	            push @concat, $concat;
            }
        },
        interpolate => q {
	        my @interp;
            push @interp, "@strings" for 1..$loops;
        },
    } );

__END__

C:\perlp\Counting\Benchmark>perl concat5_ar.pl 4000000 3 3 1000
COUNT=4000000, LIST_SIZE=3, STRING_SIZE: 3, LOOPS=1000
                 Rate      concat interpolate       joins
concat      1560671/s          --         -7%        -11%
interpolate 1684211/s          8%          --         -4%
joins       1752848/s         12%          4%          --

C:\perlp\Counting\Benchmark>perl concat5_ar.pl 4000000 100 3 1000
COUNT=4000000, LIST_SIZE=100, STRING_SIZE: 3, LOOPS=1000
                 Rate      concat interpolate       joins
concat      1479837/s          --        -13%        -16%
interpolate 1706485/s         15%          --         -3%
joins       1765225/s         19%          3%          --

C:\perlp\Counting\Benchmark>perl concat5_ar.pl 4000000 10 127 1000
COUNT=4000000, LIST_SIZE=10, STRING_SIZE: 127, LOOPS=1000
                 Rate      concat interpolate       joins
concat      1514578/s          --         -9%        -11%
interpolate 1663202/s         10%          --         -3%
joins       1707213/s         13%          3%          --

C:\perlp\Counting\Benchmark>perl concat5_ar.pl 4000000 40 127 1000
COUNT=4000000, LIST_SIZE=40, STRING_SIZE: 127, LOOPS=1000
                 Rate      concat interpolate       joins
concat      1524390/s          --        -12%        -12%
interpolate 1729356/s         13%          --         -1%
joins       1741402/s         14%          1%          --

C:\perlp\Counting\Benchmark>

#########################################################################
#########################################################################
#!/usr/bin/perl
# concat5.pl
# Benchmark concat vs. join vs. interpolate when returning strings
use strict;
use warnings;
use Benchmark qw( timethese cmpthese ) ;

# Enter count, size_list string_size and # loops from the command line
my ($count, $size_list, $string_size, $loops) = @ARGV;
my $string = "." x $string_size;
my @strings = ($string) x $size_list;
    
print "COUNT=$count, LIST_SIZE=$size_list, STRING_SIZE: $string_size, ";
print "LOOPS=$loops\n";

    my $r = cmpthese( $count, {
        joins  => q {
	        my $join;
            $join .= (join ' ', @strings) . "\n" for 1..1000;
        },
        concat => q {
	        my $concat;
	        for (1..1000) {
	            $concat .= "$_ " for @strings;
	            $concat .= "\n";
            }
        },
        interpolate => q {
	        my $interp;
            $interp .= "@strings\n" for 1..1000;
        },
    } );

__END__

C:\perlp\Counting\Benchmark>perl concat5.pl 4000 3 3 1000
COUNT=4000, LIST_SIZE=3, STRING_SIZE: 3, LOOPS=1000
              Rate      concat interpolate       joins
concat      1422/s          --        -31%        -33%
interpolate 2064/s         45%          --         -3%
joins       2133/s         50%          3%          --

C:\perlp\Counting\Benchmark>perl concat5.pl 4000 100 3 1000
COUNT=4000, LIST_SIZE=100, STRING_SIZE: 3, LOOPS=1000
              Rate      concat interpolate       joins
concat      1406/s          --        -32%        -34%
interpolate 2064/s         47%          --         -2%
joins       2116/s         50%          3%          --

C:\perlp\Counting\Benchmark>perl concat5.pl 4000 10 127 1000
COUNT=4000, LIST_SIZE=10, STRING_SIZE: 127, LOOPS=1000
              Rate      concat interpolate       joins
concat      1414/s          --        -32%        -33%
interpolate 2081/s         47%          --         -1%
joins       2099/s         48%          1%          --

C:\perlp\Counting\Benchmark>perl concat5.pl 4000 40 127 1000
COUNT=4000, LIST_SIZE=40, STRING_SIZE: 127, LOOPS=1000
              Rate      concat interpolate       joins
concat      1306/s          --        -34%        -36%
interpolate 1969/s         51%          --         -4%
joins       2048/s         57%          4%          --

C:\perlp\Counting\Benchmark>


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

Date: Wed, 13 Aug 2003 23:22:55 GMT
From: derek / nul <abuseonly@sgrail.org>
Subject: Re: Problem with join and unicode
Message-Id: <dfhljv0k878pldm2qci5ith1n6j9apl2ls@4ax.com>

Alan,

Thanks so far.

Please keep in mind I am at best a part time programmer, who is nor conversant
with C.  I say this because Perl people seem to quote C examples a lot.

My ugly code is at the bottom,  you will not be able to run it as it relies on a
number of external files, but you can at least use some sensory attributes
instead of ESP :-)


On Wed, 13 Aug 2003 17:45:37 +0200, "Alan J. Flavell" <flavell@mail.cern.ch>
wrote:

>On Wed, Aug 13, derek / nul inscribed on the eternal scroll:
>
>> >"extra" to what?
>>
>> extra to the \r\n's that are already there
>
>Yup, I _said_ you already had some (and it appears you read them in
>binmode(), otherwise there wouldn't have been \r to cope with as
>well).
>
>> >> I don't seen to be able to get rid of them.
>> >
>> >Presumably it's you who's putting them there.
>>
>> it would appear so
>
>Well, you _did_ write this:
>
>||              $linesengwagu = join("\n",@linesengwag1);
>
>What more can I say than "don't do that!"  ;-)

I hear you, but I have tried a number of other ways (other than \n) and they all
fail.

>> >> I am 'join'ing the list so that I can encode it back to unicode.
>
>When you say "back" to unicode - are you implying that it was unicode
>to start with? (presumably utf-16LE also??).  If so, then some of the
>operations you're carrying out on it in binmode() seem wrong to me,
>and unnecessarily confusing.  That's why I recommended you go for
>Perl's native unicode text coding internally.

Ok, I have read through the 2 links below, but all I seem to get is that utf8 is
the default with 5.8.
I am at a loss as to how to implement what you are saying, any pointers to some
code perhaps.

>There was a discussion here fairly recently in which utf-16LE was
>involved, maybe it'll help if you hunt it down.

I went back 3500 messages and found 2 messages that you answered, but I did not
get any usefull information from them.

>perluniintro and perlunicode, in your own documentation set or at
>http://www.perldoc.com/perl5.8.0/pod/perluniintro.html
>http://www.perldoc.com/perl5.8.0/pod/perlunicode.html
>
>> I have tried that
>
>How, exactly?
>
>>  but only cause more errors
>
>Speak out, man!  The PSI::ESP module is on the blink...

I can help you with that :-))

>Are you perhaps looking for join('', @linesengwag1); ?

tried that line, and it too fails after the first line.

below is a cut down version which shows the logic of what I am trying to do.

I have my fireproof suit on :-))) 

###################################################################
# win32 Activestate 5.8.0
# apply physics.pl
# apply physics data from Plainsmans (Bob Boudin) original V4.5 files

# hardwired to default directory for the moment

use strict;
use warnings;
use Encode qw/encode decode/;
use File::Find;
use Data::HexDump;

print "\nMSTS eng and wag physics modifier\n\n";

my $currenttableentry;
my $currentengfile;
my $currentbobsfile;
my $currentlongbobsfile;
my $currentlongengfile;
my $data;
my $databobs;
my $datad;
my $datam;
my $datatable;
my $engdata;
my $engtabledata;
my $filelocation = "c:/program files/microsoft games/train
simulator/trains/dummy";
my $flag1;
my $flag2;
my $flag3;
my $flag4;
my $flag5;
my $flag6;
my $flag7;
my $flag8;
my $i;
my $j;
my $linesengwagu;
my $linesengwagun;
my @entryengtable;
my @linesengwag;
my @linesengwag1;
my @linesengwagu;
my @linesbobs;
my @linesengtable;

# 			format for table file
#			directory,eng file name,bob's file name\n

find(\&readfile, "c:/program files/microsoft games/train simulator/trains/"); #
&readfile is a subroutine

#####################################################################
#
sub readfile {		# need to get eng and wag files
#
#####################################################################

	$datam = $File::Find::name;

	if ($_=~/.bak$/){		# lets not modify all the backup files
		# do nothing
	}	elsif ($_=~/.phy$/) {
		# do nothing
	}	elsif ($_=~/.eng$/) {
		&readfile1
	}	elsif ($_=~/.wag$/) {
		&readfile1
	}	else {
		# do nothing
	}
}

#####################################################################
#
sub readfile1 {
#
#####################################################################

print "start of loop\n\n";

	$currentengfile = $_;	# this is from $File::Find
	$currentlongengfile = "$File::Find::name";
	{ 										# block to localise the local command
	local $/;								# slurp mode to get the whole file
		open ENGWAG, "$File::Find::name", or die "Cannot open $File::Find::name for
read :$!";
		$data = <ENGWAG>;
		close ENGWAG;
	}
	$datad = decode("UTF16", $data);  		# convert from utf16le to ascii
	@linesengwag = split /\r/, $datad;	# \r\n for the unicode file
#####################################################################
	# get engtable.dat   	dash9,dash9,dash9-44w  comma delimited
	{ 										# block to localise the local command
	local $/;								# slurp mode to get the whole file
		open ENGTABLE, "c:/program files/microsoft games/train
simulator/trains/engtable.dat", or die "Cannot open ENGTABLE for read :$!";
		$datatable = <ENGTABLE>;
		close ENGTABLE;
	}
	@linesengtable = split /\n/, $datatable;	# \n for the text file
	# we now have the engtable.dat in memory
#####################################################################
	# work out which of Bob's files to get
	for (@linesengtable) {
		@entryengtable = split /\,/, $_;
		$currenttableentry = $entryengtable[1] . ".eng";
		if ($currentengfile eq $currenttableentry) {
			$currentbobsfile = $entryengtable[2] . ".eng.phy";		# build the file
name
			$currentlongbobsfile = $filelocation;
			$currentlongbobsfile =~ s/dummy/$currentbobsfile/;
			{ 										# block to localise the local command
			local $/;								# slurp mode to get the whole file
				open BOBSENGWAG, "$currentlongbobsfile", or die "Cannot open
$currentlongbobsfile for read :$!";
				$databobs = <BOBSENGWAG>;
				close BOBSENGWAG;
			}
			@linesbobs = split /\r/, $databobs;		# will only split on \r
			# and then save it back to the disk

####	TrainBrakesControllerGraduatedSelfLapLimitedHoldingStart

			$i = -1;
			$j = -1;
			for (@linesengwag) {
				$i++;
				if ($_=~/TrainBrakesControllerGraduatedSelfLapLimitedStart/) {
					for (@linesbobs) {
						$j++;
						if ($_=~/TrainBrakesControllerGraduatedSelfLapLimitedHoldingStart/)
{
							$linesengwag1[$i] = $linesbobs[$j];
						}
					}
				} else {
					$linesengwag1[$i] = $linesengwag[$i];
				}
			}
			@linesengwag = @linesengwag1;

			$linesengwagu = join("\n", @linesengwag1);
			$linesengwagun = encode("UTF16LE", $linesengwagu);

			open ENGWAG, ">$currentlongengfile", or die "Cannot open
$currentlongengfile for write :$!";
			binmode ENGWAG;
			print ENGWAG "\xFF","\xFE",$linesengwagun;
			close ENGWAG;

		}
	}
}			# end of subroutine readfile1



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

Date: Wed, 13 Aug 2003 23:35:21 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Simple tr/// script
Message-Id: <3F3ACBCC.22073479@earthlink.net>


I can't believe I can't figure this out, but I could use some
help here.  I have so many questions about this script,
but I'm going to limit myself to only 3 with this post.

1)  The script runs as written, but gives an error after running
"Use of uninitialized value in transliteration (tr///) . . . at line 12,

<DATA> line 3."  Then there are more errors about
concatenation at line 13 and 16.
Can anybody explain these errors for me.  I can't figure it out.
I thought I was smart, but Perl is proving me wrong.

2) Why won't this script run is I remove the space between the
<DATA> and the line with "Gur ebbgf bs gur snyyra gerr ner
evtug orfvqr gur genvy naq gur gerr unf snyyra gb gur evtug.
Whfg sbyybj gur gerr."?  I have only one new line after the
data line.  I have tried with and without a new line (carriage
return) at the end.

3) Why won't this script process the whole thing if I put a
newline in the middle like so:
Gur ebbgf bs gur snyyra gerr ner evtug orfvqr
gur genvy naq gur gerr unf snyyra gb gur evtug. Whfg sbyybj gur gerr.


I'm guessing these are somewhat related.
__________________________________

use strict;
use warnings;

my $ki;
my @kites;
while (<DATA>) {
    $ki = <DATA>;
    push @kites, $ki;
    }

foreach my $num (@kites) {
    $num =~ tr/a-zA-Z\. /n-za-mN-ZA-M\. /;
    print "$num\n";
    }

print "$kites[0]\n$kites[1]\n";


__DATA__

Gur ebbgf bs gur snyyra gerr ner evtug orfvqr gur genvy naq gur gerr unf
snyyra gb gur evtug. Whfg sbyybj gur gerr.




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

Date: Thu, 14 Aug 2003 00:09:48 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Simple tr/// script
Message-Id: <3F3AD310.90806@rochester.rr.com>

Mike Flannigan wrote:

 ...
> 1)  The script runs as written, but gives an error after running
> "Use of uninitialized value in transliteration (tr///) . . . at line 12,
> <DATA> line 3."  Then there are more errors about
> concatenation at line 13 and 16.
> Can anybody explain these errors for me.  I can't figure it out.
> I thought I was smart, but Perl is proving me wrong.


The root of your problem is your two statements (shown here with 
commentary):

 ...
while (<DATA>) { #read a line from filehandle DATA to default
                  #variable $_ and execute a block of code
                  #if not end of file
      $ki = <DATA>; #read a line of code and put it in scalar $ki
 ...

So you see that you read a line of data, discard it, and read another 
line of data which you proceed to process.  Then you repeat.  So you 
process every second line of data.  This problem also leads to why it is 
doing all the other undesired things you are complaining about.

Recognize that the construct <FILEHANDLE> in scalar context reads a line 
  from FILEHANDLE, whether it is in a while loop or a scalar assignment, 
or anywhere else where a scalar context exists.  In a list context, it 
will read the whole file in one gulp.

The fix?  The second line above should be:

      $ki=$_;


> 
> 2) Why won't this script run is I remove the space between the
> <DATA> and the line with "Gur ebbgf bs gur snyyra gerr ner
> evtug orfvqr gur genvy naq gur gerr unf snyyra gb gur evtug.
> Whfg sbyybj gur gerr."?  I have only one new line after the
> data line.  I have tried with and without a new line (carriage
> return) at the end.

> 
> 3) Why won't this script process the whole thing if I put a
> newline in the middle like so:
> Gur ebbgf bs gur snyyra gerr ner evtug orfvqr
> gur genvy naq gur gerr unf snyyra gb gur evtug. Whfg sbyybj gur gerr.
> 
> 
> I'm guessing these are somewhat related.
> __________________________________
> 
> use strict;
> use warnings;
> 
> my $ki;
> my @kites;
> while (<DATA>) {
>     $ki = <DATA>;
>     push @kites, $ki;
>     }
> 
> foreach my $num (@kites) {
>     $num =~ tr/a-zA-Z\. /n-za-mN-ZA-M\. /;
>     print "$num\n";
>     }
> 
> print "$kites[0]\n$kites[1]\n";
> 
> 
> __DATA__
> 
> Gur ebbgf bs gur snyyra gerr ner evtug orfvqr gur genvy naq gur gerr unf
> snyyra gb gur evtug. Whfg sbyybj gur gerr.
> 
HTH.

-- 
Bob Walton



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

Date: Thu, 14 Aug 2003 00:11:49 GMT
From: Christopher Shatto <l0g0m0tion@earthlink.net>
Subject: Re: Simple tr/// script
Message-Id: <9tA_a.11650$M6.990763@newsread1.prod.itd.earthlink.net>

Mike Flannigan wrote:

> I can't believe I can't figure this out, but I could use some
> help here.  I have so many questions about this script,
> but I'm going to limit myself to only 3 with this post.
> 
> 1)  The script runs as written, but gives an error after running
> "Use of uninitialized value in transliteration (tr///) . . . at line 12,
> 
> <DATA> line 3."  Then there are more errors about
> concatenation at line 13 and 16.
> Can anybody explain these errors for me.  I can't figure it out.
> I thought I was smart, but Perl is proving me wrong.
> 
> 2) Why won't this script run is I remove the space between the
> <DATA> and the line with "Gur ebbgf bs gur snyyra gerr ner
> evtug orfvqr gur genvy naq gur gerr unf snyyra gb gur evtug.
> Whfg sbyybj gur gerr."?  I have only one new line after the
> data line.  I have tried with and without a new line (carriage
> return) at the end.
> 
> 3) Why won't this script process the whole thing if I put a
> newline in the middle like so:
> Gur ebbgf bs gur snyyra gerr ner evtug orfvqr
> gur genvy naq gur gerr unf snyyra gb gur evtug. Whfg sbyybj gur gerr.
> 
> 
> I'm guessing these are somewhat related.
> __________________________________
> 
> use strict;
> use warnings;
> 
> my $ki;
> my @kites;
> while (<DATA>) {
>     $ki = <DATA>;
>     push @kites, $ki;
>     }
> 
> foreach my $num (@kites) {
>     $num =~ tr/a-zA-Z\. /n-za-mN-ZA-M\. /;
>     print "$num\n";
>     }
> 
> print "$kites[0]\n$kites[1]\n";
> 
> 
> __DATA__
> 
> Gur ebbgf bs gur snyyra gerr ner evtug orfvqr gur genvy naq gur gerr unf
> snyyra gb gur evtug. Whfg sbyybj gur gerr.
> 
> 
You are calling while(<DATA>) which is reading a line into $_ . 
Immediately thereafter, you call $ki = <DATA> which is reading in 
ANOTHER line.  In effect, you are reading a line of DATA into $_, 
ignoring it, then reading the NEXT line into $ki.  Try using

while ($ki = <DATA>)
{
   push @kites, $ki;
}

instead.



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

Date: 13 Aug 2003 17:40:00 -0700
From: chussung@operamail.com (Chad)
Subject: Suggestions for further perl reading
Message-Id: <97a530bb.0308131640.60c0b7c8@posting.google.com>

Ok I have finished the Llama book and am now creating simple scripts.

My question is what should I read to further myself at this.  is the
camel book the way to go or is there something better?

One of my goals(among many) is to be able to streamline my code
better(what takes me a whole screen would probably take you about 3
lines).


as always, Thank you for your time

Chad


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

Date: Thu, 14 Aug 2003 00:51:01 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Suggestions for further perl reading
Message-Id: <x7he4l2haj.fsf@mail.sysarch.com>

>>>>> "C" == Chad  <chussung@operamail.com> writes:

  C> Ok I have finished the Llama book and am now creating simple scripts.
  C> My question is what should I read to further myself at this.  is the
  C> camel book the way to go or is there something better?

the new alpaca book (perl objects, references and modules) by randal
schwartz (author of the llama) is a good next step. it was written to be
a followup and it is the basis of the classes he teaches at that level.

the perl cookbook is very good. so is effective perl programming (i call
it idiomatic perl).

the camel is more a reference but you can learn plenty from it.

if you want to get into OO coding in a deep way then object oriented
perl by conway is the winner there.

perl debugged is a good book on how to write better perl programs and to
debug them effectively.

there are others too. it all depends on where you want to go. just ask
about books before you buy them. there are so many bad perl books out
there (maybe 10-20% of all perl books are decent).

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 13 Aug 2003 22:15:50 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: To count a number of lines in C++ or Java or ASCII files  by  exluding white spaces and comments
Message-Id: <3F3AB886.A2DF3C17@acm.org>

John Smith wrote:
> 
> We have huge files in Java and C++ and I need to count the total
> number of lines in each of them by excluding white spaces (from the
> beginning of a line) and comments (C++, Java comments etc).
> 
> There must be some scripts in perl to do this job.
> 
> Can anyone kindly let me know? Or, are there any third-party tools to
> do this job?

http://www.dwheeler.com/sloccount/


John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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