[22897] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5117 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 13 14:05:37 2003

Date: Fri, 13 Jun 2003 11:05:06 -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           Fri, 13 Jun 2003     Volume: 10 Number: 5117

Today's topics:
        Adding a leading 0 character automatically... <beaudet@cyber.kodak.com>
    Re: Adding a leading 0 character automatically... <glex_nospam@qwest.net>
    Re: Adding a leading 0 character automatically... <beaudet@cyber.kodak.com>
    Re: calling functions from another perl script <thens@nospam.com>
    Re: How to do a 'wrapper' on Windows? <tzz@lifelogs.com>
        Perl 5.8 UTF-8 RedHat SLOW (Mike)
    Re: Permute List of Lists? <ian@onemore.org>
    Re: Permute List of Lists? <tzz@lifelogs.com>
    Re: Permute List of Lists? <bdonlan@bd-home-comp.no-ip.org>
    Re: Question about regular expression optimization <drumspoorly@reachone.net>
    Re: Question about regular expression optimization <bdonlan@bd-home-comp.no-ip.org>
    Re: Question about regular expression optimization nono547@hotmail.com
    Re: Sanitizing a regular expression <tzz@lifelogs.com>
    Re: Sorting Algorithm: organize data into a tree <jeffrey@jhu.edu>
    Re: Strange errors with huge hash ctcgag@hotmail.com
    Re: Using a while loop to search/remove lines.. <john.thetenant-s@moving-picture.com>
    Re: Using a while loop to search/remove lines.. <bdonlan@bd-home-comp.no-ip.org>
    Re: Using GET with $ENV{'QUERY_STRING'} <woll@yahoo.com>
        Variable value being interpreted as HTML (Ian)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 13 Jun 2003 17:13:50 +0200
From: Jean-Luc BEAUDET <beaudet@cyber.kodak.com>
Subject: Adding a leading 0 character automatically...
Message-Id: <3EE9EA2E.1000904@cyber.kodak.com>

Hi all,

Well i've got a little pb concerning the following:

** exerpt of code **
 ../..
@dtt = Today;
print "@dtt\n";

my $search_pattern = qr/@{[ sprintf '%s-%s-%2s', @dtt[0,2,1] ]}/;
print "search_pattern: $search_pattern\n";
 ../..

which gives:

pingoo1 # 2003 6 13
pingoo1 # search_pattern: (?-xism:2003-13- 6)

As yu can see, when days are in the range [1-9], i'm getting in trouble 
for my parsins since i'm looking for smth like:
2003-06-13

All is ok with days after the 9th...

So the question: how can i do to automatically add the leading '0' ???

Any help welcome.

Best regards.

Jean-Luc B :-)






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

Date: Fri, 13 Jun 2003 10:26:26 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: Adding a leading 0 character automatically...
Message-Id: <r2mGa.74$vb7.20051@news.uswest.net>

Jean-Luc BEAUDET wrote:
> Hi all,
> 
> Well i've got a little pb concerning the following:
> 
> ** exerpt of code **
> ../..
> @dtt = Today;
> print "@dtt\n";
> 
> my $search_pattern = qr/@{[ sprintf '%s-%s-%2s', @dtt[0,2,1] ]}/;
> print "search_pattern: $search_pattern\n";
> ../..
> 
> which gives:
> 
> pingoo1 # 2003 6 13
> pingoo1 # search_pattern: (?-xism:2003-13- 6)
> 
> As yu can see, when days are in the range [1-9], i'm getting in trouble 
> for my parsins since i'm looking for smth like:
> 2003-06-13
> 
> All is ok with days after the 9th...
> 
> So the question: how can i do to automatically add the leading '0' ???

Just need to modify your sprintf a bit. %02d

perldoc -f sprintf



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

Date: Fri, 13 Jun 2003 17:46:41 +0200
From: Jean-Luc BEAUDET <beaudet@cyber.kodak.com>
Subject: Re: Adding a leading 0 character automatically...
Message-Id: <3EE9F1E1.9010208@cyber.kodak.com>

It fits all mys needs !

Seems so trivial sometimes...

Thanks for all.

Jean-Luc B :-)

J. Gleixner wrote:

>> automatically add the leading '0' ???
>
>
> Just need to modify your sprintf a bit. %02d
>
> perldoc -f sprintf
>



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

Date: Fri, 13 Jun 2003 22:47:28 +0530
From: Thens <thens@nospam.com>
Subject: Re: calling functions from another perl script
Message-Id: <20030613224728.4f997b07.thens@nospam.com>

On Fri, 13 Jun 2003 13:55:51 +0100
JS <vervoom@hotmail.com> wrote:

>Hi,
>
>Is it possible to have 2 perl scripts e.g. script-A.pl and script-B.pl 
>and call a function e.g. getdata() in script-B.pl from script-A.pl that 
>returns an array? If so, how do you do that?

  Here is an example that does that

A.pl 
----
use strict;
use warnings;
sub getArray{
 ....
}

1; # This is important. Otherwise will say "A.pl does not require true value"


B.pl
----
use strict;
use warnings;
require "A.pl";
my @array = getArray();
 ...


Regards,
Thens.


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

Date: Fri, 13 Jun 2003 11:52:39 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How to do a 'wrapper' on Windows?
Message-Id: <4nadcmasag.fsf@lockgroove.bwh.harvard.edu>

On 12 Jun 2003, carltonbrown@hotmail.com wrote:
> Ted Zlatanov <tzz@lifelogs.com> wrote in message
> news:<4nn0gnl4m7.fsf@lockgroove.bwh.harvard.edu>...
>> I agree with Carlton's ideas, but he relies on a CR/LF being
>> pressed.  The user could be typing, backspacing, hitting TAB, etc.
> 
> Well yeah, but anybody who doesn't hit return at least every 15
> minutes is probably sandbagging.  They don't need to hog a database
> license while they're playing Monkey Lander or having a narcoleptic
> attack or whatever.

I understand this, and generally agree with it, but specifically in
this case the OP asked for "keyboard input," not CR/LF input
watching.

Ted


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

Date: 13 Jun 2003 09:36:17 -0700
From: mike@kamloopsbc.com (Mike)
Subject: Perl 5.8 UTF-8 RedHat SLOW
Message-Id: <5478acb6.0306130836.5612021e@posting.google.com>

Hi,

I have built a new P4 RedHat 9 webserver to replace my old P3 Linux
7.2 webserver, and found it to be significantly slower than the old P3
machine.  After much research, I stumbled onto what 'may' be a partial
fix for the problem.  Although this has not been tested over a long
period yet (24hrs), I've seen my loads drop by about 75% with one
SIMPLE update:

If you don't WANT to use UTF-8, all you want is RedHat 8 or 9 with
perl 5.8 and apache to run somewhat normally, try this:

Edit the /etc/sysconfig/i18n file and replace:

LANG="en_US.UTF-8"
SUPPORTED="en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"

with the 7.2 settings:

LANG="en_US.iso885915"
SUPPORTED="en_US.iso885915:en_US:en"
SYSFONT="latarcyrheb-sun16"

The effect was that my perl scripts "instantly" decided they could run
a lot faster once again.  The P4 is still noticeably slower than the
P3, but at least now the loads are only moderately higher instead of
crippling.

NOTE:  This is being posted to the RedHat board as well, just to help
make it easier to find...  I'm sure someone else out there has less
hair than I do.

Mike


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

Date: Fri, 13 Jun 2003 16:48:04 +0100
From: Ian Brayshaw <ian@onemore.org>
Subject: Re: Permute List of Lists?
Message-Id: <3ee9f234$0$7748$fa0fcedb@lovejoy.zen.co.uk>

David wrote:

> I have a list of lists, something like ([a,b],[i,j,k],[y,z]) and need
> to permute every possible combination i.e. aiy aiz ajy ajz aky akz ..
> bkz etc. 

The following seems to work. Not sure it's the most efficient way of
building the permutations, but for the numbers you're talking about, it
should be sufficient.

Ian

--- begin script ---

#!/usr/bin/perl

use strict;
use warnings;

my      @data   = ( [ qw( a b ) ] , [ qw( i j k ) ] , [ qw( y z ) ] );

print join( "\n" , permute( \@data ) ) , "\n";

# build the permutations
sub permute
{
        my      $data   = $_[ 0 ];
        my      @perm   = ( '' );

        foreach my $d ( @{ $data } ) {
                @perm   = map { my $current = $_;
                                map { $current . $_ } @{ $d } } @perm;
        }
        
        return ( wantarray ) ? @perm : \@perm;
} # permute()

--- end script ---

-- 
s&&@#^#@#@##@@#&&&y&^#@&712&&&($;='z')&&s&(..)&0$1&g&&s&$&0&&&s&(.)([^01])&
$1x$2&xge&&($.='a')&&s&$&d4823604df80d7e51d7018b9&&&(@_=$...$;)&&undef$.;do
{s&(.)(.*)(.)&$..=$1.$3,$2&e}while(length);s&&$.&;$*=0;undef$.;$..=($_?$_[(
$*+=$_)%@_]:$")foreach(map{hex}m&(..)&g);s&.*&$.$/&&&s&(\b.)&\U$1&go&&print


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

Date: Fri, 13 Jun 2003 12:10:07 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Permute List of Lists?
Message-Id: <4n65naarhc.fsf@lockgroove.bwh.harvard.edu>

On 13 Jun 2003, david.evans@vir.gla.ac.uk wrote:
> I have a list of lists, something like ([a,b],[i,j,k],[y,z]) and
> need to permute every possible combination i.e. aiy aiz ajy ajz aky
> akz ..  bkz etc.  Each internal list can have 1,2,3,4 or 6 scalar
> values (often 4), the outer list may contain 10 or so inner lists.
> T appreciate the scale of possible variation (up to 6x10e7 or so).
> I can easily calculate the latter (e.g. 2 x 3 x 2), but actually
> need the list of possible variation ([aiy aiz ajy ajz etc.]) for
> further calculations. This is clearly - to my untutored eye anyway -
> an exercise in recursion, never my strong point.  I've searched CPAN
> for modules - particularly Math:: and Algorithm:: - that may help,
> and c.l.p.m for 'permute list of lists' and the like, and struggled
> with code 'til the early hours.  All were fruitless exercises.

Something like this might work:

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my @loa =  (['a','b'],['i','j','k'],['y','z']); # list of arrays

my $permutations = permute(@loa); # this in an array reference
print Dumper $permutations;

sub permute
{
 my $array = shift @_;
 my $dist = [];

 return $array unless scalar @_;

 my $lower_dist = permute(@_);
 foreach my $p (@$lower_dist)
 {
  push @$dist, map { $_ . $p } @$array;
 }
 return $dist;
}


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

Date: Fri, 13 Jun 2003 12:36:47 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Permute List of Lists?
Message-Id: <pan.2003.06.13.16.36.45.936689@bd-home-comp.no-ip.org>

On Fri, 13 Jun 2003 07:38:15 +0000, David wrote:

> I have a list of lists, something like ([a,b],[i,j,k],[y,z]) and need
> to permute every possible combination i.e. aiy aiz ajy ajz aky akz ..
> bkz etc.  Each internal list can have 1,2,3,4 or 6 scalar values
> (often 4), the outer list may contain 10 or so inner lists.  T
> appreciate the scale of possible variation (up to 6x10e7 or so).  I
> can easily calculate the latter (e.g. 2 x 3 x 2), but actually need
> the list of possible variation ([aiy aiz ajy ajz etc.]) for further
> calculations. This is clearly - to my untutored eye anyway - an
> exercise in  recursion, never my strong point.

Break the problem down - you can rephrase it as permuting two such lists,
then permuting the results with the next, and so on.

>   I've searched CPAN for modules - particularly Math:: and Algorithm::
> - that may help, and c.l.p.m for 'permute list of lists' and the like,
> and struggled with code 'til the early hours.  All were fruitless
> exercises.
> 
>   Has anyone else tackled and solved this type of problem?
> 
>   To put the problem in context, I'm interested in thermodynamic
> prediction of nucleic acid structures that encode proteins - for any
> particular peptide I want to calculate the possible range of sequences
> that (taking account of codon degeneracy) could encode it.

Using recursion, it's simple:
sub permute {
  my @lists = @_;
  my @flist = @{shift @lists};
  my @out;
  my @slist;
  if(!$#lists){
    @slist = @{shift @lists};
  }else{
    @slist = permute(@lists);
  }
  foreach my $l (@flist) {
    foreach my $r (@slist) {
      push @out, "$l$r";
    }
  }
  return @out;
}



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

Date: Fri, 13 Jun 2003 09:36:30 -0700
From: Steve May <drumspoorly@reachone.net>
Subject: Re: Question about regular expression optimization
Message-Id: <vejuuce45ht283@corp.supernews.com>

nono547@hotmail.com wrote:
> Hi all
> 
> Does anyone know where I can find information about the optimizations the
> perl interpreter performs on regular expressions while compiling them ?
> 
> 
> For example, considering the following expression : "ab|ac", does the perl
> compiler transform it into "a(?:b|c)", which is more effective ?
> 
> 
> Thanks
> 
> 
> Pascal

You might want to pick up a copy of Mastering Regular Experssions
by Jeffery Friedl (O'Reilly & Associates).

I found this book very enlightening.

s.



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

Date: Fri, 13 Jun 2003 12:44:37 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Question about regular expression optimization
Message-Id: <pan.2003.06.13.16.44.35.841738@bd-home-comp.no-ip.org>

On Fri, 13 Jun 2003 15:21:08 +0200, nono54 wrote:

> Hi all
> 
> Does anyone know where I can find information about the optimizations the
> perl interpreter performs on regular expressions while compiling them ?
> 
> 
> For example, considering the following expression : "ab|ac", does the perl
> compiler transform it into "a(?:b|c)", which is more effective ?

Using -Mre=debug, dosen't look like it, but it might disable optimizations
in this case. (In this case, BTW, a[bc] would be better). Also, a(?:b|c)
wouldn't be better, because it needs more matches:

Compiling REx `a(?:b|c)'
size 10 Got 84 bytes for offset annotations.
first at 1
   1: EXACT <a>(3)
   3: BRANCH(6)
   4:   EXACT <b>(10)
   6: BRANCH(9)
   7:   EXACT <c>(10)
   9: TAIL(10)
  10: END(0)

Compiling REx `ab|bc'
size 7 Got 60 bytes for offset annotations.

   1: BRANCH(4)
   2:   EXACT <ab>(7)
   4: BRANCH(7)
   5:   EXACT <bc>(7)
   7: END(0)


As you can see, ab|bc requires less regex tokens. Also, it needs less
comparisons, which is always good.


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

Date: Fri, 13 Jun 2003 19:18:16 +0200
From: nono547@hotmail.com
Subject: Re: Question about regular expression optimization
Message-Id: <bcd10a$m5i$1@news-reader14.wanadoo.fr>

bd wrote:

> On Fri, 13 Jun 2003 15:21:08 +0200, nono54 wrote:
> 
>> Hi all
>> 
>> Does anyone know where I can find information about the optimizations the
>> perl interpreter performs on regular expressions while compiling them ?
>> 
>> 
>> For example, considering the following expression : "ab|ac", does the
>> perl compiler transform it into "a(?:b|c)", which is more effective ?
> 
> Using -Mre=debug, dosen't look like it, but it might disable optimizations
> in this case. (In this case, BTW, a[bc] would be better). Also, a(?:b|c)
> wouldn't be better, because it needs more matches:
> 
> Compiling REx `a(?:b|c)'
> size 10 Got 84 bytes for offset annotations.
> first at 1
>    1: EXACT <a>(3)
>    3: BRANCH(6)
>    4:   EXACT <b>(10)
>    6: BRANCH(9)
>    7:   EXACT <c>(10)
>    9: TAIL(10)
>   10: END(0)
> 
> Compiling REx `ab|bc'
> size 7 Got 60 bytes for offset annotations.
> 
>    1: BRANCH(4)
>    2:   EXACT <ab>(7)
>    4: BRANCH(7)
>    5:   EXACT <bc>(7)
>    7: END(0)
> 
> 
> As you can see, ab|bc requires less regex tokens. Also, it needs less
> comparisons, which is always good.

You're comparing two regular expressions that are not equivalent. "a(?:b|c)"
and "ab|bc" don't match the same words.

When I sait that "a(?:b|c)" is more effective than "ab|ac", I meant that, in
the first case, there is no need to backtrack. By contrast, in the second
case, if the first part of the alternative doesn't match, the regex engine
needs to start again from the current start position, although it should
already know if there is an 'a' at this position. If the compiler doesn't
perform the optimization mentioned above, it will make unnecessary
comparisons.



Pascal


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

Date: Fri, 13 Jun 2003 11:48:07 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Sanitizing a regular expression
Message-Id: <4nel1yasi0.fsf@lockgroove.bwh.harvard.edu>

On Thu, 12 Jun 2003, bernie@rev.net wrote:
> On Thu, 12 Jun 2003 13:29:38 -0400, Ted Zlatanov <tzz@lifelogs.com>
> wrote:
> 
>>On Thu, 12 Jun 2003, bernie@rev.net wrote:
>>> What I'd like to do is give the users "normal"/classical REs --
>>> alternation, char classes, grouping, quantifiers -- without giving
>>> the user access to any of Perl's "fancier" machinery..  Short
>>> term, as I said, I'm just brute-force emasculating the RE, but is
>>> there some clever way to allow _only_ "plain-jane" REs?
>>
>>Why not give the users a simple query language which can be easily
>>translated (e.g. by Parse::RecDescent) into regular expressions?
> 
> That's what I'm contemplating doing.  Coming up with one isn't all
> that easy, but I guess the idea is as you suggest: not even a query
> language, but use something I can specify with a grammar [which is
> easy to do for classical REs] and then write a little
> parser/compiler to turn it into the corresponding Perl RE...

That sounds pretty feasible.  I'm pretty sure Parse::RecDsecent can
handle simple RE syntax, if not all of it.  You could write your own,
but it's probably going to be unpleasant.

>>- users don't have to learn Perl regexes (most won't)
> 
> As far as that goes, Perl REs *ARE* the same as classical ones --
> given I'm going to limit the users to "only classical", that subset
> of Perl's RE machinery is fine.

Well, I mean just regular expressions in general.  Users that I've
tried to teach regexes in the past have been very resistant (until I
used the fluffy pillows, of course).

Ted


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

Date: Fri, 13 Jun 2003 11:06:21 -0400
From: "Jeffrey Silverman" <jeffrey@jhu.edu>
Subject: Re: Sorting Algorithm: organize data into a tree
Message-Id: <pan.2003.06.13.15.06.18.594616@jhu.edu>

On Fri, 13 Jun 2003 10:36:06 -0400, Jeffrey Silverman wrote:

<snip!>
> Also, I have a wee problem:
> I have to write this thing in PHP, and as such will not have access to
> Data::Dumper.  Does Data::Dumper do anything critical for the algorithm
> here, or is it just for printing the result out at the end? (i.e. will
> this thing work without it?)
> 
> Also, what is the ||= operator?
> 
> Actually, it occurs to me that I am going to look up the answers to these
> questions for myself, but feel free to answer for posterity's sake and for the
> interest of anyone else tuning in...
> 
> Also, also, is this sort of algorithm typically covered in CS classes?
> (Just to put a not-completely-relevant question out there) I no take CS
> classes cause me dumb. (Actually, 'cause I have a biology degree instead.)
> 
> Thanks for your help!

I've answered two of my own questions:

question 1:
the functionality of Data::Dumper is provided in PHP by print_r(), which
recursively prints an array.

question 2:
||= is short-cicuit or-assign, and thus this:

$x=1;
$x ||= "yup";

is the same as this:

$x=1;
if (! $x) {
    $x="yup";
}

Just curious on that last question, though.

-- 
    Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
                 Website | http://www.wse.jhu.edu/newtnotes/



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

Date: 13 Jun 2003 16:29:45 GMT
From: ctcgag@hotmail.com
Subject: Re: Strange errors with huge hash
Message-Id: <20030613122945.377$PD@newsreader.com>

emcee <res1uzbe@verizon.net> wrote:
> emcee wrote:

> >             $hash->{$_}=~s/'/\'/g;
> >             $hash->{$_}=~s/\\/\\\\/g;
> >             $hasht.="'$_'=>'$hash->{$_}',";
> >         }
> >     }
> > }
> > 1;
> >
>
> So does no one has any ideas what I'm doing wrong here (except of course
> using a custom module), or is no one willing to help me?

Have you bothered to actually test this section to see if it does what
you think it does?

#!/user/bin/perl -wl
while (<>) {
  s/'/\'/g;
  s/\\/\\\\/g;
  print;
};

Now type in a few lines containing single quotes and/or backwhacks and see
what it does.

Yeesh!

Hint, the backwhack in the first substitution isn't doing what you think
it is.  2nd hint, fixing that will only expose another bug.


> Remember it works fine pretty all time except for this particular
> instance involving a very large hash.

The size of the hash has nothing to do with it, other than offering more
chances for your bugs to be exposed.  Your escaping mechanism
is crap.  If a small hash happened to contain the right characters, the
small hash would cause the same problems.


> Should I be escaping something I'm
> not before adding it to the file? Would it help if I walk through what
> each part does?

Writing escaping code that works in *every possible case* is quite
difficult. I don't trust myself to do it correctly when I have an ready
alternative, and I'm obviously a far better Perl programmer than your sorry
ass.  We have provided you with the proper solution, yes it or go the hell
away.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Fri, 13 Jun 2003 17:12:05 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Using a while loop to search/remove lines..
Message-Id: <20030613171205.6dbf8aff.john.thetenant-s@moving-picture.com>

On 13 Jun 2003 07:46:51 -0700
evia@excel.com (Eric) wrote:
>
> Perl friends,
> 
>   I am doing something in a script that is WORKING - but it's a
> bonehead way of doing it - and so it's bugging me - please glance at
> the code below - what it does in a nutshell is open a file of hundreds
> of thousands of lines, and search EACH line for a number - if FOUND -
> it's removed.
> 
>   But - look below - see the times I look for "tpn" in my big input
> file?  In reality I do 150 OTHER numbers - so my script is basically
> silly - it just so happens I'm good with SED and VI and can easily
> modify my Perl script to do so many lines of "if ($tpn != "nnnnn").
> 
>   I'd RATHER do it a more professional way - that being to open my
> huge input, THEN open the listing of 150 numbers - and loop through
> them - but what happens when I tried it that way was that each time I
> searched one line in my input for 150 different numbers, if the number
> was NOT found I'd print it 150 times - so if I wanted to strip an
> input file of 10 records of a possible 150 numbers - when it was all
> said and done I'd end up with HUNDREDS of lines of output where it
> didn't match my number (Sure I could sort it after-the-fact but that's
> hokey too!) it was something about WHERE I was putting the "print
> OUTPUT" line in the loop - and it confused me no end.
> 
>   Here's what my code looks like - works fine - but again - must I
> list EACH number to search for!?:

keep your numbers in a separate file. 
populate a hash from them.  this example
assumes a file called stuff_to_ignore with
each item to be ignored on a separate line:

my %ignore=();
open (IGNORE,"<stuff_to_ignore") or die "cannot read numbers file, $!\n";
while (<IGNORE>) {
    chomp;
    $ignore{$_}=1;
}

> 
> open(OUTPUT, ">MODIFIED_$file") || die "Can't open the output
> file!\n";
> open(INFO, $file) || die "WHERE IS IT ERIC!!?  Fool!\n";
> while(<INFO>){
> $originalcount++;
> $tpn = substr($_,196,5);
> if ($tpn != "10638" 
> && $tpn != "10638" 
> && $tpn != "40843" 
> && $tpn != "30808" 
> && $tpn != "33548") {

replace that if statement with:
unless (exists $ignore{$_}) {

> print OUTPUT "$_";
> $keep++
>   } else {
>   $removecount++
>   }
>   }
> 
>    I hope I make sense and I thank you for your time!
> 
> Eric






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail


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

Date: Fri, 13 Jun 2003 12:48:49 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Using a while loop to search/remove lines..
Message-Id: <pan.2003.06.13.16.48.48.249766@bd-home-comp.no-ip.org>

On Fri, 13 Jun 2003 07:46:51 +0000, Eric wrote:

> Perl friends,
> 
>   I am doing something in a script that is WORKING - but it's a
> bonehead way of doing it - and so it's bugging me - please glance at
> the code below - what it does in a nutshell is open a file of hundreds
> of thousands of lines, and search EACH line for a number - if FOUND -
> it's removed.
> 
>   But - look below - see the times I look for "tpn" in my big input
> file?  In reality I do 150 OTHER numbers - so my script is basically
> silly - it just so happens I'm good with SED and VI and can easily
> modify my Perl script to do so many lines of "if ($tpn != "nnnnn").
> 
>   I'd RATHER do it a more professional way - that being to open my
> huge input, THEN open the listing of 150 numbers - and loop through
> them - but what happens when I tried it that way was that each time I
> searched one line in my input for 150 different numbers, if the number
> was NOT found I'd print it 150 times - so if I wanted to strip an
> input file of 10 records of a possible 150 numbers - when it was all
> said and done I'd end up with HUNDREDS of lines of output where it
> didn't match my number (Sure I could sort it after-the-fact but that's
> hokey too!) it was something about WHERE I was putting the "print
> OUTPUT" line in the loop - and it confused me no end.
> 
>   Here's what my code looks like - works fine - but again - must I
> list EACH number to search for!?:
> 

Nope. How about this:

my %numbers = {
  10638 => 0,
  40843 => 0,
  30808 => 0,
  33548 => 0
};

> open(OUTPUT, ">MODIFIED_$file") || die "Can't open the output
> file!\n";
> open(INFO, $file) || die "WHERE IS IT ERIC!!?  Fool!\n";
> while(<INFO>){
> $originalcount++;
> $tpn = substr($_,196,5);
> if ($tpn != "10638" 
> && $tpn != "10638" 
> && $tpn != "40843" 
> && $tpn != "30808" 
> && $tpn != "33548") {

if(!exists $numbers{$tpn}){

> print OUTPUT "$_";
> $keep++
>   } else {
>   $removecount++
>   }
>   }

You could build the hash with some other method if you like. Also, this
method is likely to be faster.



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

Date: Fri, 13 Jun 2003 15:22:43 +1000
From: "Bob" <woll@yahoo.com>
Subject: Re: Using GET with $ENV{'QUERY_STRING'}
Message-Id: <bcd17m$i4e0f$1@ID-82947.news.dfncis.de>


Tad McClellan <tadmc@augustmail.com> wrote in message
news:slrnbehtcq.3ap.tadmc@magna.augustmail.com...
: Bob <woll@yahoo.com> wrote:
:
: > the doco I have says to do it like this . . .
: > @values = split(/&/,$ENV{'QUERY_STRING'});
:
:
: What docs are you referring to?
:

well . . . cgi101.com.  Funny though the whole of the site hardly nmentions
CGI.Heh, after reading all the good advice here I might be giving
Jacqueline D.Hamilton the flick as my on line tutor.
(do I hear a roaring big "Yay Bob welcome aboard" with that comment ?)

Cheers,
Bob

: It would be of service to all of your fellow programmers if you
: could warn them off of such poor advice.
:
:
:    use CGI;
:
:
: --
:     Tad McClellan                          SGML consulting
:     tadmc@augustmail.com                   Perl programming
:     Fort Worth, Texas




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

Date: 13 Jun 2003 08:55:48 -0700
From: ianp@myrealbox.com (Ian)
Subject: Variable value being interpreted as HTML
Message-Id: <c90e496e.0306130755.7d123c41@posting.google.com>

I'm trying to use Win32::ODBC to pull some data from an existing
table. The trouble is that one of the table columns is called "title"
which appears to be confusing Perl. When I have a variable with that
name it gets mangled in the process going from "title" to "<title />"
which of course screws things up.

Here's a section of the code I've used to find this:
#Initialize beginning values
$DSN=helpdesk_db;
$table1=problems;
$cols[0]=ulocation;
$cols[1]=rep;
$cols[2]=status;
$cols[3]=title;
$cols[4]=description;
$cols[5]=start_date;
$cols[6]=priority;


### Begin
print header();
print start_html();
print "<P>$cols[0], $cols[1], $cols[2], $cols[3], $cols[4], $cols[5],
$cols[6]\n";

Here's the output:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
	"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
lang="en-US"><head><title>Untitled Document</title>
</head><body>
<P>ulocation, rep, status, <title />, description, start_date,
priority

Has anyone seen this before?

TIA,
Ian


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

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


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